hydrogen
1.2.3
ColorSelectionButton.cpp
Go to the documentation of this file.
1
/*
2
* Hydrogen
3
* Copyright(c) 2008-2024 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
void
ColorSelectionButton::enterEvent
(QEvent *ev) {
60
UNUSED
( ev );
61
m_bMouseOver
=
true
;
62
update();
63
}
64
65
66
void
ColorSelectionButton::setColor
(
const
QColor& color) {
67
m_sColor
= color;
68
update();
69
}
70
71
void
ColorSelectionButton::leaveEvent
(QEvent *ev) {
72
UNUSED
( ev );
73
m_bMouseOver
=
false
;
74
update();
75
}
76
77
void
ColorSelectionButton::paintEvent
( QPaintEvent* ev) {
78
QPainter painter(
this
);
79
QColor color(
m_sColor
);
80
QColor backgroundColor(
"#333"
);
81
if
(
m_bMouseOver
) {
82
if
( isEnabled() ) {
83
backgroundColor =
H2Core::Preferences::get_instance
()->
getColorTheme
()->m_highlightColor;
84
}
else
{
85
backgroundColor =
H2Core::Preferences::get_instance
()->
getColorTheme
()->m_lightColor;
86
}
87
}
88
89
painter.setPen( backgroundColor );
90
painter.drawRect( 0, 0, width() - 1, height() -1 );
91
painter.setPen( color );
92
painter.fillRect( 3, 3, width() - 6, height() - 6, color );
93
}
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:63
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:71
ColorSelectionButton::setColor
void setColor(const QColor &color)
Definition
ColorSelectionButton.cpp:66
ColorSelectionButton::colorChanged
void colorChanged()
ColorSelectionButton::paintEvent
virtual void paintEvent(QPaintEvent *ev) override
Definition
ColorSelectionButton.cpp:77
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:59
H2Core::Preferences::get_instance
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
Definition
Preferences.h:398
H2Core::Preferences::getColorTheme
const std::shared_ptr< ColorTheme > getColorTheme() const
Definition
Preferences.h:1351
UNUSED
#define UNUSED(v)
Definition
Globals.h:42
src
gui
src
Widgets
ColorSelectionButton.cpp
Generated by
1.10.0