diff options
Diffstat (limited to 'muse2')
-rw-r--r-- | muse2/ChangeLog | 3 | ||||
-rw-r--r-- | muse2/awl/sigedit.cpp | 227 | ||||
-rw-r--r-- | muse2/awl/sigedit.h | 23 | ||||
-rw-r--r-- | muse2/muse/master/lmaster.cpp | 5 |
4 files changed, 73 insertions, 185 deletions
diff --git a/muse2/ChangeLog b/muse2/ChangeLog index e7ddcec9..76feeabe 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,6 @@ +02.09.2011: + - SigEdit reworked to use two spinboxes, plan on adding Enter/Return detection so the widget will close when + Enter/Return is pressed (rj) 30.09.2011: - Fixed long-standing problem with themes (Ia Ora / Bespin etc) and MusE button icons. Some themes don't support multiple-pixmap icons. So mute/solo/rec/stereo/thru always showed the same icon. Replaced w single pm icons. (Tim) diff --git a/muse2/awl/sigedit.cpp b/muse2/awl/sigedit.cpp index 1d2bce48..74e4b060 100644 --- a/muse2/awl/sigedit.cpp +++ b/muse2/awl/sigedit.cpp @@ -28,6 +28,7 @@ #include <QKeyEvent> #include <QLineEdit> +#include <QPainter> namespace Awl { @@ -38,212 +39,92 @@ namespace Awl { //--------------------------------------------------------- SigEdit::SigEdit(QWidget* parent) - : QAbstractSpinBox(parent) + : QWidget(parent) { initialized = false; - setReadOnly(false); - setMinimumWidth(100); //TD: sizeHint - lineEdit()->setInputMask("99/99"); - } + slash = new QLabel("/",this); + zSpin = new QSpinBox(this); + nSpin = new QSpinBox(this); + zSpin->setRange(1,100); + nSpin->setRange(1,100); + layout = new QHBoxLayout(this); + layout->setContentsMargins(0,0,0,0); + layout->setSpacing(1); + layout->addWidget(zSpin); + layout->addWidget(slash); + layout->addWidget(nSpin); + layout->addSpacing(40); + connect(zSpin, SIGNAL(valueChanged(int)), SLOT(setZ(int))); + connect(nSpin, SIGNAL(valueChanged(int)), SLOT(setN(int))); -SigEdit::~SigEdit() - { } -//--------------------------------------------------------- -// event -// filter Tab and Backtab key events -//--------------------------------------------------------- - -bool SigEdit::event(QEvent* event) - { - if (event->type() == QEvent::KeyPress) { - QKeyEvent* ke = static_cast<QKeyEvent*>(event); - int segment = curSegment(); - if (ke->key() == Qt::Key_Return) - { - int z, n; - sscanf(lineEdit()->text().toLatin1().data(), "%d/%d", &z, &n); - AL::TimeSignature sig(z, n); - _sig = sig; - - emit returnPressed(); - return true; - } - if (ke->key() == Qt::Key_Backtab) { - if (segment == 2) { - lineEdit()->setSelection(5, 2); - return true; - } - if (segment == 1) { - lineEdit()->setSelection(0, 4); - return true; - } - } - if (ke->key() == Qt::Key_Tab) { - if (segment == 0) { - lineEdit()->setSelection(5, 2); - return true; - } - if (segment == 1) { - lineEdit()->setSelection(8, 3); - return true; - } - } - } - else if (event->type() == QEvent::FocusIn) { - QFocusEvent* fe = static_cast<QFocusEvent*>(event); - QAbstractSpinBox::focusInEvent(fe); - int segment = curSegment(); - switch(segment) { - case 0: lineEdit()->setSelection(0,4); break; - case 1: lineEdit()->setSelection(5,2); break; - case 2: lineEdit()->setSelection(8,3); break; - } - return true; - } - return QAbstractSpinBox::event(event); - } - -//--------------------------------------------------------- -// setValue -//--------------------------------------------------------- - -void SigEdit::setValue(const AL::TimeSignature& s) +SigEdit::~SigEdit() { - _sig = s; - updateValue(); + delete layout; + delete zSpin; + delete nSpin; } -void SigEdit::setValue(const QString& s) - { - int z = 4, n = 4; - sscanf(s.toLatin1().constData(), "%d/%d", &z, &n); - AL::TimeSignature sig(z, n); - setValue(sig); - } //--------------------------------------------------------- -// updateValue +// setZ //--------------------------------------------------------- -void SigEdit::updateValue() - { - //printf("updateValue\n"); - char buffer[64]; - sprintf(buffer, "%d/%d", _sig.z, _sig.n); - lineEdit()->setText(buffer); - } - +void SigEdit::setZ(const int z) +{ + _sig.z=z; + if (_sig.isValid()) { + zSpin->setStyleSheet(""); + emit valueChanged(_sig); + } + else + zSpin->setStyleSheet("QSpinBox { background-color: red; }"); +} //--------------------------------------------------------- -// stepEnables +// setN //--------------------------------------------------------- -QAbstractSpinBox::StepEnabled SigEdit::stepEnabled() const - { - int segment = curSegment(); - QAbstractSpinBox::StepEnabled en = QAbstractSpinBox::StepUpEnabled | QAbstractSpinBox::StepDownEnabled; - - switch (segment) { - case 0: - if (_sig.z == 1) - en &= ~QAbstractSpinBox::StepDownEnabled; - break; - case 1: - if (_sig.n == 1) - en &= ~QAbstractSpinBox::StepDownEnabled; - break; - } - return en; - } +void SigEdit::setN(const int n) +{ + _sig.n=n; + if (_sig.isValid()) { + nSpin->setStyleSheet(""); + emit valueChanged(_sig); + } + else + nSpin->setStyleSheet("QSpinBox { background-color: red; }"); -//--------------------------------------------------------- -// fixup -//--------------------------------------------------------- - -void SigEdit::fixup(QString& /*input*/) const - { -// printf("fixup <%s>\n", input.toLatin1().constData()); - } +} //--------------------------------------------------------- -// validate +// setValue //--------------------------------------------------------- -QValidator::State SigEdit::validate(QString&,int&) const +void SigEdit::setValue(const AL::TimeSignature& s) { - // TODO - //printf("validate\n"); - return QValidator::Acceptable; - } - -//--------------------------------------------------------- -// curSegment -//--------------------------------------------------------- + _sig = s; -int SigEdit::curSegment() const - { - QLineEdit* le = lineEdit(); - int pos = le->cursorPosition(); - int segment = -1; - - if (pos >= 0 && pos <= 4) - segment = 0; - else if (pos >= 5 && pos <= 7) - segment = 1; - else if (pos >= 8) - segment = 2; - else - printf("curSegment = -1, pos %d\n", pos); - return segment; + updateValue(); } //--------------------------------------------------------- -// stepBy +// updateValue //--------------------------------------------------------- -void SigEdit::stepBy(int steps) +void SigEdit::updateValue() { - int segment = curSegment(); - int selPos; - int selLen; - - bool changed = false; - AL::TimeSignature osig(_sig); - - switch(segment) { - case 0: - _sig.z += steps; - if (_sig.z < 1) - _sig.z = 1; - selPos = 0; - selLen = 2; - break; - case 1: - _sig.n += steps; - if (_sig.n < 1) - _sig.n = 1; - selPos = 3; - selLen = 2; - break; - default: - return; - } - if (osig.z != _sig.z || osig.n != _sig.n) { - changed = true; - } - if (changed) { - updateValue(); - emit valueChanged(_sig); - } - lineEdit()->setSelection(selPos, selLen); + zSpin->setValue(_sig.z); + nSpin->setValue(_sig.n); } - void SigEdit::paintEvent(QPaintEvent* event) { + void SigEdit::paintEvent(QPaintEvent* event) { if (!initialized) updateValue(); initialized = true; - QAbstractSpinBox::paintEvent(event); + QPainter p(this); + p.fillRect(event->rect(), Qt::white); + QWidget::paintEvent(event); } } diff --git a/muse2/awl/sigedit.h b/muse2/awl/sigedit.h index 259812dd..acb0b9d8 100644 --- a/muse2/awl/sigedit.h +++ b/muse2/awl/sigedit.h @@ -26,7 +26,10 @@ #include "al/sig.h" //#include "sig.h" -#include <QAbstractSpinBox> +#include <QWidget> +#include <QSpinBox> +#include <QHBoxLayout> +#include <QLabel> namespace AL { class TimeSignature; @@ -38,29 +41,29 @@ namespace Awl { // SigEdit //--------------------------------------------------------- -class SigEdit : public QAbstractSpinBox +class SigEdit : public QWidget { Q_OBJECT AL::TimeSignature _sig; bool initialized; + QLabel *slash; + QSpinBox *zSpin; + QSpinBox *nSpin; + QHBoxLayout *layout; virtual void paintEvent(QPaintEvent* event); - virtual void stepBy(int steps); - virtual StepEnabled stepEnabled() const; - virtual void fixup(QString& input) const; - virtual QValidator::State validate(QString&, int&) const; void updateValue(); - int curSegment() const; - virtual bool event(QEvent*); signals: void valueChanged(const AL::TimeSignature&); - void returnPressed(); + + private slots: + void setN(const int n); + void setZ(const int z); public slots: void setValue(const AL::TimeSignature&); - void setValue(const QString& s); public: SigEdit(QWidget* parent = 0); diff --git a/muse2/muse/master/lmaster.cpp b/muse2/muse/master/lmaster.cpp index a2cc8538..ce6010c7 100644 --- a/muse2/muse/master/lmaster.cpp +++ b/muse2/muse/master/lmaster.cpp @@ -601,7 +601,8 @@ void LMaster::itemDoubleClicked(QTreeWidgetItem* i) tempo_editor->selectAll(); } else if (editedItem->getType() == LMASTER_SIGEVENT) { // Edit signatur value: - sig_editor->setValue(editedItem->text(LMASTER_VAL_COL)); + //sig_editor->setValue(editedItem->text(LMASTER_VAL_COL)); + sig_editor->setValue(((LMasterSigEventItem*)editedItem)->getEvent()->sig); sig_editor->setGeometry(itemRect); sig_editor->show(); sig_editor->setFocus(); @@ -923,7 +924,7 @@ LMasterSigEventItem::LMasterSigEventItem(QTreeWidget* parent, const AL::SigEvent int msec = int((time - (min*60 + sec)) * 1000.0); c2.sprintf("%03d:%02d:%03d", min, sec, msec); c3 = "Timesig"; - c4.sprintf("%d/%d", ev->sig.z, ev->sig.n); + c4.sprintf("%d / %d", ev->sig.z, ev->sig.n); setText(0, c1); setText(1, c2); setText(2, c3); |