hydrogen 1.2.3
Button Class Reference

Generic Button with SVG icons or text. More...

#include <Button.h>

Inheritance diagram for Button:
WidgetWithScalableFont< 6, 8, 10 > Object< Button > MidiLearnable Base EventListener

Public Types

enum class  Type { Push , Toggle , Icon }
 

Public Slots

void onPreferencesChanged (H2Core::Preferences::Changes changes)
 

Signals

void rightClicked ()
 

Public Member Functions

 Button (const Button &)=delete
 
 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.
 
virtual ~Button ()
 
int getBorderRadius () const
 
int getFixedFontSize () const
 
bool getIsActive () const
 
Type getType () const
 
bool getUseRedBackground () const
 
Buttonoperator= (const Button &rhs)=delete
 
void setBaseToolTip (const QString &sNewTip)
 
void setBorderRadius (int nBorderRadius)
 
void setFixedFontSize (int nPixelSize)
 Overwrites the automatically set value.
 
void setIsActive (bool bIsActive)
 
void setSize (QSize size)
 
void setType (Type type)
 
void setUseRedBackground (bool bUseRedBackground)
 
- Public Member Functions inherited from Object< Button >
 Object ()
 
 Object (const Object< Button > &other)
 
- Public Member Functions inherited from Base
 Base ()
 
 Base (const Base &other)
 
virtual const char * class_name () const
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG.
 
virtual QString toQString (const QString &sPrefix="", bool bShort=true) const
 Formatted string version for debugging purposes.
 
- Public Member Functions inherited from MidiLearnable
 MidiLearnable ()
 
 ~MidiLearnable ()
 
std::shared_ptr< ActiongetAction () const
 
void midiMapChangedEvent () override
 Update m_registeredMidiEvents since the underlying #H2Core::MidiMap changed.
 
void setAction (std::shared_ptr< Action > pAction)
 

Private Slots

void onClick ()
 

Private Member Functions

virtual void mousePressEvent (QMouseEvent *ev) override
 
virtual void paintEvent (QPaintEvent *ev) override
 
void updateFont ()
 
void updateIcon ()
 
void updateStyleSheet ()
 
void updateTooltip () override
 Indicates child class to recalculate its tool tip in case m_registeredMidiEvents changed.
 

Private Attributes

bool m_bColorful
 
bool m_bIsActive
 
bool m_bLastCheckedState
 
bool m_bModifyOnChange
 Whether Hydrogen::setIsModified() is invoked with true as soon as the value of the widget does change.
 
bool m_bUseRedBackground
 
QSize m_iconSize
 
int m_nBorderRadius
 
int m_nFixedFontSize
 
QString m_sBaseTooltip
 
QString m_sIcon
 
QSize m_size
 
Type m_type
 

Additional Inherited Members

- Static Public Member Functions inherited from Base
static const char * _class_name ()
 return the class name
 
static QString base_clock (const QString &sMsg)
 Measures the current time and stores it in __last_clock.
 
static QString base_clock_in (const QString &sMsg)
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation !
 
static bool count_active ()
 
static int getAliveObjectCount ()
 
static object_map_t getObjectMap ()
 
static Loggerlogger ()
 return the logger instance
 
static int objects_count ()
 
static void printObjectMapDiff (object_map_t map)
 Creates the difference between a snapshot of the object map and its current state and prints it to std::cout.
 
static void set_count (bool flag)
 enable/disable class instances counting
 
static void write_objects_map_to (std::ostream &out, object_map_t *map=nullptr)
 output the full objects map to a given ostream
 
static void write_objects_map_to_cerr ()
 output objects map to stderr
 
- Static Public Attributes inherited from Base
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes.
 
- Protected Member Functions inherited from WidgetWithScalableFont< 6, 8, 10 >
constexpr int getPointSize (H2Core::FontTheme::FontSize fontSize) const
 
- Protected Member Functions inherited from Object< Button >
 ~Object ()
 
 Object ()
 
 Object (const Object< Button > &other)
 
