diff options
Diffstat (limited to 'src/gui/styles/qstyle.cpp')
-rw-r--r-- | src/gui/styles/qstyle.cpp | 118 |
1 files changed, 82 insertions, 36 deletions
diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp index af7e719..90ae5ea 100644 --- a/src/gui/styles/qstyle.cpp +++ b/src/gui/styles/qstyle.cpp @@ -168,12 +168,21 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C \section1 Creating a Custom Style - If you want to design a custom look and feel for your application, - the first step is to pick one of the styles provided with Qt to - build your custom style from. The choice will depend on which - existing style resembles your style the most. The most general - class that you can use as base is QCommonStyle (and not QStyle). - This is because Qt requires its styles to be \l{QCommonStyle}s. + You can create a custom look and feel for your application by + creating a custom style. There are two approaches to creating a + custom style. In the static approach, you either choose an + existing QStyle class, subclass it, and reimplement virtual + functions to provide the custom behavior, or you create an entire + QStyle class from scratch. In the dynamic approach, you modify the + behavior of your system style at runtime. The static approach is + described below. The dynamic approach is described in QProxyStyle. + + The first step in the static approach is to pick one of the styles + provided by Qt from which you will build your custom style. Your + choice of QStyle class will depend on which style resembles your + desired style the most. The most general class that you can use as + a base is QCommonStyle (not QStyle). This is because Qt requires + its styles to be \l{QCommonStyle}s. Depending on which parts of the base style you want to change, you must reimplement the functions that are used to draw those @@ -222,7 +231,7 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C \section1 Using a Custom Style There are several ways of using a custom style in a Qt - application. The simplest way is call the + application. The simplest way is to pass the custom style to the QApplication::setStyle() static function before creating the QApplication object: @@ -232,8 +241,8 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C it before the constructor, you ensure that the user's preference, set using the \c -style command-line option, is respected. - You may want to make your style available for use in other - applications, some of which may not be yours and are not available for + You may want to make your custom style available for use in other + applications, which may not be yours and hence not available for you to recompile. The Qt Plugin system makes it possible to create styles as plugins. Styles created as plugins are loaded as shared objects at runtime by Qt itself. Please refer to the \link @@ -325,9 +334,10 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C QStyle::QStyle() : QObject(*new QStylePrivate) { + Q_D(QStyle); + d->proxyStyle = this; } - /*! \internal @@ -336,6 +346,8 @@ QStyle::QStyle() QStyle::QStyle(QStylePrivate &dd) : QObject(dd) { + Q_D(QStyle); + d->proxyStyle = this; } /*! @@ -514,8 +526,9 @@ void QStyle::drawItemText(QPainter *painter, const QRect &rect, int alignment, c } if (!enabled) { if (styleHint(SH_DitherDisabledText)) { - painter->drawText(rect, alignment, text); - painter->fillRect(painter->boundingRect(rect, alignment, text), QBrush(painter->background().color(), Qt::Dense5Pattern)); + QRect br; + painter->drawText(rect, alignment, text, &br); + painter->fillRect(br, QBrush(painter->background().color(), Qt::Dense5Pattern)); return; } else if (styleHint(SH_EtchDisabledText)) { QPen pen = painter->pen(); @@ -551,7 +564,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, /*! \enum QStyle::PrimitiveElement - This enum describes that various primitive elements. A + This enum describes the various primitive elements. A primitive element is a common GUI element, such as a checkbox indicator or button bevel. @@ -1048,6 +1061,8 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value SE_TabBarTabRightButton Area for a widget on the right side of a tab in a tab bar. \value SE_TabBarTabText Area for the text on a tab in a tab bar. + \value SE_ToolBarHandle Area for the handle of a tool bar. + \sa subElementRect() */ @@ -1093,7 +1108,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value CC_ScrollBar A scroll bar, like QScrollBar. \value CC_Slider A slider, like QSlider. \value CC_ToolButton A tool button, like QToolButton. - \value CC_TitleBar A Title bar, like those used in QWorkspace. + \value CC_TitleBar A Title bar, like those used in QMdiSubWindow. \value CC_Q3ListView Used for drawing the Q3ListView class. \value CC_GroupBox A group box, like QGroupBox. \value CC_Dial A dial, like QDial. @@ -1177,6 +1192,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value SC_All Special value that matches all sub-controls. \omitvalue SC_Q3ListViewBranch + \omitvalue SC_CustomBase \sa ComplexControl */ @@ -1330,7 +1346,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value PM_LayoutVerticalSpacing Default \l{QLayout::spacing}{vertical spacing} for a QLayout. \value PM_MaximumDragDistance The maximum allowed distance between - the mouse and a slider when dragging. Exceeding the specified + the mouse and a scrollbar when dragging. Exceeding the specified distance will cause the slider to jump back to the original position; a value of -1 disables this behavior. @@ -1570,6 +1586,20 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, */ /*! + \enum QStyle::RequestSoftwareInputPanel + + This enum describes under what circumstances a software input panel will be + requested by input capable widgets. + + \value RSIP_OnMouseClickAndAlreadyFocused Requests an input panel if the user + clicks on the widget, but only if it is already focused. + \value RSIP_OnMouseClick Requests an input panel if the user clicks on the + widget. + + \sa QEvent::RequestSoftwareInputPanel, QInputContext +*/ + +/*! \enum QStyle::StyleHint This enum describes the available style hints. A style hint is a general look @@ -1850,6 +1880,11 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value SH_DockWidget_ButtonsHaveFrame Determines if dockwidget buttons should have frames. Default is true. + \value SH_ToolButtonStyle Determines the default system style for tool buttons that uses Qt::ToolButtonFollowStyle. + + \value SH_RequestSoftwareInputPanel Determines when a software input panel should + be requested by input widgets. Returns an enum of type QStyle::RequestSoftwareInputPanel. + \omitvalue SH_UnderlineAccelerator \sa styleHint() @@ -1876,7 +1911,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, can follow some existing GUI style or guideline. \value SP_TitleBarMinButton Minimize button on title bars (e.g., - in QWorkspace). + in QMdiSubWindow). \value SP_TitleBarMenuButton Menu button on a title bar. \value SP_TitleBarMaxButton Maximize button on title bars. \value SP_TitleBarCloseButton Close button on title bars. @@ -1948,22 +1983,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value SP_CustomBase Base value for custom standard pixmaps; custom values must be greater than this value. - \sa standardPixmap() standardIcon() -*/ - -/*### - \enum QStyle::IconMode - - This enum represents the effects performed on a pixmap to achieve a - GUI style's perferred way of representing the image in different - states. - - \value IM_Disabled A disabled pixmap (drawn on disabled widgets) - \value IM_Active An active pixmap (drawn on active tool buttons and menu items) - \value IM_CustomBase Base value for custom PixmapTypes; custom - values must be greater than this value - - \sa generatedIconPixmap() + \sa standardIcon() */ /*! @@ -2246,7 +2266,7 @@ QPalette QStyle::standardPalette() const slot in your subclass instead. The standardIcon() function will dynamically detect the slot and call it. - \sa standardIconImplementation(), standardPixmap() + \sa standardIconImplementation() */ QIcon QStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const @@ -2271,8 +2291,7 @@ QIcon QStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *opti subclass; because of binary compatibility constraints, the standardIcon() function (introduced in Qt 4.1) is not virtual. Instead, standardIcon() will dynamically detect and call - \e this slot. The default implementation simply calls the - standardPixmap() function with the given parameters. + \e this slot. The \a standardIcon is a standard pixmap which can follow some existing GUI style or guideline. The \a option argument can be @@ -2437,9 +2456,36 @@ QDebug operator<<(QDebug debug, QStyle::State state) qSort(states); debug << states.join(QLatin1String(" | ")); - debug << ")"; + debug << ')'; return debug; } #endif +/*! + \since 4.6 + + \fn const QStyle *QStyle::proxy() const + + This function returns the current proxy for this style. + By default most styles will return themselves. However + when a proxy style is in use, it will allow the style to + call back into its proxy. +*/ +const QStyle * QStyle::proxy() const +{ + Q_D(const QStyle); + return d->proxyStyle; +} + +/* \internal + + This function sets the base style that style calls will be + redirected to. Note that ownership is not transferred. +*/ +void QStyle::setProxy(QStyle *style) +{ + Q_D(QStyle); + d->proxyStyle = style; +} + QT_END_NAMESPACE |