hydrogen 1.2.3
StatusMessageDisplay.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, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
25#include "../HydrogenApp.h"
26
29
30StatusMessageDisplay::StatusMessageDisplay( QWidget * pParent, QSize size )
31 : LCDDisplay( pParent, size, false, false )
32 , m_bEntered( false )
33 , m_nShowTimeout( 5500 )
34 , m_nScrollTimeout( 150 )
35 , m_nPreScrollTimeout( 1500 )
36 , m_nHistorySize( 100 )
37 , m_bPreScroll( true )
38{
39 setReadOnly( true );
40 setEnabled( true );
41
42 m_pStatusTimer = new QTimer( this );
43 connect( m_pStatusTimer, SIGNAL( timeout() ), this, SLOT( onStatusTimerEvent() ) );
44
45 m_pScrollTimer = new QTimer( this );
46 connect( m_pScrollTimer, SIGNAL( timeout() ), this, SLOT( onScrollTimerEvent() ) );
48
51
54}
55
58
67
68// We need the widget to be enabled in order to handle mouse
69// clicks. But the line edit itself if read-only and does not nicely
70// integrate into the current GUI design using the active LCDDisplay
71// foreground and background colors.
73
75
76 QColor textColor = pPref->getColorTheme()->m_windowTextColor;
77 QColor backgroundColor = pPref->getColorTheme()->m_windowColor;
78
79 QString sStyleSheet = QString( "\
80QLineEdit { \
81 color: %1; \
82 background-color: %2; \
83}" )
84 .arg( textColor.name() )
85 .arg( backgroundColor.name() );
86
87 setStyleSheet( sStyleSheet );
88}
89
90void StatusMessageDisplay::paintEvent( QPaintEvent *ev ) {
91
93
95
96 if ( m_bEntered || hasFocus() ) {
97 QPainter painter(this);
98
99 QColor colorHighlightActive = pPref->getColorTheme()->m_highlightColor;
100
101 // If the mouse is placed on the widget but the user hasn't
102 // clicked it yet, the highlight will be done more transparent to
103 // indicate that keyboard inputs are not accepted yet.
104 if ( ! hasFocus() ) {
105 colorHighlightActive.setAlpha( 150 );
106 }
107
108 QPen pen;
109 pen.setColor( colorHighlightActive );
110 pen.setWidth( 3 );
111 painter.setPen( pen );
112 painter.drawRoundedRect( QRect( 0, 0, m_size.width() - 1, m_size.height() - 1 ), 3, 3 );
113 }
114}
115
117 LCDDisplay::enterEvent( ev );
118 m_bEntered = true;
119 update();
120}
121
123 LCDDisplay::leaveEvent( ev );
124 m_bEntered = false;
125 update();
126}
127
129 QMenu* messageMenu = new QMenu( this );
130
131 for ( const auto& sMessage : m_statusMessages ) {
132 messageMenu->addAction( sMessage );
133 }
134
135 messageMenu->popup( ev->globalPos() );
136}
137
138void StatusMessageDisplay::showMessage( const QString& sMessage, const QString& sCaller ) {
139
140 // Make sure widgets like sliders or rotaries do not flood the
141 // status message history.
142 if ( ! sCaller.isEmpty() && sCaller == m_sLastCaller ) {
143 m_statusMessages.removeLast();
144 }
145 m_sLastCaller = sCaller;
146
147 m_statusMessages << sMessage;
148
149 if ( m_statusMessages.size() > m_nHistorySize ) {
150 m_statusMessages.removeFirst();
151 }
152
153 m_sScrollMessage = sMessage;
154 m_bPreScroll = true;
155
156 displayMessage( sMessage );
157}
158
159void StatusMessageDisplay::displayMessage( const QString& sMessage )
160{
161 if ( m_pScrollTimer->isActive() ) {
162 m_pScrollTimer->stop();
163 }
164 if ( m_pStatusTimer->isActive() ) {
165 m_pStatusTimer->stop();
166 }
167
168 setText( sMessage );
169
170 if ( sMessage.length() >= maxLength() ) {
171 // Text is too large to fit in the display. Use scrolled
172 // message instead.
173 if ( m_bPreScroll ) {
175 m_bPreScroll = false;
176 }
177 else {
179 }
180 }
181 else {
183 }
184}
185
192
197
199{
200 m_pStatusTimer->stop();
201 m_pScrollTimer->stop();
202 setText( "" );
203 m_sScrollMessage = "";
204}
205
207{
208 QString sLongString( "ThisIsALongOneThatShouldNotFitInTheLCDDisplayEvenWithVeryNarrowFonts" );
209 setMaxLength( 120 );
210
211 while ( fontMetrics().size( Qt::TextSingleLine, sLongString ).width() >
212 width() && ! sLongString.isEmpty() ) {
213 sLongString.chop( 1 );
214 }
215
216 setMaxLength( sLongString.length() );
217}
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...
@ Font
Either the font size or font family have 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.
Non-interactive display used for both numerical values and the status display.
Definition LCDDisplay.h:40
QSize m_size
Definition LCDDisplay.h:57
void onPreferencesChanged(H2Core::Preferences::Changes changes)
virtual void paintEvent(QPaintEvent *ev) override
virtual void mousePressEvent(QMouseEvent *ev) override
void onPreferencesChanged(H2Core::Preferences::Changes changes)
virtual void leaveEvent(QEvent *ev) override
int m_nScrollTimeout
Amount of time in milliseconds that pass between chopping characters for messages to long to display ...
int m_nPreScrollTimeout
Amount of time in milliseconds that pass before a message is being scrolled.
virtual void paintEvent(QPaintEvent *ev) override
void showMessage(const QString &sMessage, const QString &sCaller="")
StatusMessageDisplay(QWidget *pParent, QSize size)
virtual void enterEvent(QEvent *ev) override
void displayMessage(const QString &sMessage)
int m_nShowTimeout
Amount of time in milliseconds for which the status message will be displayed.