X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fcolorbutton.cpp;h=4a833d06dd06ab2b793b5c19d12012a558f4c505;hp=61e6c14db5d304c461a8418be11b9b7f851c23dd;hb=68efe6df6d72f1ac498d0594866455418552665d;hpb=c6e866f973fdf13b512e44cb193819230d160d49;ds=sidebyside diff --git a/src/uisupport/colorbutton.cpp b/src/uisupport/colorbutton.cpp index 61e6c14d..4a833d06 100644 --- a/src/uisupport/colorbutton.cpp +++ b/src/uisupport/colorbutton.cpp @@ -44,20 +44,25 @@ QColor ColorButton::color() const { } void ColorButton::paintEvent(QPaintEvent *event) { + //TODO: work on a good button style solution QPushButton::paintEvent(event); QPainter painter(this); int border = QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin); - painter.fillRect(rect().adjusted(border+1, border+1, -border-1, -border-1), QBrush(_color)); + + // if twice buttonMargin (+2 px from the adjust) is greater than the button height + // then set the border to a third of the button height. + if(2*border+2 >= event->rect().height()) border = event->rect().height()/3; + + QBrush brush; + if(isEnabled()) { + brush = QBrush(_color); + } else { + brush = QBrush(_color, Qt::Dense4Pattern); + } + painter.fillRect(rect().adjusted(border+1, border+1, -border-1, -border-1), brush); QStyleOptionFrame option; option.state = QStyle::State_Sunken; option.rect = rect().adjusted(border, border, -border, -border); - //TODO: setBackground instead of the fillRect() - //painter.setBackground(_color); - //painter.setBackgroundMode(Qt::OpaqueMode); - //painter.fillRect(QApplication::style()->subElementRect(QStyle::SE_FrameContents, &option), QBrush(_color)); - //qDebug() << option << QApplication::style()->subElementRect(QStyle::SE_PushButtonContents, &option); + QApplication::style()->drawPrimitive(QStyle::PE_Frame, &option, &painter); - //painter.fillRect(QApplication::style()->subElementRect(QStyle::SE_FrameContents, &option), QBrush(_color)); - //border += QStyle::PM_DefaultFrameWidth; - //painter.fillRect(rect().adjusted(border, border, -border, -border), QBrush(_color)); }