hydrogen 1.2.6
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-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, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
25
27#include "../HydrogenApp.h"
28
31
32StatusMessageDisplay::StatusMessageDisplay( QWidget * pParent, QSize size )
33 : LCDDisplay( pParent, size, false, false )
34 , m_bEntered( false )
35 , m_nShowTimeout( 5500 )
36 , m_nScrollTimeout( 150 )
37 , m_nPreScrollTimeout( 1500 )
38 , m_nHistorySize( 100 )
39 , m_bPreScroll( true )
40{
41 setReadOnly( true );
42 setEnabled( true );
43
44 m_pStatusTimer = new QTimer( this );
45 connect( m_pStatusTimer, SIGNAL( timeout() ), this, SLOT( onStatusTimerEvent() ) );
46
47 m_pScrollTimer = new QTimer( this );
48 connect( m_pScrollTimer, SIGNAL( timeout() ), this, SLOT( onScrollTimerEvent() ) );
50
53
56}
57
60
69
70// We need the widget to be enabled in order to handle mouse
71// clicks. But the line edit itself if read-only and does not nicely
72// integrate into the current GUI design using the active LCDDisplay
73// foreground and background colors.
75
77
78 QColor textColor = pPref->getColorTheme()->m_windowTextColor;
79 QColor backgroundColor = pPref->getColorTheme()->m_windowColor;
80
81 QString sStyleSheet = QString( "\
82QLineEdit { \
83 color: %1; \
84 background-color: %2; \
85}" )
86 .arg( textColor.name() )
87 .arg( backgroundColor.name() );
88
89 setStyleSheet( sStyleSheet );
90}
91
92void StatusMessageDisplay::paintEvent( QPaintEvent *ev ) {
93
95
97
98 if ( m_bEntered || hasFocus() ) {
99 QPainter painter(this);
100
101 QColor colorHighlightActive = pPref->getColorTheme()->m_highlightColor;
102
103 // If the mouse is placed on the widget but the user hasn't
104 // clicked it yet, the highlight will be done more transparent to
105 // indicate that keyboard inputs are not accepted yet.
106 if ( ! hasFocus() ) {
107 colorHighlightActive.setAlpha( 150 );
108 }
109
110 QPen pen;
111 pen.setColor( colorHighlightActive );
112 pen.setWidth( 3 );
113 painter.setPen( pen );
114 painter.drawRoundedRect( QRect( 0, 0, m_size.width() - 1, m_size.height() - 1 ), 3, 3 );
115 }
116}
117
118#ifdef H2CORE_HAVE_QT6
119void StatusMessageDisplay::enterEvent( QEnterEvent *ev ) {
120#else
122#endif
123 LCDDisplay::enterEvent( ev );
124 m_bEntered = true;
125 update();
126}
127
129 LCDDisplay::leaveEvent( ev );
130 m_bEntered = false;
131 update();
132}
133
135 QMenu* messageMenu = new QMenu( this );
136
137 for ( const auto& sMessage : m_statusMessages ) {
138 messageMenu->addAction( sMessage );
139 }
140
141 auto pEv = static_cast<MouseEvent*>( ev );
142
143 messageMenu->popup( pEv->globalPosition().toPoint() );
144}
145
146void StatusMessageDisplay::showMessage( const QString& sMessage, const QString& sCaller ) {
147
148 // Make sure widgets like sliders or rotaries do not flood the
149 // status message history.
150 if ( ! sCaller.isEmpty() && sCaller == m_sLastCaller ) {
151 m_statusMessages.removeLast();
152 }
153 m_sLastCaller = sCaller;
154
155 m_statusMessages << sMessage;
156
157 if ( m_statusMessages.size() > m_nHistorySize ) {
158 m_statusMessages.removeFirst();
159 }
160
161 m_sScrollMessage = sMessage;
162 m_bPreScroll = true;
163
164 displayMessage( sMessage );
165}
166
167void StatusMessageDisplay::displayMessage( const QString& sMessage )
168{
169 if ( m_pScrollTimer->isActive() ) {
170 m_pScrollTimer->stop();
171 }
172 if ( m_pStatusTimer->isActive() ) {
173 m_pStatusTimer->stop();
174 }
175
176 setText( sMessage );
177
178 if ( sMessage.length() >= maxLength() ) {
179 // Text is too large to fit in the display. Use scrolled
180 // message instead.
181 if ( m_bPreScroll ) {
183 m_bPreScroll = false;
184 }
185 else {
187 }
188 }
189 else {
191 }
192}
193
200
205
207{
208 m_pStatusTimer->stop();
209 m_pScrollTimer->stop();
210 setText( "" );
211 m_sScrollMessage = "";
212}
213
215{
216 QString sLongString( "ThisIsALongOneThatShouldNotFitInTheLCDDisplayEvenWithVeryNarrowFonts" );
217 setMaxLength( 120 );
218
219 while ( fontMetrics().size( Qt::TextSingleLine, sLongString ).width() >
220 width() && ! sLongString.isEmpty() ) {
221 sLongString.chop( 1 );
222 }
223
224 setMaxLength( sLongString.length() );
225}
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.
QSize m_size
Definition LCDDisplay.h:57
void onPreferencesChanged(H2Core::Preferences::Changes changes)
virtual void paintEvent(QPaintEvent *ev) override
LCDDisplay(QWidget *pParent, QSize size=QSize(0, 0), bool bFixedFont=false, bool bIsActive=true)
Compatibility class to support QMouseEvent more esily in Qt5 and Qt6.
Definition MouseEvent.h:35
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.