コード例 #1
0
void QCommonStyle_QtDShell::__override_drawItemPixmap(QPainter*  painter0, const QRect&  rect1, int  alignment2, const QPixmap&  pixmap3, bool static_call) const
{
    if (static_call) {
        QStyle::drawItemPixmap((QPainter* )painter0, (const QRect& )rect1, (int )alignment2, (const QPixmap& )pixmap3);
    } else {
        drawItemPixmap((QPainter* )painter0, (const QRect& )rect1, (int )alignment2, (const QPixmap& )pixmap3);
    }
}
コード例 #2
0
void
Style::drawComboBoxLabel(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
    ASSURE_OPTION(cb, ComboBox);
    OPT_ENABLED

    QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
    painter->save();
    painter->setClipRect(editRect);

    if (!(cb->currentIcon.isNull() || cb->iconSize.isNull()))
    {   // icon ===============================================
        QIcon::Mode mode = isEnabled ? QIcon::Normal : QIcon::Disabled;
        QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
        QRect iconRect(editRect);
        iconRect.setWidth(cb->iconSize.width() + 4);
        iconRect = alignedRect( cb->direction, Qt::AlignLeft | Qt::AlignVCenter, iconRect.size(), editRect);
//       if (cb->editable)
//          painter->fillRect(iconRect, opt->palette.brush(QPalette::Base));
        drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);

        if (cb->direction == Qt::LeftToRight)
            editRect.setLeft(editRect.left() + cb->iconSize.width() + 4);
        else
            editRect.setRight(editRect.right() - (cb->iconSize.width() + 4));
    }

    if (!cb->currentText.isEmpty() && !cb->editable)
    {   // text ==================================================
        if (cb->frame)
        {
            OPT_FOCUS
            if (animStep < 0)
            {
                OPT_HOVER
                animStep = hover ? 6 : 0;
            }
            else
            {
                if (const QComboBox* combo = qobject_cast<const QComboBox*>(widget))
                if (combo->view() && ((QWidget*)(combo->view()))->isVisible())
                    animStep = 6;
            }
            editRect.adjust(F(3),0, -F(3), -F(1)*(config.chooser.layer != Sunken));
            // trick btnFg
            const int btn_layer = config.btn.layer;
            config.btn.layer = config.chooser.layer;
            painter->setPen(btnFg(PAL, isEnabled, hasFocus, animStep));
            config.btn.layer = btn_layer;
        }
        int tf = Qt::AlignCenter;
        if ( !((cb->subControls & SC_ComboBoxFrame) && cb->frame) )
            tf = Qt::AlignVCenter | (cb->direction == Qt::LeftToRight ? Qt::AlignLeft : Qt::AlignRight);
        drawItemText(painter, editRect, tf, PAL, isEnabled, cb->currentText);
    }
