QRect QMdStyle::subControlRect(ComplexControl whichControl, const QStyleOptionComplex *option, SubControl whichSubControl, const QWidget *widget) const { if (whichControl == CC_SpinBox) { int frameWidth = pixelMetric(PM_DefaultFrameWidth, option, widget); int buttonWidth = 40; switch (whichSubControl) { case SC_SpinBoxFrame: return option->rect; case SC_SpinBoxEditField: return option->rect.adjusted(+buttonWidth, +frameWidth, -buttonWidth, -frameWidth); case SC_SpinBoxDown: return visualRect(option->direction, option->rect, QRect(option->rect.x(), option->rect.y(), buttonWidth, option->rect.height())); case SC_SpinBoxUp: return visualRect(option->direction, option->rect, QRect(option->rect.right() - buttonWidth, option->rect.y(), buttonWidth, option->rect.height())); default: return QRect(); } } else { return QWindowsStyle::subControlRect(whichControl, option, whichSubControl, widget); } }
int QCommonStyle_QtDShell::__override_pixelMetric(int m0, const QStyleOption* opt1, const QWidget* widget2, bool static_call) const { if (static_call) { return QCommonStyle::pixelMetric((QStyle::PixelMetric )m0, (const QStyleOption* )opt1, (const QWidget* )widget2); } else { return pixelMetric((QStyle::PixelMetric )m0, (const QStyleOption* )opt1, (const QWidget* )widget2); } }
PreviewWarningDialog::PreviewWarningDialog(QWidget *parent) : QDialog{parent} , ui{new Ui::PreviewWarningDialog} { // Setup UI controls. ui->setupUi(this); auto style = QApplication::style(); auto iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize); ui->iconLabel->setPixmap(style->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(iconSize, iconSize)); }
bool MailTreeDelegate::editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem& option, const QModelIndex& index) { if (Mode_ != MailListMode::MultiSelect) return QStyledItemDelegate::editorEvent (event, model, option, index); switch (event->type ()) { case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseButtonDblClick: case QEvent::MouseMove: break; default: return QStyledItemDelegate::editorEvent (event, model, option, index); } const auto mouseEvent = static_cast<QMouseEvent*> (event); const auto xPos = mouseEvent->pos ().x (); const auto style = GetStyle (option); const auto checkBoxWidth = style->pixelMetric (QStyle::PM_IndicatorWidth); const auto left = option.rect.left (); if (xPos < left || xPos > left + checkBoxWidth) return QStyledItemDelegate::editorEvent (event, model, option, index); if (event->type () == QEvent::MouseButtonRelease) { const auto current = index.data (Qt::CheckStateRole).toInt (); const auto desired = current == Qt::Checked ? Qt::Unchecked : Qt::Checked; model->setData (index, desired, Qt::CheckStateRole); if (mouseEvent->button () == Qt::RightButton) { QList<QModelIndex> children { index }; while (!children.isEmpty ()) { const auto& nextIndex = children.takeFirst (); model->setData (nextIndex, desired, Qt::CheckStateRole); for (int i = 0, rc = model->rowCount (nextIndex); i < rc; ++i) children << model->index (i, 0, nextIndex); } } } return true; }
static int GetLayoutHorizontalSpacing(const QGridLayout* layout) { // TODO: shouldn't layout->horizontalSpacing() do all this? Why does it return -1? int hspacing = layout->horizontalSpacing(); if (hspacing >= 0) return hspacing; // According to docs, this is the fallback if horizontalSpacing() isn't set. auto style = layout->parentWidget()->style(); hspacing = style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing); if (hspacing >= 0) return hspacing; // Docs claim this is deprecated, but on macOS with Qt 5.8 this is the only one that actually // works. float pixel_ratio = QGuiApplication::primaryScreen()->devicePixelRatio(); hspacing = pixel_ratio * style->pixelMetric(QStyle::PM_DefaultLayoutSpacing); if (hspacing >= 0) return hspacing; // Ripped from qtbase/src/widgets/styles/qcommonstyle.cpp return pixel_ratio * 6; }
void WindowsModernStyle::drawComplexControl( ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const { switch ( control ) { case CC_ToolButton: { QToolBar* toolBar; if ( widget && ( toolBar = qobject_cast<QToolBar*>( widget->parentWidget() ) ) ) { if ( const QStyleOptionToolButton* optionToolButton = qstyleoption_cast<const QStyleOptionToolButton*>( option ) ) { QRect buttonRect = subControlRect( control, option, SC_ToolButton, widget ); QStyle::State buttonState = option->state & ~State_Sunken; if ( option->state & State_Sunken ) { if ( optionToolButton->activeSubControls & SC_ToolButton ) buttonState |= State_Sunken; else if ( optionToolButton->activeSubControls & SC_ToolButtonMenu ) buttonState |= State_MouseOver; } bool selected = buttonState & State_MouseOver && option->state & State_Enabled; bool checked = buttonState & State_On; bool sunken = buttonState & State_Sunken; if ( selected || checked || sunken ) { QRect rect = buttonRect.adjusted( 0, 0, -1, -1 ); painter->setPen( m_colorItemBorder ); QLinearGradient gradient; if ( toolBar->orientation() == Qt::Vertical ) gradient = QLinearGradient( rect.topLeft(), rect.topRight() ); else gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() ); if ( sunken || (selected && checked) ) { gradient.setColorAt( 0.0, m_colorItemSunkenBegin ); gradient.setColorAt( 0.5, m_colorItemSunkenMiddle ); gradient.setColorAt( 1.0, m_colorItemSunkenEnd ); } else if ( checked ) { gradient.setColorAt( 0.0, m_colorItemCheckedBegin ); gradient.setColorAt( 0.5, m_colorItemCheckedMiddle ); gradient.setColorAt( 1.0, m_colorItemCheckedEnd ); } else { gradient.setColorAt( 0.0, m_colorItemBackgroundBegin ); gradient.setColorAt( 0.5, m_colorItemBackgroundMiddle ); gradient.setColorAt( 1.0, m_colorItemBackgroundEnd ); } painter->setBrush( gradient ); painter->drawRect( rect ); } QStyleOptionToolButton optionLabel = *optionToolButton; int fw = pixelMetric( PM_DefaultFrameWidth, option, widget ); optionLabel.rect = buttonRect.adjusted( fw, fw, -fw, -fw ); drawControl( CE_ToolButtonLabel, &optionLabel, painter, widget ); if ( optionToolButton->subControls & SC_ToolButtonMenu ) { QStyleOption optionMenu = *optionToolButton; optionMenu.rect = subControlRect( control, option, SC_ToolButtonMenu, widget ); optionMenu.state = optionToolButton->state & ~State_Sunken; if ( optionToolButton->state & State_Sunken ) { if ( optionToolButton->activeSubControls & SC_ToolButton ) optionMenu.state |= State_MouseOver | State_Sunken; else if ( optionToolButton->activeSubControls & SC_ToolButtonMenu ) optionMenu.state |= State_Sunken; } drawPrimitive( PE_IndicatorButtonDropDown, &optionMenu, painter, widget ); } else if ( optionToolButton->features & QStyleOptionToolButton::HasMenu ) { int size = pixelMetric( PM_MenuButtonIndicator, option, widget ); QRect rect = optionToolButton->rect; QStyleOptionToolButton optionArrow = *optionToolButton; optionArrow.rect = QRect( rect.right() + 4 - size, rect.height() - size + 4, size - 5, size - 5 ); drawPrimitive( PE_IndicatorArrowDown, &optionArrow, painter, widget ); } return; } } break; } default: break; } if ( useVista() ) QWindowsVistaStyle::drawComplexControl( control, option, painter, widget ); else QWindowsXPStyle::drawComplexControl( control, option, painter, widget ); }
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 ); }
/*! \reimp */ void QCDEStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *widget) const { switch (pe) { case PE_IndicatorCheckBox: { bool down = opt->state & State_Sunken; bool on = opt->state & State_On; bool showUp = !(down ^ on); QBrush fill = (showUp || (opt->state & State_NoChange)) ? opt->palette.brush(QPalette::Button) : opt->palette.brush(QPalette::Mid); qDrawShadePanel(p, opt->rect, opt->palette, !showUp, pixelMetric(PM_DefaultFrameWidth), &opt->palette.brush(QPalette::Button)); if (on || (opt->state & State_NoChange)) { QRect r = opt->rect; QPolygon a(7 * 2); int i, xx, yy; xx = r.x() + 3; yy = r.y() + 5; if (opt->rect.width() <= 9) { // When called from CE_MenuItem in QMotifStyle xx -= 2; yy -= 2; } for (i = 0; i < 3; i++) { a.setPoint(2 * i, xx, yy); a.setPoint(2 * i + 1, xx, yy + 2); xx++; yy++; } yy -= 2; for (i = 3; i < 7; i++) { a.setPoint(2 * i, xx, yy); a.setPoint(2 * i + 1, xx, yy + 2); xx++; yy--; } if (opt->state & State_NoChange) p->setPen(opt->palette.dark().color()); else p->setPen(opt->palette.foreground().color()); p->drawPolyline(a); } if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText)) p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern)); } break; case PE_IndicatorRadioButton: { QRect r = opt->rect; #define INTARRLEN(x) sizeof(x)/(sizeof(int)*2) static const int pts1[] = { // up left lines 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 }; static const int pts4[] = { // bottom right lines 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7, 11,4, 10,3, 10,2 }; static const int pts5[] = { // inner fill 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 }; bool down = opt->state & State_Sunken; bool on = opt->state & State_On; QPolygon a(INTARRLEN(pts1), pts1); //center when rect is larger than indicator size int xOffset = 0; int yOffset = 0; int indicatorWidth = pixelMetric(PM_ExclusiveIndicatorWidth); int indicatorHeight = pixelMetric(PM_ExclusiveIndicatorWidth); if (r.width() > indicatorWidth) xOffset += (r.width() - indicatorWidth)/2; if (r.height() > indicatorHeight) yOffset += (r.height() - indicatorHeight)/2; p->translate(xOffset, yOffset); a.translate(r.x(), r.y()); QPen oldPen = p->pen(); QBrush oldBrush = p->brush(); p->setPen((down || on) ? opt->palette.dark().color() : opt->palette.light().color()); p->drawPolyline(a); a.setPoints(INTARRLEN(pts4), pts4); a.translate(r.x(), r.y()); p->setPen((down || on) ? opt->palette.light().color() : opt->palette.dark().color()); p->drawPolyline(a); a.setPoints(INTARRLEN(pts5), pts5); a.translate(r.x(), r.y()); QColor fillColor = on ? opt->palette.dark().color() : opt->palette.background().color(); p->setPen(fillColor); p->setBrush(on ? opt->palette.brush(QPalette::Dark) : opt->palette.brush(QPalette::Window)); p->drawPolygon(a); if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText)) p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern)); p->setPen(oldPen); p->setBrush(oldBrush); p->translate(-xOffset, -yOffset); } break; default: QMotifStyle::drawPrimitive(pe, opt, p, widget); } }
/*!\reimp */ void QPlatinumStyle::drawControl( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how, const QStyleOption& opt ) const { switch( element ) { case CE_PushButton: { #ifndef QT_NO_PUSHBUTTON QColorGroup myCg( cg ); const QPushButton *btn; int x1, y1, x2, y2; bool useBevelButton; SFlags flags; flags = Style_Default; btn = (const QPushButton*)widget; p->setBrushOrigin( -widget->backgroundOffset().x(), -widget->backgroundOffset().y() ); // take care of the flags based on what we know... if ( btn->isDown() ) flags |= Style_Down; if ( btn->isOn() ) flags |= Style_On; if ( btn->isEnabled() ) flags |= Style_Enabled; if ( btn->isDefault() ) flags |= Style_Default; if (! btn->isFlat() && !(flags & Style_Down)) flags |= Style_Raised; r.coords( &x1, &y1, &x2, &y2 ); p->setPen( cg.foreground() ); p->setBrush( QBrush(cg.button(), NoBrush) ); QBrush fill; if ( btn->isDown() ) { fill = cg.brush( QColorGroup::Dark ); // this could be done differently, but this // makes a down Bezel drawn correctly... myCg.setBrush( QColorGroup::Mid, fill ); } else if ( btn->isOn() ) { fill = QBrush( cg.mid(), Dense4Pattern ); myCg.setBrush( QColorGroup::Mid, fill ); } // to quote the old QPlatinumStlye drawPushButton... // small or square image buttons as well as toggle buttons are // bevel buttons (what a heuristic....) if ( btn->isToggleButton() || ( btn->pixmap() && (btn->width() * btn->height() < 1600 || QABS( btn->width() - btn->height()) < 10 )) ) useBevelButton = TRUE; else useBevelButton = FALSE; int diw = pixelMetric( PM_ButtonDefaultIndicator, widget ); if ( btn->isDefault() ) { x1 += 1; y1 += 1; x2 -= 1; y2 -= 1; QColorGroup cg2( myCg ); SFlags myFlags = flags; // don't draw the default button sunken, unless it's necessary. if ( myFlags & Style_Down ) myFlags ^= Style_Down; if ( myFlags & Style_Sunken ) myFlags ^= Style_Sunken; cg2.setColor( QColorGroup::Button, cg.mid() ); if ( useBevelButton ) { drawPrimitive( PE_ButtonBevel, p, QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1 ), myCg, myFlags, opt ); } else { drawPrimitive( PE_ButtonCommand, p, QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1 ), cg2, myFlags, opt ); } } if ( btn->isDefault() || btn->autoDefault() ) { x1 += diw; y1 += diw; x2 -= diw; y2 -= diw; } if ( !btn->isFlat() || btn->isOn() || btn->isDown() ) { if ( useBevelButton ) { // fix for toggle buttons... if ( flags & (Style_Down | Style_On) ) flags |= Style_Sunken; drawPrimitive( PE_ButtonBevel, p, QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1 ), myCg, flags, opt ); } else { drawPrimitive( PE_ButtonCommand, p, QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1 ), myCg, flags, opt ); } } if ( p->brush().style() != NoBrush ) p->setBrush( NoBrush ); break; #endif } case CE_PushButtonLabel: { #ifndef QT_NO_PUSHBUTTON const QPushButton *btn; bool on; int x, y, w, h; SFlags flags; flags = Style_Default; btn = (const QPushButton*)widget; on = btn->isDown() || btn->isOn(); r.rect( &x, &y, &w, &h ); if ( btn->isMenuButton() ) { int dx = pixelMetric( PM_MenuButtonIndicator, widget ); QColorGroup g = cg; int xx = x + w - dx - 4; int yy = y - 3; int hh = h + 6; if ( !on ) { p->setPen( g.mid() ); p->drawLine( xx, yy + 2, xx, yy + hh - 3 ); p->setPen( g.button() ); p->drawLine( xx + 1, yy + 1, xx + 1, yy + hh - 2 ); p->setPen( g.light() ); p->drawLine( xx + 2, yy + 2, xx + 2, yy + hh - 2 ); } if ( btn->isEnabled() ) flags |= Style_Enabled; drawPrimitive( PE_ArrowDown, p, QRect(x + w - dx - 1, y + 2, dx, h - 4), g, flags, opt ); w -= dx; } #ifndef QT_NO_ICONSET if ( btn->iconSet() && !btn->iconSet()->isNull() ) { QIconSet::Mode mode = btn->isEnabled() ? QIconSet::Normal : QIconSet::Disabled; if ( mode == QIconSet::Normal && btn->hasFocus() ) mode = QIconSet::Active; QIconSet::State state = QIconSet::Off; if ( btn->isToggleButton() && btn->isOn() ) state = QIconSet::On; QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small, mode, state ); int pixw = pixmap.width(); int pixh = pixmap.height(); p->drawPixmap( x + 2, y + h / 2 - pixh / 2, pixmap ); x += pixw + 4; w -= pixw + 4; } #endif drawItem( p, QRect( x, y, w, h ), AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(), btn->pixmap(), btn->text(), -1, on ? &btn->colorGroup().brightText() : &btn->colorGroup().buttonText() ); if ( btn->hasFocus() ) drawPrimitive( PE_FocusRect, p, subRect(SR_PushButtonFocusRect, widget), cg, flags ); break; #endif } default: QWindowsStyle::drawControl( element, p, widget, r, cg, how, opt ); break; } }
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return QProxyStyle::drawComplexControl(control, option, painter, widget); QRect rect = option->rect; switch (control) { case CC_ToolButton: if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { QRect button, menuarea; button = subControlRect(control, toolbutton, SC_ToolButton, widget); menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget); State bflags = toolbutton->state; if (bflags & State_AutoRaise) { if (!(bflags & State_MouseOver)) { bflags &= ~State_Raised; } } State mflags = bflags; if (toolbutton->state & State_Sunken) { if (toolbutton->activeSubControls & SC_ToolButton) bflags |= State_Sunken; if (toolbutton->activeSubControls & SC_ToolButtonMenu) mflags |= State_Sunken; } QStyleOption tool(0); tool.palette = toolbutton->palette; if (toolbutton->subControls & SC_ToolButton) { tool.rect = button; tool.state = bflags; drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); } QStyleOptionToolButton label = *toolbutton; label.palette = panelPalette(option->palette, lightColored(widget)); int fw = pixelMetric(PM_DefaultFrameWidth, option, widget); label.rect = button.adjusted(fw, fw, -fw, -fw); drawControl(CE_ToolButtonLabel, &label, painter, widget); if (toolbutton->subControls & SC_ToolButtonMenu) { tool.state = mflags; tool.rect = menuarea.adjusted(1, 1, -1, -1); if (mflags & (State_Sunken | State_On | State_Raised)) { painter->setPen(Qt::gray); painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft()); if (mflags & (State_Sunken)) { QColor shade(0, 0, 0, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #ifndef Q_WS_MAC else if (mflags & (State_MouseOver)) { QColor shade(255, 255, 255, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #endif } tool.rect = tool.rect.adjusted(2, 2, -2, -2); drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget); } else if (toolbutton->features & QStyleOptionToolButton::HasMenu && !widget->property("noArrow").toBool()) { int arrowSize = 6; QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1); QStyleOptionToolButton newBtn = *toolbutton; newBtn.palette = panelPalette(option->palette); newBtn.rect = QRect(ir.right() - arrowSize - 1, ir.height() - arrowSize - 2, arrowSize, arrowSize); drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget); } } break; case CC_ComboBox: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { painter->save(); bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull(); bool reverse = option->direction == Qt::RightToLeft; bool drawborder = !(widget && widget->property("hideborder").toBool()); bool alignarrow = !(widget && widget->property("alignarrow").toBool()); // Draw tool button if (drawborder) { QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight()); grad.setColorAt(0, QColor(255, 255, 255, 20)); grad.setColorAt(0.4, QColor(255, 255, 255, 60)); grad.setColorAt(0.7, QColor(255, 255, 255, 50)); grad.setColorAt(1, QColor(255, 255, 255, 40)); painter->setPen(QPen(grad, 0)); painter->drawLine(rect.topRight(), rect.bottomRight()); grad.setColorAt(0, QColor(0, 0, 0, 30)); grad.setColorAt(0.4, QColor(0, 0, 0, 70)); grad.setColorAt(0.7, QColor(0, 0, 0, 70)); grad.setColorAt(1, QColor(0, 0, 0, 40)); painter->setPen(QPen(grad, 0)); if (!reverse) painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0)); else painter->drawLine(rect.topLeft(), rect.bottomLeft()); } QStyleOption toolbutton = *option; if (isEmpty) toolbutton.state &= ~(State_Enabled | State_Sunken); painter->save(); if (drawborder) painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0)); drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget); painter->restore(); // Draw arrow int menuButtonWidth = 12; int left = !reverse ? rect.right() - menuButtonWidth : rect.left(); int right = !reverse ? rect.right() : rect.left() + menuButtonWidth; QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9); if (!alignarrow) { int labelwidth = option->fontMetrics.width(cb->currentText); if (reverse) arrowRect.moveLeft(qMax(rect.width() - labelwidth - menuButtonWidth - 2, 4)); else arrowRect.moveLeft(qMin(labelwidth + menuButtonWidth - 2, rect.width() - menuButtonWidth - 4)); } if (option->state & State_On) arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget), QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget)); QStyleOption arrowOpt = *option; arrowOpt.rect = arrowRect; if (isEmpty) arrowOpt.state &= ~(State_Enabled | State_Sunken); if (styleHint(SH_ComboBox_Popup, option, widget)) { arrowOpt.rect.translate(0, -3); drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget); arrowOpt.rect.translate(0, 6); drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } else { drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } painter->restore(); } break; default: QProxyStyle::drawComplexControl(control, option, painter, widget); break; } }
void TabBarWidgetMacStyle::drawControl(ControlElement pElement, const QStyleOption *pOption, QPainter *pPainter, const QWidget *pWidget) const { // Draw a tab bar tab label // Note: anything else is done by our parent... if (pElement == CE_TabBarTabLabel) { // Note: adapted from QCommonStyle::drawControl()... if (auto tab = qstyleoption_cast<const QStyleOptionTab *>(pOption)) { uint alignment = Qt::AlignCenter|Qt::TextShowMnemonic; if (styleHint(SH_UnderlineShortcut, pOption, pWidget) == 0) { alignment |= Qt::TextHideMnemonic; } bool isVerticalTab = (tab->shape == QTabBar::RoundedWest) || (tab->shape == QTabBar::RoundedEast) || (tab->shape == QTabBar::TriangularWest) || (tab->shape == QTabBar::TriangularEast); QRect tabRect = tab->rect; if (isVerticalTab) { pPainter->save(); int x, y, rotation; if ( (tab->shape == QTabBar::RoundedEast) || (tab->shape == QTabBar::TriangularEast)) { x = tabRect.x()+tabRect.width(); y = tabRect.y(); rotation = 90; } else { x = tabRect.x(); y = tabRect.y()+tabRect.height(); rotation = -90; } QTransform transform = QTransform::fromTranslate(x, y); transform.rotate(rotation); pPainter->setTransform(transform, true); } QRect iconRect; tabLayout(tab, pWidget, &tabRect, &iconRect); if (!tab->icon.isNull()) { pPainter->drawPixmap(iconRect.x(), iconRect.y(), tab->icon.pixmap(pWidget->window()->windowHandle(), tab->iconSize, ((tab->state & State_Enabled) != 0)? QIcon::Normal: QIcon::Disabled, ((tab->state & State_Selected) != 0)? QIcon::On: QIcon::Off)); } drawItemText(pPainter, tabRect, int(alignment), tab->palette, (tab->state & State_Enabled) != 0, tab->text, ( ((tab->state & State_Selected) != 0) && ((tab->state & State_Active) != 0))? QPalette::BrightText: QPalette::WindowText); if (isVerticalTab) { pPainter->restore(); } if ((tab->state & State_HasFocus) != 0) { const int Offset = 1+pixelMetric(PM_DefaultFrameWidth); int x1 = tab->rect.left(); int x2 = tab->rect.right()-1; QStyleOptionFocusRect option; option.QStyleOption::operator=(*tab); option.rect.setRect(x1+1+Offset, tab->rect.y()+Offset, x2-x1-2*Offset, tab->rect.height()-2*Offset); drawPrimitive(PE_FrameFocusRect, &option, pPainter, pWidget); } } } else { QProxyStyle::drawControl(pElement, pOption, pPainter, pWidget); } }
void TabBarWidgetMacStyle::tabLayout(const QStyleOptionTab *pOption, const QWidget *pWidget, QRect *pTextRect, QRect *pIconRect) const { // Compute our tab layout // Note: adapted from QCommonStylePrivate::tabLayout()... Q_ASSERT(pTextRect); Q_ASSERT(pIconRect); QRect textRect = pOption->rect; bool verticalTab = (pOption->shape == QTabBar::RoundedWest) || (pOption->shape == QTabBar::RoundedEast) || (pOption->shape == QTabBar::TriangularWest) || (pOption->shape == QTabBar::TriangularEast); if (verticalTab) { textRect.setRect(0, 0, textRect.height(), textRect.width()); } if (!pOption->leftButtonSize.isEmpty()) { textRect.adjust(-4, 0, 0, 0); } int horizontalShift = pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, pOption, pWidget); int verticalShift = pixelMetric(QStyle::PM_TabBarTabShiftVertical, pOption, pWidget); int horizontalPadding = pixelMetric(QStyle::PM_TabBarTabHSpace, pOption, pWidget)/2; int verticalPadding = pixelMetric(QStyle::PM_TabBarTabVSpace, pOption, pWidget)/2; if ( (pOption->shape == QTabBar::RoundedSouth) || (pOption->shape == QTabBar::TriangularSouth)) { verticalShift = -verticalShift; } textRect.adjust(horizontalPadding, verticalShift-verticalPadding, horizontalShift-horizontalPadding, verticalPadding); if ((pOption->state & QStyle::State_Selected) != 0) { textRect.setTop(textRect.top()-verticalShift); textRect.setRight(textRect.right()-horizontalShift); } if (!pOption->leftButtonSize.isEmpty()) { textRect.setLeft( textRect.left() +(verticalTab? pOption->leftButtonSize.height(): pOption->leftButtonSize.width())); } if (!pOption->rightButtonSize.isEmpty()) { textRect.setRight( textRect.right() -(verticalTab? pOption->rightButtonSize.height(): pOption->rightButtonSize.width())); } if (!pOption->icon.isNull()) { QSize iconSize = pOption->iconSize; if (!iconSize.isValid()) { int iconExtent = pixelMetric(QStyle::PM_SmallIconSize); iconSize = QSize(iconExtent, iconExtent); } QSize tabIconSize = pOption->icon.actualSize(iconSize, ((pOption->state & QStyle::State_Enabled) != 0)? QIcon::Normal: QIcon::Disabled, ((pOption->state & QStyle::State_Selected) != 0)? QIcon::On: QIcon::Off); tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height())); *pIconRect = QRect(textRect.left(), textRect.center().y()-tabIconSize.height()/2, tabIconSize.width(), tabIconSize.height()); if (!verticalTab) { *pIconRect = visualRect(pOption->direction, pOption->rect, *pIconRect); } textRect.setLeft(textRect.left()+tabIconSize.width()+4); } if (!verticalTab) { textRect = visualRect(pOption->direction, pOption->rect, textRect); } *pTextRect = textRect; }
QRect subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *widget) const { switch (sr) { case SE_TabBarScrollLeftButton: { // Return the rect of the left scroll button const bool vertical = opt->rect.height() > opt->rect.width(); const int buttonWidth = pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, widget) + g_margins; return vertical ? QRect(0, 0, opt->rect.width() - 1, buttonWidth) : QStyle::visualRect(widget->layoutDirection(), opt->rect, QRect(0, 0, buttonWidth, opt->rect.height() - 1)); break; } case SE_TabBarScrollRightButton: { // Return the rect of the right scroll button const bool vertical = opt->rect.height() > opt->rect.width(); const int buttonWidth = pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, widget) + g_margins; return vertical ? QRect(0, opt->rect.height() - buttonWidth, opt->rect.width() - 1, buttonWidth) : QStyle::visualRect(widget->layoutDirection(), opt->rect, QRect(opt->rect.width() - buttonWidth, 0, buttonWidth, opt->rect.height())); break; } case SE_TabBarTearIndicatorLeft: { // Return the rect of the fade out area on the left side of the tabbar. const QStyleOptionTabV4 *tabOpt = static_cast<const QStyleOptionTabV4 *>(opt); const bool vertical = opt->rect.height() > opt->rect.width(); const int buttonWidth = pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, widget); int pixelsOutOnLeft; QRect unionRect = tabOpt->unionRect; if (vertical) { pixelsOutOnLeft = buttonWidth - unionRect.y(); } else if (widget->layoutDirection() == Qt::LeftToRight) { pixelsOutOnLeft = buttonWidth - unionRect.x(); } else { int diff = tabOpt->unionRect.width() - tabOpt->rect.width(); pixelsOutOnLeft = diff + buttonWidth + tabOpt->unionRect.x(); } int fadeout = qMax(5, qMin(g_fadeoutWidth, pixelsOutOnLeft)); return vertical ? QRect(0, buttonWidth, opt->rect.width() - 2, fadeout) : QStyle::visualRect(widget->layoutDirection(), opt->rect, QRect(buttonWidth, 0, fadeout, opt->rect.height() - 2)); break; } case SE_TabBarTearIndicatorRight: { // Return the rect of the fade out area on the right side of the tabbar. const QStyleOptionTabV4 *tabOpt = static_cast<const QStyleOptionTabV4 *>(opt); const bool vertical = opt->rect.height() > opt->rect.width(); const int buttonWidth = pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, widget); int pixelsOutOnRight; QRect unionRect = tabOpt->unionRect; if (vertical) { int diff = tabOpt->unionRect.height() - tabOpt->rect.height(); pixelsOutOnRight = diff + buttonWidth + tabOpt->unionRect.y(); } else if (widget->layoutDirection() == Qt::RightToLeft) { pixelsOutOnRight = buttonWidth - unionRect.x(); } else { int diff = tabOpt->unionRect.width() - tabOpt->rect.width(); pixelsOutOnRight = diff + buttonWidth + tabOpt->unionRect.x(); } int fadeout = qMax(5, qMin(g_fadeoutWidth, pixelsOutOnRight - (buttonWidth * 2))); const int x = opt->rect.width() - buttonWidth - fadeout; return vertical ? QRect(0, opt->rect.height() - buttonWidth - fadeout, opt->rect.width() - 2, fadeout) : QStyle::visualRect(widget->layoutDirection(), opt->rect, QRect(x, 0, fadeout, opt->rect.height() - 2)); break; } default: break; } return QProxyStyle::subElementRect(sr, opt, widget); }
/*!\reimp */ void QPlatinumStyle::drawComplexControl( ComplexControl control, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how, SCFlags sub, SCFlags subActive, const QStyleOption& opt ) const { switch ( control ) { case CC_ComboBox: { int x, y, w, h; r.rect( &x, &y, &w, &h ); p->fillRect( x + 2, y + 2, w - 4, h - 4, cg.brush(QColorGroup::Button) ); // the bright side p->setPen(cg.shadow()); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.light() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); // the dark side! p->setPen( cg.mid() ); p->drawLine( x + 2, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 2, x + w - 2, y + h - 2 ); p->setPen (cg.shadow() ); p->drawLine( x + 1, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 ); // top left corner: p->setPen( cg.background() ); p->drawPoint( x, y ); p->drawPoint( x + 1, y ); p->drawPoint( x, y + 1 ); p->setPen( cg.shadow() ); p->drawPoint( x + 1, y + 1 ); p->setPen( white ); p->drawPoint( x + 3, y + 3 ); // bottom left corner: p->setPen( cg.background() ); p->drawPoint( x, y + h - 1 ); p->drawPoint( x + 1, y + h - 1 ); p->drawPoint( x, y + h - 2 ); p->setPen( cg.shadow() ); p->drawPoint( x + 1, y + h - 2 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y ); p->drawPoint( x + w - 2, y ); p->drawPoint( x + w - 1, y + 1 ); p->setPen( cg.shadow() ); p->drawPoint( x + w - 2, y + 1 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y + h - 1 ); p->drawPoint( x + w - 2, y + h - 1 ); p->drawPoint( x + w - 1, y + h - 2 ); p->setPen( cg.shadow() ); p->drawPoint( x + w - 2, y + h - 2 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 3, y + h - 3 ); if ( sub & SC_ComboBoxArrow ) { QRect rTmp = querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxArrow, opt ); int xx = rTmp.x(), yy = rTmp.y(), ww = rTmp.width(), hh = rTmp.height(); // the bright side p->setPen( cg.mid() ); p->drawLine( xx, yy+2, xx, yy+hh-3 ); p->setPen( cg.button() ); p->drawLine( xx+1, yy+1, xx+ww-2, yy+1 ); p->drawLine( xx+1, yy+1, xx+1, yy+hh-2 ); p->setPen( cg.light() ); p->drawLine( xx+2, yy+2, xx+2, yy+hh-2 ); p->drawLine( xx+2, yy+2, xx+ww-2, yy+2 ); // the dark side! p->setPen( cg.mid() ); p->drawLine( xx+3, yy+hh-3 ,xx+ww-3, yy+hh-3 ); p->drawLine( xx+ww-3, yy+3, xx+ww-3, yy+hh-3 ); p->setPen( cg.dark() ); p->drawLine( xx+2, yy+hh-2 ,xx+ww-2, yy+hh-2 ); p->drawLine( xx+ww-2, yy+2, xx+ww-2, yy+hh-2 ); p->setPen( cg.shadow() ); p->drawLine( xx+1, yy+hh-1,xx+ww-1, yy+hh-1 ); p->drawLine( xx+ww-1, yy, xx+ww-1, yy+hh-1 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( xx + ww - 1, yy ); p->drawPoint( xx + ww - 2, yy ); p->drawPoint( xx + ww - 1, yy + 1 ); p->setPen( cg.shadow() ); p->drawPoint( xx + ww - 2, yy + 1 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( xx + ww - 1, yy + hh - 1 ); p->drawPoint( xx + ww - 2, yy + hh - 1 ); p->drawPoint( xx + ww - 1, yy + hh - 2 ); p->setPen( cg.shadow() ); p->drawPoint( xx + ww - 2, yy + hh - 2 ); p->setPen( cg.dark() ); p->drawPoint( xx + ww - 3, yy + hh - 3 ); p->setPen( cg.mid() ); p->drawPoint( xx + ww - 4, yy + hh - 4 ); // and the arrows p->setPen( cg.foreground() ); QPointArray a ; a.setPoints( 7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2 ); a.translate( xx + ww / 2, yy + hh / 2 - 3 ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); a.setPoints( 7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2 ); a.translate( xx + ww / 2, yy + hh / 2 + 2 ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); } #ifndef QT_NO_COMBOBOX if ( sub & SC_ComboBoxEditField ) { const QComboBox *cmb; cmb = (const QComboBox*)widget; // sadly this is pretty much the windows code, except // for the first fillRect call... QRect re = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxEditField ), widget ); if ( cmb->hasFocus() && !cmb->editable() ) p->fillRect( re.x() + 1, re.y() + 1, re.width() - 2, re.height() - 2, cg.brush( QColorGroup::Highlight ) ); if ( cmb->hasFocus() ) { p->setPen( cg.highlightedText() ); p->setBackgroundColor( cg.highlight() ); } else { p->setPen( cg.text() ); p->setBackgroundColor( cg.background() ); } if ( cmb->hasFocus() && !cmb->editable() ) { QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cmb ), widget ); drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight())); } if ( cmb->editable() ) { // need this for the moment... // was the code in comboButton rect QRect ir( x + 3, y + 3, w - 6 - 16, h - 6 ); if ( QApplication::reverseLayout() ) ir.moveBy( 16, 0 ); // end comboButtonRect... ir.setRect( ir.left() - 1, ir.top() - 1, ir.width() + 2, ir.height() + 2 ); qDrawShadePanel( p, ir, cg, TRUE, 2, 0 ); } } #endif break; } case CC_Slider: { #ifndef QT_NO_SLIDER const QSlider *slider = (const QSlider *) widget; int thickness = pixelMetric( PM_SliderControlThickness, widget ); int len = pixelMetric( PM_SliderLength, widget ); int ticks = slider->tickmarks(); QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, opt), handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, opt); if ((sub & SC_SliderGroove) && groove.isValid()) { p->fillRect( groove, cg.brush(QColorGroup::Background) ); int x, y, w, h; int mid = thickness / 2; if ( ticks & QSlider::Above ) mid += len / 8; if ( ticks & QSlider::Below ) mid -= len / 8; if ( slider->orientation() == Horizontal ) { x = 0; y = groove.y() + mid - 3; w = slider->width(); h = 7; } else { x = groove.x() + mid - 3; y = 0; w = 7; h = slider->height(); } p->fillRect( x, y, w, h, cg.brush( QColorGroup::Dark )); // the dark side p->setPen( cg.dark() ); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1); p->setPen( cg.shadow() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); // the bright side! p->setPen(cg.shadow()); p->drawLine( x + 1, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 1, x + w - 2, y + h - 2 ); p->setPen( cg.light() ); p->drawLine( x, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 ); // top left corner: p->setPen(cg.background()); p->drawPoint( x, y ); p->drawPoint( x + 1, y ); p->drawPoint( x, y + 1 ); p->setPen(cg.shadow()); p->drawPoint( x + 1, y + 1 ); // bottom left corner: p->setPen( cg.background() ); p->drawPoint( x, y + h - 1 ); p->drawPoint( x + 1, y + h - 1 ); p->drawPoint( x, y + h - 2 ); p->setPen( cg.light() ); p->drawPoint( x + 1, y + h - 2 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y ); p->drawPoint( x + w - 2, y ); p->drawPoint( x + w - 1, y + 1 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 2, y + 1 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y + h - 1 ); p->drawPoint( x + w - 2, y + h - 1 ); p->drawPoint( x + w - 1, y + h - 2 ); p->setPen( cg.light() ); p->drawPoint( x + w - 2, y + h - 2 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 3, y + h - 3 ); // ### end slider groove if ( how & Style_HasFocus ) drawPrimitive( PE_FocusRect, p, groove, cg ); } if ((sub & SC_SliderHandle) && handle.isValid()) { const QColor c0 = cg.shadow(); const QColor c1 = cg.dark(); const QColor c3 = cg.light(); int x1 = handle.x(); int x2 = handle.x() + handle.width() - 1; int y1 = handle.y(); int y2 = handle.y() + handle.height() - 1; int mx = handle.width() / 2; int my = handle.height() / 2; if ( slider->orientation() == Vertical ) { // Background QBrush oldBrush = p->brush(); p->setBrush( cg.brush( QColorGroup::Button ) ); p->setPen( NoPen ); QPointArray a(6); a.setPoint( 0, x1 + 1, y1 + 1 ); a.setPoint( 1, x2 - my + 2, y1 + 1 ); a.setPoint( 2, x2 - 1, y1 + my - 1 ); a.setPoint( 3, x2 - 1, y2 - my + 1 ); a.setPoint( 4, x2 - my + 2, y2 - 1 ); a.setPoint( 5, x1 + 1, y2 - 1 ); p->drawPolygon( a ); p->setBrush( oldBrush ); // shadow border p->setPen( c0 ); p->drawLine( x1, y1 + 1, x1,y2 - 1 ); p->drawLine( x2 - my + 2, y1, x2, y1 + my - 2 ); p->drawLine( x2 - my + 2, y2, x2, y1 + my + 2 ); p->drawLine( x2, y1 + my - 2, x2, y1 + my + 2 ); p->drawLine( x1 + 1, y1, x2 - my + 2, y1 ); p->drawLine( x1 + 1, y2, x2 - my + 2, y2 ); // light shadow p->setPen( c3 ); p->drawLine( x1 + 1, y1 + 2, x1 + 1, y2 - 2 ); p->drawLine( x1 + 1, y1 + 1, x2 - my + 2, y1 + 1 ); p->drawLine( x2 - my + 2, y1 + 1, x2 - 1, y1 + my - 2 ); // dark shadow p->setPen(c1); p->drawLine( x2 - 1, y1 + my - 2, x2 - 1, y1 + my + 2 ); p->drawLine( x2 - my + 2, y2 - 1, x2 - 1, y1 + my + 2 ); p->drawLine( x1 + 1, y2 - 1, x2 -my + 2, y2 - 1 ); drawRiffles( p, handle.x(), handle.y() + 2, handle.width() - 3, handle.height() - 4, cg, TRUE ); } else { // Horizontal QBrush oldBrush = p->brush(); p->setBrush( cg.brush( QColorGroup::Button ) ); p->setPen( NoPen ); QPointArray a(6); a.setPoint( 0, x2 - 1, y1 + 1 ); a.setPoint( 1, x2 - 1, y2 - mx + 2 ); a.setPoint( 2, x2 - mx + 1, y2 - 1 ); a.setPoint( 3, x1 + mx - 1, y2 - 1 ); a.setPoint( 4, x1 + 1, y2 - mx + 2 ); a.setPoint( 5, x1 + 1, y1 + 1 ); p->drawPolygon( a ); p->setBrush( oldBrush ); // shadow border p->setPen( c0 ); p->drawLine( x1 + 1, y1, x2 - 1, y1 ); p->drawLine( x1, y2 - mx + 2, x1 + mx - 2, y2 ); p->drawLine( x2, y2 - mx + 2, x1 + mx + 2, y2 ); p->drawLine( x1 + mx - 2, y2, x1 + mx + 2, y2 ); p->drawLine( x1, y1 + 1, x1, y2 - mx + 2 ); p->drawLine( x2, y1 + 1, x2, y2 - mx + 2 ); // light shadow p->setPen(c3); p->drawLine( x1 + 1, y1 + 1, x2 - 1, y1 + 1 ); p->drawLine( x1 + 1, y1 + 1, x1 + 1, y2 - mx + 2 ); // dark shadow p->setPen(c1); p->drawLine( x2 - 1, y1 + 1, x2 - 1, y2 - mx + 2 ); p->drawLine( x1 + 1, y2 - mx + 2, x1 + mx - 2, y2 - 1 ); p->drawLine( x2 - 1, y2 - mx + 2, x1 + mx + 2, y2 - 1 ); p->drawLine( x1 + mx - 2, y2 - 1, x1 + mx + 2, y2 - 1 ); drawRiffles( p, handle.x() + 2, handle.y(), handle.width() - 4, handle.height() - 5, cg, FALSE ); } } if ( sub & SC_SliderTickmarks ) QCommonStyle::drawComplexControl( control, p, widget, r, cg, how, SC_SliderTickmarks, subActive, opt ); #endif break; } default: QWindowsStyle::drawComplexControl( control, p, widget, r, cg, how, sub, subActive, opt ); break; } }
void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return d->style->drawPrimitive(element, option, painter, widget); bool animating = (option->state & State_Animating); int state = option->state; QRect rect = option->rect; QRect oldRect; QRect newRect; if (widget && (element == PE_PanelButtonTool) && !animating) { QWidget *w = const_cast<QWidget *> (widget); int oldState = w->property("_q_stylestate").toInt(); oldRect = w->property("_q_stylerect").toRect(); newRect = w->rect(); w->setProperty("_q_stylestate", (int)option->state); w->setProperty("_q_stylerect", w->rect()); // Determine the animated transition bool doTransition = ((state & State_On) != (oldState & State_On) || (state & State_MouseOver) != (oldState & State_MouseOver)); if (oldRect != newRect) { doTransition = false; d->animator.stopAnimation(widget); } if (doTransition) { QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); Animation *anim = d->animator.widgetAnimation(widget); QStyleOption opt = *option; opt.state = (QStyle::State)oldState; opt.state |= (State)State_Animating; startImage.fill(0); Transition *t = new Transition; t->setWidget(w); QPainter startPainter(&startImage); if (!anim) { drawPrimitive(element, &opt, &startPainter, widget); } else { anim->paint(&startPainter, &opt); d->animator.stopAnimation(widget); } QStyleOption endOpt = *option; endOpt.state |= (State)State_Animating; t->setStartImage(startImage); d->animator.startAnimation(t); endImage.fill(0); QPainter endPainter(&endImage); drawPrimitive(element, &endOpt, &endPainter, widget); t->setEndImage(endImage); t->setDuration(130); t->setStartTime(QTime::currentTime()); } } switch (element) { case PE_PanelLineEdit: { painter->save(); if (option->state & State_Enabled) drawCornerImage(d->lineeditImage, painter, option->rect, 2, 2, 2, 2); else drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 2, 2, 2, 2); if (option->state & State_HasFocus || option->state & State_MouseOver) { QColor hover = StyleHelper::baseColor(); if (state & State_HasFocus) hover.setAlpha(100); else hover.setAlpha(50); painter->setPen(QPen(hover, 1)); painter->drawRect(option->rect.adjusted(1, 1, -2 ,-2)); } painter->restore(); } break; case PE_FrameStatusBarItem: break; case PE_PanelButtonTool: { Animation *anim = d->animator.widgetAnimation(widget); if (!animating && anim) { anim->paint(painter, option); } else { bool pressed = option->state & State_Sunken || option->state & State_On; QColor shadow(0, 0, 0, 30); painter->setPen(shadow); if (pressed) { QColor shade(0, 0, 0, 40); painter->fillRect(rect, shade); painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0)); painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topRight(), rect.bottomRight()); // painter->drawLine(rect.bottomLeft() + QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); QColor highlight(255, 255, 255, 30); painter->setPen(highlight); } else if (option->state & State_Enabled && option->state & State_MouseOver) { QColor lighter(255, 255, 255, 37); painter->fillRect(rect, lighter); } } } break; case PE_PanelStatusBar: { painter->save(); QLinearGradient grad(option->rect.topLeft(), QPoint(rect.center().x(), rect.bottom())); QColor startColor = StyleHelper::shadowColor().darker(164); QColor endColor = StyleHelper::baseColor().darker(130); grad.setColorAt(0, endColor); grad.setColorAt(1, endColor); painter->fillRect(option->rect, grad); painter->setPen(QColor(255, 255, 255, 60)); painter->drawLine(rect.topLeft() + QPoint(0,1), rect.topRight()+ QPoint(0,1)); painter->setPen(StyleHelper::borderColor().darker(110)); painter->drawLine(rect.topLeft(), rect.topRight()); painter->restore(); } break; case PE_IndicatorToolBarSeparator: { QColor separatorColor = StyleHelper::borderColor(); separatorColor.setAlpha(100); painter->setPen(separatorColor); const int margin = 3; if (option->state & State_Horizontal) { const int offset = rect.width()/2; painter->drawLine(rect.bottomLeft().x() + offset, rect.bottomLeft().y() - margin, rect.topLeft().x() + offset, 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); } } break; case PE_IndicatorToolBarHandle: { bool horizontal = option->state & State_Horizontal; painter->save(); QPainterPath path; int x = option->rect.x() + horizontal ? 2 : 6; int y = option->rect.y() + horizontal ? 6 : 2; static const int RectHeight = 2; if (horizontal) { while (y < option->rect.height() - RectHeight - 6) { path.moveTo(x, y); path.addRect(x, y, RectHeight, RectHeight); y += 6; } } else { while (x < option->rect.width() - RectHeight - 6) { path.moveTo(x, y); path.addRect(x, y, RectHeight, RectHeight); x += 6; } } painter->setPen(Qt::NoPen); QColor dark = StyleHelper::borderColor(); dark.setAlphaF(0.4); QColor light = StyleHelper::baseColor(); light.setAlphaF(0.4); painter->fillPath(path, light); painter->save(); painter->translate(1, 1); painter->fillPath(path, dark); painter->restore(); painter->translate(3, 3); painter->fillPath(path, light); painter->translate(1, 1); painter->fillPath(path, dark); painter->restore(); } break; case PE_IndicatorArrowUp: case PE_IndicatorArrowDown: case PE_IndicatorArrowRight: case PE_IndicatorArrowLeft: { // From windowsstyle but modified to enable AA if (option->rect.width() <= 1 || option->rect.height() <= 1) break; QRect r = option->rect; int size = qMin(r.height(), r.width()); QPixmap pixmap; QString pixmapName; pixmapName.sprintf("%s-%s-%d-%d-%d-%lld", "$qt_ia", metaObject()->className(), uint(option->state), element, size, option->palette.cacheKey()); if (!QPixmapCache::find(pixmapName, pixmap)) { int border = size/5; int sqsize = 2*(size/2); QImage image(sqsize, sqsize, QImage::Format_ARGB32); image.fill(Qt::transparent); QPainter imagePainter(&image); imagePainter.setRenderHint(QPainter::Antialiasing, true); imagePainter.translate(0.5, 0.5); QPolygon a; switch (element) { case PE_IndicatorArrowUp: a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); break; case PE_IndicatorArrowDown: a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); break; case PE_IndicatorArrowRight: a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); break; case PE_IndicatorArrowLeft: a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); break; default: break; } int bsx = 0; int bsy = 0; if (option->state & State_Sunken) { bsx = pixelMetric(PM_ButtonShiftHorizontal); bsy = pixelMetric(PM_ButtonShiftVertical); } QRect bounds = a.boundingRect(); int sx = sqsize / 2 - bounds.center().x() - 1; int sy = sqsize / 2 - bounds.center().y() - 1; imagePainter.translate(sx + bsx, sy + bsy); if (!(option->state & State_Enabled)) { QColor foreGround(150, 150, 150, 150); imagePainter.setBrush(option->palette.mid().color()); imagePainter.setPen(option->palette.mid().color()); } else { QColor shadow(0, 0, 0, 100); imagePainter.translate(0, 1); imagePainter.setPen(shadow); imagePainter.setBrush(shadow); QColor foreGround(255, 255, 255, 210); imagePainter.drawPolygon(a); imagePainter.translate(0, -1); imagePainter.setPen(foreGround); imagePainter.setBrush(foreGround); } imagePainter.drawPolygon(a); imagePainter.end(); pixmap = QPixmap::fromImage(image); QPixmapCache::insert(pixmapName, pixmap); } int xOffset = r.x() + (r.width() - size)/2; int yOffset = r.y() + (r.height() - size)/2; painter->drawPixmap(xOffset, yOffset, pixmap); } break; default: d->style->drawPrimitive(element, option, painter, widget); break; } }
void Style::drawSlider(const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { ASSURE_OPTION(slider, Slider); OPT_SUNKEN OPT_ENABLED OPT_HOVER if (isEnabled && slider->subControls & SC_SliderTickmarks) { int ticks = slider->tickPosition; if (ticks != QSlider::NoTicks) { int available = pixelMetric(PM_SliderSpaceAvailable, slider, widget); int interval = slider->tickInterval; if (interval < 1) interval = slider->pageStep; if (interval) { // const int thickness = pixelMetric(PM_SliderControlThickness, slider, widget); const int len = pixelMetric(PM_SliderLength, slider, widget); const int fudge = len / 2; int pos, v = slider->minimum, nextInterval; // Since there is no subrect for tickmarks do a translation here. painter->save(); painter->translate(RECT.x(), RECT.y()); #define DRAW_TICKS(_X1_, _Y1_, _X2_, _Y2_) \ while (v <= slider->maximum) { \ pos = sliderPositionFromValue(slider->minimum, slider->maximum, v, available) + fudge;\ painter->drawLine(_X1_, _Y1_, _X2_, _Y2_);\ nextInterval = v + interval;\ if (nextInterval < v) break;\ v = nextInterval; \ } // skip semicolon painter->setPen(Colors::mid(BGCOLOR, FGCOLOR, 3,1)); if (slider->orientation == Qt::Horizontal) { const int y = RECT.height()/2; if (ticks == QSlider::TicksAbove) { DRAW_TICKS(pos, 0, pos, y); } else if (ticks == QSlider::TicksBelow) { DRAW_TICKS(pos, y, pos, RECT.height()); } else { DRAW_TICKS(pos, RECT.y(), pos, RECT.height()); } } else { const int x = RECT.width()/2; if (ticks == QSlider::TicksAbove) { DRAW_TICKS(0, pos, x, pos); } else if (ticks == QSlider::TicksBelow) { DRAW_TICKS(x, pos, RECT.width(), pos); } else { DRAW_TICKS(0, pos, RECT.width(), pos); } } painter->restore(); } } } QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget); QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget); isEnabled = isEnabled && (slider->maximum > slider->minimum); hover = isEnabled && (appType == GTK || (hover && (slider->activeSubControls & SC_SliderHandle))); sunken = sunken && (slider->activeSubControls & SC_SliderHandle); // const int ground = 0; // groove if ((slider->subControls & SC_SliderGroove) && groove.isValid()) { QStyleOption grooveOpt = *option; grooveOpt.rect = groove; const Groove::Mode gType = config.scroll.groove; if (gType) config.scroll.groove = Groove::Groove; drawScrollBarGroove(&grooveOpt, painter, widget); config.scroll.groove = gType; #if 1 // thermometer, #2 if (slider->minimum > -1 && (slider->maximum - slider->minimum) > 20 && slider->sliderPosition != slider->minimum) { SAVE_PEN; bool hadAntiAlias = painter->testRenderHint(QPainter::Antialiasing); painter->setRenderHint( QPainter::Antialiasing, gType ); painter->setPen(QPen(CCOLOR(scroll._, Fg), gType ? F(3) : F(1), Qt::SolidLine, Qt::RoundCap)); if ( slider->orientation == Qt::Horizontal ) { const int y = groove.center().y() + (gType ? 1 : 0); bool ltr = slider->direction == Qt::LeftToRight; if (slider->upsideDown) ltr = !ltr; const int x2 = ltr ? groove.left() + F(5) : groove.right() - F(5); painter->drawLine(handle.center().x(), y, x2, y); } else { const int x = groove.center().x(); const int y2 = slider->upsideDown ? groove.bottom() - F(5) : groove.top() + F(5); painter->drawLine(x, handle.center().y(), x, y2); } painter->setRenderHint( QPainter::Antialiasing, hadAntiAlias ); RESTORE_PEN; } #endif } // int direction = 0; // if (slider->orientation == Qt::Vertical) // ++direction; // handle ====================================== if (slider->subControls & SC_SliderHandle) { int step = 0; if (sunken) step = 6; else if (isEnabled) { const Animator::ComplexInfo *info = Animator::HoverComplex::info(widget, slider->activeSubControls & SC_SliderHandle); if (info && ( info->fades[Animator::In] & SC_SliderHandle || info->fades[Animator::Out] & SC_SliderHandle )) step = info->step(SC_SliderHandle); if (hover && !step) step = 6; } drawSliderHandle(handle, option, painter, step); } }
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return d->style->drawComplexControl(control, option, painter, widget); QRect rect = option->rect; switch (control) { case CC_ToolButton: if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { QString buttonType = widget->property("type").toString(); QRect button, menuarea; button = subControlRect(control, toolbutton, SC_ToolButton, widget); menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget); State bflags = toolbutton->state; if (bflags & State_AutoRaise) { if (!(bflags & State_MouseOver)) { bflags &= ~State_Raised; } } State mflags = bflags; if (toolbutton->state & State_Sunken) { if (toolbutton->activeSubControls & SC_ToolButton) bflags |= State_Sunken; if (toolbutton->activeSubControls & SC_ToolButtonMenu) mflags |= State_Sunken; } QStyleOption tool(0); tool.palette = toolbutton->palette; if (toolbutton->subControls & SC_ToolButton) { // if (buttonType == "dockbutton") { tool.rect = button; tool.state = bflags; drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); // } /*else { // paint status bar button style if (bflags & State_Sunken || bflags & State_On) drawCornerImage(d->buttonImage_pressed, painter, option->rect, 2, 2, 2, 2); else if (bflags & State_Enabled) { #ifndef Q_WS_MAC if (bflags & State_MouseOver) { drawCornerImage(d->buttonImage, painter, option->rect, 2, 2, 2, 2); QColor shade(255, 255, 255, 50); painter->fillRect(button.adjusted(1, 1, -1, -1), shade); } #endif } }*/ } if (toolbutton->state & State_HasFocus) { QStyleOptionFocusRect fr; fr.QStyleOption::operator=(*toolbutton); fr.rect.adjust(3, 3, -3, -3); if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup) fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator, toolbutton, widget), 0); QPen oldPen = painter->pen(); QColor focusColor = StyleHelper::panelTextColor(); focusColor.setAlpha(120); QPen outline(focusColor, 1); outline.setStyle(Qt::DotLine); painter->setPen(outline); QRect r = option->rect.adjusted(2, 2, -2, -2); painter->drawRect(r); painter->setPen(oldPen); } QStyleOptionToolButton label = *toolbutton; label.palette = panelPalette(option->palette); int fw = pixelMetric(PM_DefaultFrameWidth, option, widget); label.rect = button.adjusted(fw, fw, -fw, -fw); drawControl(CE_ToolButtonLabel, &label, painter, widget); if (toolbutton->subControls & SC_ToolButtonMenu) { tool.state = mflags; tool.rect = menuarea.adjusted(1, 1, -1, -1); if (mflags & (State_Sunken | State_On | State_Raised)) { painter->setPen(Qt::gray); painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft()); if (mflags & (State_Sunken)) { QColor shade(0, 0, 0, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #ifndef Q_WS_MAC else if (mflags & (State_MouseOver)) { QColor shade(255, 255, 255, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #endif } tool.rect = tool.rect.adjusted(2, 2, -2, -2); drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget); } else if (toolbutton->features & QStyleOptionToolButton::HasMenu) { int arrowSize = 6; QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1); QStyleOptionToolButton newBtn = *toolbutton; newBtn.palette = panelPalette(option->palette); newBtn.rect = QRect(ir.right() - arrowSize - 1, ir.height() - arrowSize - 2, arrowSize, arrowSize); drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget); } } break; case CC_ComboBox: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { painter->save(); bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull(); bool reverse = option->direction == Qt::RightToLeft; // Draw tool button QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight()); grad.setColorAt(0, QColor(255, 255, 255, 20)); grad.setColorAt(0.4, QColor(255, 255, 255, 60)); grad.setColorAt(0.7, QColor(255, 255, 255, 50)); grad.setColorAt(1, QColor(255, 255, 255, 40)); painter->setPen(QPen(grad, 0)); painter->drawLine(rect.topRight(), rect.bottomRight()); painter->drawLine(rect.topLeft(), rect.bottomLeft()); grad.setColorAt(0, QColor(0, 0, 0, 30)); grad.setColorAt(0.4, QColor(0, 0, 0, 70)); grad.setColorAt(0.7, QColor(0, 0, 0, 70)); grad.setColorAt(1, QColor(0, 0, 0, 40)); painter->setPen(QPen(grad, 0)); if (!reverse) painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0)); else painter->drawLine(rect.topLeft(), rect.bottomLeft()); QStyleOption toolbutton = *option; if (isEmpty) toolbutton.state &= ~(State_Enabled | State_Sunken); painter->save(); painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0)); drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget); painter->restore(); // Draw arrow int menuButtonWidth = 12; int left = !reverse ? rect.right() - menuButtonWidth : rect.left(); int right = !reverse ? rect.right() : rect.left() + menuButtonWidth; QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9); if (option->state & State_On) arrowRect.translate(d->style->pixelMetric(PM_ButtonShiftHorizontal, option, widget), d->style->pixelMetric(PM_ButtonShiftVertical, option, widget)); QStyleOption arrowOpt = *option; arrowOpt.rect = arrowRect; if (isEmpty) arrowOpt.state &= ~(State_Enabled | State_Sunken); if (styleHint(SH_ComboBox_Popup, option, widget)) { arrowOpt.rect.translate(0, -3); drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget); arrowOpt.rect.translate(0, 6); drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } else { drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } painter->restore(); } break; default: d->style->drawComplexControl(control, option, painter, widget); break; } }
/*!\reimp */ QRect QPlatinumStyle::querySubControlMetrics( ComplexControl control, const QWidget *widget, SubControl sc, const QStyleOption& opt ) const { switch( control ) { #ifndef QT_NO_COMBOBOX case CC_ComboBox: const QComboBox *cb; cb = (const QComboBox *)widget; switch( sc ) { case SC_ComboBoxArrow: { QRect ir = cb->rect(); int xx; if( QApplication::reverseLayout() ) xx = ir.x(); else xx = ir.x() + ir.width() - 20; return QRect( xx, ir.y(), 20, ir.height()); } default: break; } break; #endif #ifndef QT_NO_SCROLLBAR case CC_ScrollBar: { const QScrollBar *sb; sb = (const QScrollBar *)widget; int sliderStart = sb->sliderStart(); int sbextent = pixelMetric( PM_ScrollBarExtent, widget ); int maxlen = ((sb->orientation() == Qt::Horizontal) ? sb->width() : sb->height()) - ( sbextent * 2 ); int sliderlen; // calculate length if ( sb->maxValue() != sb->minValue() ) { uint range = sb->maxValue() - sb->minValue(); sliderlen = ( sb->pageStep() * maxlen ) / ( range + sb->pageStep() ); int slidermin = pixelMetric( PM_ScrollBarSliderMin, widget ); if ( sliderlen < slidermin || range > INT_MAX / 2 ) sliderlen = slidermin; if ( sliderlen > maxlen ) sliderlen = maxlen; } else { sliderlen = maxlen; } switch ( sc ) { case SC_ScrollBarSubLine: if ( sb->orientation() == Qt::Horizontal ) { int buttonw = QMIN( sb->width() / 2, sbextent ); return QRect( sb->width() - 2 * buttonw, 0, buttonw, sbextent ); } else { int buttonh = QMIN( sb->height() / 2, sbextent ); return QRect( 0, sb->height() - 2 * buttonh, sbextent, buttonh ); } case SC_ScrollBarAddLine: if ( sb->orientation() == Qt::Horizontal ) { int buttonw = QMIN( sb->width() / 2, sbextent ); return QRect( sb->width() - buttonw, 0, sbextent, buttonw ); } else { int buttonh = QMIN( sb->height() / 2, sbextent ); return QRect(0, sb->height() - buttonh, sbextent, buttonh ); } case SC_ScrollBarSubPage: if ( sb->orientation() == Qt::Horizontal ) return QRect( 1, 0, sliderStart, sbextent ); return QRect( 0, 1, sbextent, sliderStart ); case SC_ScrollBarAddPage: if ( sb->orientation() == Qt::Horizontal ) return QRect( sliderStart + sliderlen, 0, maxlen - sliderStart - sliderlen, sbextent ); return QRect( 0, sliderStart + sliderlen, sbextent, maxlen - sliderStart - sliderlen ); case SC_ScrollBarGroove: if ( sb->orientation() == Qt::Horizontal ) return QRect( 1, 0, sb->width() - sbextent * 2, sb->height() ); return QRect( 0, 1, sb->width(), sb->height() - sbextent * 2 ); default: break; } break; } #endif #ifndef QT_NO_SLIDER case CC_Slider: { const QSlider *slider = (const QSlider *) widget; int tickOffset = pixelMetric( PM_SliderTickmarkOffset, widget); int thickness = pixelMetric( PM_SliderControlThickness, widget); int mid = thickness / 2; int ticks = slider->tickmarks(); int len = pixelMetric( PM_SliderLength, widget ); switch ( sc ) { case SC_SliderGroove: if ( ticks & QSlider::Above ) mid += len / 8; if ( ticks & QSlider::Below ) mid -= len / 8; if ( slider->orientation() == QSlider::Horizontal ) return QRect( 0, tickOffset, slider->width(), thickness ); return QRect( tickOffset, 0, thickness, slider->height() ); default: break; } break; } #endif default: break; } return QWindowsStyle::querySubControlMetrics( control, widget, sc, opt ); }