hydrogen
1.2.6
ColorSelectionButton.cpp
Go to the documentation of this file.
1
/*
2
* Hydrogen
3
* Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
4
*
5
* http://www.hydrogen-music.org
6
*
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY, without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
*
21
*/
22
23
#include "
ColorSelectionButton.h
"
24
25
#include <QColorDialog>
26
#include <
core/Globals.h
>
27
28
ColorSelectionButton::ColorSelectionButton
( QWidget* pParent, QColor sInitialColor,
int
nSize )
29
: QPushButton( pParent )
30
,
m_sColor
( sInitialColor )
31
,
m_bMouseOver
( false )
32
{
33
setFlat(
true
);
34
35
if
( nSize != 0 ) {
36
QSize size( nSize, nSize );
37
setFixedSize( size );
38
resize( size );
39
}
40
}
41
42
ColorSelectionButton::~ColorSelectionButton
() {
43
}
44
45
void
ColorSelectionButton::mousePressEvent
(QMouseEvent*ev) {
46
47
if
( isEnabled() ) {
48
49
QColor newColor = QColorDialog::getColor(
m_sColor
,
this
, tr(
"Pick a pattern color"
) );
50
51
if
(
m_sColor
!= newColor && newColor.isValid() ) {
52
m_sColor
= newColor;
53
update();
54
emit
colorChanged
();
55
}
56
}
57
}
58
59
#ifdef H2CORE_HAVE_QT6
60
void
ColorSelectionButton::enterEvent
( QEnterEvent *ev ) {
61
#else
62
void
ColorSelectionButton::enterEvent
( QEvent *ev ) {
63
#endif
64
UNUSED
( ev );
65
m_bMouseOver
=
true
;
66
update();
67
}
68
69
70
void
ColorSelectionButton::setColor
(
const
QColor& color) {
71
m_sColor
= color;
72
update();
73
}
74
75
void
ColorSelectionButton::leaveEvent
(QEvent *ev) {
76
UNUSED
( ev );
77
m_bMouseOver
=
false
;
78
update();
79
}
80
81
void
ColorSelectionButton::paintEvent
( QPaintEvent* ev) {
82
QPainter painter(
this
);
83
QColor color(
m_sColor
);
84
QColor backgroundColor(
"#333"
);
85
if
(
m_bMouseOver
) {
86
if
( isEnabled() ) {
87
backgroundColor =
H2Core::Preferences::get_instance
()->
getColorTheme
()->m_highlightColor;
88
}
else
{
89
backgroundColor =
H2Core::Preferences::get_instance
()->
getColorTheme
()->m_lightColor;
90
}
91
}
92
93
painter.setPen( backgroundColor );
94
painter.drawRect( 0, 0, width() - 1, height() -1 );
95
painter.setPen( color );
96
painter.fillRect( 3, 3, width() - 6, height() - 6, color );
97
}
ColorSelectionButton.h
Globals.h
ColorSelectionButton::mousePressEvent
virtual void mousePressEvent(QMouseEvent *ev) override
Definition
ColorSelectionButton.cpp:45
ColorSelectionButton::m_sColor
QColor m_sColor
Definition
ColorSelectionButton.h:67
ColorSelectionButton::ColorSelectionButton
ColorSelectionButton(QWidget *pParent, QColor sInitialColor=Qt::black, int nSize=0)
Definition
ColorSelectionButton.cpp:28
ColorSelectionButton::leaveEvent
virtual void leaveEvent(QEvent *ev) override
Definition
ColorSelectionButton.cpp:75
ColorSelectionButton::setColor
void setColor(const QColor &color)
Definition
ColorSelectionButton.cpp:70
ColorSelectionButton::colorChanged
void colorChanged()
ColorSelectionButton::paintEvent
virtual void paintEvent(QPaintEvent *ev) override
Definition
ColorSelectionButton.cpp:81
ColorSelectionButton::~ColorSelectionButton
~ColorSelectionButton()
Definition
ColorSelectionButton.cpp:42
ColorSelectionButton::m_bMouseOver
bool m_bMouseOver
Definition
ColorSelectionButton.h:56
ColorSelectionButton::enterEvent
virtual void enterEvent(QEvent *ev) override
Definition
ColorSelectionButton.cpp:62
H2Core::Preferences::get_instance
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
Definition
Preferences.h:406
H2Core::Preferences::getColorTheme
const std::shared_ptr< ColorTheme > getColorTheme() const
Definition
Preferences.h:1372
UNUSED
#define UNUSED(v)
Definition
Globals.h:42
src
gui
src
Widgets
ColorSelectionButton.cpp
Generated by
1.13.2