summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Jonsson <spamatica@gmail.com>2011-10-04 18:58:03 +0000
committerRobert Jonsson <spamatica@gmail.com>2011-10-04 18:58:03 +0000
commitad507206af844ea5f9ca0b89726a92e159fc9c8c (patch)
tree7ab0904cf67ba9000ca0e1c751ced32d068f7782
parentf3313cc78e637ec9bc11efce5eb943434da93416 (diff)
fixes to SigEdit
-rw-r--r--muse2/ChangeLog2
-rw-r--r--muse2/awl/CMakeLists.txt2
-rw-r--r--muse2/awl/sigedit.cpp36
-rw-r--r--muse2/awl/sigedit.h9
-rw-r--r--muse2/awl/sigspinbox.cpp24
-rw-r--r--muse2/awl/sigspinbox.h23
6 files changed, 88 insertions, 8 deletions
diff --git a/muse2/ChangeLog b/muse2/ChangeLog
index 4c45bc99..6487f593 100644
--- a/muse2/ChangeLog
+++ b/muse2/ChangeLog
@@ -1,3 +1,5 @@
+04.09.2011:
+ - More fixes to SigEdit, close on enter, navigate with arrows and / between values, fixed background color, focus (rj)
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)
diff --git a/muse2/awl/CMakeLists.txt b/muse2/awl/CMakeLists.txt
index f84194a8..7586b1c2 100644
--- a/muse2/awl/CMakeLists.txt
+++ b/muse2/awl/CMakeLists.txt
@@ -45,6 +45,7 @@ QT4_WRAP_CPP (awl_mocs
posedit.h
# poslabel.h
sigedit.h
+ sigspinbox.h
slider.h
# tcanvas.h
tempoedit.h
@@ -80,6 +81,7 @@ file (GLOB awl_source_files
posedit.cpp
# poslabel.cpp
sigedit.cpp
+ sigspinbox.cpp
slider.cpp
# tcanvas.cpp
tempoedit.cpp
diff --git a/muse2/awl/sigedit.cpp b/muse2/awl/sigedit.cpp
index 74e4b060..0cad9057 100644
--- a/muse2/awl/sigedit.cpp
+++ b/muse2/awl/sigedit.cpp
@@ -43,8 +43,8 @@ SigEdit::SigEdit(QWidget* parent)
{
initialized = false;
slash = new QLabel("/",this);
- zSpin = new QSpinBox(this);
- nSpin = new QSpinBox(this);
+ zSpin = new SigSpinBox(this);
+ nSpin = new SigSpinBox(this);
zSpin->setRange(1,100);
nSpin->setRange(1,100);
layout = new QHBoxLayout(this);
@@ -53,10 +53,15 @@ SigEdit::SigEdit(QWidget* parent)
layout->addWidget(zSpin);
layout->addWidget(slash);
layout->addWidget(nSpin);
- layout->addSpacing(40);
+ layout->addSpacing(30);
connect(zSpin, SIGNAL(valueChanged(int)), SLOT(setZ(int)));
connect(nSpin, SIGNAL(valueChanged(int)), SLOT(setN(int)));
+ connect(nSpin, SIGNAL(returnPressed()), SIGNAL(returnPressed()));
+ connect(zSpin, SIGNAL(returnPressed()), SIGNAL(returnPressed()));
+ connect(zSpin, SIGNAL(moveFocus()), SLOT(moveFocus()));
+ connect(nSpin, SIGNAL(moveFocus()), SLOT(moveFocus()));
+ zSpin->selectAll();
}
SigEdit::~SigEdit()
@@ -68,6 +73,22 @@ SigEdit::~SigEdit()
//---------------------------------------------------------
+// moveFocus
+//---------------------------------------------------------
+
+void SigEdit::moveFocus()
+{
+ if (zSpin->hasFocus()) {
+ nSpin->setFocus();
+ nSpin->selectAll();
+ }
+ else {
+ zSpin->setFocus();
+ zSpin->selectAll();
+ }
+}
+
+//---------------------------------------------------------
// setZ
//---------------------------------------------------------
@@ -118,13 +139,18 @@ void SigEdit::updateValue()
nSpin->setValue(_sig.n);
}
- void SigEdit::paintEvent(QPaintEvent* event) {
+void SigEdit::paintEvent(QPaintEvent* event) {
if (!initialized)
updateValue();
initialized = true;
QPainter p(this);
- p.fillRect(event->rect(), Qt::white);
+ p.fillRect(event->rect(), p.background());
QWidget::paintEvent(event);
}
+void SigEdit::setFocus()
+{
+ zSpin->setFocus();
+}
+
}
diff --git a/muse2/awl/sigedit.h b/muse2/awl/sigedit.h
index acb0b9d8..5fe8186d 100644
--- a/muse2/awl/sigedit.h
+++ b/muse2/awl/sigedit.h
@@ -25,9 +25,9 @@
#include "al/sig.h"
//#include "sig.h"
+#include <awl/sigspinbox.h>
#include <QWidget>
-#include <QSpinBox>
#include <QHBoxLayout>
#include <QLabel>
@@ -48,8 +48,8 @@ class SigEdit : public QWidget
AL::TimeSignature _sig;
bool initialized;
QLabel *slash;
- QSpinBox *zSpin;
- QSpinBox *nSpin;
+ SigSpinBox *zSpin;
+ SigSpinBox *nSpin;
QHBoxLayout *layout;
virtual void paintEvent(QPaintEvent* event);
@@ -57,13 +57,16 @@ class SigEdit : public QWidget
signals:
void valueChanged(const AL::TimeSignature&);
+ void returnPressed();
private slots:
void setN(const int n);
void setZ(const int z);
+ void moveFocus();
public slots:
void setValue(const AL::TimeSignature&);
+ void setFocus();
public:
SigEdit(QWidget* parent = 0);
diff --git a/muse2/awl/sigspinbox.cpp b/muse2/awl/sigspinbox.cpp
new file mode 100644
index 00000000..3f1bf1f4
--- /dev/null
+++ b/muse2/awl/sigspinbox.cpp
@@ -0,0 +1,24 @@
+#include "sigspinbox.h"
+#include <QKeyEvent>
+#include <stdio.h>
+
+SigSpinBox::SigSpinBox(QWidget *parent) :
+ QSpinBox(parent)
+{
+}
+void SigSpinBox::keyPressEvent(QKeyEvent*ev)
+{
+ switch (ev->key()) {
+ case Qt::Key_Return:
+ emit returnPressed();
+ break;
+ case Qt::Key_Left:
+ case Qt::Key_Right:
+ case Qt::Key_Slash:
+ emit moveFocus();
+ break;
+ default:
+ break;
+ }
+ QSpinBox::keyPressEvent(ev);
+}
diff --git a/muse2/awl/sigspinbox.h b/muse2/awl/sigspinbox.h
new file mode 100644
index 00000000..ca893a24
--- /dev/null
+++ b/muse2/awl/sigspinbox.h
@@ -0,0 +1,23 @@
+#ifndef SIGSPINBOX_H
+#define SIGSPINBOX_H
+
+#include <QSpinBox>
+
+class SigSpinBox : public QSpinBox
+{
+ Q_OBJECT
+
+protected:
+ virtual void keyPressEvent(QKeyEvent*);
+public:
+ explicit SigSpinBox(QWidget *parent = 0);
+
+signals:
+ void returnPressed();
+ void moveFocus();
+
+public slots:
+
+};
+
+#endif // SIGSPINBOX_H