32 : QDoubleSpinBox( pParent )
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();
141 if ( ev->matches( QKeySequence::StandardKey::Undo )
142 || ev->matches( QKeySequence::StandardKey::Redo )
143 || ev->key() == Qt::Key_Space ) {
149 ( ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down ||
150 ev->key() == Qt::Key_PageUp || ev->key() == Qt::Key_PageDown ) ) {
153 if ( ev->key() == Qt::Key_Up ) {
156 else if ( ev->key() == Qt::Key_Down ) {
159 else if ( ev->key() == Qt::Key_PageUp ) {
162 else if ( ev->key() == Qt::Key_PageDown ) {
166 if ( fNextValue == 0 ) {
167 ERRORLOG( QString(
"Couldn't find next value for input: %1" ).arg( value() ) );
173 QDoubleSpinBox::keyPressEvent( ev );
177 QDoubleSpinBox::keyPressEvent( ev );
184 QDoubleSpinBox::keyPressEvent( ev );
195 std::vector vChoices{ 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 192 };
197 double fNextValue = 1.0;
198 double fOffset = 0.0;
200 if ( bAccelerated ) {
205 for (
int ii = 0; ii < vChoices.size(); ii++ ) {
206 if ( vChoices[ ii ] == value() ) {
209 if ( ii < vChoices.size() - 1 ) {
210 fNextValue = vChoices[ ii + 1 ] - fOffset;
212 fNextValue = vChoices[ ii ] - fOffset;
214 if ( fNextValue < 0 ) {
219 fNextValue = vChoices[ ii - 1 ] + fOffset;
221 fNextValue = vChoices[ ii ] + fOffset;
237 result = QString(
"%1" ).arg( fValue, 0,
'f', 0 );
240 result = QString(
"%1" ).arg( fValue ) ;
249 std::vector vChoices{
"1",
"2",
"3",
"4",
"6",
"8",
"12",
"16",
"24",
"32",
"48",
"64",
"96",
"192" };
250 std::vector vCandidates1{
"1",
"2",
"3",
"4",
"6",
"9" };
251 QString sCandidate2(
"19" );
252 bool bContained =
false;
253 bool bIsCandidate =
false;
254 for (
const auto& ii : vChoices ) {
259 for (
const auto& ii : vCandidates1 ) {
260 if ( ii == text.left( 1 ) ) {
264 if ( sCandidate2 == text.left( 2 ) ) {
269 return QValidator::Acceptable;
270 }
else if ( bIsCandidate ) {
271 return QValidator::Intermediate;
273 return QValidator::Invalid;
276 return QDoubleSpinBox::validate( text, pos );
283 if ( sText ==
"off" ){
286 fResult = QDoubleSpinBox::valueFromText( sText );
293 if ( value() == fValue ) {
297 QDoubleSpinBox::setValue( fValue );
302 if ( ev->type() == QEvent::KeyPress &&
dynamic_cast<QKeyEvent*
>( ev)->key() == Qt::Key_Slash ) {
307 return QDoubleSpinBox::event( ev );
311 double fOldValue = value();
313 QDoubleSpinBox::mousePressEvent( ev );
321 double fOldValue = value();
323 QDoubleSpinBox::mouseMoveEvent( ev );
331 double fOldValue = value();
333 QDoubleSpinBox::mouseReleaseEvent( ev );
344 QDoubleSpinBox::paintEvent( ev );
347 QPainter painter(
this);
350 QColor colorHighlightActive;
352 colorHighlightActive = pPref->getColorTheme()->m_highlightColor;
354 colorHighlightActive = pPref->getColorTheme()->m_lightColor;
360 if ( ! hasFocus() ) {
361 colorHighlightActive.setAlpha( 150 );
365 pen.setColor( colorHighlightActive );
367 painter.setPen( pen );
368 painter.drawRoundedRect( QRect( 0, 0,
m_size.width(),
m_size.height() ), 3, 3 );
372#ifdef H2CORE_HAVE_QT6
377 QDoubleSpinBox::enterEvent( ev );
382 QDoubleSpinBox::leaveEvent( ev );
390 QColor spinBoxColor = pPref->getColorTheme()->m_spinBoxColor;
391 QColor spinBoxTextColor = pPref->getColorTheme()->m_spinBoxTextColor;
392 QColor selectionColor = spinBoxColor.darker( 120 );
394 QColor spinBoxInactiveColor =
396 QColor spinBoxTextInactiveColor =
398 QColor selectionInactiveColor =
402 setStyleSheet( QString(
"\
403QAbstractSpinBox:enabled { \
405 background-color: %2; \
406 selection-color: %1; \
407 selection-background-color: %3; \
409QAbstractSpinBox:disabled { \
411 background-color: %5; \
412 selection-color: %4; \
413 selection-background-color: %6; \
415 .arg( spinBoxTextColor.name() )
416 .arg( spinBoxColor.name() )
417 .arg( selectionColor.name() )
418 .arg( spinBoxTextInactiveColor.name() )
419 .arg( spinBoxInactiveColor.name() )
420 .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
@ Default
Behaves like QDoubleSpinBox.
@ 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.