summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-04-28 15:54:46 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2010-04-28 15:54:46 +0200
commit1ab9164ae7c782854a89f4a5021633c1c2c67aa5 (patch)
treee4ae9d4c591ea58da1cb036a7fc5b94d5f6b61b3
parent6c647efe01575fec074c105f625899891e29df65 (diff)
Move scroll bar styling out of Manhattan style and into separate class.
To ease merging with the Creator style. Done-with: Jens Bache-Wiig
-rw-r--r--library/remotecontrolwidget.pro2
-rw-r--r--library/style/manhattanstyle.cpp117
-rw-r--r--library/style/scrollbarstyle.cpp126
-rw-r--r--library/style/scrollbarstyle.h16
-rw-r--r--library/toolbox.cpp5
5 files changed, 148 insertions, 118 deletions
diff --git a/library/remotecontrolwidget.pro b/library/remotecontrolwidget.pro
index ad036bd..3174d14 100644
--- a/library/remotecontrolwidget.pro
+++ b/library/remotecontrolwidget.pro
@@ -27,6 +27,7 @@ SOURCES += \
style/manhattanstyle.cpp \
style/filterlineedit.cpp \
style/fancylineedit.cpp \
+ style/scrollbarstyle.cpp \
components/locationui.cpp \
components/powerbutton.cpp \
components/batterybutton.cpp \
@@ -56,6 +57,7 @@ HEADERS += $$PUBLIC_HEADERS \
style/manhattanstyle.h \
style/filterlineedit.h \
style/fancylineedit.h \
+ style/scrollbarstyle.h \
style/stylehelper.h
RESOURCES += \
diff --git a/library/style/manhattanstyle.cpp b/library/style/manhattanstyle.cpp
index b304b79..5ab7f9c 100644
--- a/library/style/manhattanstyle.cpp
+++ b/library/style/manhattanstyle.cpp
@@ -105,24 +105,6 @@ bool panelWidget(const QWidget *widget)
return false;
}
-bool styledScrollBar(const QWidget *widget)
-{
- if (!widget)
- return false;
-
- // Don't style dialogs or explicitly ignored widgets
- if (qobject_cast<const QDialog *>(widget->window()))
- return false;
-
- const QWidget *p = widget;
- while (p) {
- if (p->property("styledScrollBar").toBool())
- return true;
- p = p->parentWidget();
- }
- return false;
-}
-
// Consider making this a QStyle state
bool lightColored(const QWidget *widget)
{
@@ -632,7 +614,7 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const
{
- if (!panelWidget(widget) && !styledScrollBar(widget))
+ if (!panelWidget(widget))
return QProxyStyle::drawControl(element, option, painter, widget);
switch (element) {
@@ -840,47 +822,6 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
}
}
break;
- case CE_ScrollBarAddLine:
- case CE_ScrollBarSubLine: {
- PrimitiveElement arrow;
- if (option->state & State_Horizontal) {
- if (element == CE_ScrollBarAddLine)
- arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
- else
- arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
- } else {
- if (element == CE_ScrollBarAddLine)
- arrow = PE_IndicatorArrowDown;
- else
- arrow = PE_IndicatorArrowUp;
- }
- QStyleOption arrowOpt = *option;
- arrowOpt.palette.setColor(QPalette::Active, QPalette::ButtonText, Utils::StyleHelper::baseColor());
- arrowOpt.palette.setColor(QPalette::Disabled, QPalette::ButtonText, Utils::StyleHelper::shadowColor());
- int squareSide = qMin(option->rect.width(), option->rect.height());
- arrowOpt.rect.setSize(QSize(squareSide, squareSide));
- arrowOpt.rect.adjust(5, 5, -1, -3);
-
- drawPrimitive(arrow, &arrowOpt, painter, widget);
- }
- break;
-
- case CE_ScrollBarSlider: {
- QRect rect = option->rect.adjusted(5, 0, -3, 0);
- if (option->state & State_Enabled) {
- painter->save();
- QColor base = Utils::StyleHelper::baseColor();
- QLinearGradient grad(rect.topRight(), rect.topLeft());
- grad.setColorAt(0, base.lighter());
- grad.setColorAt(1, base.lighter(190));
- painter->setRenderHint(QPainter::Antialiasing);
- painter->setBrush(grad);
- painter->setPen(Qt::NoPen);
- painter->drawRoundedRect(rect, 3, 3);
- painter->restore();
- }
- }
- break;
default:
QProxyStyle::drawControl(element, option, painter, widget);
@@ -891,7 +832,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
QPainter *painter, const QWidget *widget) const
{
- if (!panelWidget(widget) && !styledScrollBar(widget))
+ if (!panelWidget(widget))
return QProxyStyle::drawComplexControl(control, option, painter, widget);
QRect rect = option->rect;
@@ -1032,60 +973,6 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
}
break;
-
- case CC_ScrollBar:
- if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
- painter->save();
- // Make a copy here and reset it for each primitive.
- QStyleOptionSlider newScrollbar = *scrollbar;
- State saveFlags = scrollbar->state;
- if (scrollbar->minimum == scrollbar->maximum)
- saveFlags &= ~State_Enabled;
-
- painter->save();
- painter->setBrush(QBrush(widget->palette().background()));
- painter->setPen(Qt::NoPen);
- painter->drawRect(rect);
- QPen pen = painter->pen();
- pen.setColor(Utils::StyleHelper::highlightColor().lighter());
- pen.setStyle(Qt::SolidLine);
- painter->setPen(pen);
- painter->drawLine(rect.topLeft(), rect.bottomLeft());
- painter->restore();
-
- if (scrollbar->subControls & SC_ScrollBarSubLine) {
- newScrollbar.state = saveFlags;
- newScrollbar.rect = proxy()->subControlRect(control, &newScrollbar, SC_ScrollBarSubLine, widget);
- if (newScrollbar.rect.isValid()) {
- if (!(scrollbar->activeSubControls & SC_ScrollBarSubLine))
- newScrollbar.state &= ~(State_Sunken | State_MouseOver);
- drawControl(CE_ScrollBarSubLine, &newScrollbar, painter, widget);
- }
- }
- if (scrollbar->subControls & SC_ScrollBarAddLine) {
- newScrollbar.rect = scrollbar->rect;
- newScrollbar.state = saveFlags;
- newScrollbar.rect = proxy()->subControlRect(control, &newScrollbar, SC_ScrollBarAddLine, widget);
- if (newScrollbar.rect.isValid()) {
- if (!(scrollbar->activeSubControls & SC_ScrollBarAddLine))
- newScrollbar.state &= ~(State_Sunken | State_MouseOver);
- drawControl(CE_ScrollBarAddLine, &newScrollbar, painter, widget);
- }
- }
- if (scrollbar->subControls & SC_ScrollBarSlider) {
- newScrollbar.rect = scrollbar->rect;
- newScrollbar.state = saveFlags;
- newScrollbar.rect = proxy()->subControlRect(control, &newScrollbar, SC_ScrollBarSlider, widget);
- if (newScrollbar.rect.isValid()) {
- if (!(scrollbar->activeSubControls & SC_ScrollBarSlider))
- newScrollbar.state &= ~(State_Sunken | State_MouseOver);
- drawControl(CE_ScrollBarSlider, &newScrollbar, painter, widget);
- }
- }
- painter->restore();
- }
- break;
-
default:
QProxyStyle::drawComplexControl(control, option, painter, widget);
break;
diff --git a/library/style/scrollbarstyle.cpp b/library/style/scrollbarstyle.cpp
new file mode 100644
index 0000000..a025f68
--- /dev/null
+++ b/library/style/scrollbarstyle.cpp
@@ -0,0 +1,126 @@
+#include "scrollbarstyle.h"
+
+#include "stylehelper.h"
+
+#include <QtGui/QStyleOption>
+#include <QtGui/QPainter>
+
+ScrollBarStyle::ScrollBarStyle()
+{
+}
+
+void ScrollBarStyle::drawControl(ControlElement element, const QStyleOption *option,
+ QPainter *painter, const QWidget *widget) const
+{
+ switch (element) {
+ case CE_ScrollBarAddLine:
+ case CE_ScrollBarSubLine: {
+ PrimitiveElement arrow;
+ if (option->state & State_Horizontal) {
+ if (element == CE_ScrollBarAddLine)
+ arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
+ else
+ arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
+ } else {
+ if (element == CE_ScrollBarAddLine)
+ arrow = PE_IndicatorArrowDown;
+ else
+ arrow = PE_IndicatorArrowUp;
+ }
+ QStyleOption arrowOpt = *option;
+ arrowOpt.palette.setColor(QPalette::Active, QPalette::ButtonText, Utils::StyleHelper::baseColor());
+ arrowOpt.palette.setColor(QPalette::Disabled, QPalette::ButtonText, Utils::StyleHelper::shadowColor());
+ int squareSide = qMin(option->rect.width(), option->rect.height());
+ arrowOpt.rect.setSize(QSize(squareSide, squareSide));
+ arrowOpt.rect.adjust(5, 5, -1, -3);
+
+ drawPrimitive(arrow, &arrowOpt, painter, widget);
+ }
+ break;
+
+ case CE_ScrollBarSlider: {
+ QRect rect = option->rect.adjusted(5, 0, -3, 0);
+ if (option->state & State_Enabled) {
+ painter->save();
+ QColor base = Utils::StyleHelper::baseColor();
+ QLinearGradient grad(rect.topRight(), rect.topLeft());
+ grad.setColorAt(0, base.lighter());
+ grad.setColorAt(1, base.lighter(190));
+ painter->setRenderHint(QPainter::Antialiasing);
+ painter->setBrush(grad);
+ painter->setPen(Qt::NoPen);
+ painter->drawRoundedRect(rect, 3, 3);
+ painter->restore();
+ }
+ }
+ break;
+
+ default:
+ QCleanlooksStyle::drawControl(element, option, painter, widget);
+ break;
+ }
+}
+
+void ScrollBarStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
+ QPainter *painter, const QWidget *widget) const
+{
+ QRect rect = option->rect;
+ switch (control) {
+ case CC_ScrollBar:
+ if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
+ painter->save();
+ // Make a copy here and reset it for each primitive.
+ QStyleOptionSlider newScrollbar = *scrollbar;
+ State saveFlags = scrollbar->state;
+ if (scrollbar->minimum == scrollbar->maximum)
+ saveFlags &= ~State_Enabled;
+
+ painter->save();
+ painter->setBrush(QBrush(widget->palette().background()));
+ painter->setPen(Qt::NoPen);
+ painter->drawRect(rect);
+ QPen pen = painter->pen();
+ pen.setColor(Utils::StyleHelper::highlightColor().lighter());
+ pen.setStyle(Qt::SolidLine);
+ painter->setPen(pen);
+ painter->drawLine(rect.topLeft(), rect.bottomLeft());
+ painter->restore();
+
+ if (scrollbar->subControls & SC_ScrollBarSubLine) {
+ newScrollbar.state = saveFlags;
+ newScrollbar.rect = proxy()->subControlRect(control, &newScrollbar, SC_ScrollBarSubLine, widget);
+ if (newScrollbar.rect.isValid()) {
+ if (!(scrollbar->activeSubControls & SC_ScrollBarSubLine))
+ newScrollbar.state &= ~(State_Sunken | State_MouseOver);
+ drawControl(CE_ScrollBarSubLine, &newScrollbar, painter, widget);
+ }
+ }
+ if (scrollbar->subControls & SC_ScrollBarAddLine) {
+ newScrollbar.rect = scrollbar->rect;
+ newScrollbar.state = saveFlags;
+ newScrollbar.rect = proxy()->subControlRect(control, &newScrollbar, SC_ScrollBarAddLine, widget);
+ if (newScrollbar.rect.isValid()) {
+ if (!(scrollbar->activeSubControls & SC_ScrollBarAddLine))
+ newScrollbar.state &= ~(State_Sunken | State_MouseOver);
+ drawControl(CE_ScrollBarAddLine, &newScrollbar, painter, widget);
+ }
+ }
+ if (scrollbar->subControls & SC_ScrollBarSlider) {
+ newScrollbar.rect = scrollbar->rect;
+ newScrollbar.state = saveFlags;
+ newScrollbar.rect = proxy()->subControlRect(control, &newScrollbar, SC_ScrollBarSlider, widget);
+ if (newScrollbar.rect.isValid()) {
+ if (!(scrollbar->activeSubControls & SC_ScrollBarSlider))
+ newScrollbar.state &= ~(State_Sunken | State_MouseOver);
+ drawControl(CE_ScrollBarSlider, &newScrollbar, painter, widget);
+ }
+ }
+ painter->restore();
+ }
+ break;
+
+ default:
+ QCleanlooksStyle::drawComplexControl(control, option, painter, widget);
+ break;
+ }
+}
diff --git a/library/style/scrollbarstyle.h b/library/style/scrollbarstyle.h
new file mode 100644
index 0000000..1bba238
--- /dev/null
+++ b/library/style/scrollbarstyle.h
@@ -0,0 +1,16 @@
+#ifndef SCROLLBARSTYLE_H
+#define SCROLLBARSTYLE_H
+
+#include <QCleanlooksStyle>
+
+class ScrollBarStyle : public QCleanlooksStyle
+{
+ Q_OBJECT
+public:
+ ScrollBarStyle();
+
+ virtual void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = 0) const;
+ virtual void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget = 0) const;
+};
+
+#endif // SCROLLBARSTYLE_H
diff --git a/library/toolbox.cpp b/library/toolbox.cpp
index e0b69a2..5077858 100644
--- a/library/toolbox.cpp
+++ b/library/toolbox.cpp
@@ -29,7 +29,7 @@
#include "toolbox.h"
#include "style/styledbar.h"
-#include "style/manhattanstyle.h"
+#include "style/scrollbarstyle.h"
#include <QtCore/QStringList>
#include <QtCore/QVariant>
@@ -61,11 +61,10 @@ ToolBox::ToolBox(bool pagesOpenOnInsertion, QWidget *parent)
setWidgetResizable(true);
// Some styles have extra up/down buttons in the scrollbar. We only support
// the plain scrollbars and therefore force the style to be derived from cleanlooks for them.
- QStyle *forceScrollbarStyle = new ManhattanStyle("cleanlooks");
+ QStyle *forceScrollbarStyle = new ScrollBarStyle;
setStyle(forceScrollbarStyle);
verticalScrollBar()->setStyle(forceScrollbarStyle);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
- verticalScrollBar()->setProperty("styledScrollBar", true);
setWidget(contentWidget);
}