diff options
Diffstat (limited to 'src/libs/utils/qtcolorbutton.cpp')
-rw-r--r-- | src/libs/utils/qtcolorbutton.cpp | 90 |
1 files changed, 47 insertions, 43 deletions
diff --git a/src/libs/utils/qtcolorbutton.cpp b/src/libs/utils/qtcolorbutton.cpp index ca0aa631ba..6a8537bd5f 100644 --- a/src/libs/utils/qtcolorbutton.cpp +++ b/src/libs/utils/qtcolorbutton.cpp @@ -3,12 +3,15 @@ #include "qtcolorbutton.h" -#include <QMimeData> +#include "theme/theme.h" + #include <QApplication> #include <QColorDialog> +#include <QDrag> #include <QDragEnterEvent> +#include <QMimeData> #include <QPainter> -#include <QDrag> +#include <QStyleOption> namespace Utils { @@ -157,51 +160,52 @@ bool QtColorButton::isDialogOpen() const void QtColorButton::paintEvent(QPaintEvent *event) { - QToolButton::paintEvent(event); - if (!isEnabled()) - return; + Q_UNUSED(event) - const int pixSize = 10; - QBrush br(d_ptr->shownColor()); - if (d_ptr->m_backgroundCheckered) { - QPixmap pm(2 * pixSize, 2 * pixSize); - QPainter pmp(&pm); - pmp.fillRect(0, 0, pixSize, pixSize, Qt::white); - pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white); - pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black); - pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black); - pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, d_ptr->shownColor()); - br = QBrush(pm); - } + constexpr Theme::Color overlayColor = Theme::TextColorNormal; + constexpr qreal overlayOpacity = 0.25; QPainter p(this); - const int corr = 5; - QRect r = rect().adjusted(corr, corr, -corr, -corr); - p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); - p.fillRect(r, br); + const QColor color = d_ptr->shownColor(); + if (!color.isValid()) { + constexpr int size = 11; + const qreal horPadding = (width() - size) / 2.0; + const qreal verPadding = (height() - size) / 2.0; + const QPen pen(creatorTheme()->color(overlayColor), 2); + + p.save(); + p.setOpacity(overlayOpacity); + p.setPen(pen); + p.setRenderHint(QPainter::Antialiasing); + p.drawLine(QLineF(horPadding, height() - verPadding, width() - horPadding, verPadding)); + p.restore(); + } else if (isEnabled()) { + QBrush br(color); + if (d_ptr->m_backgroundCheckered) { + const int pixSize = 10; + QPixmap pm(2 * pixSize, 2 * pixSize); + pm.fill(Qt::white); + QPainter pmp(&pm); + pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black); + pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black); + pmp.fillRect(pm.rect(), color); + br = QBrush(pm); + p.setBrushOrigin((width() - pixSize) / 2, (height() - pixSize) / 2); + } + p.fillRect(rect(), br); + } - //const int adjX = qRound(r.width() / 4.0); - //const int adjY = qRound(r.height() / 4.0); - //p.fillRect(r.adjusted(adjX, adjY, -adjX, -adjY), - // QColor(d_ptr->shownColor().rgb())); - /* - p.fillRect(r.adjusted(0, r.height() * 3 / 4, 0, 0), - QColor(d_ptr->shownColor().rgb())); - p.fillRect(r.adjusted(0, 0, 0, -r.height() * 3 / 4), - QColor(d_ptr->shownColor().rgb())); - */ - /* - const QColor frameColor0(0, 0, 0, qRound(0.2 * (0xFF - d_ptr->shownColor().alpha()))); - p.setPen(frameColor0); - p.drawRect(r.adjusted(adjX, adjY, -adjX - 1, -adjY - 1)); - */ - - const QColor frameColor1(0, 0, 0, 26); - p.setPen(frameColor1); - p.drawRect(r.adjusted(1, 1, -2, -2)); - const QColor frameColor2(0, 0, 0, 51); - p.setPen(frameColor2); - p.drawRect(r.adjusted(0, 0, -1, -1)); + if (hasFocus()) { + QPen pen; + pen.setBrush(Qt::white); + pen.setStyle(Qt::DotLine); + p.setPen(pen); + p.setCompositionMode(QPainter::CompositionMode_Difference); + } else { + p.setPen(creatorTheme()->color(overlayColor)); + p.setOpacity(overlayOpacity); + } + p.drawRect(rect().adjusted(0, 0, -1, -1)); } void QtColorButton::mousePressEvent(QMouseEvent *event) |