Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_equalizer_button.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QStyle>
10#include <QPainter>
11#include <QStyleOption>
12
13#include <QApplication>
14
15
17#include "kis_global.h"
18#include "kis_debug.h"
19
21{
23 : q(_q),
24 isRightmost(false),
25 isHovering(false) {}
26
27 QRect boundingRect() const;
28 QRect fillingRect() const;
29
33};
34
36 : QAbstractButton(parent),
37 m_d(new Private(this))
38{
39 setFocusPolicy(Qt::WheelFocus);
40 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
41}
42
46
48{
49 m_d->isRightmost = value;
50}
51
53{
54 QRect bounds = q->rect().adjusted(0, 0, -static_cast<int>(isRightmost), 0);
55 return bounds;
56}
57
59{
60 const int offset = 3;
61 QRect filling = boundingRect().adjusted(offset + 1, offset + 1,
62 -offset, -offset);
63
64 return filling;
65}
66
67void KisEqualizerButton::paintEvent(QPaintEvent *event)
68{
69 Q_UNUSED(event);
70 const QRect bounds = m_d->boundingRect();
71 const QRect filling = m_d->fillingRect();
72 const QColor backgroundColor = palette().color(QPalette::Base);
73
74 QPainter p(this);
75
76 { // draw border
77
78 QStyleOptionViewItem option; // empty!
79 const int gridHint = style()->styleHint(QStyle::SH_Table_GridLineColor, &option, this);
80 const QColor gridColor = static_cast<QRgb>(gridHint);
81 const QPen gridPen(gridColor);
82
83 p.setPen(gridPen);
84 p.setBrush(backgroundColor);
85 p.drawRect(bounds);
86 }
87
88 {
90 QColor frameColor = KisAnimTimelineColors::instance()-> onionSkinsSliderEnabledColor();
91
92 if (isChecked() || hasFocus() || m_d->isHovering) {
93 p.setPen(hasFocus() || m_d->isHovering ? frameColor : Qt::transparent);
94 p.setBrush(isChecked() ? fillColor : Qt::transparent);
95 p.drawRect(filling);
96 }
97 }
98
99 QString textValue = text();
100
101 { // draw text
102 QPalette::ColorRole textRole = QPalette::Text;
103
104 //Draw text shadow, This will increase readability when the background of same color
105 QRect shadowRect(bounds);
106 shadowRect.translate(1,1);
107 QColor textColor = palette().color(textRole);
108 QColor shadowColor = (textColor.value() <= 128)
109 ? QColor(255,255,255,160) : QColor(0,0,0,160);
110
111 int flags = Qt::AlignCenter | Qt::TextHideMnemonic;
112
113 p.setPen(shadowColor);
114 p.drawText(shadowRect, flags, textValue);
115
116 p.setPen(textColor);
117 p.drawText(bounds, flags, textValue);
118 }
119}
120
122{
123 QFontMetrics metrics(this->font());
124 const int minHeight = metrics.height() + 10;
125 return QSize(15, minHeight);
126}
127
129{
130 QSize sh = sizeHint();
131 return QSize(10, sh.height());
132}
133
134#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
135void KisEqualizerButton::enterEvent(QEvent *event)
136#else
137void KisEqualizerButton::enterEvent(QEnterEvent *event)
138#endif
139{
140 Q_UNUSED(event);
141
142 m_d->isHovering = true;
143 update();
144}
145
147{
148 Q_UNUSED(event);
149
150 m_d->isHovering = false;
151 update();
152}
float value(const T *src, size_t ch)
const Params2D p
static KisAnimTimelineColors * instance()
QSize sizeHint() const override
const QScopedPointer< Private > m_d
void enterEvent(QEnterEvent *event) override
void setRightmost(bool value)
void leaveEvent(QEvent *event) override
QSize minimumSizeHint() const override
KisEqualizerButton(QWidget *parent)
void paintEvent(QPaintEvent *event) override
unsigned int QRgb
#define bounds(x, a, b)
rgba palette[MAX_PALETTE]
Definition palette.c:35
Private(KisEqualizerButton *_q)