コード例 #3
0
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option,
                                 QPainter *painter, const QWidget *widget) const {
    if (!panelWidget(widget))
        return d->style->drawControl(element, option, painter, widget);

    switch (element) {
    case CE_MenuBarItem:
        painter->save();
        if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
            QColor highlightOutline = StyleHelper::borderColor().lighter(120);
            bool act = mbi->state & State_Selected && mbi->state & State_Sunken;
            bool dis = !(mbi->state & State_Enabled);
            StyleHelper::menuGradient(painter, option->rect, option->rect);
            QStyleOptionMenuItem item = *mbi;
            item.rect = mbi->rect;
            QPalette pal = mbi->palette;
            pal.setBrush(QPalette::ButtonText, dis ? Qt::gray : Qt::black);
            item.palette = pal;
            QCommonStyle::drawControl(element, &item, painter, widget);
            QRect r = option->rect;

            if (act) {
                // Fill|
                QColor baseColor = StyleHelper::baseColor();
                QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft());
                grad.setColorAt(0, baseColor.lighter(120));
                grad.setColorAt(1, baseColor.lighter(130));
                painter->fillRect(option->rect.adjusted(1, 1, -1, 0), grad);

                // Outline
                painter->setPen(QPen(highlightOutline, 0));
                painter->drawLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom()));
                painter->drawLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom()));
                painter->drawLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top()));
                highlightOutline.setAlpha(60);
                painter->setPen(QPen(highlightOutline, 0));
                painter->drawPoint(r.topLeft());
                painter->drawPoint(r.topRight());

                QPalette pal = mbi->palette;
                uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
                if (!styleHint(SH_UnderlineShortcut, mbi, widget))
                    alignment |= Qt::TextHideMnemonic;
                pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60));
                drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
                pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white);
                drawItemText(painter, item.rect, alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
            }
        }
        painter->restore();
        break;

    case CE_ComboBoxLabel:
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
            if (panelWidget(widget)) {
                QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
                QPalette customPal = cb->palette;

                if (!cb->currentIcon.isNull()) {
                    QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
                                       : QIcon::Disabled;
                    QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
                    QRect iconRect(editRect);
                    iconRect.setWidth(cb->iconSize.width() + 4);
                    iconRect = alignedRect(cb->direction,
                                           Qt::AlignLeft | Qt::AlignVCenter,
                                           iconRect.size(), editRect);
                    if (cb->editable)
                        painter->fillRect(iconRect, customPal.brush(QPalette::Base));
                    drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);

                    if (cb->direction == Qt::RightToLeft)
                        editRect.translate(-4 - cb->iconSize.width(), 0);
                    else
                        editRect.translate(cb->iconSize.width() + 4, 0);

                    // Reserve some space for the down-arrow
                    editRect.adjust(0, 0, -13, 0);
                }

                customPal.setBrush(QPalette::All, QPalette::ButtonText, QColor(0, 0, 0, 70));

                QString text = option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, editRect.width());
                drawItemText(painter, editRect.translated(0, 1),
                             visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter),
                             customPal, cb->state & State_Enabled, text, QPalette::ButtonText);
                customPal.setBrush(QPalette::All, QPalette::ButtonText, StyleHelper::panelTextColor());
                drawItemText(painter, editRect,
                             visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter),
                             customPal, cb->state & State_Enabled, text, QPalette::ButtonText);
            } else {
                d->style->drawControl(element, option, painter, widget);
            }
        }
        break;

    case CE_SizeGrip: {
        painter->save();
        QColor dark = Qt::white;
        dark.setAlphaF(0.1);
        int x, y, w, h;
        option->rect.getRect(&x, &y, &w, &h);
        int sw = qMin(h, w);
        if (h > w)
            painter->translate(0, h - w);
        else
            painter->translate(w - h, 0);
        int sx = x;
        int sy = y;
        int s = 4;
        painter->setPen(dark);
        if (option->direction == Qt::RightToLeft) {
            sx = x + sw;
            for (int i = 0; i < 4; ++i) {
                painter->drawLine(x, sy, sx, sw);
                sx -= s;
                sy += s;
            }
        } else {
            for (int i = 0; i < 4; ++i) {
                painter->drawLine(sx, sw, sw, sy);
                sx += s;
                sy += s;
            }
        }
        painter->restore();
    }
    break;

    case CE_MenuBarEmptyArea: {
        StyleHelper::menuGradient(painter, option->rect, option->rect);
        painter->save();
        painter->setPen(StyleHelper::borderColor());
        painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
        painter->restore();
    }
    break;

    case CE_ToolBar: {
        QString key;
        key.sprintf("mh_toolbar %d %d %d", option->rect.width(), option->rect.height(), StyleHelper::baseColor().rgb());;

        QPixmap pixmap;
        QPainter *p = painter;
        QRect rect = option->rect;
        if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
            pixmap = QPixmap(option->rect.size());
            p = new QPainter(&pixmap);
            rect = QRect(0, 0, option->rect.width(), option->rect.height());
        }

        bool horizontal = option->state & State_Horizontal;
        // Map offset for global window gradient
        QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) -
                        widget->mapToGlobal(option->rect.topLeft());
        QRect gradientSpan;
        if (widget) {
            gradientSpan = QRect(offset, widget->window()->size());
        }
        if (horizontal)
            StyleHelper::horizontalGradient(p, gradientSpan, rect);
        else
            StyleHelper::verticalGradient(p, gradientSpan, rect);

        painter->setPen(StyleHelper::borderColor());

        if (horizontal) {
            // Note: This is a hack to determine if the
            // toolbar should draw the top or bottom outline
            // (needed for the find toolbar for instance)
            QColor lighter(255, 255, 255, 40);
            if (widget && widget->property("topBorder").toBool()) {
                p->drawLine(rect.topLeft(), rect.topRight());
                p->setPen(lighter);
                p->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1));
            } else {
                p->drawLine(rect.bottomLeft(), rect.bottomRight());
                p->setPen(lighter);
                p->drawLine(rect.topLeft(), rect.topRight());
            }
        } else {
            p->drawLine(rect.topLeft(), rect.bottomLeft());
            p->drawLine(rect.topRight(), rect.bottomRight());
        }

        if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
            painter->drawPixmap(rect.topLeft(), pixmap);
            p->end();
            delete p;
            QPixmapCache::insert(key, pixmap);
        }
    }
    break;

    default:
        d->style->drawControl(element, option, painter, widget);
        break;
    }
}
コード例 #4
0
void WindowsModernStyle::drawControl( ControlElement element, const QStyleOption* option,
	QPainter* painter, const QWidget* widget ) const
{
	switch ( element ) {
		case CE_MenuBarEmptyArea:
			return;

		case CE_MenuBarItem:
			if ( option->state & QStyle::State_Sunken && option->state & QStyle::State_Enabled ) {
				painter->setPen( m_colorMenuBorder );
				QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
				gradient.setColorAt( 0.0, m_colorMenuTitleBegin );
				gradient.setColorAt( 1.0, m_colorMenuTitleEnd );
				painter->setBrush( gradient );
				painter->drawRect( option->rect.adjusted( 0, 0, -1, 0 ) );
			} else if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) {
				painter->setPen( m_colorItemBorder );
				QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
				gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
				gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
				painter->setBrush( gradient );
				painter->drawRect( option->rect.adjusted( 0, 0, -1, -1 ) );
			}
			if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) {
				int flags = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
				if ( !styleHint( SH_UnderlineShortcut, option, widget ) )
					flags |= Qt::TextHideMnemonic;
				if ( !optionItem->icon.isNull() ) {
					QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), QIcon::Normal );
					drawItemPixmap( painter, option->rect, flags, pixmap );
				} else {
					drawItemText( painter, option->rect, flags, option->palette, true, optionItem->text, QPalette::Text );
				}
			}
			return;

		case CE_MenuEmptyArea:
			painter->fillRect( option->rect, m_colorMenuBackground );
			return;

		case CE_MenuItem: {
			if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) {
				painter->setPen( m_colorItemBorder );
				painter->setBrush( m_colorItemBackgroundBegin );
				painter->drawRect( option->rect.adjusted( 1, 0, -3, -1 ) );
			} else {
				QLinearGradient gradient( QPoint( 0, 0 ), QPoint( 25, 0 ) );
				gradient.setColorAt( 0.0, m_colorBarBegin );
				gradient.setColorAt( 1.0, m_colorBarEnd );
				QRect margin = option->rect;
				margin.setWidth( 25 );
				painter->fillRect( margin, gradient );
				QRect background = option->rect;
				background.setLeft( margin.right() + 1 );
				painter->fillRect( background, m_colorMenuBackground );
			}
			if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) {
				if ( optionItem->menuItemType == QStyleOptionMenuItem::Separator ) {
					painter->setPen( m_colorSeparator );
					painter->drawLine( option->rect.left() + 32, ( option->rect.top() + option->rect.bottom() ) / 2,
						option->rect.right(), ( option->rect.top() + option->rect.bottom() ) / 2 );
					return;
				}
				QRect checkRect = option->rect.adjusted( 2, 1, -2, -2 );
				checkRect.setWidth( 20 );
				if ( optionItem->checked && option->state & QStyle::State_Enabled ) {
					painter->setPen( m_colorItemBorder );
					if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled )
						painter->setBrush( m_colorItemSunkenBegin );
					else
						painter->setBrush( m_colorItemCheckedBegin );
					painter->drawRect( checkRect );
				}
				if ( !optionItem->icon.isNull() ) {
					QIcon::Mode mode;
					if ( optionItem->state & State_Enabled )
						mode = ( optionItem->state & State_Selected ) ? QIcon::Active : QIcon::Normal;
					else
						mode = QIcon::Disabled;
					QIcon::State state = optionItem->checked ? QIcon::On : QIcon::Off;
					QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), mode, state );
					QRect rect = pixmap.rect();
					rect.moveCenter( checkRect.center() );
					painter->drawPixmap( rect.topLeft(), pixmap );
				} else if ( optionItem->checked ) {
					QStyleOption optionCheckMark;
					optionCheckMark.initFrom( widget );
					optionCheckMark.rect = checkRect;
					if ( !( option->state & State_Enabled ) )
						optionCheckMark.palette.setBrush( QPalette::Text, optionCheckMark.palette.brush( QPalette::Disabled, QPalette::Text ) );
					drawPrimitive( PE_IndicatorMenuCheckMark, &optionCheckMark, painter, widget );
				}
				QRect textRect = option->rect.adjusted( 32, 1, -16, -1 );
				int flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
				if ( !styleHint( SH_UnderlineShortcut, option, widget ) )
					flags |= Qt::TextHideMnemonic;
				QString text = optionItem->text;
				int pos = text.indexOf( '\t' );
				if ( pos >= 0 ) {
					drawItemText( painter, textRect, flags | Qt::AlignRight, option->palette, option->state & State_Enabled,
						text.mid( pos + 1 ), QPalette::Text );
					text = text.left( pos );
				}
				drawItemText( painter, textRect, flags, option->palette, option->state & State_Enabled, text, QPalette::Text );
				if ( optionItem->menuItemType == QStyleOptionMenuItem::SubMenu ) {
					QStyleOption optionArrow;
					optionArrow.initFrom( widget );
					optionArrow.rect = option->rect.adjusted( 0, 4, -4, -4 );
					optionArrow.rect.setLeft( option->rect.right() - 12 );
					optionArrow.state = option->state & State_Enabled;
					drawPrimitive( PE_IndicatorArrowRight, &optionArrow, painter, widget );
				}
			}
			return;
		}

		case CE_ToolBar: {
			QRect rect = option->rect;
			bool vertical = false;
			if ( const QToolBar* toolBar = qobject_cast<const QToolBar*>( widget ) ) {
				vertical = ( toolBar->orientation() == Qt::Vertical );
				if ( vertical )
					rect.setBottom( toolBar->childrenRect().bottom() + 2 );
				else
					rect.setRight( toolBar->childrenRect().right() + 2 );
			}
			painter->save();
			QRegion region = rect.adjusted( 2, 0, -2, 0 );
			region += rect.adjusted( 0, 2, 0, -2 );
			region += rect.adjusted( 1, 1, -1, -1 );
			painter->setClipRegion( region );
			QLinearGradient gradient;
			if ( vertical )
				gradient = QLinearGradient( rect.topLeft(), rect.topRight() );
			else
				gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
			gradient.setColorAt( 0.0, m_colorBarBegin );
			gradient.setColorAt( 0.4, m_colorBarMiddle );
			gradient.setColorAt( 0.6, m_colorBarMiddle );
			gradient.setColorAt( 1.0, m_colorBarEnd );
			painter->fillRect( rect, gradient );

			painter->setPen( vertical ? m_colorBorderLight : m_colorBorder );
			painter->drawLine( rect.bottomLeft() + QPoint( 2, 0 ), rect.bottomRight() - QPoint( 2, 0 ) );
			painter->setPen( vertical ? m_colorBorder : m_colorBorderLight );
			painter->drawLine( rect.topRight() + QPoint( 0, 2 ), rect.bottomRight() - QPoint( 0, 2 ) );
			painter->setPen( m_colorBorderLight );
			painter->drawPoint( rect.bottomRight() - QPoint( 1, 1 ) );
			painter->restore();
			return;
		}

		case CE_DockWidgetTitle: {
			QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
			gradient.setColorAt( 0.0, m_colorBarBegin );
			gradient.setColorAt( 1.0, m_colorBarEnd );
			painter->fillRect( option->rect, gradient );
			if ( const QStyleOptionDockWidget* optionDockWidget = qstyleoption_cast<const QStyleOptionDockWidget*>( option ) ) {
				QRect rect = option->rect.adjusted( 6, 0, -4, 0 );
				if ( optionDockWidget->closable )
					rect.adjust( 0, 0, -16, 0 );
				if ( optionDockWidget->floatable )
					rect.adjust( 0, 0, -16, 0 );
				QString text = painter->fontMetrics().elidedText( optionDockWidget->title, Qt::ElideRight, rect.width() );
				drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignVCenter, option->palette,
					option->state & State_Enabled, text, QPalette::WindowText );
			}
			return;
		}

		case CE_TabBarTabShape:
			if ( isStyledTabBar( widget ) ) {
				bool firstTab = false;
				bool lastTab = false;
				bool bottom = false;
				if ( const QStyleOptionTab* optionTab = qstyleoption_cast<const QStyleOptionTab*>( option ) ) {
					if ( optionTab->position == QStyleOptionTab::Beginning )
						firstTab = true;
					else if ( optionTab->position == QStyleOptionTab::End )
						lastTab = true;
					else if ( optionTab->position == QStyleOptionTab::OnlyOneTab )
						firstTab = lastTab = true;
					if ( optionTab->shape == QTabBar::RoundedSouth )
						bottom = true;
				}
				QRect rect = option->rect;
				painter->save();
				if ( option->state & State_Selected ) {
					if ( bottom )
						rect.adjust( firstTab ? 0 : -2, -1, lastTab ? -1 : 1, -1 );
					else
						rect.adjust( firstTab ? 0 : -2, 0, lastTab ? -1 : 1, 1 );
				} else {
					if ( bottom ) {
						rect.adjust( 0, -1, lastTab ? -1 : 0, -2 );
						painter->setClipRect( rect.adjusted( 0, 1, 1, 1 ) );
					} else {
						rect.adjust( 0, 1, lastTab ? -1 : 0, 0 );
						painter->setClipRect( rect.adjusted( 0, 0, 1, 0 ) );
					}
				}
				QLinearGradient gradient;
				if ( bottom )
					gradient = QLinearGradient( rect.bottomLeft(), rect.topLeft() );
				else
					gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
				if ( option->state & State_Selected ) {
					gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
					gradient.setColorAt( 1.0, option->palette.window().color() );
					painter->setPen( m_colorBorder );
				} else if ( option->state & State_MouseOver && option->state & State_Enabled ) {
					gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
					gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
					painter->setPen( m_colorBorderLight );
				} else {
					gradient.setColorAt( 0.0, m_colorBarMiddle );
					gradient.setColorAt( 1.0, m_colorBarEnd );
					painter->setPen( m_colorBorderLight );
				}
				painter->setBrush( gradient );
				painter->drawRect( rect );
				painter->restore();
				return;
			}
			break;

		case CE_ToolBoxTabShape: {
			QRect rect = option->rect.adjusted( 0, 0, -1, -1 );
			QLinearGradient gradient( rect.topLeft(), rect.bottomLeft() );
			if ( option->state & QStyle::State_Sunken ) {
				gradient.setColorAt( 0.0, m_colorItemSunkenBegin );
				gradient.setColorAt( 1.0, m_colorItemSunkenEnd );
				painter->setPen( m_colorBorder );
			} else if ( option->state & State_MouseOver && option->state & State_Enabled ) {
				gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
				gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
				painter->setPen( m_colorBorder );
			} else {
				gradient.setColorAt( 0.0, m_colorBarMiddle );
				gradient.setColorAt( 1.0, m_colorBarEnd );
				painter->setPen( m_colorBorderLight );
			}
			painter->setBrush( gradient );
			painter->drawRect( rect );
			return;
		}

		case CE_Splitter:
			if ( qobject_cast<const QMainWindow*>( widget->window() ) )
				return;
			break;

		default:
			break;
	}

	if ( useVista() )
		QWindowsVistaStyle::drawControl( element, option, painter, widget );
	else
		QWindowsXPStyle::drawControl( element, option, painter, widget );
}
コード例 #5
0
void DarkStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
                                 QPainter *painter, const QWidget *widget) const
{
	switch (control)
	{
#if 0
		case CC_TitleBar:
			if (const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) 
			{
				painter->save();
				bool active = (titleBar->titleBarState & State_Active);
				QRect fullRect = titleBar->rect;
				
				// ### use palette colors instead
				//QColor titleBarGradientStart(active ? 0x3b508a : 0x6e6e6e);
				//QColor titleBarGradientStop(active ? 0x5d6e9e : 0x818181);
				//QColor titleBarFrameBorder(0x393939);
				//QColor titleBarAlphaCorner(active ? 0x4b5e7f : 0x6a6a6a);
				//QColor titleBarInnerTopLine(active ? 0x8e98ba : 0xa4a4a4);
				//QColor titleBarInnerInnerTopLine(active ? 0x57699b : 0x808080);
				//QColor leftCorner(active ? 0x6f7ea8 : 0x8e8e8e);
				//QColor rightCorner(active ? 0x44537d : 0x676767);
				QColor textColor(active ? 0x282e40 : 0x282e40);
				QColor textAlphaColor(active ? 0x3f4862 : 0x3f4862);
				
				
				// max button
				if ((titleBar->subControls & SC_TitleBarMaxButton)
                    && (titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint)
                    && !(titleBar->titleBarState & Qt::WindowMaximized)) {
					bool hover = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_MouseOver);
					bool sunken = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_Sunken);
					
					QRect maxButtonRect = subControlRect(CC_TitleBar, titleBar, SC_TitleBarMaxButton, widget);
					QImage image(Maximize_xpm);
					//qt_plastique_draw_mdibutton(painter, titleBar, maxButtonRect, hover, sunken);
					painter->drawImage(maxButtonRect, image);
					
					//int xoffset = maxButtonRect.width() / 3;
					//int yoffset = maxButtonRect.height() / 3;
					
					//QRect maxButtonIconRect(maxButtonRect.left() + xoffset, maxButtonRect.top() + yoffset,
					//                        maxButtonRect.width() - xoffset * 2, maxButtonRect.height() - yoffset * 2);
					
					//painter->setPen(textColor);
					//painter->drawRect(maxButtonIconRect.adjusted(0, 0, -1, -1));
					//painter->drawLine(maxButtonIconRect.left() + 1, maxButtonIconRect.top() + 1,
					//                  maxButtonIconRect.right() - 1, maxButtonIconRect.top() + 1);
					//painter->setPen(textAlphaColor);
					//const QPoint points[4] = {
					//    maxButtonIconRect.topLeft(), maxButtonIconRect.topRight(),
					//    maxButtonIconRect.bottomLeft(), maxButtonIconRect.bottomRight() };
					//painter->drawPoints(points, 4);
				}
				
				// close button
				if (titleBar->subControls & SC_TitleBarCloseButton && titleBar->titleBarFlags & Qt::WindowSystemMenuHint) {
					bool hover = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_MouseOver);
					bool sunken = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_Sunken);
					
					QRect closeButtonRect = subControlRect(CC_TitleBar, titleBar, SC_TitleBarCloseButton, widget);
					QImage image(Office2007_FrameCaptionClose23_xpm);
					//qt_plastique_draw_mdibutton(painter, titleBar, closeButtonRect, hover, sunken);
					painter->drawImage(closeButtonRect, image);
					
					//int xoffset = closeButtonRect.width() / 3;
					//int yoffset = closeButtonRect.height() / 3;
					
					//QRect closeIconRect(closeButtonRect.left() + xoffset, closeButtonRect.top() + yoffset,
					//                    closeButtonRect.width() - xoffset * 2, closeButtonRect.height() - yoffset * 2);
					
					//painter->setPen(textAlphaColor);
					//{
					//    const QLine lines[4] = {
					//        QLine(closeIconRect.left() + 1, closeIconRect.top(),
					//              closeIconRect.right(), closeIconRect.bottom() - 1),
					//        QLine(closeIconRect.left(), closeIconRect.top() + 1,
					//              closeIconRect.right() - 1, closeIconRect.bottom()),
					//        QLine(closeIconRect.right() - 1, closeIconRect.top(),
					//              closeIconRect.left(), closeIconRect.bottom() - 1),
					//        QLine(closeIconRect.right(), closeIconRect.top() + 1,
					//              closeIconRect.left() + 1, closeIconRect.bottom()) };
					//    painter->drawLines(lines, 4);
					//    const QPoint points[4] = {
					//        closeIconRect.topLeft(), closeIconRect.topRight(),
					//        closeIconRect.bottomLeft(), closeIconRect.bottomRight() };
					//    painter->drawPoints(points, 4);
					//}
					//painter->setPen(textColor);
					//{
					//    const QLine lines[2] = {
					//        QLine(closeIconRect.left() + 1, closeIconRect.top() + 1,
					//              closeIconRect.right() - 1, closeIconRect.bottom() - 1),
					//        QLine(closeIconRect.left() + 1, closeIconRect.bottom() - 1,
					//              closeIconRect.right() - 1, closeIconRect.top() + 1) };
					//    painter->drawLines(lines, 2);
					//}
				}
				
				// from qwindowsstyle.cpp
				if ((titleBar->subControls & SC_TitleBarSysMenu) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
					bool hover = (titleBar->activeSubControls & SC_TitleBarSysMenu) && (titleBar->state & State_MouseOver);
					bool sunken = (titleBar->activeSubControls & SC_TitleBarSysMenu) && (titleBar->state & State_Sunken);
					
					QRect iconRect = subControlRect(CC_TitleBar, titleBar, SC_TitleBarSysMenu, widget);
					if (hover)
						qt_plastique_draw_mdibutton(painter, titleBar, iconRect, hover, sunken);
					
					if (!titleBar->icon.isNull()) {
						titleBar->icon.paint(painter, iconRect);
					} else {
						QStyleOption tool(0);
						tool.palette = titleBar->palette;
						QPixmap pm = standardPixmap(SP_TitleBarMenuButton, &tool, widget);
						tool.rect = iconRect;
						painter->save();
						drawItemPixmap(painter, iconRect, Qt::AlignCenter, pm);
						painter->restore();
					}
				}
				
				painter->restore();
			}
			break;
