void PushButtonOrientated::paintEvent(QPaintEvent* event) { Q_UNUSED(event); QStylePainter painter(this); switch (m_orientation) { case Qt::Horizontal: if (m_mirrored) { painter.rotate(180); painter.translate(-width(), -height()); } break; case Qt::Vertical: if (m_mirrored) { painter.rotate(-90); painter.translate(-height(), 0); } else { painter.rotate(90); painter.translate(0, -width()); } break; } painter.drawControl(QStyle::CE_PushButton, getStyleOption()); }
void toRotatingButton::paintEvent(QPaintEvent *) { updateGeometry(); QStylePainter painter(this); painter.rotate(rotate); switch (rotate) { case UpsideDown: painter.translate(-width(), -height()); break; case Clockwise: painter.translate(0, -width()); break; case CounterClockwise: painter.translate(-height(), 0); break; default: // nothing to do break; } const QStyleOptionButton option = getStyleOption(); painter.drawControl(QStyle::CE_PushButton, option); }
void KonqCombo::paintEvent( QPaintEvent *pe ) { QComboBox::paintEvent( pe ); QLineEdit *edit = lineEdit(); QStyleOptionComboBox comboOpt; getStyleOption(&comboOpt); QRect re = style()->subControlRect( QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxEditField, this ); re = QStyle::visualRect(layoutDirection(), rect(), re); if (m_pageSecurity!= KonqMainWindow::NotCrypted) { QPainter p( this ); p.setClipRect( re ); QPixmap pix = SmallIcon(QLatin1String(m_pageSecurity == KonqMainWindow::Encrypted ? "security-high" : "security-medium")); QRect r = edit->geometry(); r.setRight( re.right() - pix.width() - 2 ); if ( r != edit->geometry() ) edit->setGeometry( r ); p.drawPixmap( re.right() - pix.width() -1 , re.y() + ( re.height() - pix.height() ) / 2, pix ); p.setClipping( false ); } else { QRect r = edit->geometry(); r.setRight( re.right() ); if ( r != edit->geometry() ) edit->setGeometry( r ); } }
void KonqCombo::mousePressEvent( QMouseEvent *e ) { m_dragStart = QPoint(); // null QPoint if ( e->button() == Qt::LeftButton && !itemIcon( currentIndex()).isNull() ) { // check if the pixmap was clicked int x = e->pos().x(); QStyleOptionComboBox comboOpt; getStyleOption(&comboOpt); int x0 = QStyle::visualRect( layoutDirection(), rect(), style()->subControlRect( QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxEditField, this ) ).x(); if ( x > x0 + 2 && x < lineEdit()->x() ) { m_dragStart = e->pos(); return; // don't call KComboBox::mousePressEvent! } } QStyleOptionComboBox optCombo; optCombo.initFrom(this); if ( e->button() == Qt::LeftButton && m_pageSecurity != KonqMainWindow::NotCrypted && style()->subElementRect( QStyle::SE_ComboBoxFocusRect, &optCombo, this ).contains( e->pos() ) ) emit showPageSecurity(); KComboBox::mousePressEvent( e ); }
/*! \reimp */ QSize Q3ProgressBar::sizeHint() const { ensurePolished(); QFontMetrics fm = fontMetrics(); QStyleOptionProgressBar opt = getStyleOption(this); int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, this); return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, QSize(cw * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8), this); }
QSize ComboBoxItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionMenuItem opt = getStyleOption(option, index); QSize size = mCombo->style()->sizeFromContents( QStyle::CT_MenuItem, &opt, option.rect.size(), mCombo); //Fix width for some reason size.setWidth(opt.rect.width()); return size; }
void Q3SpinWidget::arrange() { QStyleOptionSpinBox opt = getStyleOption(this); d->up = style()->subControlRect(QStyle::CC_SpinBox, &opt, QStyle::SC_SpinBoxUp, this); d->down = style()->subControlRect(QStyle::CC_SpinBox, &opt, QStyle::SC_SpinBoxDown, this); if (d->ed) { QRect r = style()->subControlRect(QStyle::CC_SpinBox, &opt, QStyle::SC_SpinBoxEditField, this); d->ed->setGeometry(r); } }
/*! */ void Q3SpinWidget::paintEvent(QPaintEvent *) { QPainter p(this); QStyleOptionSpinBox opt = getStyleOption(this); if (d->theButton & 1) { opt.activeSubControls = QStyle::SC_SpinBoxDown; opt.state |= QStyle::State_Sunken; } else if (d->theButton & 2) { opt.activeSubControls = QStyle::SC_SpinBoxUp; opt.state |= QStyle::State_Sunken; } else opt.activeSubControls = QStyle::SC_None; opt.rect = style()->subControlRect(QStyle::CC_SpinBox, &opt, QStyle::SC_SpinBoxFrame, this); opt.subControls = QStyle::SC_All; style()->drawComplexControl(QStyle::CC_SpinBox, &opt, &p, this); }
QSize KxMenuItemWidget::sizeHint() const { // Do not give invisible menu items any space if(!fMenuItem->isVisible()) return QSize(0,0); QSize sz; QWidget *q = parentWidget(); QStyleOptionMenuItem opt = getStyleOption(); KxMenuItem *action = fMenuItem; const int hmargin = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q), iconWidth = q->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, q); QFontMetrics fm(action->font().resolve(q->font())); if (action->isSeparator()) { sz = QSize(2, 2); } else { // Text QString s = action->text(); int w = fm.width(s); QKeySequence shortcutSeq = fMenuItem->shortcut(); sz.setWidth(w); sz.setHeight(fm.height()); // Keyboard shortcut if(!shortcutSeq.isEmpty()) { QString shortcut = shortcutSeq.toString(QKeySequence::NativeText); w = fm.width(shortcut); sz.rwidth() += w + kShortcutRightMargin; } // Checkbox if(action->isCheckable()) { sz.rwidth() += iconWidth; } // option boxes sz.rwidth() += iconWidth; // Margins sz.rwidth() += 2 * hmargin; } opt.rect = q->rect(); sz = q->style()->sizeFromContents(QStyle::CT_MenuItem, &opt, sz, q); return sz; }
/*! \reimp */ void Q3ProgressBar::paintEvent(QPaintEvent *) { QPainter paint(this); QPainter *p = &paint; drawFrame(p); QStyleOptionProgressBar opt = getStyleOption(this); opt.rect = style()->subElementRect(QStyle::SE_ProgressBarGroove, &opt, this); style()->drawControl(QStyle::CE_ProgressBarGroove, &opt, p, this); opt.rect = contentsRect(); opt.rect = style()->subElementRect(QStyle::SE_ProgressBarContents, &opt, this); style()->drawControl(QStyle::CE_ProgressBarContents, &opt, p, this); if (percentageVisible()) { opt.rect = contentsRect(); opt.rect = style()->subElementRect(QStyle::SE_ProgressBarLabel, &opt, this); style()->drawControl(QStyle::CE_ProgressBarLabel, &opt, p, this); } }
void ComboBoxItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionMenuItem opt = getStyleOption(option, index); #ifndef Q_WS_S60 painter->fillRect(option.rect, opt.palette.background()); #endif mCombo->style()->drawControl(QStyle::CE_MenuItem, &opt, painter, mCombo); if (index.data(Qt::UserRole).toString() != INVALID_DATA) { int height = option.fontMetrics.height(); QStyleOptionViewItemV4 optionIcon(option); optionIcon.rect.setX(option.rect.width()-height); optionIcon.rect.setWidth(height); bool showDelIcon = true; QVariant removable = index.data(ITEM_REMOVABLE_ROLE); if (removable.type() == QVariant::Bool) showDelIcon = removable.toBool(); if (showDelIcon) mDeleteIcon.paint(painter, optionIcon.rect); } }
bool ComboBoxItemDelegate::mouseReleased(QEvent * event) { if (event->type() != QEvent::MouseButtonRelease) return false; QAbstractItemModel* model = mCombo->model(); QMouseEvent *ev = static_cast<QMouseEvent*>(event); QModelIndex index = mCombo->view()->indexAt(ev->pos()); QVariant removable = index.data(ITEM_REMOVABLE_ROLE); bool remove = true; if (removable.type() == QVariant::Bool) remove = removable.toBool(); if (remove && mLastIndex == index && model && index.data(Qt::UserRole).toString() != INVALID_DATA) { QStyleOptionMenuItem opt = getStyleOption(mLastStyleOption, index); int height = opt.rect.height(); if (ev->x() >= opt.rect.width()-height) { emit removeItem(index.row()); return true; } } return false; }
int QxtStarsPrivate::pixelPosToRangeValue(int pos) const { const QxtStars* p = &qxt_p(); QStyleOptionSlider opt = getStyleOption(); QRect gr = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, p); QRect sr = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, p); int sliderMin, sliderMax, sliderLength; gr.setSize(qxt_p().sizeHint()); if (p->orientation() == Qt::Horizontal) { sliderLength = sr.width(); sliderMin = gr.x(); sliderMax = gr.right() - sliderLength + 1; } else { sliderLength = sr.height(); sliderMin = gr.y(); sliderMax = gr.bottom() - sliderLength + 1; } return QStyle::sliderValueFromPosition(p->minimum(), p->maximum(), pos - sliderMin, sliderMax - sliderMin, opt.upsideDown); }
void YaTabBarBase::drawTab(QPainter* painter, int index, const QRect& tabRect) { QStyleOptionTabV2 tab = getStyleOption(index); if (!(tab.state & QStyle::State_Enabled)) { tab.palette.setCurrentColorGroup(QPalette::Disabled); } // Don't bother drawing a tab if the entire tab is outside of the visible tab bar. if (tabRect.right() < 0 || tabRect.left() > width() || tabRect.bottom() < 0 || tabRect.top() > height() || tabRect.width() < 3) { return; } bool isCurrent = index == currentIndex(); bool isHovered = tabHovered(index); bool isHighlighted = tabData(index).toBool(); QColor backgroundColor = this->tabBackgroundColor(); if (isCurrent) { #ifndef WIDGET_PLUGIN backgroundColor = Ya::VisualUtil::editAreaColor(); #else backgroundColor = Qt::white; #endif } else if (isHovered) { #ifndef WIDGET_PLUGIN backgroundColor = Ya::VisualUtil::tabHighlightColor(); #else backgroundColor = Qt::gray; #endif } else if (isHighlighted) { backgroundColor = highlightColor(); } if (backgroundColor.isValid()) { painter->fillRect(tabRect, backgroundColor); } painter->save(); #ifndef WIDGET_PLUGIN painter->setPen(Ya::VisualUtil::rosterTabBorderColor()); #endif bool drawLeftLine = tabRect.left() != rect().left(); bool drawRightLine = true; // tabRect.right() != rect().right() || rect().width() < maximumWidth(); switch (shape()) { case YaTabBarBase::RoundedSouth: case YaTabBarBase::TriangularSouth: if (isMultiLine()) drawRightLine = tabRect.right() + 1 < maximumWidth(); if (!isCurrent || isMultiLine()) painter->drawLine(tabRect.topLeft(), tabRect.topRight()); if (isCurrent) { if (drawLeftLine && !isMultiLine()) painter->drawLine(tabRect.topLeft(), tabRect.bottomLeft()); if (drawRightLine) painter->drawLine(tabRect.topRight(), tabRect.bottomRight()); } else { if (isHovered || isMultiLine()) { if (currentIndex() != (index - 1) && !isMultiLine()) if (drawLeftLine) painter->drawLine(tabRect.topLeft(), tabRect.bottomLeft()); if (currentIndex() != (index + 1) || isMultiLine()) if (drawRightLine) painter->drawLine(tabRect.topRight(), tabRect.bottomRight()); } } break; default: Q_ASSERT(false); break; } painter->restore(); tabIcon(index).paint(painter, tabIconRect(index)); QRect textRect = tabTextRect(index); QString text = tabText(index); if (drawTabNumbers_ && index < 10) { int numberToDraw = index + 1; if (numberToDraw > 9) { numberToDraw = 0; } painter->save(); painter->setPen(Qt::gray); QString numberToDrawText = QString::number(numberToDraw) + " "; painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, numberToDrawText); textRect.adjust(fontMetrics().width(numberToDrawText), 0, 0, 0); painter->restore(); } painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, text); #ifndef WIDGET_PLUGIN if (textWidth(text) > textRect.width() && backgroundColor.isValid()) { Ya::VisualUtil::drawTextFadeOut(painter, textRect.adjusted(1, 0, 1, 0), backgroundColor, 15); } #endif if (isMultiLine()) { QPixmap shadow(tabShadow(isCurrent)); QRect r(tabRect); r.setHeight(shadow.height()); painter->drawTiledPixmap(r, shadow); } }
void M11TabBar::paintEvent(QPaintEvent*) { QStyleOptionTab tabOverlap; tabOverlap.shape = shape(); int overlap = style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, &tabOverlap, this); QWidget *theParent = parentWidget(); QStyleOptionTabBarBase optTabBase; optTabBase.init(this); optTabBase.shape = shape(); if (theParent && overlap > 0) { QRect rect; switch (tabOverlap.shape) { case M11TabBar::RoundedNorth: case M11TabBar::TriangularNorth: rect.setRect(0, height() - overlap, width(), overlap); break; case M11TabBar::RoundedSouth: case M11TabBar::TriangularSouth: rect.setRect(0, 0, width(), overlap); break; case M11TabBar::RoundedEast: case M11TabBar::TriangularEast: rect.setRect(0, 0, overlap, height()); break; case M11TabBar::RoundedWest: case M11TabBar::TriangularWest: rect.setRect(width() - overlap, 0, overlap, height()); break; } optTabBase.rect = rect; } QStylePainter p(this); p.fillRect(rect(), Utils::instance().gradientTopToBottom(rect())); QPen pen = p.pen(); int selected = -1; int cut = -1; bool rtl = optTabBase.direction == Qt::RightToLeft; bool verticalTabs = (shape() == M11TabBar::RoundedWest || shape() == M11TabBar::RoundedEast || shape() == M11TabBar::TriangularWest || shape() == M11TabBar::TriangularEast); QStyleOptionTab cutTab; QStyleOptionTab selectedTab; for (int i = 0; i < count(); ++i) { QStyleOptionTabV2 tab = getStyleOption(i); if (!(tab.state & QStyle::State_Enabled)) { tab.palette.setCurrentColorGroup(QPalette::Disabled); } // If this tab is partially obscured, make a note of it so that we can pass the information // along when we draw the tear. if ((!verticalTabs && (!rtl && tab.rect.left() < 0) || (rtl && tab.rect.right() > width())) || (verticalTabs && tab.rect.top() < 0)) { cut = i; cutTab = tab; } // Don't bother drawing a tab if the entire tab is outside of the visible tab bar. if ((!verticalTabs && (tab.rect.right() < 0 || tab.rect.left() > width())) || (verticalTabs && (tab.rect.bottom() < 0 || tab.rect.top() > height()))) continue; optTabBase.tabBarRect |= tab.rect; if (i == currentIndex()) { selected = i; selectedTab = tab; optTabBase.selectedTabRect = tab.rect; } QIcon icon = tabIcon(i); QSize iconSize = icon.actualSize(QSize(tab.rect.height(), tab.rect.height())); int iconMargin = (tab.rect.height() - iconSize.height()) / 2; QRect iconRect(tab.rect.left() + iconMargin, tab.rect.top(), iconSize.width(), tab.rect.height()); QString text = tabText(i); QRect textRect( tab.rect.left() + iconMargin + iconSize.width(), tab.rect.top(), tab.rect.width() - iconSize.width(), tab.rect.height() ); p.fillRect( tab.rect, i == currentIndex() ? Utils::instance().palette().base() : tab.rect.contains(mapFromGlobal(QCursor::pos())) ? Utils::instance().palette().light() : Utils::instance().gradientTopToBottom(tab.rect) ); p.setPen(Utils::instance().palette().dark().color()); switch (shape()) { // override the widget's border to make it consistent over inactive tabs case M11TabBar::RoundedNorth: case M11TabBar::TriangularNorth: if (i == currentIndex()) { p.drawRect(tab.rect.adjusted(0, 0, -1, 0)); } else { p.drawLine(tab.rect.bottomLeft(), tab.rect.bottomRight()); } break; case M11TabBar::RoundedSouth: case M11TabBar::TriangularSouth: if (i == currentIndex()) { p.drawRect(tab.rect.adjusted(0, -1, -1, -1)); } else { p.drawLine(tab.rect.topLeft(), tab.rect.topRight()); } break; case M11TabBar::RoundedEast: case M11TabBar::TriangularEast: if (i == currentIndex()) { p.drawRect(tab.rect.adjusted(-1, 0, -1, -1)); } else { p.drawLine(tab.rect.topLeft(), tab.rect.bottomLeft()); } break; case M11TabBar::RoundedWest: case M11TabBar::TriangularWest: if (i == currentIndex()) { p.drawRect(tab.rect.adjusted(0, 0, 0, -1)); } else { p.drawLine(tab.rect.topRight(), tab.rect.bottomRight()); } break; default: Q_ASSERT(false); break; } p.setPen(m_tabLabelColors.contains(i) ? m_tabLabelColors.value(i).color() : pen); QString textToDraw = fontMetrics().elidedText( text, elideMode(), 1 + ( verticalTabs ? tabRect(i).height() : tabRect(i).width() ) - style()->pixelMetric(QStyle::PM_TabBarTabHSpace, &tab, this), Qt::TextShowMnemonic ); p.drawItemPixmap(iconRect, Qt::AlignCenter, icon.pixmap(iconSize)); p.drawItemText( textRect, Qt::AlignLeft | Qt::AlignVCenter, QPalette(), tab.state & QStyle::State_Enabled, textToDraw ); p.setPen(pen); } if (!drawBase()) { p.setBackgroundMode(Qt::TransparentMode); } else { // p.drawPrimitive(QStyle::PE_FrameTabBarBase, optTabBase); } // Only draw the tear indicator if necessary. Most of the time we don't need too. if (cut >= 0) { cutTab.rect = rect(); cutTab.rect = style()->subElementRect(QStyle::SE_TabBarTearIndicator, &cutTab, this); p.drawPrimitive(QStyle::PE_IndicatorTabTear, cutTab); } // p.setPen(Qt::black); // p.drawRect(rect()); }
void KxMenuItemWidget::paintEvent(QPaintEvent *event) { // Do not draw invisible menu items if(!fMenuItem->isVisible()) return; QStylePainter painter(this); QStyleOptionMenuItem opt = getStyleOption(); QRect boxRect; bool inOptionBox = false; QWidget *q = parentWidget(); const int hmargin = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q), iconWidth = q->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, q); if(!fMenuItem->isSeparator()) { if(fMenuItem->hasOptionBox()) { boxRect.setRect(rect().right() - hmargin - iconWidth, rect().top(), iconWidth, rect().height()); QPoint p = QCursor::pos(); p = mapFromGlobal(p); if(boxRect.contains(p)) { inOptionBox = true; } else { // Subtract option box rect from style option rect int newRight = opt.rect.right() - iconWidth - hmargin; opt.rect.setRight(newRight); } } } // Draw general menu item opt.rect.adjust(0, 0, -1, 0); painter.drawControl(QStyle::CE_MenuItem, opt); // Draw shortcut QKeySequence shortcutSeq = fMenuItem->shortcut(); if(!shortcutSeq.isEmpty()) { // shortcut bounds QRect scRect = opt.rect; QString shortcut = shortcutSeq.toString(QKeySequence::NativeText); QMenu *menu = qobject_cast<QMenu *>(parentWidget()); Q_ASSERT(menu != NULL); int shortcutWidth = 12; // default value in case there is no font if ( menu ) { QFontMetrics metrics(fMenuItem->font().resolve(menu->font())); shortcutWidth = metrics.width(shortcut); } scRect.setLeft(scRect.right() - shortcutWidth); if(inOptionBox || !fMenuItem->hasOptionBox()) { scRect.translate(-iconWidth, 0); } scRect.translate(-kShortcutRightMargin, 0); painter.drawItemText(scRect, Qt::AlignRight | Qt::AlignVCenter, palette(), true, shortcut); } // Draw option box if(!fMenuItem->isSeparator() && fMenuItem->hasOptionBox()) { QIcon* boxIcon = NULL; QVariant v = fMenuItem->optionBoxAction()->property( "optionBoxIcon" ); if ( v.isValid() ) { QString optionBoxIcon; optionBoxIcon = v.toString(); boxIcon = KxQtHelper::createIcon( optionBoxIcon ); } if ( boxIcon == NULL ) { boxIcon = new QIcon(":/optionBox.png"); } boxRect.setRect(rect().right() - hmargin - iconWidth, rect().top()+(rect().height()-iconWidth)/2, iconWidth, iconWidth); boxIcon->paint(&painter, boxRect, Qt::AlignCenter, fMenuItem->isEnabled() ? QIcon::Normal : QIcon::Disabled); delete boxIcon; } }