32 : QDoubleSpinBox( pParent )
35 , m_kind(
Kind::Default )
37 , m_bModifyOnChange( bModifyOnChange )
38 , m_bMinusOneAsOff( bMinusOneAsOff )
40 setFocusPolicy( Qt::ClickFocus );
41 setLocale( QLocale( QLocale::C, QLocale::AnyCountry ) );
43 if ( size.isNull() || size.isEmpty() ) {
73 setDecimals( std::numeric_limits<double>::max_exponent );
89 setEnabled( bIsActive );
90 setReadOnly( ! bIsActive );
94 static float fCumulatedDelta;
96 double fOldValue = value();
102 fCumulatedDelta += ev->angleDelta().y();
104 if ( std::fabs( fCumulatedDelta ) >= 120 ) {
110 if ( fNextValue == 0 ) {
111 ERRORLOG( QString(
"Couldn't find next value for input: %1" ).arg( value() ) );
115 if ( ev->angleDelta().y() > 0 ) {
122 QDoubleSpinBox::wheelEvent( ev );
127 QDoubleSpinBox::wheelEvent( ev );
137 double fOldValue = value();
140 if ( ev->matches( QKeySequence::StandardKey::Undo )
141 || ev->matches( QKeySequence::StandardKey::Redo ) ) {
147 ( ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down ||
148 ev->key() == Qt::Key_PageUp || ev->key() == Qt::Key_PageDown ) ) {
151 if ( ev->key() == Qt::Key_Up ) {
153 }
else if ( ev->key() == Qt::Key_Down ) {
155 }
else if ( ev->key() == Qt::Key_PageUp ) {
157 }
else if ( ev->key() == Qt::Key_PageDown ) {
161 if ( fNextValue == 0 ) {
162 ERRORLOG( QString(
"Couldn't find next value for input: %1" ).arg( value() ) );
168 QDoubleSpinBox::keyPressEvent( ev );
172 QDoubleSpinBox::keyPressEvent( ev );
179 QDoubleSpinBox::keyPressEvent( ev );
190 std::vector vChoices{ 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 192 };
192 double fNextValue = 1.0;
193 double fOffset = 0.0;
195 if ( bAccelerated ) {
200 for (
int ii = 0; ii < vChoices.size(); ii++ ) {
201 if ( vChoices[ ii ] == value() ) {
204 if ( ii < vChoices.size() - 1 ) {
205 fNextValue = vChoices[ ii + 1 ] - fOffset;
207 fNextValue = vChoices[ ii ] - fOffset;
209 if ( fNextValue < 0 ) {
214 fNextValue = vChoices[ ii - 1 ] + fOffset;
216 fNextValue = vChoices[ ii ] + fOffset;
232 result = QString(
"%1" ).arg( fValue, 0,
'f', 0 );
235 result = QString(
"%1" ).arg( fValue ) ;
244 std::vector vChoices{
"1",
"2",
"3",
"4",
"6",
"8",
"12",
"16",
"24",
"32",
"48",
"64",
"96",
"192" };
245 std::vector vCandidates1{
"1",
"2",
"3",
"4",
"6",
"9" };
246 QString sCandidate2(
"19" );
247 bool bContained =
false;
248 bool bIsCandidate =
false;
249 for (
const auto& ii : vChoices ) {
254 for (
const auto& ii : vCandidates1 ) {
255 if ( ii == text.left( 1 ) ) {
259 if ( sCandidate2 == text.left( 2 ) ) {
264 return QValidator::Acceptable;
265 }
else if ( bIsCandidate ) {
266 return QValidator::Intermediate;
268 return QValidator::Invalid;
271 return QDoubleSpinBox::validate( text, pos );
278 if ( sText ==
"off" ){
281 fResult = QDoubleSpinBox::valueFromText( sText );
288 if ( value() == fValue ) {
292 QDoubleSpinBox::setValue( fValue );
297 if ( ev->type() == QEvent::KeyPress &&
dynamic_cast<QKeyEvent*
>( ev)->key() == Qt::Key_Slash ) {
302 return QDoubleSpinBox::event( ev );
306 double fOldValue = value();
308 QDoubleSpinBox::mousePressEvent( ev );
316 double fOldValue = value();
318 QDoubleSpinBox::mouseMoveEvent( ev );
326 double fOldValue = value();
328 QDoubleSpinBox::mouseReleaseEvent( ev );
339 QDoubleSpinBox::paintEvent( ev );
342 QPainter painter(
this);
345 QColor colorHighlightActive;
347 colorHighlightActive = pPref->getColorTheme()->m_highlightColor;
349 colorHighlightActive = pPref->getColorTheme()->m_lightColor;
355 if ( ! hasFocus() ) {
356 colorHighlightActive.setAlpha( 150 );
360 pen.setColor( colorHighlightActive );
362 painter.setPen( pen );
363 painter.drawRoundedRect( QRect( 0, 0,
m_size.width(),
m_size.height() ), 3, 3 );
368 QDoubleSpinBox::enterEvent( ev );
373 QDoubleSpinBox::leaveEvent( ev );
381 QColor spinBoxColor = pPref->getColorTheme()->m_spinBoxColor;
382 QColor spinBoxTextColor = pPref->getColorTheme()->m_spinBoxTextColor;
383 QColor selectionColor = spinBoxColor.darker( 120 );
385 QColor spinBoxInactiveColor =
387 QColor spinBoxTextInactiveColor =
389 QColor selectionInactiveColor =
393 setStyleSheet( QString(
"\
394QAbstractSpinBox:enabled { \
396 background-color: %2; \
397 selection-color: %1; \
398 selection-background-color: %3; \
400QAbstractSpinBox:disabled { \
402 background-color: %5; \
403 selection-color: %4; \
404 selection-background-color: %6; \
406 .arg( spinBoxTextColor.name() )
407 .arg( spinBoxColor.name() )
408 .arg( selectionColor.name() )
409 .arg( spinBoxTextInactiveColor.name() )
410 .arg( spinBoxInactiveColor.name() )
411 .arg( selectionInactiveColor.name() ) );
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
void setIsModified(bool bIsModified)
Wrapper around Song::setIsModified() that checks whether a song is set.
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 valueChanged(double fNewValue)
virtual void mouseMoveEvent(QMouseEvent *ev) override
double nextValueInPatternSizeDenominator(bool bUp, bool bAccelerated)
virtual void mousePressEvent(QMouseEvent *ev) override
virtual double valueFromText(const QString &sText) const override
void setValue(double fValue)
void onPreferencesChanged(H2Core::Preferences::Changes changes)
LCDSpinBox(QWidget *pParent, QSize size=QSize(), Type type=Type::Int, double fMin=0.0, double fMax=1.0, bool bModifyOnChange=false, bool bMinusOneAsOff=false)
bool m_bModifyOnChange
Whether Hydrogen::setIsModified() is invoked with true as soon as the value of the widget does change...
virtual QValidator::State validate(QString &text, int &pos) const override
bool m_bMinusOneAsOff
In some widgets the QString "off" will be displayed instead of -1.
virtual void leaveEvent(QEvent *ev) override
virtual void wheelEvent(QWheelEvent *ev) override
virtual void keyPressEvent(QKeyEvent *ev) override
virtual void mouseReleaseEvent(QMouseEvent *ev) override
virtual bool event(QEvent *ev) override
@ PatternSizeNumerator
The minimum value - a fractional one - can only be reached by entering it using the keyboard.
@ PatternSizeDenominator
Only a limited number of values is allowed.
virtual QString textFromValue(double fValue) const override
virtual void paintEvent(QPaintEvent *ev) override
void setIsActive(bool bIsActive)
virtual void enterEvent(QEvent *ev) override
static QColor makeTextColorInactive(QColor color)
If a widget is marked inactive the value of its text color are reduced by this factor.
static QColor makeWidgetColorInactive(QColor color)
If a widget is marked inactive the value of its background color are reduced by this factor.