void QDockWidgetTitleButton::paintEvent(QPaintEvent *) { QPainter p(this); QStyleOptionToolButton opt; opt.init(this); opt.state |= QStyle::State_AutoRaise; if (style()->styleHint(QStyle::SH_DockWidget_ButtonsHaveFrame, 0, this)) { if (isEnabled() && underMouse() && !isChecked() && !isDown()) opt.state |= QStyle::State_Raised; if (isChecked()) opt.state |= QStyle::State_On; if (isDown()) opt.state |= QStyle::State_Sunken; style()->drawPrimitive(QStyle::PE_PanelButtonTool, &opt, &p, this); } opt.icon = icon(); opt.subControls = 0; opt.activeSubControls = 0; opt.features = QStyleOptionToolButton::None; opt.arrowType = Qt::NoArrow; int size = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); opt.iconSize = QSize(size, size); style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &p, this); }
void ToolButton::paintEvent(QPaintEvent* e) { if (!m_usingMultiIcon) { QToolButton::paintEvent(e); return; } QPainter p(this); QStyleOptionToolButton opt; opt.init(this); if (!isEnabled()) { p.drawPixmap(0, 0, m_disabledIcon); return; } if (isDown()) { p.drawPixmap(0, 0, m_activeIcon); return; } if (opt.state & QStyle::State_MouseOver) { p.drawPixmap(0, 0, m_hoverIcon); return; } p.drawPixmap(0, 0, m_normalIcon); }
ToolWindowManagerTabBar::ToolWindowManagerTabBar(QWidget *parent) : QTabBar(parent) { m_tabsClosable = false; setMouseTracking(true); m_area = qobject_cast<ToolWindowManagerArea *>(parent); // Workaround for extremely dodgy KDE behaviour - by default the KDE theme will install event // filters on various widgets such as QTabBar and any descendents, and if a click is detected on // them that isn't on a tab it will immediately start moving the window, interfering with our own // click-to-drag behaviour. setProperty("_kde_no_window_grab", true); QStyleOptionToolButton buttonOpt; int size = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); buttonOpt.initFrom(parentWidget()); buttonOpt.iconSize = QSize(size, size); buttonOpt.subControls = 0; buttonOpt.activeSubControls = 0; buttonOpt.features = QStyleOptionToolButton::None; buttonOpt.arrowType = Qt::NoArrow; buttonOpt.state |= QStyle::State_AutoRaise; // TODO make our own pin icon, that is pinned/unpinned m_pin.icon = style()->standardIcon(QStyle::SP_TitleBarNormalButton, &buttonOpt, this); m_close.icon = style()->standardIcon(QStyle::SP_TitleBarCloseButton, &buttonOpt, this); m_pin.hover = m_pin.clicked = false; m_close.hover = m_close.clicked = false; }
void QColorPickerTool::paintEvent ( QPaintEvent * ) { QStyleOptionToolButton option; option.initFrom( this ); option.features = QStyleOptionToolButton::HasMenu; //option.state = this->style()->stat QPixmap icon( 10, 10 ); QPainter iconPainter( &icon ); iconPainter.fillRect( 0, 0, 10, 10, _selectedColor ); //option.icon = icon; QPainter painter ( this ); //option.text = "COLOR"; option.text = text(); //painter.fillRect( 0, 0, 10, 10, _selectedColor ); //painter.setPen( _selectedColor ); //painter.drawText( 0 ,20, "A" ); //this->setIcon( icon ); style()->drawComplexControl( QStyle::CC_ToolButton, &option, &painter, this ); }
bool UIControllerSetting::eventFilter( QObject* object, QEvent* event ) { if ( event->type() == QEvent::Paint ) { QToolButton* tb = qobject_cast<QToolButton*>( object ); if ( tb ) { if ( tb->isChecked() ) { QStylePainter sp( tb ); QStyleOptionToolButton options; options.initFrom( tb ); options.arrowType = Qt::NoArrow; options.features = QStyleOptionToolButton::None; options.icon = tb->icon(); options.iconSize = tb->iconSize(); options.state = QStyle::State_Enabled | QStyle::State_HasFocus | QStyle::State_On | QStyle::State_AutoRaise; sp.drawComplexControl( QStyle::CC_ToolButton, options ); return true; } } } return false; }
void GuiToolButton::paintEvent(QPaintEvent *e) { QStyleOptionToolButton option; option.initFrom(this); QPainter painter(this); if (option.state & QStyle::State_MouseOver) painter.drawPixmap(e->rect(), QPixmap(":/images/menu-hover.png")); else painter.drawPixmap(e->rect(), QPixmap(":/images/drag.png")); }
void KDatePicker::setFontSize(int s) { QWidget *buttons[]= { // yearBackward, // monthBackward, d->selectMonth, d->selectYear, // monthForward, // yearForward }; const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); int count; QFont font; QRect r; // ----- d->fontsize=s; for(count=0; count<NoOfButtons; ++count) { font=buttons[count]->font(); font.setPointSize(s); buttons[count]->setFont(font); } QFontMetrics metrics(d->selectMonth->fontMetrics()); for (int i = 1; ; ++i) { QString str = KGlobal::locale()->calendar()->monthName(i, KGlobal::locale()->calendar()->year(d->table->date()), KCalendarSystem::ShortName); if (str.isNull()) break; r=metrics.boundingRect(str); d->maxMonthRect.setWidth(qMax(r.width(), d->maxMonthRect.width())); d->maxMonthRect.setHeight(qMax(r.height(), d->maxMonthRect.height())); } QStyleOptionToolButton opt; // stolen from KToolBarButton opt.init(this); opt.font = d->selectMonth->font(); opt.icon = d->selectMonth->icon(); opt.text = d->selectMonth->text(); opt.features = d->selectMonth->menu() ? QStyleOptionToolButton::Menu : QStyleOptionToolButton::None; //### FIXME: delay? opt.subControls = QStyle::SC_All; opt.activeSubControls = 0; //### FIXME: !! QSize metricBound = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, d->maxMonthRect, d->selectMonth); d->selectMonth->setMinimumSize(metricBound); d->table->setFontSize(s); }
void KexiDropDownButton::paintEvent(QPaintEvent *e) { QToolButton::paintEvent(e); QPainter p(this); QStyleOptionToolButton option; option.initFrom(this); style()->drawPrimitive(QStyle::PE_IndicatorButtonDropDown, &option, &p); //! @todo use tableview's appearance parameters for color QRect r = rect(); QPen linePen(Qt::black); linePen.setWidth(1); p.setPen(linePen); p.drawLine(r.topLeft(), r.topRight()); }
/*! \internal Returns the rectangle occupied by this button, depending on \a child. */ QRect QAccessibleToolButton::rect(int child) const { if (!toolButton()->isVisible()) return QRect(); if (!child) return QAccessibleButton::rect(child); QStyleOptionToolButton opt; opt.init(widget()); QRect subrect = widget()->style()->subControlRect(QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButtonMenu, toolButton()); if (child == ButtonExecute) subrect = QRect(0, 0, subrect.x(), widget()->height()); QPoint ntl = widget()->mapToGlobal(subrect.topLeft()); subrect.moveTopLeft(ntl); return subrect; }
QSize kMyMoneyCalendar::sizeHint() const { QSize tableSize = table->sizeHint(); QWidget *buttons[] = { styleControl, yearBackward, monthBackward, selectMonth, selectYear, monthForward, yearForward, d->closeButton, d->userButton1, d->userButton2 }; const int NoOfButtons = sizeof(buttons) / sizeof(buttons[0]); QSize sizes[NoOfButtons]; int cx = 0, cy = 0, count; // ----- store the size hints: for (count = 0; count < NoOfButtons; ++count) { if (buttons[count]) sizes[count] = buttons[count]->sizeHint(); else sizes[count] = QSize(0, 0); if (buttons[count] == selectMonth) { QStyleOptionToolButton opt; opt.initFrom(selectMonth); QSize metricBound = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, maxMonthRect); cx += qMax(metricBound.width(), maxMonthRect.width() + 2 * QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin)); } else { cx += sizes[count].width(); } cy = qMax(sizes[count].height(), cy); } // ----- calculate width hint: cx = qMax(cx, tableSize.width()); // line edit ignored // ----- calculate height hint: cy += tableSize.height() + line->sizeHint().height(); return QSize(cx, cy); }
void ToolWindowManagerTabBar::paintEvent(QPaintEvent *event) { if(useMinimalBar()) { if(floatingWindowChild()) return; QStylePainter p(this); QStyleOptionDockWidget option; option.initFrom(parentWidget()); option.rect = m_titleRect; option.title = tabText(0); option.closable = m_tabsClosable; option.movable = false; // we only set floatable true so we can hijack the float button for our own pin/auto-hide button option.floatable = true; Shape s = shape(); option.verticalTitleBar = s == RoundedEast || s == TriangularEast || s == RoundedWest || s == TriangularWest; p.drawControl(QStyle::CE_DockWidgetTitle, option); int size = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); QStyleOptionToolButton buttonOpt; buttonOpt.initFrom(parentWidget()); buttonOpt.iconSize = QSize(size, size); buttonOpt.subControls = 0; buttonOpt.activeSubControls = 0; buttonOpt.features = QStyleOptionToolButton::None; buttonOpt.arrowType = Qt::NoArrow; buttonOpt.state = QStyle::State_Active | QStyle::State_Enabled | QStyle::State_AutoRaise; buttonOpt.rect = m_pin.rect; buttonOpt.icon = m_pin.icon; ToolWindowManager::ToolWindowProperty props = m_area->m_manager->toolWindowProperties(m_area->widget(0)); bool tabClosable = (props & ToolWindowManager::HideCloseButton) == 0; if(!tabClosable && !m_pin.rect.isEmpty()) buttonOpt.rect = m_close.rect; QStyle::State prevState = buttonOpt.state; if(m_pin.clicked) buttonOpt.state |= QStyle::State_Sunken; else if(m_pin.hover) buttonOpt.state |= QStyle::State_Raised | QStyle::State_MouseOver; if(style()->styleHint(QStyle::SH_DockWidget_ButtonsHaveFrame, 0, this)) { style()->drawPrimitive(QStyle::PE_PanelButtonTool, &buttonOpt, &p, this); } style()->drawComplexControl(QStyle::CC_ToolButton, &buttonOpt, &p, this); if(m_tabsClosable && tabClosable) { buttonOpt.rect = m_close.rect; buttonOpt.icon = m_close.icon; buttonOpt.state = prevState; if(m_close.clicked) buttonOpt.state |= QStyle::State_Sunken; else if(m_close.hover) buttonOpt.state |= QStyle::State_Raised | QStyle::State_MouseOver; style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &buttonOpt, &p, this); } return; } QTabBar::paintEvent(event); }
void kMyMoneyCalendar::resizeEvent(QResizeEvent*) { QWidget *buttons[] = { styleControl, d->userButton1, d->userButton2, yearBackward, monthBackward, selectMonth, selectYear, monthForward, yearForward, d->closeButton }; const int NoOfButtons = sizeof(buttons) / sizeof(buttons[0]); QSize sizes[NoOfButtons]; int buttonHeight = 0; int count; int w; int x = 0; // ----- calculate button row height: for (count = 0; count < NoOfButtons; ++count) { if (buttons[count]) { // closeButton may be 0 sizes[count] = buttons[count]->sizeHint(); buttonHeight = qMax(buttonHeight, sizes[count].height()); } else sizes[count] = QSize(0, 0); // closeButton } // ----- calculate size of the month button: for (count = 0; count < NoOfButtons; ++count) { if (buttons[count] == selectMonth) { QStyleOptionToolButton opt; opt.initFrom(selectMonth); QSize metricBound = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, maxMonthRect); sizes[count].setWidth(qMax(metricBound.width(), maxMonthRect.width() + 2*QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin))); } } // ----- place the buttons: // Put the style button and user buttons to the left and the rest to the right x = 0; int noUserButtons = 2; buttons[0]->setGeometry(x, 0, sizes[0].width(), buttonHeight); x += sizes[0].width(); for (count = 1; count <= noUserButtons; ++count) { if (buttons[count]) { buttons[count]->setGeometry(x, 0, sizes[count].width(), buttonHeight); x += sizes[count].width(); } } x = width(); for (count = (1 + noUserButtons); count < NoOfButtons; ++count) { w = sizes[count].width(); x -= w; } for (count = (1 + noUserButtons); count < NoOfButtons; ++count) { w = sizes[count].width(); if (buttons[count]) buttons[count]->setGeometry(x, 0, w, buttonHeight); x += w; } // ----- place the line edit for direct input: sizes[0] = line->sizeHint(); int week_width = d->selectWeek->fontMetrics().width(i18n("Week XX")) + ((d->closeButton != 0) ? 50 : 20); line->setGeometry(0, height() - sizes[0].height(), width() - week_width, sizes[0].height()); d->selectWeek->setGeometry(width() - week_width, height() - sizes[0].height(), week_width, sizes[0].height()); // ----- adjust the table: table->setGeometry(0, buttonHeight, width(), height() - buttonHeight - sizes[0].height()); table->setFocus(); }