#endif
			
		default:
			QPlastiqueStyle::drawComplexControl(control, option, painter, widget);
			break;
	}
}
コード例 #6
0
ファイル: manhattanstyle.cpp プロジェクト: Bfunni87/smartpay
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option,
                                 QPainter *painter, const QWidget *widget) const
{
    if (!panelWidget(widget))
        return QProxyStyle::drawControl(element, option, painter, widget);

    switch (element) {
    case CE_Splitter:
        painter->fillRect(option->rect, Utils::StyleHelper::borderColor());
        break;

    case CE_TabBarTabShape:
        // Most styles draw a single dark outline. This looks rather ugly when combined with our
        // single pixel dark separator so we adjust the first tab to compensate for this

        if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
            QStyleOptionTabV3 adjustedTab = *tab;
            if (tab->cornerWidgets == QStyleOptionTab::NoCornerWidgets && (
                    tab->position == QStyleOptionTab::Beginning ||
                    tab->position == QStyleOptionTab::OnlyOneTab))
            {
                if (option->direction == Qt::LeftToRight)
                    adjustedTab.rect = adjustedTab.rect.adjusted(-1, 0, 0, 0);
                else
                    adjustedTab.rect = adjustedTab.rect.adjusted(0, 0, 1 ,0);
            }
            QProxyStyle::drawControl(element, &adjustedTab, painter, widget);
            return;
        }
        break;

    case CE_MenuBarItem:
        painter->save();
        if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
            QColor highlightOutline = Utils::StyleHelper::borderColor().lighter(120);
            bool act = mbi->state & State_Selected && mbi->state & State_Sunken;
            bool dis = !(mbi->state & State_Enabled);
            Utils::StyleHelper::menuGradient(painter, option->rect, option->rect);
            QStyleOptionMenuItem item = *mbi;
            item.rect = mbi->rect;
            QPalette pal = mbi->palette;
            pal.setBrush(QPalette::ButtonText, dis ? Qt::gray : Qt::black);
            item.palette = pal;
            QCommonStyle::drawControl(element, &item, painter, widget);
            QRect r = option->rect;

            if (act) {
                // Fill|
                QColor baseColor = Utils::StyleHelper::baseColor();
                QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft());
                grad.setColorAt(0, baseColor.lighter(120));
                grad.setColorAt(1, baseColor.lighter(130));
                painter->fillRect(option->rect.adjusted(1, 1, -1, 0), grad);

                // Outline
                painter->setPen(QPen(highlightOutline, 0));
                painter->drawLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom()));
                painter->drawLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom()));
                painter->drawLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top()));
                highlightOutline.setAlpha(60);
                painter->setPen(QPen(highlightOutline, 0));
                painter->drawPoint(r.topLeft());
                painter->drawPoint(r.topRight());

                QPalette pal = mbi->palette;
                uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
                if (!styleHint(SH_UnderlineShortcut, mbi, widget))
                    alignment |= Qt::TextHideMnemonic;
                pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60));
                drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
                pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white);
                drawItemText(painter, item.rect, alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
            }
        }
        painter->restore();
        break;

    case CE_ComboBoxLabel:
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
            if (panelWidget(widget)) {
                painter->save();
                QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
                QPalette customPal = cb->palette;

                if (!cb->currentIcon.isNull()) {
                    QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
                                                                 : QIcon::Disabled;
                    QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
                    QRect iconRect(editRect);
                    iconRect.setWidth(cb->iconSize.width() + 4);
                    iconRect = alignedRect(cb->direction,
                                           Qt::AlignLeft | Qt::AlignVCenter,
                                           iconRect.size(), editRect);
                    if (cb->editable)
                        painter->fillRect(iconRect, customPal.brush(QPalette::Base));
                    drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);

                    if (cb->direction == Qt::RightToLeft)
                        editRect.translate(-4 - cb->iconSize.width(), 0);
                    else
                        editRect.translate(cb->iconSize.width() + 4, 0);

                    // Reserve some space for the down-arrow
                    editRect.adjust(0, 0, -13, 0);
                }

                QString text = option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, editRect.width());
                if ((option->state & State_Enabled)) {
                    painter->setPen(QColor(0, 0, 0, 70));
                    painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text);
                } else {
                    painter->setOpacity(0.8);
                }
                painter->setPen(Utils::StyleHelper::panelTextColor());
                painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text);

                painter->restore();
            } else {
                QProxyStyle::drawControl(element, option, painter, widget);
            }
        }
        break;

    case CE_SizeGrip: {
            painter->save();
            QColor dark = Qt::white;
            dark.setAlphaF(0.1);
            int x, y, w, h;
            option->rect.getRect(&x, &y, &w, &h);
            int sw = qMin(h, w);
            if (h > w)
                painter->translate(0, h - w);
            else
                painter->translate(w - h, 0);
            int sx = x;
            int sy = y;
            int s = 4;
            painter->setPen(dark);
            if (option->direction == Qt::RightToLeft) {
                sx = x + sw;
                for (int i = 0; i < 4; ++i) {
                    painter->drawLine(x, sy, sx, sw);
                    sx -= s;
                    sy += s;
                }
            } else {
                for (int i = 0; i < 4; ++i) {
                    painter->drawLine(sx, sw, sw, sy);
                    sx += s;
                    sy += s;
                }
            }
            painter->restore();
        }
        break;

    case CE_MenuBarEmptyArea: {
            Utils::StyleHelper::menuGradient(painter, option->rect, option->rect);
            painter->save();
            painter->setPen(Utils::StyleHelper::borderColor());
            painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
            painter->restore();
        }
        break;

    case CE_ToolBar:
        {
            QRect rect = option->rect;
            bool horizontal = option->state & State_Horizontal;
            rect = option->rect;

            // Map offset for global window gradient
            QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) -
                            widget->mapToGlobal(option->rect.topLeft());
            QRect gradientSpan;
            if (widget)
                gradientSpan = QRect(offset, widget->window()->size());

            bool drawLightColored = lightColored(widget);
            if (horizontal)
                Utils::StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored);
            else
                Utils::StyleHelper::verticalGradient(painter, gradientSpan, rect, drawLightColored);

            if (!drawLightColored)
                painter->setPen(Utils::StyleHelper::borderColor());
            else
                painter->setPen(QColor(0x888888));

            if (horizontal) {
                // Note: This is a hack to determine if the
                // toolbar should draw the top or bottom outline
                // (needed for the find toolbar for instance)
                QColor lighter(Utils::StyleHelper::sidebarHighlight());
                if (drawLightColored)
                    lighter = QColor(255, 255, 255, 180);
                if (widget && widget->property("topBorder").toBool()) {
                    painter->drawLine(rect.topLeft(), rect.topRight());
                    painter->setPen(lighter);
                    painter->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1));
                } else {
                    painter->drawLine(rect.bottomLeft(), rect.bottomRight());
                    painter->setPen(lighter);
                    painter->drawLine(rect.topLeft(), rect.topRight());
                }
            } else {
                painter->drawLine(rect.topLeft(), rect.bottomLeft());
                painter->drawLine(rect.topRight(), rect.bottomRight());
            }
        }
        break;

    default:
        QProxyStyle::drawControl(element, option, painter, widget);
        break;
    }
}
コード例 #7
0
ファイル: ManhattanStyle.cpp プロジェクト: ntadej/tano
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option,
                                 QPainter *painter, const QWidget *widget) const
{
    if (!panelWidget(widget))
        return QProxyStyle::drawControl(element, option, painter, widget);

    switch (element) {
    case CE_Splitter:
        painter->fillRect(option->rect, StyleHelper::borderColor());
        break;

    case CE_TabBarTabShape:
        // Most styles draw a single dark outline. This looks rather ugly when combined with our
        // single pixel dark separator so we adjust the first tab to compensate for this

        if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
            QStyleOptionTabV3 adjustedTab = *tab;
            if (tab->cornerWidgets == QStyleOptionTab::NoCornerWidgets && (
                    tab->position == QStyleOptionTab::Beginning ||
                    tab->position == QStyleOptionTab::OnlyOneTab))
            {
                if (option->direction == Qt::LeftToRight)
                    adjustedTab.rect = adjustedTab.rect.adjusted(-1, 0, 0, 0);
                else
                    adjustedTab.rect = adjustedTab.rect.adjusted(0, 0, 1 ,0);
            }
            QProxyStyle::drawControl(element, &adjustedTab, painter, widget);
            return;
        }
        break;

    case CE_MenuBarItem:
        painter->save();
        if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
            QColor highlightOutline = StyleHelper::borderColor().lighter(120);
            bool act = mbi->state & State_Sunken;
            bool dis = !(mbi->state & State_Enabled);
            StyleHelper::menuGradient(painter, option->rect, option->rect);
            QStyleOptionMenuItem item = *mbi;
            item.rect = mbi->rect;
            QPalette pal = mbi->palette;
            pal.setBrush(QPalette::ButtonText, dis ? Qt::gray : Qt::black);
            item.palette = pal;
            QCommonStyle::drawControl(element, &item, painter, widget);
            QRect r = option->rect;

            if (act) {
                // Fill|
                QColor baseColor = StyleHelper::baseColor();
                QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft());
                grad.setColorAt(0, baseColor.lighter(120));
                grad.setColorAt(1, baseColor.lighter(130));
                painter->fillRect(option->rect.adjusted(1, 1, -1, 0), grad);

                // Outline
                painter->setPen(QPen(highlightOutline, 0));
                painter->drawLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom()));
                painter->drawLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom()));
                painter->drawLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top()));
                highlightOutline.setAlpha(60);
                painter->setPen(QPen(highlightOutline, 0));
                painter->drawPoint(r.topLeft());
                painter->drawPoint(r.topRight());

                QPalette pal = mbi->palette;
                uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
                if (!styleHint(SH_UnderlineShortcut, mbi, widget))
                    alignment |= Qt::TextHideMnemonic;
                pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60));
                drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
                pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white);
                drawItemText(painter, item.rect, alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
            }
        }
        painter->restore();
        break;

    case CE_ComboBoxLabel:
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
            if (panelWidget(widget)) {
                painter->save();
                QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
                QPalette customPal = cb->palette;
                bool drawIcon = !(widget && widget->property("hideicon").toBool());

                if (!cb->currentIcon.isNull() && drawIcon) {
                    QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
                                                                 : QIcon::Disabled;
                    QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
                    QRect iconRect(editRect);
                    iconRect.setWidth(cb->iconSize.width() + 4);
                    iconRect = alignedRect(cb->direction,
                                           Qt::AlignLeft | Qt::AlignVCenter,
                                           iconRect.size(), editRect);
                    if (cb->editable)
                        painter->fillRect(iconRect, customPal.brush(QPalette::Base));
                    drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);

                    if (cb->direction == Qt::RightToLeft)
                        editRect.translate(-4 - cb->iconSize.width(), 0);
                    else
                        editRect.translate(cb->iconSize.width() + 4, 0);

                    // Reserve some space for the down-arrow
                    editRect.adjust(0, 0, -13, 0);
                }

                QLatin1Char asterisk('*');
                int elideWidth = editRect.width();

                bool notElideAsterisk = widget && widget->property("notelideasterisk").toBool()
                                        && cb->currentText.endsWith(asterisk)
                                        && option->fontMetrics.width(cb->currentText) > elideWidth;

                QString text;
                if (notElideAsterisk) {
                    elideWidth -= option->fontMetrics.width(asterisk);
                    text = asterisk;
                }
                text.prepend(option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, elideWidth));

                if ((option->state & State_Enabled)) {
                    painter->setPen(QColor(0, 0, 0, 70));
                    painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text);
                } else {
                    painter->setOpacity(0.8);
                }
                painter->setPen(StyleHelper::panelTextColor());
                painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text);

                painter->restore();
            } else {
                QProxyStyle::drawControl(element, option, painter, widget);
            }
        }
        break;

    case CE_SizeGrip: {
            painter->save();
            QColor dark = Qt::white;
            dark.setAlphaF(0.1);
            int x, y, w, h;
            option->rect.getRect(&x, &y, &w, &h);
            int sw = qMin(h, w);
            if (h > w)
                painter->translate(0, h - w);
            else
                painter->translate(w - h, 0);
            int sx = x;
            int sy = y;
            int s = 4;
            painter->setPen(dark);
            if (option->direction == Qt::RightToLeft) {
                sx = x + sw;
                for (int i = 0; i < 4; ++i) {
                    painter->drawLine(x, sy, sx, sw);
                    sx -= s;
                    sy += s;
                }
            } else {
                for (int i = 0; i < 4; ++i) {
                    painter->drawLine(sx, sw, sw, sy);
                    sx += s;
                    sy += s;
                }
            }
            painter->restore();
        }
        break;

    case CE_MenuBarEmptyArea: {
            StyleHelper::menuGradient(painter, option->rect, option->rect);
            painter->save();
            painter->setPen(StyleHelper::borderColor());
            painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
            painter->restore();
        }
        break;

    case CE_ToolBar:
        {
            QRect rect = option->rect;
            bool horizontal = option->state & State_Horizontal;
            rect = option->rect;

            // Map offset for global window gradient
            QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) -
                            widget->mapToGlobal(option->rect.topLeft());
            QRect gradientSpan;
            if (widget)
                gradientSpan = QRect(offset, widget->window()->size());

            bool drawLightColored = lightColored(widget);
            if (horizontal)
                StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored);
            else
                StyleHelper::verticalGradient(painter, gradientSpan, rect, drawLightColored);

            if (!drawLightColored)
                painter->setPen(StyleHelper::borderColor());
            else
                painter->setPen(QColor(0x888888));

            if (horizontal) {
                // Note: This is a hack to determine if the
                // toolbar should draw the top or bottom outline
                // (needed for the find toolbar for instance)
                QColor lighter(StyleHelper::sidebarHighlight());
                if (drawLightColored)
                    lighter = QColor(255, 255, 255, 180);
                if (widget && widget->property("topBorder").toBool()) {
                    painter->drawLine(rect.topLeft(), rect.topRight());
                    painter->setPen(lighter);
                    painter->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1));
                } else {
                    painter->drawLine(rect.bottomLeft(), rect.bottomRight());
                    painter->setPen(lighter);
                    painter->drawLine(rect.topLeft(), rect.topRight());
                }
            } else {
                painter->drawLine(rect.topLeft(), rect.bottomLeft());
                painter->drawLine(rect.topRight(), rect.bottomRight());
            }
        }
        break;