- Protected Member Functions inherited from Base
 ~Base ()
 
 Base ()
 
 Base (const Base &other)
 
virtual const char * class_name () const
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG.
 
virtual QString toQString (const QString &sPrefix="", bool bShort=true) const
 Formatted string version for debugging purposes.
 
- Protected Member Functions inherited from MidiLearnable
 MidiLearnable ()
 
 ~MidiLearnable ()
 
std::shared_ptr< ActiongetAction () const
 
void midiMapChangedEvent () override
 Update m_registeredMidiEvents since the underlying #H2Core::MidiMap changed.
 
void setAction (std::shared_ptr< Action > pAction)
 
- Static Protected Member Functions inherited from Base
static void registerClass (const char *name, const atomic_obj_cpt_t *counters)
 
static const char * _class_name ()
 return the class name
 
static QString base_clock (const QString &sMsg)
 Measures the current time and stores it in __last_clock.
 
static QString base_clock_in (const QString &sMsg)
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation !
 
static bool count_active ()
 
static int getAliveObjectCount ()
 
static object_map_t getObjectMap ()
 
static Loggerlogger ()
 return the logger instance
 
static int objects_count ()
 
static void printObjectMapDiff (object_map_t map)
 Creates the difference between a snapshot of the object map and its current state and prints it to std::cout.
 
static void set_count (bool flag)
 enable/disable class instances counting
 
static void write_objects_map_to (std::ostream &out, object_map_t *map=nullptr)
 output the full objects map to a given ostream
 
static void write_objects_map_to_cerr ()
 output objects map to stderr
 
- Protected Attributes inherited from MidiLearnable
std::shared_ptr< Actionm_pAction
 
std::vector< std::pair< H2Core::MidiMessage::Event, int > > m_registeredMidiEvents
 Stores all MIDI events mapped to m_pAction.
 
- Static Protected Attributes inherited from Base
static bool __count = false
 should we count class instances
 
static timeval __last_clock = { 0, 0 }
 
static Logger__logger = nullptr
 
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes.
 

Detailed Description

Generic Button with SVG icons or text.

The class comes in two different types, as Button::Type::Push and Button::Type::Toggle. If it is set checkabale via Button::Type::Toggle, the button will change color after it is clicked by mouse and the button is released. The action associated with the button will, however, be triggered once the button is clicked (this is implemented in the parent wigets and can be changed. But giving immediate feedback seems to be intuitive.)

Most icons used are black and white. For those, the black one will be used in unchecked state and the white one in checked.

Buttons are MIDI learnable. This means they can be associated with a MIDI action. If done, the action (and the binding) will show up in the tooltip.

Definition at line 59 of file Button.h.

Member Enumeration Documentation

◆ Type

enum class Type
strong
Enumerator
Push 

Button is not set checkable.

Toggle 

Button is set checkable.

Icon 

Button is both flat and has a transparent background.

It can not be checked and its sole purpose is to show its icon.

Definition at line 66 of file Button.h.

Constructor & Destructor Documentation

◆ Button() [1/2]

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.

If both are given, the icon will be used over the text. If the text should be used instead, sIcon must the an empty string.

Parameters
pParent
size
type
sIcon
sText
bUseRedBackground
iconSize
sBaseTooltip
bColorfulIf set to false, the icon sIcon is expected to exist in both subfolders "black" and "white" in the "icons" folder. If the button is not checked, the black version is used and if checked, the white one is used instead.
bModifyOnChangeWhether Hydrogen::setIsModified() is invoked with true as soon as the value of the widget does change.
nBorderRadiusRadius of the button in pixel, which will be passed to the style sheet.

Definition at line 37 of file Button.cpp.

◆ ~Button()

~Button ( )
virtual

Definition at line 96 of file Button.cpp.

◆ Button() [2/2]

Button ( const Button & )
delete

Member Function Documentation

◆ getBorderRadius()

int getBorderRadius ( ) const
inline

Definition at line 195 of file Button.h.

◆ getFixedFontSize()

int getFixedFontSize ( ) const
inline

Definition at line 185 of file Button.h.

◆ getIsActive()

bool getIsActive ( ) const
inline

Definition at line 178 of file Button.h.

◆ getType()

Button::Type getType ( ) const
inline

Definition at line 191 of file Button.h.

◆ getUseRedBackground()

bool getUseRedBackground ( ) const
inline

Definition at line 188 of file Button.h.

◆ mousePressEvent()

void mousePressEvent ( QMouseEvent * ev)
overrideprivatevirtual

Definition at line 311 of file Button.cpp.

◆ onClick

void onClick ( )
privateslot

Definition at line 481 of file Button.cpp.

◆ onPreferencesChanged

void onPreferencesChanged ( H2Core::Preferences::Changes changes)
slot

Definition at line 468 of file Button.cpp.

◆ operator=()

Button & operator= ( const Button & rhs)
delete

◆ paintEvent()

void paintEvent ( QPaintEvent * ev)
overrideprivatevirtual

Definition at line 455 of file Button.cpp.

◆ rightClicked

void rightClicked ( )
signal

◆ setBaseToolTip()

void setBaseToolTip ( const QString & sNewTip)

Definition at line 306 of file Button.cpp.

◆ setBorderRadius()

void setBorderRadius ( int nBorderRadius)

Definition at line 487 of file Button.cpp.

◆ setFixedFontSize()

void setFixedFontSize ( int nPixelSize)
inline

Overwrites the automatically set value.

If nPixelSize is negative, the automatically set value will be used instead.

Definition at line 182 of file Button.h.

◆ setIsActive()

void setIsActive ( bool bIsActive)

Definition at line 99 of file Button.cpp.

◆ setSize()

void setSize ( QSize size)

Definition at line 364 of file Button.cpp.

◆ setType()

void setType ( Type type)

Definition at line 376 of file Button.cpp.

◆ setUseRedBackground()

void setUseRedBackground ( bool bUseRedBackground)

Definition at line 122 of file Button.cpp.

◆ updateFont()

void updateFont ( )
private

Definition at line 396 of file Button.cpp.

◆ updateIcon()

void updateIcon ( )
private

Definition at line 108 of file Button.cpp.

◆ updateStyleSheet()

void updateStyleSheet ( )
private

Definition at line 129 of file Button.cpp.

◆ updateTooltip()

void updateTooltip ( )
overrideprivatevirtual

Indicates child class to recalculate its tool tip in case m_registeredMidiEvents changed.

Reimplemented from MidiLearnable.

Definition at line 329 of file Button.cpp.

Field Documentation

◆ m_bColorful

bool m_bColorful
private

Definition at line 165 of file Button.h.

◆ m_bIsActive

bool m_bIsActive
private

Definition at line 168 of file Button.h.

◆ m_bLastCheckedState

bool m_bLastCheckedState
private

Definition at line 166 of file Button.h.

◆ m_bModifyOnChange

bool m_bModifyOnChange
private

Whether Hydrogen::setIsModified() is invoked with true as soon as the value of the widget does change.

Definition at line 172 of file Button.h.

◆ m_bUseRedBackground

bool m_bUseRedBackground
private

Definition at line 155 of file Button.h.

◆ m_iconSize

QSize m_iconSize
private

Definition at line 158 of file Button.h.

◆ m_nBorderRadius

int m_nBorderRadius
private

Definition at line 163 of file Button.h.

◆ m_nFixedFontSize

int m_nFixedFontSize
private

Definition at line 161 of file Button.h.

◆ m_sBaseTooltip

QString m_sBaseTooltip
private

Definition at line 159 of file Button.h.

◆ m_sIcon

QString m_sIcon
private

Definition at line 160 of file Button.h.

◆ m_size

QSize m_size
private

Definition at line 157 of file Button.h.

◆ m_type

Type m_type
private

Definition at line 156 of file Button.h.