summaryrefslogtreecommitdiffstats
path: root/src/gui/styles
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-06-16 12:16:23 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-06-16 12:16:23 (GMT)
commit714a62490fd30986dc86559e6f14194a34b3a5bc (patch)
treec5c189fb22eb2f20a6cf70c176f02dd348c83610 /src/gui/styles
parentaa1120804708c44ac72e20e228d5ef383a1cd62a (diff)
parentc41591d57377cd7c520efc93d9c087ad34d2bb6f (diff)
downloadQt-714a62490fd30986dc86559e6f14194a34b3a5bc.zip
Qt-714a62490fd30986dc86559e6f14194a34b3a5bc.tar.gz
Qt-714a62490fd30986dc86559e6f14194a34b3a5bc.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Conflicts: doc/src/qnamespace.qdoc doc/src/snippets/code/src_gui_qproxystyle.cpp src/3rdparty/webkit/VERSION src/3rdparty/webkit/WebKit/qt/ChangeLog src/gui/graphicsview/qgraphicsscene.cpp src/gui/kernel/qapplication.cpp src/gui/kernel/qapplication_x11.cpp src/gui/kernel/qt_x11_p.h src/gui/kernel/qwidget.cpp src/gui/styles/qproxystyle.cpp src/gui/styles/qstyle.cpp src/scripttools/debugging/qscriptdebugger.cpp src/scripttools/debugging/qscriptenginedebugger.cpp src/sql/drivers/odbc/qsql_odbc.cpp src/sql/kernel/qsqldatabase.cpp src/sql/kernel/qsqldriver.cpp
Diffstat (limited to 'src/gui/styles')
-rw-r--r--src/gui/styles/qproxystyle.cpp144
-rw-r--r--src/gui/styles/qstyle.cpp32
2 files changed, 119 insertions, 57 deletions
diff --git a/src/gui/styles/qproxystyle.cpp b/src/gui/styles/qproxystyle.cpp
index f36ad64..37f25be 100644
--- a/src/gui/styles/qproxystyle.cpp
+++ b/src/gui/styles/qproxystyle.cpp
@@ -53,27 +53,28 @@ QT_BEGIN_NAMESPACE
/*!
\class QProxyStyle
- \brief The QProxyStyle is a convenience class that simplifies
- the creation of proxy styles in Qt.
+ \brief The QProxyStyle class is a convenience class that simplifies
+ the overriding of QStyle elements.
\since 4.6
- A proxy style is a style that wraps a different,
- usually the default system style, to override the painting or
- behavior of only specific parts.
+ A QProxyStyle wraps a QStyle (usually the default system style) for the
+ purpose of overriding the painting or other specific behavior of the
+ wrapped style.
- Here's an example allowing you to override the shortcut underline
+ Below is an example that overrides the shortcut underline
behavior on all platforms:
- \snippet doc/src/snippets/code/src_gui_proxystyle.cpp 0
+ \snippet doc/src/snippets/code/src_gui_qproxystyle.cpp 1
- Warning: Note that even though Qt's internal styles should respect this.
- hint, there is no guarantee that it will work for all styles.
- The example above would for instance not work on Mac since menus are
- handled by the operating system.
+ Warning: Although Qt's internal styles should respect this hint,
+ there is no guarantee that it will work for all styles. It would
+ not work on a Mac, for example, because menus are handled by the
+ operating system on the Mac.
\sa QStyle
*/
+
void QProxyStylePrivate::ensureBaseStyle() const
{
Q_Q(const QProxyStyle);
@@ -92,7 +93,7 @@ void QProxyStylePrivate::ensureBaseStyle() const
baseStyle = 0;
}
}
- }
+ }
if (!baseStyle) // Use application desktop style
baseStyle = QStyleFactory::create(QApplicationPrivate::desktopStyleKey());
@@ -105,12 +106,12 @@ void QProxyStylePrivate::ensureBaseStyle() const
}
/*!
- Constructs a QProxyStyle object.
-
- If no base style is provided, the current application style
- will be used as the base style.
+ Constructs a QProxyStyle object for overriding behavior in \a style
+ or in the current application \l{QStyle}{style} if \a style is 0
+ (default). Normally \a style is 0, because you want to override
+ behavior in the system style.
- Ownership of \style is transferred to QProxyStyle.
+ Ownership of \a style is transferred to QProxyStyle.
*/
QProxyStyle::QProxyStyle(QStyle *style) :
QCommonStyle(*new QProxyStylePrivate())
@@ -147,7 +148,7 @@ QStyle *QProxyStyle::baseStyle() const
/*!
Sets the base style that should be proxied.
- Ownership of \style is transferred to QProxyStyle.
+ Ownership of \a style is transferred to QProxyStyle.
If style is zero, a desktop-dependant style will be
assigned automatically.
@@ -167,7 +168,8 @@ void QProxyStyle::setBaseStyle(QStyle *style)
}
}
-/*! reimp */
+/*! \reimp
+ */
void QProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
Q_D (const QProxyStyle);
@@ -175,7 +177,9 @@ void QProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *op
d->baseStyle->drawPrimitive(element, option, painter, widget);
}
-/*! reimp */
+/*!
+ \reimp
+ */
void QProxyStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
Q_D (const QProxyStyle);
@@ -183,7 +187,8 @@ void QProxyStyle::drawControl(ControlElement element, const QStyleOption *option
d->baseStyle->drawControl(element, option, painter, widget);
}
-/*! reimp */
+/*! \reimp
+ */
void QProxyStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
{
Q_D (const QProxyStyle);
@@ -191,7 +196,8 @@ void QProxyStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
d->baseStyle->drawComplexControl(control, option, painter, widget);
}
-/*! reimp */
+/*! \reimp
+ */
void QProxyStyle::drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled,
const QString &text, QPalette::ColorRole textRole) const
{
@@ -200,7 +206,8 @@ void QProxyStyle::drawItemText(QPainter *painter, const QRect &rect, int flags,
d->baseStyle->drawItemText(painter, rect, flags, pal, enabled, text, textRole);
}
-/*! reimp */
+/*! \reimp
+ */
void QProxyStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
{
Q_D (const QProxyStyle);
@@ -208,7 +215,8 @@ void QProxyStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int align
d->baseStyle->drawItemPixmap(painter, rect, alignment, pixmap);
}
-/*! reimp */
+/*! \reimp
+ */
QSize QProxyStyle::sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const
{
Q_D (const QProxyStyle);
@@ -216,7 +224,8 @@ QSize QProxyStyle::sizeFromContents(ContentsType type, const QStyleOption *optio
return d->baseStyle->sizeFromContents(type, option, size, widget);
}
-/*! reimp */
+/*! \reimp
+ */
QRect QProxyStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
{
Q_D (const QProxyStyle);
@@ -224,7 +233,8 @@ QRect QProxyStyle::subElementRect(SubElement element, const QStyleOption *option
return d->baseStyle->subElementRect(element, option, widget);
}
-/*! reimp */
+/*! \reimp
+ */
QRect QProxyStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *option, SubControl sc, const QWidget *widget) const
{
Q_D (const QProxyStyle);
@@ -232,7 +242,8 @@ QRect QProxyStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *
return d->baseStyle->subControlRect(cc, option, sc, widget);
}
-/*! reimp */
+/*! \reimp
+ */
QRect QProxyStyle::itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const
{
Q_D (const QProxyStyle);
@@ -240,7 +251,8 @@ QRect QProxyStyle::itemTextRect(const QFontMetrics &fm, const QRect &r, int flag
return d->baseStyle->itemTextRect(fm, r, flags, enabled, text);
}
-/*! reimp */
+/*! \reimp
+ */
QRect QProxyStyle::itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
{
Q_D (const QProxyStyle);
@@ -248,7 +260,8 @@ QRect QProxyStyle::itemPixmapRect(const QRect &r, int flags, const QPixmap &pixm
return d->baseStyle->itemPixmapRect(r, flags, pixmap);
}
-/*! reimp */
+/*! \reimp
+ */
QStyle::SubControl QProxyStyle::hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget) const
{
Q_D (const QProxyStyle);
@@ -256,7 +269,8 @@ QStyle::SubControl QProxyStyle::hitTestComplexControl(ComplexControl control, co
return d->baseStyle->hitTestComplexControl(control, option, pos, widget);
}
-/*! reimp */
+/*! \reimp
+ */
int QProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const
{
Q_D (const QProxyStyle);
@@ -264,7 +278,8 @@ int QProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWi
return d->baseStyle->styleHint(hint, option, widget, returnData);
}
-/*! reimp */
+/*! \reimp
+ */
int QProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
{
Q_D (const QProxyStyle);
@@ -272,7 +287,8 @@ int QProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, con
return d->baseStyle->pixelMetric(metric, option, widget);
}
-/*! reimp */
+/*! \reimp
+ */
QPixmap QProxyStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const
{
Q_D (const QProxyStyle);
@@ -280,7 +296,8 @@ QPixmap QProxyStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleO
return d->baseStyle->standardPixmap(standardPixmap, opt, widget);
}
-/*! reimp */
+/*! \reimp
+ */
QPixmap QProxyStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const
{
Q_D (const QProxyStyle);
@@ -288,7 +305,8 @@ QPixmap QProxyStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pi
return d->baseStyle->generatedIconPixmap(iconMode, pixmap, opt);
}
-/*! reimp */
+/*! \reimp
+ */
QPalette QProxyStyle::standardPalette() const
{
Q_D (const QProxyStyle);
@@ -296,7 +314,8 @@ QPalette QProxyStyle::standardPalette() const
return d->baseStyle->standardPalette();
}
-/*! reimp */
+/*! \reimp
+ */
void QProxyStyle::polish(QWidget *widget)
{
Q_D (QProxyStyle);
@@ -304,7 +323,8 @@ void QProxyStyle::polish(QWidget *widget)
d->baseStyle->polish(widget);
}
-/*! reimp */
+/*! \reimp
+ */
void QProxyStyle::polish(QPalette &pal)
{
Q_D (QProxyStyle);
@@ -312,7 +332,8 @@ void QProxyStyle::polish(QPalette &pal)
d->baseStyle->polish(pal);
}
-/*! reimp */
+/*! \reimp
+ */
void QProxyStyle::polish(QApplication *app)
{
Q_D (QProxyStyle);
@@ -320,7 +341,8 @@ void QProxyStyle::polish(QApplication *app)
d->baseStyle->polish(app);
}
-/*! reimp */
+/*! \reimp
+ */
void QProxyStyle::unpolish(QWidget *widget)
{
Q_D (QProxyStyle);
@@ -328,7 +350,8 @@ void QProxyStyle::unpolish(QWidget *widget)
d->baseStyle->unpolish(widget);
}
-/*! reimp */
+/*! \reimp
+ */
void QProxyStyle::unpolish(QApplication *app)
{
Q_D (QProxyStyle);
@@ -336,7 +359,8 @@ void QProxyStyle::unpolish(QApplication *app)
d->baseStyle->unpolish(app);
}
-/*! reimp */
+/*! \reimp
+ */
bool QProxyStyle::event(QEvent *e)
{
Q_D (QProxyStyle);
@@ -344,17 +368,47 @@ bool QProxyStyle::event(QEvent *e)
return d->baseStyle->event(e);
}
-/*! reimp */
-QIcon QProxyStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const
+/*!
+ Returns an icon for the given \a standardIcon.
+
+ Reimplement this slot to provide your own icons in a QStyle
+ subclass. The \a option argument can be used to pass extra
+ information required to find the appropriate icon. The \a widget
+ argument is optional and can also be used to help find the icon.
+
+ \note Because of binary compatibility constraints, standardIcon()
+ introduced in Qt 4.1 is not virtual. Therefore it must dynamically
+ detect and call \e this slot. This default implementation simply
+ calls standardIcon() with the given parameters.
+
+ \sa standardIcon()
+ */
+QIcon QProxyStyle::standardIconImplementation(StandardPixmap standardIcon,
+ const QStyleOption *option,
+ const QWidget *widget) const
{
Q_D (const QProxyStyle);
d->ensureBaseStyle();
return d->baseStyle->standardIcon(standardIcon, option, widget);
}
-/*! reimp */
-int QProxyStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2,
- Qt::Orientation orientation, const QStyleOption *option, const QWidget *widget) const
+/*!
+ This slot is called by layoutSpacing() to determine the spacing that
+ should be used between \a control1 and \a control2 in a layout. \a
+ orientation specifies whether the controls are laid out side by side
+ or stacked vertically. The \a option parameter can be used to pass
+ extra information about the parent widget. The \a widget parameter
+ is optional and can also be used if \a option is 0.
+
+ The default implementation returns -1.
+
+ \sa layoutSpacing(), combinedLayoutSpacing()
+ */
+int QProxyStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1,
+ QSizePolicy::ControlType control2,
+ Qt::Orientation orientation,
+ const QStyleOption *option,
+ const QWidget *widget) const
{
Q_D (const QProxyStyle);
d->ensureBaseStyle();
diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp
index c0fdc83..c848022 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
@@ -1182,6 +1191,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
*/
@@ -2450,14 +2460,12 @@ QDebug operator<<(QDebug debug, QStyle::State state)
/*!
\since 4.6
- \fn const QStyle * proxy() const
+ \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.
-
- \sa setProxyStyle
*/
const QStyle * QStyle::proxy() const
{