From 0013105db011ff214f527c28875f1ab764d6a956 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 29 Jan 2022 23:52:45 +0200 Subject: [PATCH] format and indent QCleanlooksStyle::drawPrimitive() Signed-off-by: Ivailo Monev --- src/gui/styles/qcleanlooksstyle.cpp | 715 ++++++++++++++-------------- 1 file changed, 349 insertions(+), 366 deletions(-) diff --git a/src/gui/styles/qcleanlooksstyle.cpp b/src/gui/styles/qcleanlooksstyle.cpp index 73aff473f..ea8d8128c 100644 --- a/src/gui/styles/qcleanlooksstyle.cpp +++ b/src/gui/styles/qcleanlooksstyle.cpp @@ -648,7 +648,7 @@ void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem, switch(elem) { #ifndef QT_NO_TABBAR - case PE_FrameTabBarBase: + case PE_FrameTabBarBase: { if (const QStyleOptionTabBarBase *tbb = qstyleoption_cast(option)) { painter->save(); @@ -662,8 +662,8 @@ void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem, painter->setPen(option->palette.light().color()); painter->drawLine(tbb->rect.topLeft() + QPoint(0, 1), tbb->rect.topRight() + QPoint(0, 1)); - } break; + } case QTabBar::RoundedWest: painter->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.left(), tbb->rect.bottom()); break; @@ -685,16 +685,16 @@ void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem, painter->restore(); } return; + } #endif // QT_NO_TABBAR - case PE_IndicatorViewItemCheck: - { - QStyleOptionButton button; - button.QStyleOption::operator=(*option); - button.state &= ~State_MouseOver; - proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget); - } + case PE_IndicatorViewItemCheck: { + QStyleOptionButton button; + button.QStyleOption::operator=(*option); + button.state &= ~State_MouseOver; + proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget); return; - case PE_IndicatorHeaderArrow: + } + case PE_IndicatorHeaderArrow: { if (const QStyleOptionHeader *header = qstyleoption_cast(option)) { QRect r = header->rect; QImage arrow; @@ -712,196 +712,191 @@ void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem, } } break; - case PE_IndicatorButtonDropDown: + } + case PE_IndicatorButtonDropDown: { proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget); break; - case PE_IndicatorToolBarSeparator: - { - QRect rect = option->rect; - const int margin = 6; - if (option->state & State_Horizontal) { - const int offset = rect.width()/2; - painter->setPen(QPen(option->palette.background().color().darker(110))); - painter->drawLine(rect.bottomLeft().x() + offset, - rect.bottomLeft().y() - margin, - rect.topLeft().x() + offset, - rect.topLeft().y() + margin); - painter->setPen(QPen(option->palette.background().color().lighter(110))); - painter->drawLine(rect.bottomLeft().x() + offset + 1, - rect.bottomLeft().y() - margin, - rect.topLeft().x() + offset + 1, - rect.topLeft().y() + margin); - } else { //Draw vertical separator - const int offset = rect.height()/2; - painter->setPen(QPen(option->palette.background().color().darker(110))); - painter->drawLine(rect.topLeft().x() + margin , - rect.topLeft().y() + offset, - rect.topRight().x() - margin, - rect.topRight().y() + offset); - painter->setPen(QPen(option->palette.background().color().lighter(110))); - painter->drawLine(rect.topLeft().x() + margin , - rect.topLeft().y() + offset + 1, - rect.topRight().x() - margin, - rect.topRight().y() + offset + 1); - } + } + case PE_IndicatorToolBarSeparator: { + QRect rect = option->rect; + const int margin = 6; + if (option->state & State_Horizontal) { + const int offset = rect.width()/2; + painter->setPen(QPen(option->palette.background().color().darker(110))); + painter->drawLine(rect.bottomLeft().x() + offset, + rect.bottomLeft().y() - margin, + rect.topLeft().x() + offset, + rect.topLeft().y() + margin); + painter->setPen(QPen(option->palette.background().color().lighter(110))); + painter->drawLine(rect.bottomLeft().x() + offset + 1, + rect.bottomLeft().y() - margin, + rect.topLeft().x() + offset + 1, + rect.topLeft().y() + margin); + } else { //Draw vertical separator + const int offset = rect.height()/2; + painter->setPen(QPen(option->palette.background().color().darker(110))); + painter->drawLine(rect.topLeft().x() + margin , + rect.topLeft().y() + offset, + rect.topRight().x() - margin, + rect.topRight().y() + offset); + painter->setPen(QPen(option->palette.background().color().lighter(110))); + painter->drawLine(rect.topLeft().x() + margin , + rect.topLeft().y() + offset + 1, + rect.topRight().x() - margin, + rect.topRight().y() + offset + 1); } break; - case PE_Frame: + } + case PE_Frame: { painter->save(); painter->setPen(dark.lighter(108)); painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); painter->restore(); break; - case PE_FrameMenu: + } + case PE_FrameMenu: { painter->save(); - { - painter->setPen(QPen(darkOutline, 1)); - painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); - QColor frameLight = option->palette.background().color().lighter(160); - QColor frameShadow = option->palette.background().color().darker(110); + painter->setPen(QPen(darkOutline, 1)); + painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); + QColor frameLight = option->palette.background().color().lighter(160); + QColor frameShadow = option->palette.background().color().darker(110); - //paint beveleffect - QRect frame = option->rect.adjusted(1, 1, -1, -1); - painter->setPen(frameLight); - painter->drawLine(frame.topLeft(), frame.bottomLeft()); - painter->drawLine(frame.topLeft(), frame.topRight()); + //paint beveleffect + QRect frame = option->rect.adjusted(1, 1, -1, -1); + painter->setPen(frameLight); + painter->drawLine(frame.topLeft(), frame.bottomLeft()); + painter->drawLine(frame.topLeft(), frame.topRight()); - painter->setPen(frameShadow); - painter->drawLine(frame.topRight(), frame.bottomRight()); - painter->drawLine(frame.bottomLeft(), frame.bottomRight()); - } + painter->setPen(frameShadow); + painter->drawLine(frame.topRight(), frame.bottomRight()); + painter->drawLine(frame.bottomLeft(), frame.bottomRight()); painter->restore(); break; - case PE_FrameDockWidget: - + } + case PE_FrameDockWidget: { painter->save(); - { - QColor softshadow = option->palette.background().color().darker(120); + QColor softshadow = option->palette.background().color().darker(120); - QRect rect= option->rect; - painter->setPen(softshadow); - painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); - painter->setPen(QPen(option->palette.light(), 0)); - painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1), QPoint(rect.left() + 1, rect.bottom() - 1)); - painter->setPen(QPen(option->palette.background().color().darker(120), 0)); - painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1), QPoint(rect.right() - 2, rect.bottom() - 1)); - painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1), QPoint(rect.right() - 1, rect.bottom() - 1)); + QRect rect= option->rect; + painter->setPen(softshadow); + painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); + painter->setPen(QPen(option->palette.light(), 0)); + painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1), QPoint(rect.left() + 1, rect.bottom() - 1)); + painter->setPen(QPen(option->palette.background().color().darker(120), 0)); + painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1), QPoint(rect.right() - 2, rect.bottom() - 1)); + painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1), QPoint(rect.right() - 1, rect.bottom() - 1)); - } painter->restore(); break; - case PE_PanelButtonTool: + } + case PE_PanelButtonTool: { painter->save(); if ((option->state & State_Enabled || option->state & State_On) || !(option->state & State_AutoRaise)) { QPen oldPen = painter->pen(); if (widget && widget->inherits("QDockWidgetTitleButton")) { - if (option->state & State_MouseOver) - proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget); + if (option->state & State_MouseOver) + proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget); } else { proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget); } } painter->restore(); break; - case PE_IndicatorDockWidgetResizeHandle: - { - QStyleOption dockWidgetHandle = *option; - bool horizontal = option->state & State_Horizontal; - if (horizontal) - dockWidgetHandle.state &= ~State_Horizontal; - else - dockWidgetHandle.state |= State_Horizontal; - proxy()->drawControl(CE_Splitter, &dockWidgetHandle, painter, widget); - } + } + case PE_IndicatorDockWidgetResizeHandle: { + QStyleOption dockWidgetHandle = *option; + bool horizontal = option->state & State_Horizontal; + if (horizontal) + dockWidgetHandle.state &= ~State_Horizontal; + else + dockWidgetHandle.state |= State_Horizontal; + proxy()->drawControl(CE_Splitter, &dockWidgetHandle, painter, widget); break; - case PE_FrameWindow: + } + case PE_FrameWindow: { painter->save(); - { - QRect rect= option->rect; - painter->setPen(QPen(dark.darker(150), 0)); - painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); - painter->setPen(QPen(option->palette.light(), 0)); - painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1), - QPoint(rect.left() + 1, rect.bottom() - 1)); - painter->setPen(QPen(option->palette.background().color().darker(120), 0)); - painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1), - QPoint(rect.right() - 2, rect.bottom() - 1)); - painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1), - QPoint(rect.right() - 1, rect.bottom() - 1)); - } + QRect rect= option->rect; + painter->setPen(QPen(dark.darker(150), 0)); + painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); + painter->setPen(QPen(option->palette.light(), 0)); + painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1), + QPoint(rect.left() + 1, rect.bottom() - 1)); + painter->setPen(QPen(option->palette.background().color().darker(120), 0)); + painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1), + QPoint(rect.right() - 2, rect.bottom() - 1)); + painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1), + QPoint(rect.right() - 1, rect.bottom() - 1)); painter->restore(); break; + } #ifndef QT_NO_LINEEDIT - case PE_FrameLineEdit: - // fall through -#endif // QT_NO_LINEEDIT - { - QPen oldPen = painter->pen(); - if (option->state & State_Enabled) { - painter->setPen(QPen(option->palette.background(), 0)); - painter->drawRect(rect.adjusted(0, 0, 0, 0)); - painter->drawRect(rect.adjusted(1, 1, -1, -1)); - } else { - painter->fillRect(rect, option->palette.background()); - } - QRect r = rect.adjusted(0, 1, 0, -1); - painter->setPen(buttonShadowAlpha); - painter->drawLine(QPoint(r.left() + 2, r.top() - 1), QPoint(r.right() - 2, r.top() - 1)); - const QPoint points[8] = { - QPoint(r.right() - 1, r.top()), - QPoint(r.right(), r.top() + 1), - QPoint(r.right() - 1, r.bottom()), - QPoint(r.right(), r.bottom() - 1), - QPoint(r.left() + 1, r.top() ), - QPoint(r.left(), r.top() + 1), - QPoint(r.left() + 1, r.bottom() ), - QPoint(r.left(), r.bottom() - 1) - }; - painter->drawPoints(points, 8); - painter->setPen(QPen(option->palette.background().color(), 1)); - painter->drawLine(QPoint(r.left() + 2, r.top() + 1), QPoint(r.right() - 2, r.top() + 1)); - - if (option->state & State_HasFocus) { - QColor darkoutline = option->palette.highlight().color().darker(150); - QColor innerline = mergedColors(option->palette.highlight().color(), Qt::white); - painter->setPen(QPen(innerline, 0)); - painter->drawRect(rect.adjusted(1, 2, -2, -3)); - painter->setPen(QPen(darkoutline, 0)); - } - else { - QColor highlight = Qt::white; - highlight.setAlpha(130); - painter->setPen(option->palette.base().color().darker(120)); - painter->drawLine(QPoint(r.left() + 1, r.top() + 1), - QPoint(r.right() - 1, r.top() + 1)); - painter->drawLine(QPoint(r.left() + 1, r.top() + 1), - QPoint(r.left() + 1, r.bottom() - 1)); - painter->setPen(option->palette.base().color()); - painter->drawLine(QPoint(r.right() - 1, r.top() + 1), - QPoint(r.right() - 1, r.bottom() - 1)); - painter->setPen(highlight); - painter->drawLine(QPoint(r.left() + 1, r.bottom() + 1), - QPoint(r.right() - 1, r.bottom() + 1)); - painter->drawPoint(QPoint(r.left(), r.bottom())); - painter->drawPoint(QPoint(r.right(), r.bottom() )); - painter->setPen(QPen(darkOutline.lighter(115), 1)); - } - painter->drawLine(QPoint(r.left(), r.top() + 2), QPoint(r.left(), r.bottom() - 2)); - painter->drawLine(QPoint(r.right(), r.top() + 2), QPoint(r.right(), r.bottom() - 2)); - painter->drawLine(QPoint(r.left() + 2, r.bottom()), QPoint(r.right() - 2, r.bottom())); - const QPoint points2[4] = { - QPoint(r.right() - 1, r.bottom() - 1), - QPoint(r.right() - 1, r.top() + 1), - QPoint(r.left() + 1, r.bottom() - 1), - QPoint(r.left() + 1, r.top() + 1) - }; - painter->drawPoints(points2, 4); - painter->drawLine(QPoint(r.left() + 2, r.top()), QPoint(r.right() - 2, r.top())); - painter->setPen(oldPen); + case PE_FrameLineEdit: { + QPen oldPen = painter->pen(); + if (option->state & State_Enabled) { + painter->setPen(QPen(option->palette.background(), 0)); + painter->drawRect(rect.adjusted(0, 0, 0, 0)); + painter->drawRect(rect.adjusted(1, 1, -1, -1)); + } else { + painter->fillRect(rect, option->palette.background()); } + QRect r = rect.adjusted(0, 1, 0, -1); + painter->setPen(buttonShadowAlpha); + painter->drawLine(QPoint(r.left() + 2, r.top() - 1), QPoint(r.right() - 2, r.top() - 1)); + const QPoint points[8] = { + QPoint(r.right() - 1, r.top()), + QPoint(r.right(), r.top() + 1), + QPoint(r.right() - 1, r.bottom()), + QPoint(r.right(), r.bottom() - 1), + QPoint(r.left() + 1, r.top() ), + QPoint(r.left(), r.top() + 1), + QPoint(r.left() + 1, r.bottom() ), + QPoint(r.left(), r.bottom() - 1) + }; + painter->drawPoints(points, 8); + painter->setPen(QPen(option->palette.background().color(), 1)); + painter->drawLine(QPoint(r.left() + 2, r.top() + 1), QPoint(r.right() - 2, r.top() + 1)); + + if (option->state & State_HasFocus) { + QColor darkoutline = option->palette.highlight().color().darker(150); + QColor innerline = mergedColors(option->palette.highlight().color(), Qt::white); + painter->setPen(QPen(innerline, 0)); + painter->drawRect(rect.adjusted(1, 2, -2, -3)); + painter->setPen(QPen(darkoutline, 0)); + } else { + QColor highlight = Qt::white; + highlight.setAlpha(130); + painter->setPen(option->palette.base().color().darker(120)); + painter->drawLine(QPoint(r.left() + 1, r.top() + 1), + QPoint(r.right() - 1, r.top() + 1)); + painter->drawLine(QPoint(r.left() + 1, r.top() + 1), + QPoint(r.left() + 1, r.bottom() - 1)); + painter->setPen(option->palette.base().color()); + painter->drawLine(QPoint(r.right() - 1, r.top() + 1), + QPoint(r.right() - 1, r.bottom() - 1)); + painter->setPen(highlight); + painter->drawLine(QPoint(r.left() + 1, r.bottom() + 1), + QPoint(r.right() - 1, r.bottom() + 1)); + painter->drawPoint(QPoint(r.left(), r.bottom())); + painter->drawPoint(QPoint(r.right(), r.bottom() )); + painter->setPen(QPen(darkOutline.lighter(115), 1)); + } + painter->drawLine(QPoint(r.left(), r.top() + 2), QPoint(r.left(), r.bottom() - 2)); + painter->drawLine(QPoint(r.right(), r.top() + 2), QPoint(r.right(), r.bottom() - 2)); + painter->drawLine(QPoint(r.left() + 2, r.bottom()), QPoint(r.right() - 2, r.bottom())); + const QPoint points2[4] = { + QPoint(r.right() - 1, r.bottom() - 1), + QPoint(r.right() - 1, r.top() + 1), + QPoint(r.left() + 1, r.bottom() - 1), + QPoint(r.left() + 1, r.top() + 1) + }; + painter->drawPoints(points2, 4); + painter->drawLine(QPoint(r.left() + 2, r.top()), QPoint(r.right() - 2, r.top())); + painter->setPen(oldPen); break; - case PE_IndicatorCheckBox: + } +#endif // QT_NO_LINEEDIT + case PE_IndicatorCheckBox: { painter->save(); if (const QStyleOptionButton *checkbox = qstyleoption_cast(option)) { QRect checkRect; @@ -933,26 +928,26 @@ void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem, } painter->restore(); break; - case PE_IndicatorRadioButton: + } + case PE_IndicatorRadioButton: { painter->save(); - { - QRect checkRect = rect.adjusted(0, 0, 0, 0); - if (state & (State_On )) { - painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton)); - painter->drawImage(checkRect, QImage(qt_cleanlooks_radiobutton_checked)); - } - else if (state & State_Sunken) { - painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton)); - painter->setBrush(buttonShadow); - painter->setPen(Qt::NoPen); - painter->drawEllipse(rect.adjusted(1, 1, -1, -1)); } - else { - painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton)); - } + QRect checkRect = rect.adjusted(0, 0, 0, 0); + if (state & (State_On )) { + painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton)); + painter->drawImage(checkRect, QImage(qt_cleanlooks_radiobutton_checked)); + } + else if (state & State_Sunken) { + painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton)); + painter->setBrush(buttonShadow); + painter->setPen(Qt::NoPen); + painter->drawEllipse(rect.adjusted(1, 1, -1, -1)); } + else { + painter->drawImage(rect, QImage(qt_cleanlooks_radiobutton)); } painter->restore(); - break; - case PE_IndicatorToolBarHandle: + break; + } + case PE_IndicatorToolBarHandle: { painter->save(); if (option->state & State_Horizontal) { for (int i = rect.height()/5; i <= 4*(rect.height()/5) ; ++i) { @@ -966,8 +961,7 @@ void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem, painter->setPen(QPen(dark.lighter(110), 0)); painter->drawLine(x1, y, x2, y); } - } - else { //vertical toolbar + } else { //vertical toolbar for (int i = rect.width()/5; i <= 4*(rect.width()/5) ; ++i) { int x = rect.topLeft().x() + i + 1; int y1 = rect.topLeft().y() + 3; @@ -982,8 +976,9 @@ void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem, } painter->restore(); break; + } case PE_FrameDefaultButton: - case PE_FrameFocusRect: + case PE_FrameFocusRect: { if (const QStyleOptionFocusRect *focusFrame = qstyleoption_cast(option)) { if (!(focusFrame->state & State_KeyboardFocusChange)) return; @@ -1003,184 +998,172 @@ void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem, painter->restore(); } break; - case PE_PanelButtonCommand: - { - bool isDefault = false; - bool isFlat = false; - bool isDown = (option->state & State_Sunken) || (option->state & State_On); - QPen oldPen = painter->pen(); - QBrush oldBrush = painter->brush(); - QRect r; + } + case PE_PanelButtonCommand: { + bool isDefault = false; + bool isFlat = false; + bool isDown = (option->state & State_Sunken) || (option->state & State_On); + QPen oldPen = painter->pen(); + QBrush oldBrush = painter->brush(); + QRect r; - if (const QStyleOptionButton *button = qstyleoption_cast(option)) { - isDefault = (button->features & QStyleOptionButton::DefaultButton) && (button->state & State_Enabled); - isFlat = (button->features & QStyleOptionButton::Flat); - } - - if (isFlat && !isDown) { - if (isDefault) { - r = option->rect.adjusted(0, 1, 0, -1); - painter->setPen(QPen(Qt::black, 0)); - const QLine lines[4] = { - QLine(QPoint(r.left() + 2, r.top()), - QPoint(r.right() - 2, r.top())), - QLine(QPoint(r.left(), r.top() + 2), - QPoint(r.left(), r.bottom() - 2)), - QLine(QPoint(r.right(), r.top() + 2), - QPoint(r.right(), r.bottom() - 2)), - QLine(QPoint(r.left() + 2, r.bottom()), - QPoint(r.right() - 2, r.bottom())) - }; - painter->drawLines(lines, 4); - const QPoint points[4] = { - QPoint(r.right() - 1, r.bottom() - 1), - QPoint(r.right() - 1, r.top() + 1), - QPoint(r.left() + 1, r.bottom() - 1), - QPoint(r.left() + 1, r.top() + 1) - }; - painter->drawPoints(points, 4); - painter->setPen(oldPen); - } - return; - } - - BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("pushbutton-%1").arg(isDefault)) - r = rect.adjusted(0, 1, 0, -1); - - bool isEnabled = (option->state & State_Enabled); - - QColor highlightedGradientStartColor = option->palette.button().color().lighter(107); - QColor highlightedGradientMidColor = option->palette.button().color().lighter(105); - QColor highlightedGradientStopColor = buttonShadow.lighter(107); - QColor gradientStartColor = option->palette.button().color().lighter(108); - - QColor buttonColor = option->palette.button().color(); - QColor gradientMidColor = option->palette.button().color(); - QColor gradientStopColor; - gradientStopColor.setHsv(buttonColor.hue(), - qMin(255, (int)(buttonColor.saturation()*1.9)), - qMin(255, (int)(buttonColor.value()*0.96))); - - QRect gradRect = rect.adjusted(1, 2, -1, -2); - // gradient fill - QRect innerBorder = r.adjusted(1, 1, -1, 0); - - if (isDown) { - QBrush fillColor = gradientStopColor.darker(110); - if (option->palette.button().gradient()) - fillColor = option->palette.button(); - p->fillRect(gradRect, fillColor); - p->setPen(gradientStopColor.darker(125)); - p->drawLine(innerBorder.topLeft(), innerBorder.topRight()); - p->drawLine(innerBorder.topLeft(), innerBorder.bottomLeft()); - } else { - if (isEnabled && option->state & State_MouseOver ) { - qt_cleanlooks_draw_buttongradient(p, gradRect, - highlightedGradientStartColor, - highlightedGradientMidColor, - highlightedGradientStopColor, TopDown, option->palette.button()); - } else { - qt_cleanlooks_draw_buttongradient(p, gradRect, - gradientStartColor, - gradientMidColor, - gradientStopColor, TopDown, option->palette.button()); - } - } - - bool hasFocus = option->state & State_HasFocus; - - if (!isEnabled) - p->setPen(QPen(dark.lighter(115))); - else if (isDefault) - p->setPen(QPen(Qt::black, 1)); - else - p->setPen(QPen(darkOutline, 1)); - - p->drawLine(QPoint(r.left(), r.top() + 2), - QPoint(r.left(), r.bottom() - 2)); - p->drawLine(QPoint(r.right(), r.top() + 2), - QPoint(r.right(), r.bottom() - 2)); - p->drawLine(QPoint(r.left() + 2, r.bottom()), - QPoint(r.right() - 2, r.bottom())); - const QPoint points[4] = { - QPoint(r.right() - 1, r.bottom() - 1), - QPoint(r.right() - 1, r.top() + 1), - QPoint(r.left() + 1, r.bottom() - 1), - QPoint(r.left() + 1, r.top() + 1) - }; - p->drawPoints(points, 4); - - if (!isDefault && !hasFocus && isEnabled) - p->setPen(QPen(darkOutline.darker(110), 0)); - - p->drawLine(QPoint(r.left() + 2, r.top()), - QPoint(r.right() - 2, r.top())); - - QColor highlight = Qt::white; - highlight.setAlpha(110); - p->setPen(highlight); - p->drawLine(QPoint(r.left() + 1, r.top() + 2), - QPoint(r.left() + 1, r.bottom() - 2)); - p->drawLine(QPoint(r.left() + 3, r.bottom() + 1), - QPoint(r.right() - 3, r.bottom() + 1)); - - QColor topShadow = darkOutline; - topShadow.setAlpha(60); - - p->setPen(topShadow); - const QPoint points2[8] = { - QPoint(r.right(), r.top() + 1), - QPoint(r.right() - 1, r.top() ), - QPoint(r.right(), r.bottom() - 1), - QPoint(r.right() - 1, r.bottom() ), - QPoint(r.left() + 1, r.bottom()), - QPoint(r.left(), r.bottom() - 1), - QPoint(r.left() + 1, r.top()), - QPoint(r.left(), r.top() + 1) - }; - p->drawPoints(points2, 8); - - topShadow.setAlpha(30); - p->setPen(topShadow); - - p->drawLine(QPoint(r.right() - 1, r.top() + 2), - QPoint(r.right() - 1, r.bottom() - 2)); - p->drawLine(QPoint(r.left() + 2, r.top() - 1), - QPoint(r.right() - 2, r.top() - 1)); + if (const QStyleOptionButton *button = qstyleoption_cast(option)) { + isDefault = (button->features & QStyleOptionButton::DefaultButton) && (button->state & State_Enabled); + isFlat = (button->features & QStyleOptionButton::Flat); + } + if (isFlat && !isDown) { if (isDefault) { - r.adjust(-1, -1, 1, 1); - p->setPen(buttonShadowAlpha.darker(120)); + r = option->rect.adjusted(0, 1, 0, -1); + painter->setPen(QPen(Qt::black, 0)); const QLine lines[4] = { - QLine(r.topLeft() + QPoint(3, 0), r.topRight() - QPoint(3, 0)), - QLine(r.bottomLeft() + QPoint(3, 0), r.bottomRight() - QPoint(3, 0)), - QLine(r.topLeft() + QPoint(0, 3), r.bottomLeft() - QPoint(0, 3)), - QLine(r.topRight() + QPoint(0, 3), r.bottomRight() - QPoint(0, 3)) + QLine(QPoint(r.left() + 2, r.top()), QPoint(r.right() - 2, r.top())), + QLine(QPoint(r.left(), r.top() + 2), QPoint(r.left(), r.bottom() - 2)), + QLine(QPoint(r.right(), r.top() + 2), QPoint(r.right(), r.bottom() - 2)), + QLine(QPoint(r.left() + 2, r.bottom()), QPoint(r.right() - 2, r.bottom())) }; - p->drawLines(lines, 4); - const QPoint points3[8] = { - r.topRight() + QPoint(-2, 1), - r.topRight() + QPoint(-1, 2), - r.bottomRight() + QPoint(-1, -2), - r.bottomRight() + QPoint(-2, -1), - r.topLeft() + QPoint(1, 2), - r.topLeft() + QPoint(2, 1), - r.bottomLeft() + QPoint(1, -2), - r.bottomLeft() + QPoint(2, -1) + painter->drawLines(lines, 4); + const QPoint points[4] = { + QPoint(r.right() - 1, r.bottom() - 1), + QPoint(r.right() - 1, r.top() + 1), + QPoint(r.left() + 1, r.bottom() - 1), + QPoint(r.left() + 1, r.top() + 1) }; - p->drawPoints(points3, 8); + painter->drawPoints(points, 4); + painter->setPen(oldPen); } - painter->setPen(oldPen); - painter->setBrush(oldBrush); - END_STYLE_PIXMAPCACHE + return; } + + BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("pushbutton-%1").arg(isDefault)) + r = rect.adjusted(0, 1, 0, -1); + + bool isEnabled = (option->state & State_Enabled); + + QColor highlightedGradientStartColor = option->palette.button().color().lighter(107); + QColor highlightedGradientMidColor = option->palette.button().color().lighter(105); + QColor highlightedGradientStopColor = buttonShadow.lighter(107); + QColor gradientStartColor = option->palette.button().color().lighter(108); + + QColor buttonColor = option->palette.button().color(); + QColor gradientMidColor = option->palette.button().color(); + QColor gradientStopColor; + gradientStopColor.setHsv(buttonColor.hue(), + qMin(255, (int)(buttonColor.saturation()*1.9)), + qMin(255, (int)(buttonColor.value()*0.96))); + + QRect gradRect = rect.adjusted(1, 2, -1, -2); + // gradient fill + QRect innerBorder = r.adjusted(1, 1, -1, 0); + + if (isDown) { + QBrush fillColor = gradientStopColor.darker(110); + if (option->palette.button().gradient()) + fillColor = option->palette.button(); + p->fillRect(gradRect, fillColor); + p->setPen(gradientStopColor.darker(125)); + p->drawLine(innerBorder.topLeft(), innerBorder.topRight()); + p->drawLine(innerBorder.topLeft(), innerBorder.bottomLeft()); + } else { + if (isEnabled && option->state & State_MouseOver ) { + qt_cleanlooks_draw_buttongradient(p, gradRect, + highlightedGradientStartColor, + highlightedGradientMidColor, + highlightedGradientStopColor, TopDown, option->palette.button()); + } else { + qt_cleanlooks_draw_buttongradient(p, gradRect, + gradientStartColor, + gradientMidColor, + gradientStopColor, TopDown, option->palette.button()); + } + } + + bool hasFocus = option->state & State_HasFocus; + + if (!isEnabled) + p->setPen(QPen(dark.lighter(115))); + else if (isDefault) + p->setPen(QPen(Qt::black, 1)); + else + p->setPen(QPen(darkOutline, 1)); + + p->drawLine(QPoint(r.left(), r.top() + 2), QPoint(r.left(), r.bottom() - 2)); + p->drawLine(QPoint(r.right(), r.top() + 2), QPoint(r.right(), r.bottom() - 2)); + p->drawLine(QPoint(r.left() + 2, r.bottom()), QPoint(r.right() - 2, r.bottom())); + const QPoint points[4] = { + QPoint(r.right() - 1, r.bottom() - 1), + QPoint(r.right() - 1, r.top() + 1), + QPoint(r.left() + 1, r.bottom() - 1), + QPoint(r.left() + 1, r.top() + 1) + }; + p->drawPoints(points, 4); + + if (!isDefault && !hasFocus && isEnabled) + p->setPen(QPen(darkOutline.darker(110), 0)); + + p->drawLine(QPoint(r.left() + 2, r.top()), QPoint(r.right() - 2, r.top())); + + QColor highlight = Qt::white; + highlight.setAlpha(110); + p->setPen(highlight); + p->drawLine(QPoint(r.left() + 1, r.top() + 2), QPoint(r.left() + 1, r.bottom() - 2)); + p->drawLine(QPoint(r.left() + 3, r.bottom() + 1), QPoint(r.right() - 3, r.bottom() + 1)); + + QColor topShadow = darkOutline; + topShadow.setAlpha(60); + + p->setPen(topShadow); + const QPoint points2[8] = { + QPoint(r.right(), r.top() + 1), + QPoint(r.right() - 1, r.top() ), + QPoint(r.right(), r.bottom() - 1), + QPoint(r.right() - 1, r.bottom() ), + QPoint(r.left() + 1, r.bottom()), + QPoint(r.left(), r.bottom() - 1), + QPoint(r.left() + 1, r.top()), + QPoint(r.left(), r.top() + 1) + }; + p->drawPoints(points2, 8); + + topShadow.setAlpha(30); + p->setPen(topShadow); + + p->drawLine(QPoint(r.right() - 1, r.top() + 2), + QPoint(r.right() - 1, r.bottom() - 2)); + p->drawLine(QPoint(r.left() + 2, r.top() - 1), + QPoint(r.right() - 2, r.top() - 1)); + + if (isDefault) { + r.adjust(-1, -1, 1, 1); + p->setPen(buttonShadowAlpha.darker(120)); + const QLine lines[4] = { + QLine(r.topLeft() + QPoint(3, 0), r.topRight() - QPoint(3, 0)), + QLine(r.bottomLeft() + QPoint(3, 0), r.bottomRight() - QPoint(3, 0)), + QLine(r.topLeft() + QPoint(0, 3), r.bottomLeft() - QPoint(0, 3)), + QLine(r.topRight() + QPoint(0, 3), r.bottomRight() - QPoint(0, 3)) + }; + p->drawLines(lines, 4); + const QPoint points3[8] = { + r.topRight() + QPoint(-2, 1), + r.topRight() + QPoint(-1, 2), + r.bottomRight() + QPoint(-1, -2), + r.bottomRight() + QPoint(-2, -1), + r.topLeft() + QPoint(1, 2), + r.topLeft() + QPoint(2, 1), + r.bottomLeft() + QPoint(1, -2), + r.bottomLeft() + QPoint(2, -1) + }; + p->drawPoints(points3, 8); + } + painter->setPen(oldPen); + painter->setBrush(oldBrush); + END_STYLE_PIXMAPCACHE break; + } #ifndef QT_NO_TABBAR - case PE_FrameTabWidget: - painter->save(); - { - painter->fillRect(option->rect, tabFrameColor); - } + case PE_FrameTabWidget: { + painter->save(); + painter->fillRect(option->rect, tabFrameColor); #ifndef QT_NO_TABWIDGET if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast(option)) { QColor borderColor = darkOutline.lighter(110); @@ -1202,20 +1185,20 @@ void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem, twf->rect.top(), twf->tabBarSize.width(), borderThickness); } - break ; + break; case QTabBar::RoundedWest: tabBarRect = QRect(twf->rect.left(), twf->rect.top() + twf->leftCornerWidgetSize.height(), borderThickness, twf->tabBarSize.height()); tabBarRect = tabBarRect; //adjust - break ; + break; case QTabBar::RoundedEast: tabBarRect = QRect(twf->rect.right() - borderThickness + 1, twf->rect.top() + twf->leftCornerWidgetSize.height(), 0, twf->tabBarSize.height()); - break ; + break; case QTabBar::RoundedSouth: if (reverse) { tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1, @@ -1291,22 +1274,22 @@ void QCleanlooksStyle::drawPrimitive(PrimitiveElement elem, painter->drawPoints(points, 6); } #endif // QT_NO_TABWIDGET - painter->restore(); - break ; + painter->restore(); + break; + } case PE_FrameStatusBarItem: break; - case PE_IndicatorTabClose: - { - Q_D(const QCleanlooksStyle); - if (d->tabBarcloseButtonIcon.isNull()) - d->tabBarcloseButtonIcon = standardIcon(SP_DialogCloseButton, option, widget); - if ((option->state & State_Enabled) && (option->state & State_MouseOver)) - proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget); - QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(16, 16), QIcon::Normal, QIcon::On); - proxy()->drawItemPixmap(painter, option->rect, Qt::AlignCenter, pixmap); - } + case PE_IndicatorTabClose: { + Q_D(const QCleanlooksStyle); + if (d->tabBarcloseButtonIcon.isNull()) + d->tabBarcloseButtonIcon = standardIcon(SP_DialogCloseButton, option, widget); + if ((option->state & State_Enabled) && (option->state & State_MouseOver)) + proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget); + QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(16, 16), QIcon::Normal, QIcon::On); + proxy()->drawItemPixmap(painter, option->rect, Qt::AlignCenter, pixmap); break; + } #endif // QT_NO_TABBAR default: