hydrogen 1.2.3
InfoBar.cpp
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-2024 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#include "InfoBar.h"
24#include "../Skin.h"
25
26#include <QHBoxLayout>
27#include <QLabel>
28#include <QPushButton>
29#include <QStyle>
30
32
33#include "../HydrogenApp.h"
34
35InfoBar::InfoBar( QWidget *parent )
36 : QWidget( parent )
37{
38 setAutoFillBackground( true );
39
41 createIcon();
44
46
48}
49
52
53 setStyleSheet( QString( "background: %1;" ).arg( pPref->getColorTheme()->m_highlightColor.name() ) );
54}
55
61
63{
64 m_pLayout = new QHBoxLayout();
65 m_pLayout->setContentsMargins( 2, 2, 2, 2 );
66 setLayout( m_pLayout );
67}
68
69
71{
72 QLabel *icon = new QLabel();
73 icon->setPixmap( QPixmap( Skin::getImagePath() + "/warning.png" ) );
74 m_pLayout->addWidget( icon );
75}
76
77
79{
80 m_pLabel = new QLabel();
81 m_pLabel->setWordWrap( true );
82 m_pLayout->addWidget( m_pLabel, 1 );
83
84 QFont font = m_pLabel->font();
85 font.setPointSize( 11 );
86 m_pLabel->setFont( font );
87}
88
89
91{
92 QPushButton *close = new QPushButton();
93 QIcon closeIcon = style()->standardIcon( QStyle::SP_TitleBarCloseButton );
94 close->setIcon( closeIcon );
95 close->setFlat( true );
96 m_pLayout->addWidget( close );
97
98 QObject::connect(close, SIGNAL(clicked()), this, SLOT(hide()));
99}
100
101
102void InfoBar::setTitle(const QString &title)
103{
104 m_sTitle = title;
105 updateText();
106}
107
108
109void InfoBar::setText(const QString &str)
110{
111 m_sText = str;
112 updateText();
113}
114
115
117{
118 auto html = QString("<html><b>%1</b><br/>%2</html>").arg(m_sTitle).arg(m_sText);
119 m_pLabel->setText(html);
120}
121
122
123QPushButton *InfoBar::addButton( const QString &label )
124{
125 QPushButton *button = new QPushButton();
126 button->setText( label );
127 m_pLayout->insertWidget( m_pLayout->count() - 1, button );
128 m_buttons.push_back(button);
129 return button;
130}
131
132
134{
135 m_sTitle = "";
136 m_sText = "";
137 updateText();
138
139 for (QPushButton *button : m_buttons) {
140 delete button;
141 }
142 m_buttons.clear();
143}
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
Changes
Bitwise or-able options showing which part of the Preferences were altered using the PreferencesDialo...
@ Colors
At least one of the colors has changed.
static HydrogenApp * get_instance()
Returns the instance of HydrogenApp class.
void preferencesChanged(H2Core::Preferences::Changes changes)
Propagates a change in the Preferences through the GUI.
void setText(const QString &text)
Definition InfoBar.cpp:109
void createIcon()
Definition InfoBar.cpp:70
QString m_sText
Definition InfoBar.h:45
void updateText()
Definition InfoBar.cpp:116
InfoBar(QWidget *parent=Q_NULLPTR)
Definition InfoBar.cpp:35
void onPreferencesChanged(H2Core::Preferences::Changes changes)
Definition InfoBar.cpp:56
void createCloseButton()
Definition InfoBar.cpp:90
QHBoxLayout * m_pLayout
Definition InfoBar.h:41
void updateStyleSheet()
Definition InfoBar.cpp:50
QString m_sTitle
Definition InfoBar.h:44
QPushButton * addButton(const QString &label)
Definition InfoBar.cpp:123
std::vector< QPushButton * > m_buttons
Definition InfoBar.h:47
QLabel * m_pLabel
Definition InfoBar.h:42
void createLayout()
Definition InfoBar.cpp:62
void reset()
Definition InfoBar.cpp:133
void setTitle(const QString &text)
Definition InfoBar.cpp:102
void createLabel()
Definition InfoBar.cpp:78
static QString getImagePath()
Definition Skin.h:36