src/gui/styles/qmacstyle_mac_p.h
changeset 33 3e2da88830cd
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 
       
    43 #ifndef QMACSTYLE_MAC_P_H
       
    44 #define QMACSTYLE_MAC_P_H
       
    45 
       
    46 #include <qmacstyle_mac.h>
       
    47 #include <private/qapplication_p.h>
       
    48 #include <private/qcombobox_p.h>
       
    49 #include <private/qmacstylepixmaps_mac_p.h>
       
    50 #include <private/qpaintengine_mac_p.h>
       
    51 #include <private/qpainter_p.h>
       
    52 #include <private/qprintengine_mac_p.h>
       
    53 #include <private/qstylehelper_p.h>
       
    54 #include <qapplication.h>
       
    55 #include <qbitmap.h>
       
    56 #include <qcheckbox.h>
       
    57 #include <qcombobox.h>
       
    58 #include <qdialogbuttonbox.h>
       
    59 #include <qdockwidget.h>
       
    60 #include <qevent.h>
       
    61 #include <qfocusframe.h>
       
    62 #include <qformlayout.h>
       
    63 #include <qgroupbox.h>
       
    64 #include <qhash.h>
       
    65 #include <qheaderview.h>
       
    66 #include <qlayout.h>
       
    67 #include <qlineedit.h>
       
    68 #include <qlistview.h>
       
    69 #include <qmainwindow.h>
       
    70 #include <qmap.h>
       
    71 #include <qmenubar.h>
       
    72 #include <qpaintdevice.h>
       
    73 #include <qpainter.h>
       
    74 #include <qpixmapcache.h>
       
    75 #include <qpointer.h>
       
    76 #include <qprogressbar.h>
       
    77 #include <qpushbutton.h>
       
    78 #include <qradiobutton.h>
       
    79 #include <qrubberband.h>
       
    80 #include <qsizegrip.h>
       
    81 #include <qspinbox.h>
       
    82 #include <qsplitter.h>
       
    83 #include <qstyleoption.h>
       
    84 #include <qtextedit.h>
       
    85 #include <qtextstream.h>
       
    86 #include <qtoolbar.h>
       
    87 #include <qtoolbutton.h>
       
    88 #include <qtreeview.h>
       
    89 #include <qtableview.h>
       
    90 #include <qwizard.h>
       
    91 #include <qdebug.h>
       
    92 #include <qlibrary.h>
       
    93 #include <qdatetimeedit.h>
       
    94 #include <qmath.h>
       
    95 #include <QtGui/qgraphicsproxywidget.h>
       
    96 #include <QtGui/qgraphicsview.h>
       
    97 #include <private/qt_cocoa_helpers_mac_p.h>
       
    98 
       
    99 //
       
   100 //  W A R N I N G
       
   101 //  -------------
       
   102 //
       
   103 // This file is not part of the Qt API.  It exists purely as an
       
   104 // implementation detail.  This header file may change from version to
       
   105 // version without notice, or even be removed.
       
   106 //
       
   107 // We mean it.
       
   108 //
       
   109 
       
   110 QT_BEGIN_NAMESPACE
       
   111 
       
   112 #if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5)
       
   113 enum {
       
   114     kThemePushButtonTextured = 31,
       
   115     kThemePushButtonTexturedSmall = 32,
       
   116     kThemePushButtonTexturedMini = 33
       
   117 };
       
   118 
       
   119 /* Search fields */
       
   120 enum {
       
   121     kHIThemeFrameTextFieldRound = 1000,
       
   122     kHIThemeFrameTextFieldRoundSmall = 1001,
       
   123     kHIThemeFrameTextFieldRoundMini = 1002
       
   124 };
       
   125 #endif
       
   126 
       
   127 /*
       
   128     AHIG:
       
   129         Apple Human Interface Guidelines
       
   130         http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/
       
   131 
       
   132     Builder:
       
   133         Apple Interface Builder v. 3.1.1
       
   134 */
       
   135 
       
   136 // this works as long as we have at most 16 different control types
       
   137 #define CT1(c) CT2(c, c)
       
   138 #define CT2(c1, c2) ((uint(c1) << 16) | uint(c2))
       
   139 
       
   140 enum QAquaWidgetSize { QAquaSizeLarge = 0, QAquaSizeSmall = 1, QAquaSizeMini = 2,
       
   141                        QAquaSizeUnknown = -1 };
       
   142 
       
   143 #define SIZE(large, small, mini) \
       
   144     (controlSize == QAquaSizeLarge ? (large) : controlSize == QAquaSizeSmall ? (small) : (mini))
       
   145 
       
   146 // same as return SIZE(...) but optimized
       
   147 #define return_SIZE(large, small, mini) \
       
   148     do { \
       
   149         static const int sizes[] = { (large), (small), (mini) }; \
       
   150         return sizes[controlSize]; \
       
   151     } while (0)
       
   152 
       
   153 class QMacStylePrivate : public QObject
       
   154 {
       
   155     Q_OBJECT
       
   156 
       
   157 public:
       
   158     QMacStylePrivate(QMacStyle *style);
       
   159 
       
   160     // Ideally these wouldn't exist, but since they already exist we need some accessors.
       
   161     static const int PushButtonLeftOffset;
       
   162     static const int PushButtonTopOffset;
       
   163     static const int PushButtonRightOffset;
       
   164     static const int PushButtonBottomOffset;
       
   165     static const int MiniButtonH;
       
   166     static const int SmallButtonH;
       
   167     static const int BevelButtonW;
       
   168     static const int BevelButtonH;
       
   169     static const int PushButtonContentPadding;
       
   170 
       
   171 
       
   172     // Stuff from QAquaAnimate:
       
   173     bool addWidget(QWidget *);
       
   174     void removeWidget(QWidget *);
       
   175 
       
   176     enum Animates { AquaPushButton, AquaProgressBar, AquaListViewItemOpen };
       
   177     bool animatable(Animates, const QWidget *) const;
       
   178     void stopAnimate(Animates, QWidget *);
       
   179     void startAnimate(Animates, QWidget *);
       
   180     static ThemeDrawState getDrawState(QStyle::State flags);
       
   181     QAquaWidgetSize aquaSizeConstrain(const QStyleOption *option, const QWidget *widg,
       
   182                              QStyle::ContentsType ct = QStyle::CT_CustomBase,
       
   183                              QSize szHint=QSize(-1, -1), QSize *insz = 0) const;
       
   184     void getSliderInfo(QStyle::ComplexControl cc, const QStyleOptionSlider *slider,
       
   185                           HIThemeTrackDrawInfo *tdi, const QWidget *needToRemoveMe);
       
   186     bool doAnimate(Animates);
       
   187     inline int animateSpeed(Animates) const { return 33; }
       
   188 
       
   189     // Utility functions
       
   190     void drawColorlessButton(const HIRect &macRect, HIThemeButtonDrawInfo *bdi,
       
   191                              QPainter *p, const QStyleOption *opt) const;
       
   192 
       
   193     QSize pushButtonSizeFromContents(const QStyleOptionButton *btn) const;
       
   194 
       
   195     HIRect pushButtonContentBounds(const QStyleOptionButton *btn,
       
   196                                    const HIThemeButtonDrawInfo *bdi) const;
       
   197 
       
   198     void initComboboxBdi(const QStyleOptionComboBox *combo, HIThemeButtonDrawInfo *bdi,
       
   199                         const QWidget *widget, const ThemeDrawState &tds);
       
   200 
       
   201     static HIRect comboboxInnerBounds(const HIRect &outerBounds, int buttonKind);
       
   202 
       
   203     static QRect comboboxEditBounds(const QRect &outerBounds, const HIThemeButtonDrawInfo &bdi);
       
   204 
       
   205     static void drawCombobox(const HIRect &outerBounds, const HIThemeButtonDrawInfo &bdi, QPainter *p);
       
   206     static void drawTableHeader(const HIRect &outerBounds, bool drawTopBorder, bool drawLeftBorder,
       
   207                                      const HIThemeButtonDrawInfo &bdi, QPainter *p);
       
   208     bool contentFitsInPushButton(const QStyleOptionButton *btn, HIThemeButtonDrawInfo *bdi,
       
   209                                  ThemeButtonKind buttonKindToCheck) const;
       
   210     void initHIThemePushButton(const QStyleOptionButton *btn, const QWidget *widget,
       
   211                                const ThemeDrawState tds,
       
   212                                HIThemeButtonDrawInfo *bdi) const;
       
   213     QPixmap generateBackgroundPattern() const;
       
   214 protected:
       
   215     bool eventFilter(QObject *, QEvent *);
       
   216     void timerEvent(QTimerEvent *);
       
   217 
       
   218 private slots:
       
   219     void startAnimationTimer();
       
   220 
       
   221 public:
       
   222     QPointer<QPushButton> defaultButton; //default push buttons
       
   223     int timerID;
       
   224     QList<QPointer<QWidget> > progressBars; //existing progress bars that need animation
       
   225 
       
   226     struct ButtonState {
       
   227         int frame;
       
   228         enum { ButtonDark, ButtonLight } dir;
       
   229     } buttonState;
       
   230     UInt8 progressFrame;
       
   231     QPointer<QFocusFrame> focusWidget;
       
   232     CFAbsoluteTime defaultButtonStart;
       
   233     QMacStyle *q;
       
   234     bool mouseDown;
       
   235 };
       
   236 
       
   237 QT_END_NAMESPACE
       
   238 
       
   239 #endif // QMACSTYLE_MAC_P_H