hydrogen 1.2.6
Button.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23
24#ifndef BUTTON_H
25#define BUTTON_H
26
27#include <memory>
28
29#include <core/Object.h>
31#include <core/MidiAction.h>
32
33#include "MidiLearnable.h"
35
36#include <QtGui>
37#include <QPushButton>
38
39
59class Button : public QPushButton, protected WidgetWithScalableFont<6, 8, 10>, public H2Core::Object<Button>, public MidiLearnable
60{
62 Q_OBJECT
63
64public:
65
66 enum class Type {
76 };
77
102 Button(
103 QWidget *pParent,
104 QSize size = QSize(),
105 Type type = Type::Toggle,
106 const QString& sIcon = "",
107 const QString& sText = "",
108 bool bUseRedBackground = false,
109 QSize iconSize = QSize( 0, 0 ),
110 QString sBaseTooltip = "",
111 bool bColorful = false,
112 bool bModifyOnChange = false,
113 int nBorderRadius = -1
114 );
115 virtual ~Button();
116
117 Button(const Button&) = delete;
118 Button& operator=( const Button& rhs ) = delete;
119
120 void setBaseToolTip( const QString& sNewTip );
121
122 bool getIsActive() const;
123 void setIsActive( bool bIsActive );
124
125 Type getType() const;
126 void setType( Type type );
127
128 void setSize( QSize size );
131 void setFixedFontSize( int nPixelSize );
132 int getFixedFontSize() const;
133
134 void setUseRedBackground( bool bUseRedBackground );
135 bool getUseRedBackground() const;
136
137 void setBorderRadius( int nBorderRadius );
138 int getBorderRadius() const;
139
140public slots:
142
143private slots:
144 void onClick();
145
146signals:
148
149private:
150 void updateStyleSheet();
151 void updateFont();
152 void updateTooltip() override;
153 void updateIcon();
154
157 QSize m_size;
160 QString m_sIcon;
162
164
167
169
173
174 virtual void mousePressEvent(QMouseEvent *ev) override;
175 virtual void paintEvent( QPaintEvent* ev) override;
176
177};
178inline bool Button::getIsActive() const {
179 return m_bIsActive;
180}
181
182inline void Button::setFixedFontSize( int nPixelSize ) {
183 m_nFixedFontSize = nPixelSize;
184}
185inline int Button::getFixedFontSize() const {
186 return m_nFixedFontSize;
187}
188inline bool Button::getUseRedBackground() const {
189 return m_bUseRedBackground;
190}
192 return m_type;
193}
194
195inline int Button::getBorderRadius() const {
196 return m_nBorderRadius;
197}
198
199#endif
#define H2_OBJECT(name)
Definition Object.h:227
Type m_type
Definition Button.h:156
@ Icon
Button is both flat and has a transparent background.
Definition Button.h:75
@ Push
Button is not set checkable.
Definition Button.h:68
@ Toggle
Button is set checkable.
Definition Button.h:70
virtual void mousePressEvent(QMouseEvent *ev) override
Definition Button.cpp:311
int getBorderRadius() const
Definition Button.h:195
QSize m_size
Definition Button.h:157
void setFixedFontSize(int nPixelSize)
Overwrites the automatically set value.
Definition Button.h:182
void setUseRedBackground(bool bUseRedBackground)
Definition Button.cpp:122
void setBorderRadius(int nBorderRadius)
Definition Button.cpp:487
void updateTooltip() override
Indicates child class to recalculate its tool tip in case m_registeredMidiEvents changed.
Definition Button.cpp:329
Button(const Button &)=delete
void setType(Type type)
Definition Button.cpp:376
Button & operator=(const Button &rhs)=delete
void setBaseToolTip(const QString &sNewTip)
Definition Button.cpp:306
void onPreferencesChanged(H2Core::Preferences::Changes changes)
Definition Button.cpp:468
bool m_bModifyOnChange
Whether Hydrogen::setIsModified() is invoked with true as soon as the value of the widget does change...
Definition Button.h:172
void onClick()
Definition Button.cpp:481
bool getIsActive() const
Definition Button.h:178
virtual ~Button()
Definition Button.cpp:96
void updateStyleSheet()
Definition Button.cpp:129
void setSize(QSize size)
Definition Button.cpp:364
QString m_sBaseTooltip
Definition Button.h:159
QString m_sIcon
Definition Button.h:160
bool m_bColorful
Definition Button.h:165
int m_nFixedFontSize
Definition Button.h:161
int getFixedFontSize() const
Definition Button.h:185
bool m_bIsActive
Definition Button.h:168
void rightClicked()
Type getType() const
Definition Button.h:191
virtual void paintEvent(QPaintEvent *ev) override
Definition Button.cpp:455
bool getUseRedBackground() const
Definition Button.h:188
bool m_bUseRedBackground
Definition Button.h:155
void updateIcon()
Definition Button.cpp:108
void setIsActive(bool bIsActive)
Definition Button.cpp:99
int m_nBorderRadius
Definition Button.h:163
bool m_bLastCheckedState
Definition Button.h:166
QSize m_iconSize
Definition Button.h:158
Button(QWidget *pParent, QSize size=QSize(), Type type=Type::Toggle, const QString &sIcon="", const QString &sText="", bool bUseRedBackground=false, QSize iconSize=QSize(0, 0), QString sBaseTooltip="", bool bColorful=false, bool bModifyOnChange=false, int nBorderRadius=-1)
Either the path to a SVG image or a text to be displayed has to be provided.
Definition Button.cpp:37
void updateFont()
Definition Button.cpp:396
Changes
Bitwise or-able options showing which part of the Preferences were altered using the PreferencesDialo...
Widget is affected by the "Font size" settings in the PreferencesDialog.