hydrogen 1.2.3
LCDDisplay.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
24#include "LCDDisplay.h"
25#include "../HydrogenApp.h"
26#include "../Skin.h"
27
28#include <core/Globals.h>
30
31LCDDisplay::LCDDisplay( QWidget * pParent, QSize size, bool bFixedFont, bool bIsActive )
32 : QLineEdit( pParent )
33 , m_size( size )
34 , m_bFixedFont( bFixedFont )
35 , m_bUseRedFont( false )
36 , m_bIsActive( bIsActive )
37{
38 setReadOnly( ! bIsActive );
39 setEnabled( bIsActive );
40 if ( ! bIsActive ) {
41 setFocusPolicy( Qt::NoFocus );
42 }
43 setAlignment( Qt::AlignCenter );
44 setLocale( QLocale( QLocale::C, QLocale::AnyCountry ) );
45
47
48 // Derive a set of scaling-dependent font sizes on the basis of
49 // the default font size determined by Qt itself.
50 QFont currentFont = font();
51 int nStepSize = 2;
52
53 m_fontPointSizes.resize( 3 );
54 switch ( pPref->getFontSize() ) {
56 m_fontPointSizes[ 0 ] = currentFont.pointSize();
57 break;
59 m_fontPointSizes[ 0 ] = currentFont.pointSize() - 2 * nStepSize;
60 break;
61 default:
62 m_fontPointSizes[ 0 ] = currentFont.pointSize() - nStepSize;
63 }
64
65 m_fontPointSizes[ 1 ] = m_fontPointSizes[ 0 ] + nStepSize;
66 m_fontPointSizes[ 2 ] = m_fontPointSizes[ 0 ] + 2 * nStepSize;
67
68 if ( ! size.isNull() ) {
69 adjustSize();
70 setFixedSize( size );
71 }
72
73 updateFont();
75
77}
78
81
82void LCDDisplay::setUseRedFont( bool bUseRedFont ) {
83 if ( bUseRedFont != m_bUseRedFont ) {
84 m_bUseRedFont = bUseRedFont;
86 }
87}
88
89void LCDDisplay::setIsActive( bool bIsActive ) {
90 m_bIsActive = bIsActive;
91
92 update();
93
94 setReadOnly( ! bIsActive );
95 setEnabled( bIsActive );
96
97 if ( ! bIsActive ) {
98 setFocusPolicy( Qt::NoFocus );
99 }
100 else {
101 setFocusPolicy( Qt::StrongFocus );
102 }
103}
104
106
107 if ( m_bFixedFont ) {
108 return;
109 }
110
112
113 int nIndex = 1;
114 if ( pPref->getFontSize() == H2Core::FontTheme::FontSize::Small ) {
115 nIndex = 0;
116 } else if ( pPref->getFontSize() == H2Core::FontTheme::FontSize::Large ) {
117 nIndex = 2;
118 }
119
120 QFont newFont = font();
121 newFont.setFamily( pPref->getLevel3FontFamily() );
122 newFont.setPointSize( m_fontPointSizes[ nIndex ] );
123 setFont( newFont );
124}
125
128
129 QColor textColor, textColorActive;
130 if ( m_bUseRedFont ) {
131 textColor = pPref->getColorTheme()->m_buttonRedColor;
132 textColorActive = pPref->getColorTheme()->m_buttonRedColor;
133 } else {
134 textColor = pPref->getColorTheme()->m_windowTextColor;
135 textColorActive = pPref->getColorTheme()->m_widgetTextColor;
136 }
137 QColor backgroundColor = pPref->getColorTheme()->m_windowColor;
138
139 QColor backgroundColorActive = pPref->getColorTheme()->m_widgetColor;
140
141 QString sStyleSheet = QString( "\
142QLineEdit:enabled { \
143 color: %1; \
144 background-color: %2; \
145} \
146QLineEdit:disabled { \
147 color: %3; \
148 background-color: %4; \
149}" )
150 .arg( textColorActive.name() )
151 .arg( backgroundColorActive.name() )
152 .arg( textColor.name() )
153 .arg( backgroundColor.name() );
154
155 // For fixed font displays we have to add the current font
156 // parameters as well to avoid any inherited changes.
157 if ( m_bFixedFont && font().pixelSize() > 0 ) {
158 sStyleSheet.append( QString( "\
159QLineEdit { \
160 font-size: %1px; \
161 font-family: %2; \
162}" )
163 .arg( font().pixelSize() )
164 .arg( font().family() ) );
165 }
166
167 setStyleSheet( sStyleSheet );
168}
169
177
178void LCDDisplay::paintEvent( QPaintEvent *ev ) {
179
180 QLineEdit::paintEvent( ev );
181 updateFont();
182}
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.
@ 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.
std::vector< int > m_fontPointSizes
Definition LCDDisplay.h:68
bool m_bFixedFont
Definition LCDDisplay.h:64
void onPreferencesChanged(H2Core::Preferences::Changes changes)
bool m_bUseRedFont
Definition LCDDisplay.h:65
void updateStyleSheet()
void setUseRedFont(bool bUseRedFont)
bool m_bIsActive
Definition LCDDisplay.h:66
virtual void paintEvent(QPaintEvent *ev) override
void setIsActive(bool bIsActive)
LCDDisplay(QWidget *pParent, QSize size=QSize(0, 0), bool bFixedFont=false, bool bIsActive=true)
void updateFont()