diff options
Diffstat (limited to 'muse2/muse/widgets/spinbox.cpp')
-rw-r--r-- | muse2/muse/widgets/spinbox.cpp | 109 |
1 files changed, 48 insertions, 61 deletions
diff --git a/muse2/muse/widgets/spinbox.cpp b/muse2/muse/widgets/spinbox.cpp index 730e4828..b0b5d4ce 100644 --- a/muse2/muse/widgets/spinbox.cpp +++ b/muse2/muse/widgets/spinbox.cpp @@ -22,10 +22,28 @@ #include <QKeyEvent> #include <QEvent> +#include <QLineEdit> +#include <QMouseEvent> #include "spinbox.h" namespace MusEGui { +//void SpinBoxLineEdit::mouseDoubleClickEvent(QMouseEvent* e) +//{ +// QLineEdit::mouseDoubleClickEvent(e); +// emit doubleClicked(); +// if((e->buttons() & Qt::LeftButton) && (e->modifiers() & Qt::ControlModifier)) +// emit ctrlDoubleClicked(); +//} + +void SpinBoxLineEdit::mousePressEvent(QMouseEvent* e) +{ + QLineEdit::mousePressEvent(e); + //selectAll(); + if((e->buttons() & Qt::LeftButton) && (e->modifiers() & Qt::ControlModifier)) + emit ctrlClicked(); +} + //--------------------------------------------------------- // SpinBox //--------------------------------------------------------- @@ -33,85 +51,54 @@ namespace MusEGui { SpinBox::SpinBox(QWidget* parent) : QSpinBox(parent) { - _clearFocus = true; + SpinBoxLineEdit* le = new SpinBoxLineEdit(this); + setLineEdit(le); + setKeyboardTracking(false); + + //connect(le, SIGNAL(doubleClicked()), this, SIGNAL(doubleClicked())); + //connect(le, SIGNAL(ctrlDoubleClicked()), this, SIGNAL(ctrlDoubleClicked())); + connect(le, SIGNAL(ctrlClicked()), this, SIGNAL(ctrlClicked())); } SpinBox::SpinBox(int minValue, int maxValue, int step, QWidget* parent) : QSpinBox(parent) { + SpinBoxLineEdit* le = new SpinBoxLineEdit(this); + setLineEdit(le); setRange(minValue, maxValue); setSingleStep(step); - _clearFocus = true; -} + setKeyboardTracking(false); -bool SpinBox::eventFilter(QObject* o, QEvent* ev) -{ - // if (o != (QObject*)editor()) ddskrjo can't find editor() - // return QSpinBox::eventFilter(o,ev); - - bool retval = false; - if(ev->type() == QEvent::KeyPress) - { - QKeyEvent* k = (QKeyEvent*)ev; - if(k->key() == Qt::Key_Up || k->key() == Qt::Key_Down) - { - // stepUp/stepDown will be called. Set this now. - _clearFocus = false; - } - else if (k->key() == Qt::Key_Enter || k->key() == Qt::Key_Return) - { - // With this line, two enter presses after an edit will clear focus. - // Without, just one enter press clears the focus. - //if(!editor()->isModified()) - { - clearFocus(); - return true; - } - } - } - else - if(ev->type() == QEvent::MouseButtonDblClick) - { - emit doubleClicked(); - return true; - } - - retval = QSpinBox::eventFilter(o, ev); - - return retval; -} - -void SpinBox::stepUp() -{ - QSpinBox::stepUp(); - if(_clearFocus) - clearFocus(); - else - _clearFocus = true; -} - -void SpinBox::stepDown() -{ - QSpinBox::stepDown(); - if(_clearFocus) - clearFocus(); - else - _clearFocus = true; + //connect(le, SIGNAL(doubleClicked()), this, SIGNAL(doubleClicked())); + //connect(le, SIGNAL(ctrlDoubleClicked()), this, SIGNAL(ctrlDoubleClicked())); + connect(le, SIGNAL(ctrlClicked()), this, SIGNAL(ctrlClicked())); } void SpinBox::keyPressEvent(QKeyEvent* ev) { switch (ev->key()) { case Qt::Key_Return: - clearFocus(); - //emit returnPressed(); - // return; - break; + QSpinBox::keyPressEvent(ev); + emit returnPressed(); + return; + break; + case Qt::Key_Escape: + emit escapePressed(); + return; + break; default: - break; + break; } QSpinBox::keyPressEvent(ev); } +void SpinBox::wheelEvent(QWheelEvent* e) +{ + QSpinBox::wheelEvent(e); + // Need this because Qt doesn't deselect the text if not focused. + if(!hasFocus() && lineEdit()) + lineEdit()->deselect(); +} + } // namespace MusEGui |