summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrcan Ogetbil <oget.fedora@gmail.com>2010-12-05 10:13:44 +0000
committerOrcan Ogetbil <oget.fedora@gmail.com>2010-12-05 10:13:44 +0000
commitbbe8aea131a3bb0bb307c743eb00ec0ef18e39d7 (patch)
tree27a6da091998344de85a418de46e3037b5d0f49e
parent4f889afb5e60ed1f803179efffc2fcdffc9e1a33 (diff)
ported sigedit and posedit
-rw-r--r--muse2/ChangeLog3
-rw-r--r--muse2/muse/arranger/trackinfo.cpp1
-rw-r--r--muse2/muse/master/lmaster.cpp2
-rw-r--r--muse2/muse/widgets/posedit.cpp57
-rw-r--r--muse2/muse/widgets/posedit.h18
-rw-r--r--muse2/muse/widgets/sigedit.cpp86
-rw-r--r--muse2/muse/widgets/sigedit.h16
-rw-r--r--muse2/muse/widgets/spinbox.cpp48
-rw-r--r--muse2/muse/widgets/spinbox.h16
9 files changed, 137 insertions, 110 deletions
diff --git a/muse2/ChangeLog b/muse2/ChangeLog
index a585f767..3d45cb37 100644
--- a/muse2/ChangeLog
+++ b/muse2/ChangeLog
@@ -1,5 +1,8 @@
05.12.2010
- Completed porting of dlist module (the drum list). Test OK. (Tim)
+ - Ported sigedit and posedit. Used SpinBox in place of Q3SpinWidget. TODO: Needs some work on
+ locating the arrows of the SpinBox accurately. Maybe we need to implement another SpinBox
+ from scratch? (Orcan)
04.12.2010
- Fix: Escape button does not exit track renaming editor. (Orcan)
- Fix: Midi ports config table items are editable when they are not supposed to. (Orcan)
diff --git a/muse2/muse/arranger/trackinfo.cpp b/muse2/muse/arranger/trackinfo.cpp
index d3ea73b5..09185e62 100644
--- a/muse2/muse/arranger/trackinfo.cpp
+++ b/muse2/muse/arranger/trackinfo.cpp
@@ -15,7 +15,6 @@
#include "song.h"
#include "globals.h"
-#include "spinbox.h"
#include "config.h"
#include "gconfig.h"
#include "arranger.h"
diff --git a/muse2/muse/master/lmaster.cpp b/muse2/muse/master/lmaster.cpp
index 18d2e718..03054fd6 100644
--- a/muse2/muse/master/lmaster.cpp
+++ b/muse2/muse/master/lmaster.cpp
@@ -126,6 +126,8 @@ LMaster::LMaster()
<< tr("Type")
<< tr("Value");
view->setHeaderLabels(columnnames);
+ view->setColumnWidth(2,80);
+ view->header()->setStretchLastSection(true);
//---------------------------------------------------
// Rest
diff --git a/muse2/muse/widgets/posedit.cpp b/muse2/muse/widgets/posedit.cpp
index 9fad1a6f..d491c235 100644
--- a/muse2/muse/widgets/posedit.cpp
+++ b/muse2/muse/widgets/posedit.cpp
@@ -25,6 +25,7 @@
#include "posedit.h"
#include "sig.h"
+#include "spinbox.h"
extern int mtcType;
@@ -51,13 +52,13 @@ class QNumberSection
// PosEditor
//---------------------------------------------------------
-class PosEditor : public QWidget
+class PosEditor : public QLineEdit
{
PosEdit* cw;
bool frm;
QPixmap *pm;
int focusSec;
- Q3ValueList<QNumberSection> sections;
+ QList<QNumberSection> sections;
QString sep;
int offset;
@@ -69,7 +70,7 @@ class PosEditor : public QWidget
void resizeEvent(QResizeEvent*);
void paintEvent(QPaintEvent*);
void mousePressEvent(QMouseEvent *e);
-
+ void keyPressEvent(QKeyEvent * event );
void applyFocusSelection() {}
public:
@@ -87,7 +88,6 @@ class PosEditor : public QWidget
void appendSection(const QNumberSection& sec);
void clearSections();
void setSectionSelection(int sec, int selstart, int selend);
- bool eventFilter(QObject *o, QEvent *e);
};
//---------------------------------------------------------
@@ -104,7 +104,7 @@ int PosEditor::section(const QPoint& pt)
int y = 0;
int w = width();
int h = height();
- for (unsigned int i = 0; i < sections.count(); ++i) {
+ for (int i = 0; i < sections.count(); ++i) {
QString s = cw->sectionFormattedText(i);
QRect bb = p.boundingRect(x, y, w, h, Qt::AlignVCenter|Qt::AlignLeft, s);
int nx = bb.x() + bb.width();
@@ -125,8 +125,9 @@ int PosEditor::section(const QPoint& pt)
//---------------------------------------------------------
PosEditor::PosEditor(PosEdit* parent, const char* name)
- : QWidget(parent, name), sep(".")
+ : QLineEdit(parent), sep(".")
{
+ setObjectName(name);
cw = parent;
frm = true;
focusSec = 0;
@@ -153,7 +154,6 @@ void PosEditor::init()
setBackgroundMode(Qt::PaletteBase);
setFocusSection(-1);
setKeyCompression(true);
- installEventFilter(this);
setFocusPolicy(Qt::WheelFocus);
}
@@ -210,7 +210,7 @@ void PosEditor::paintEvent(QPaintEvent *)
int h = height();
p.fillRect(0, 0, w, h, bg);
- for (unsigned int i = 0; i < sections.count(); ++i) {
+ for (int i = 0; i < sections.count(); ++i) {
QRect bb;
QString s = cw->sectionFormattedText(i);
@@ -249,60 +249,45 @@ void PosEditor::mousePressEvent(QMouseEvent *e)
}
//---------------------------------------------------------
-// eventFilter
+// keyPressEvent
//---------------------------------------------------------
-bool PosEditor::eventFilter(QObject *o, QEvent *e)
+void PosEditor::keyPressEvent(QKeyEvent *e)
{
- if (o != this)
- return false;
- if (e->type() != QEvent::KeyPress )
- return false;
-
- QKeyEvent *ke = (QKeyEvent*)e;
- switch (ke->key()) {
+ switch (e->key()) {
case Qt::Key_Right:
if (unsigned(focusSec) <= sections.count()) {
if (cw->setFocusSection(focusSec+1))
repaint(rect(), false);
}
- return true;
case Qt::Key_Left:
if (focusSec > 0 ) {
if (cw->setFocusSection(focusSec-1))
repaint(rect(), false);
}
- return true;
case Qt::Key_Up:
cw->stepUp();
- return true;
case Qt::Key_Down:
cw->stepDown();
- return true;
case Qt::Key_Backspace:
case Qt::Key_Delete:
cw->removeLastNumber(focusSec);
- return true;
case Qt::Key_Return:
cw->enterPressed();
- return true;
default:
- QString txt = ke->text();
+ QString txt = e->text();
if (!txt.isEmpty() && !sep.isEmpty() && txt[0] == sep[0]) {
// do the same thing as KEY_RIGHT when the user presses the separator key
if (unsigned(focusSec) < sections.count()) {
if (cw->setFocusSection(focusSec+1))
repaint(rect(), false);
}
- return true;
}
int num = txt[0].digitValue();
if (num != -1) {
cw->addNumber(focusSec, num);
- return true;
}
}
- return false;
}
void PosEditor::appendSection(const QNumberSection& sec)
@@ -347,8 +332,9 @@ bool PosEditor::setFocusSection(int idx)
//---------------------------------------------------------
PosEdit::PosEdit(QWidget* parent, const char* name)
- : QWidget(parent, name)
+ : QWidget(parent)
{
+ setObjectName(name);
init();
updateButtons();
}
@@ -372,8 +358,8 @@ PosEdit::~PosEdit()
void PosEdit::init()
{
ed = new PosEditor(this, "pos editor");
- controls = new Q3SpinWidget(this, "pos edit controls");
- controls->setEditWidget(ed);
+ controls = new SpinBox(this);
+ controls->setEditor(ed);
setFocusProxy(ed);
connect(controls, SIGNAL(stepUpPressed()), SLOT(stepUp()));
connect(controls, SIGNAL(stepDownPressed()), SLOT(stepDown()));
@@ -776,7 +762,7 @@ void PosEdit::addNumber(int secNo, int num)
QString txt = sectionText(secNo);
- if (txt.length() == sec[secNo].len) {
+ if ((unsigned) txt.length() == sec[secNo].len) {
if (!outOfRange(secNo, num - voff)) {
accepted = true;
sec[secNo].val = num - voff;
@@ -791,7 +777,7 @@ void PosEdit::addNumber(int secNo, int num)
accepted = true;
sec[secNo].val = temp;
}
- if (adv && (txt.length() == sec[secNo].len)) {
+ if (adv && ((unsigned) txt.length() == sec[secNo].len)) {
setFocusSection(ed->focusSection() + 1);
}
}
@@ -834,7 +820,7 @@ QSize PosEdit::sizeHint() const
QFontMetrics fm(font());
int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth,0, this); // ddskrjo 0
int h = fm.height() + fw * 2;
- int w = 4 + controls->upRect().width() + fw * 4;
+ int w = 4 + controls->arrowWidth() + fw * 4;
if (_smpte)
w += fm.width('9') * 10 + fm.width(ed->separator()) * 3;
else
@@ -852,9 +838,8 @@ void PosEdit::updateButtons()
bool downEnabled = isEnabled() && (pos() > minValue());
//printf("PosEdit::updateButtons smpte:%d upEnabled:%d downEnabled:%d\n", smpte(), upEnabled, downEnabled);
-
- controls->setUpEnabled(upEnabled);
- controls->setDownEnabled(downEnabled);
+
+ controls->setStepEnabled(upEnabled, downEnabled);
}
//---------------------------------------------------------
diff --git a/muse2/muse/widgets/posedit.h b/muse2/muse/widgets/posedit.h
index b00a3c31..e17da3a2 100644
--- a/muse2/muse/widgets/posedit.h
+++ b/muse2/muse/widgets/posedit.h
@@ -8,18 +8,16 @@
#ifndef __POSEDIT_H__
#define __POSEDIT_H__
-#include <qwidget.h>
-#include <qstring.h>
-//Added by qt3to4:
-#include <QResizeEvent>
-#include <QEvent>
-#include <QTimerEvent>
+#include <QWidget>
+
#include "pos.h"
+#include "section.h"
-class PosEditor;
-class Q3SpinWidget;
+class QResizeEvent;
+class QTimerEvent;
-#include "section.h"
+class PosEditor;
+class SpinBox;
//---------------------------------------------------------
// PosEdit
@@ -48,7 +46,7 @@ class PosEdit : public QWidget
Pos max;
bool changed;
PosEditor *ed;
- Q3SpinWidget* controls;
+ SpinBox* controls;
private slots:
void stepUp();
diff --git a/muse2/muse/widgets/sigedit.cpp b/muse2/muse/widgets/sigedit.cpp
index cbfa0cd1..9af1d7eb 100644
--- a/muse2/muse/widgets/sigedit.cpp
+++ b/muse2/muse/widgets/sigedit.cpp
@@ -5,26 +5,24 @@
// (C) Copyright 2001 Werner Schweer (ws@seh.de)
//=========================================================
-#include "sigedit.h"
-
#include <stdio.h>
-#include <q3rangecontrol.h>
-#include <QApplication>
+#include <values.h>
+
+#include <QEvent>
+#include <QKeyEvent>
+#include <QList>
+#include <QMouseEvent>
+#include <QPainter>
+#include <QPaintEvent>
#include <QPixmap>
-#include <q3valuelist.h>
+#include <QResizeEvent>
#include <QString>
#include <QStyle>
-//Added by qt3to4:
#include <QTimerEvent>
-#include <QPaintEvent>
-#include <QResizeEvent>
-#include <QMouseEvent>
-#include <QKeyEvent>
-#include <QEvent>
-#include <values.h>
-#include <QPainter>
-#include <QTimer>
+
#include "sig.h"
+#include "sigedit.h"
+#include "spinbox.h"
extern int mtcType;
@@ -74,13 +72,13 @@ class NumberSection
// SigEditor
//---------------------------------------------------------
-class SigEditor : public QWidget
+class SigEditor : public QLineEdit
{
SigEdit* cw;
bool frm;
QPixmap *pm;
int focusSec;
- Q3ValueList<NumberSection> sections;
+ QList<NumberSection> sections;
int offset;
int section(const QPoint&);
@@ -91,6 +89,7 @@ class SigEditor : public QWidget
void resizeEvent(QResizeEvent*);
void paintEvent(QPaintEvent*);
void mousePressEvent(QMouseEvent *e);
+ void keyPressEvent(QKeyEvent * event );
void applyFocusSelection() {}
public:
@@ -106,7 +105,6 @@ class SigEditor : public QWidget
void appendSection(const NumberSection& sec);
void clearSections();
void setSectionSelection(int sec, int selstart, int selend);
- bool eventFilter(QObject *o, QEvent *e);
};
//---------------------------------------------------------
@@ -123,7 +121,7 @@ int SigEditor::section(const QPoint& pt)
int y = 0;
int w = width();
int h = height();
- for (unsigned int i = 0; i < sections.count(); ++i) {
+ for (int i = 0; i < sections.count(); ++i) {
QString s = cw->sectionFormattedText(i);
QRect bb = p.boundingRect(x, y, w, h, Qt::AlignVCenter|Qt::AlignLeft, s);
int nx = bb.x() + bb.width();
@@ -144,8 +142,9 @@ int SigEditor::section(const QPoint& pt)
//---------------------------------------------------------
SigEditor::SigEditor(SigEdit* parent, const char* name)
- : QWidget(parent, name)
+ : QLineEdit(parent)
{
+ setObjectName(name);
cw = parent;
frm = true;
focusSec = 0;
@@ -172,7 +171,6 @@ void SigEditor::init()
setBackgroundMode(Qt::PaletteBase);
setFocusSection(-1);
setKeyCompression(true);
- installEventFilter(this);
setFocusPolicy(Qt::WheelFocus);
}
@@ -199,13 +197,13 @@ bool SigEditor::event(QEvent *e)
break;
}
}
- return QWidget::event(e);
+ return QLineEdit::event(e);
}
void SigEditor::resizeEvent(QResizeEvent *e)
{
pm->resize(e->size());
- QWidget::resizeEvent(e);
+ QLineEdit::resizeEvent(e);
}
//---------------------------------------------------------
@@ -229,7 +227,7 @@ void SigEditor::paintEvent(QPaintEvent *)
int h = height();
p.fillRect(0, 0, w, h, bg);
- for (unsigned int i = 0; i < sections.count(); ++i) {
+ for (int i = 0; i < sections.count(); ++i) {
QRect bb;
QString s = cw->sectionFormattedText(i);
@@ -268,64 +266,49 @@ void SigEditor::mousePressEvent(QMouseEvent *e)
}
//---------------------------------------------------------
-// eventFilter
+// keyPressEvent
//---------------------------------------------------------
-bool SigEditor::eventFilter(QObject *o, QEvent *e)
+void SigEditor::keyPressEvent(QKeyEvent * e )
{
- if (o != this)
- return false;
- if (e->type() != QEvent::KeyPress )
- return false;
-
- QKeyEvent *ke = (QKeyEvent*)e;
- switch (ke->key()) {
+ switch (e->key()) {
case Qt::Key_Right:
if (unsigned(focusSec) <= sections.count()) {
if (cw->setFocusSection(focusSec+1))
repaint(rect(), false);
}
- return true;
case Qt::Key_Left:
if (focusSec > 0 ) {
if (cw->setFocusSection(focusSec-1))
repaint(rect(), false);
}
- return true;
case Qt::Key_Up:
cw->stepUp();
- return true;
case Qt::Key_Down:
cw->stepDown();
- return true;
case Qt::Key_Backspace:
case Qt::Key_Delete:
cw->removeLastNumber(focusSec);
- return true;
case Qt::Key_Enter:
case Qt::Key_Return:
cw->enterPressed();
- return true;
default:
- QString txt = ke->text();
+ QString txt = e->text();
if (!txt.isEmpty() && txt[0] == '/') {
// do the same thing as KEY_RIGHT when the user presses the separator key
if (focusSec < (signed)(sections.count())) {
if (cw->setFocusSection(focusSec+1))
repaint(rect(), false);
}
- return true;
}
int num = txt[0].digitValue();
- //printf("SigEditor::eventFilter num:%d\n", num);
+ //printf("SigEditor::keyPressEvent num:%d\n", num);
if (num != -1) {
cw->addNumber(focusSec, num);
- return true;
}
}
- return false;
}
void SigEditor::appendSection(const NumberSection& sec)
@@ -370,8 +353,9 @@ bool SigEditor::setFocusSection(int idx)
//---------------------------------------------------------
SigEdit::SigEdit(QWidget* parent, const char* name)
- : QWidget(parent, name)
+ : QWidget(parent)
{
+ setObjectName(name);
init();
updateButtons();
}
@@ -387,8 +371,8 @@ SigEdit::~SigEdit()
void SigEdit::init()
{
ed = new SigEditor(this, "pos editor");
- controls = new Q3SpinWidget(this, "pos edit controls");
- controls->setEditWidget(ed);
+ controls = new SpinBox(this);
+ controls->setEditor(ed);
setFocusProxy(ed);
connect(controls, SIGNAL(stepUpPressed()), SLOT(stepUp()));
connect(controls, SIGNAL(stepDownPressed()), SLOT(stepDown()));
@@ -641,7 +625,7 @@ void SigEdit::addNumber(int secNo, int num)
//printf("SigEdit::addNumber secNo:%d num:%d voff:%d txt:%s\n", secNo, num, voff, txt.latin1());
- if (txt.length() == sec[secNo].len) {
+ if ((unsigned) txt.length() == sec[secNo].len) {
//printf("SigEdit::addNumber txt.length() == sec[secNo].len (%d)\n", sec[secNo].len);
if (!outOfRange(secNo, num - voff)) {
@@ -668,7 +652,7 @@ void SigEdit::addNumber(int secNo, int num)
accepted = true;
sec[secNo].val = temp;
}
- if (adv && (txt.length() == sec[secNo].len)) {
+ if (adv && ((unsigned) txt.length() == sec[secNo].len)) {
setFocusSection(ed->focusSection() + 1);
}
}
@@ -711,7 +695,8 @@ QSize SigEdit::sizeHint() const
QFontMetrics fm(font());
int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this); // ddskrjo
int h = fm.height() + fw * 2;
- int w = 2 + controls->upRect().width() + fw * 4;
+
+ int w = 2 + controls->arrowWidth() + fw * 4;
w += fm.width('9') * 5 + fm.width('/');
return QSize(w, h).expandedTo(QApplication::globalStrut());
}
@@ -740,8 +725,7 @@ void SigEdit::updateButtons()
case 128: upEnabled = false; break;
}
}
- controls->setUpEnabled(isEnabled() && upEnabled);
- controls->setDownEnabled(isEnabled() && downEnabled);
+ controls->setStepEnabled(isEnabled() & upEnabled, isEnabled() & downEnabled);
}
//---------------------------------------------------------
diff --git a/muse2/muse/widgets/sigedit.h b/muse2/muse/widgets/sigedit.h
index 89cc96bc..07ae0741 100644
--- a/muse2/muse/widgets/sigedit.h
+++ b/muse2/muse/widgets/sigedit.h
@@ -9,14 +9,14 @@
#define __SIGEDIT_H__
#include <QWidget>
-#include <QString>
-//Added by qt3to4:
-#include <QResizeEvent>
-#include <QTimerEvent>
-#include <QEvent>
+
+#include "section.h"
+
+class QResizeEvent;
+class QTimerEvent;
class SigEditor;
-class Q3SpinWidget;
+class SpinBox;
struct Sig {
int z;
@@ -26,8 +26,6 @@ struct Sig {
bool isValid() const;
};
-#include "section.h"
-
//---------------------------------------------------------
// SigEdit
//---------------------------------------------------------
@@ -46,7 +44,7 @@ class SigEdit : public QWidget
bool typing;
bool changed;
SigEditor *ed;
- Q3SpinWidget* controls;
+ SpinBox* controls;
private slots:
void stepUp();
diff --git a/muse2/muse/widgets/spinbox.cpp b/muse2/muse/widgets/spinbox.cpp
index ee585da7..aa536809 100644
--- a/muse2/muse/widgets/spinbox.cpp
+++ b/muse2/muse/widgets/spinbox.cpp
@@ -5,8 +5,10 @@
// (C) Copyright 2001 Werner Schweer (ws@seh.de)
//=========================================================
-#include <QKeyEvent>
#include <QEvent>
+#include <QKeyEvent>
+#include <QMouseEvent>
+
#include "spinbox.h"
//---------------------------------------------------------
@@ -25,8 +27,52 @@ SpinBox::SpinBox(int minValue, int maxValue, int step, QWidget* parent)
setRange(minValue, maxValue);
setSingleStep(step);
_clearFocus = true;
+ upEnabled = StepUpEnabled;
+ downEnabled = StepDownEnabled;
+}
+
+QAbstractSpinBox::StepEnabled SpinBox::stepEnabled() const
+{
+ return upEnabled | downEnabled;
}
+void SpinBox::setStepEnabled(bool up, bool down)
+{
+ upEnabled = up ? StepUpEnabled : StepNone;
+ downEnabled = down ? StepDownEnabled : StepNone;
+}
+
+int SpinBox::arrowWidth() const
+{
+ QStyleOptionSpinBox styleOpt;
+ styleOpt.initFrom(this);
+ QRect upArrowRect = QApplication::style()->subControlRect(QStyle::CC_SpinBox, &styleOpt, QStyle::SC_SpinBoxUp, this);
+ return upArrowRect.width();
+}
+
+void SpinBox::setEditor(QLineEdit* ed)
+{
+ setLineEdit(ed);
+}
+
+void SpinBox::mousePressEvent ( QMouseEvent * event )
+{
+ // FIXME: I couldn't find a way to access the arrow buttons directly. Hence I am using a QRect::contains method.
+ // Unfortunately this is not 100% accurate with the Oxygen style; one needs to push to the right hand side of the
+ // buttons. But it works perfect with the QtCurve style - Orcan
+ QStyleOptionSpinBox styleOpt;
+ styleOpt.initFrom(this);
+ QRect upArrowRect = QApplication::style()->subControlRect(QStyle::CC_SpinBox, &styleOpt, QStyle::SC_SpinBoxUp, this);
+ QRect downArrowRect = QApplication::style()->subControlRect(QStyle::CC_SpinBox, &styleOpt, QStyle::SC_SpinBoxDown, this);
+
+ if (upArrowRect.contains(event->pos()))
+ emit(stepUpPressed());
+ else if (downArrowRect.contains(event->pos()))
+ emit(stepDownPressed());
+ QSpinBox::mousePressEvent(event);
+}
+
+
bool SpinBox::eventFilter(QObject* o, QEvent* ev)
{
// if (o != (QObject*)editor()) ddskrjo can't find editor()
diff --git a/muse2/muse/widgets/spinbox.h b/muse2/muse/widgets/spinbox.h
index 43ff85be..c40b97cf 100644
--- a/muse2/muse/widgets/spinbox.h
+++ b/muse2/muse/widgets/spinbox.h
@@ -13,7 +13,10 @@
#define __SPINBOX_H__
#include <QSpinBox>
-#include <QEvent>
+
+class QEvent;
+class QLineEdit;
+class QMouseEvent;
//---------------------------------------------------------
// SpinBox
@@ -23,20 +26,29 @@ class SpinBox : public QSpinBox {
Q_OBJECT
bool _clearFocus;
+ StepEnabled upEnabled;
+ StepEnabled downEnabled;
protected:
bool eventFilter(QObject* obj, QEvent* ev);
-
+ virtual void mousePressEvent ( QMouseEvent * event );
+ virtual StepEnabled stepEnabled() const;
+
public slots:
virtual void stepUp();
virtual void stepDown();
signals:
void doubleClicked();
+ void stepDownPressed();
+ void stepUpPressed();
public:
SpinBox(QWidget* parent=0);
SpinBox(int minValue, int maxValue, int step = 1, QWidget* parent=0);
+ void setStepEnabled(bool up, bool down);
+ int arrowWidth() const;
+ void setEditor(QLineEdit* ed);
};
#endif