#if defined(Q_OS_MAC)
    case CE_ToolButtonLabel:
        if (const QStyleOptionToolButton *tb = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
            QStyleOptionToolButton myTb = *tb;
            myTb.state &= ~State_AutoRaise;

            QRect cr = tb->rect;
            bool needText = false;
            int alignment = 0;
            bool down = tb->state & (State_Sunken | State_On);
            // The down state is special for QToolButtons in a toolbar on the Mac
            // The text is a bit bolder and gets a drop shadow and the icons are also darkened.
            // This doesn't really fit into any particular case in QIcon, so we
            // do the majority of the work ourselves.
            if (!(tb->features & QStyleOptionToolButton::Arrow)) {
                Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle;
                if (tb->icon.isNull() && !tb->text.isEmpty())
                    tbstyle = Qt::ToolButtonTextOnly;

                switch (tbstyle) {
                case Qt::ToolButtonTextOnly: {
                    needText = true;
                    alignment = Qt::AlignCenter;
                    break; }
                case Qt::ToolButtonIconOnly:
                case Qt::ToolButtonTextBesideIcon:
                case Qt::ToolButtonTextUnderIcon: {
                    QRect pr = cr;
                    QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal
                                                                       : QIcon::Disabled;
                    QIcon::State iconState = (tb->state & State_On) ? QIcon::On
                                                                    : QIcon::Off;
                    QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), iconMode, iconState);

                    // Draw the text if it's needed.
                    if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) {
                        needText = true;
                        if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
                            QMainWindow *mw = widget ? qobject_cast<QMainWindow *>(widget->window()) : 0;
                            if (mw && mw->unifiedTitleAndToolBarOnMac()) {
                                pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio());
                                cr.adjust(0, pr.bottom() + 1, 0, 1);
                            } else {
                                pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio() + 6);
                                cr.adjust(0, pr.bottom(), 0, -3);
                            }
                            alignment |= Qt::AlignCenter;
                        } else {
                            pr.setWidth(pixmap.width() / pixmap.devicePixelRatio() + 8);
                            cr.adjust(pr.right(), 0, 0, 0);
                            alignment |= Qt::AlignLeft | Qt::AlignVCenter;
                        }
                    }

                    proxy()->drawItemPixmap(painter, pr, Qt::AlignCenter, pixmap);
                    break; }
                default:
                    Q_ASSERT(false);
                    break;
                }

                if (needText) {
                    QPalette pal = tb->palette;
                    QPalette::ColorRole role = QPalette::WindowText;
                    if (!proxy()->styleHint(SH_UnderlineShortcut, tb, widget))
                        alignment |= Qt::TextHideMnemonic;
                    if (tbstyle == Qt::ToolButtonTextOnly || (tbstyle != Qt::ToolButtonTextOnly && !down)) {
                        painter->drawText(cr, alignment, tb->text);
                        if (down && tbstyle == Qt::ToolButtonTextOnly) {
                            pal = QApplication::palette("QMenu");
                            pal.setCurrentColorGroup(tb->palette.currentColorGroup());
                            role = QPalette::HighlightedText;
                        }
                    }
                    proxy()->drawItemText(painter, cr, alignment, pal,
                                          tb->state & State_Enabled, tb->text, role);
                }
            } else {
                QProxyStyle::drawControl(element, option, painter, widget);
            }
        }
        break;
#endif

    default:
        QProxyStyle::drawControl(element, option, painter, widget);
        break;
    }
}