summaryrefslogtreecommitdiff
path: root/muse2/awl
diff options
context:
space:
mode:
Diffstat (limited to 'muse2/awl')
-rw-r--r--muse2/awl/posedit.cpp77
-rw-r--r--muse2/awl/posedit.h13
2 files changed, 50 insertions, 40 deletions
diff --git a/muse2/awl/posedit.cpp b/muse2/awl/posedit.cpp
index cc4062ef..7441a849 100644
--- a/muse2/awl/posedit.cpp
+++ b/muse2/awl/posedit.cpp
@@ -31,6 +31,7 @@
#include <QKeyEvent>
#include <QLineEdit>
#include <QStyle>
+#include <QString>
namespace MusEGlobal {
extern int mtcType;
@@ -48,6 +49,10 @@ namespace Awl {
PosEdit::PosEdit(QWidget* parent)
: QAbstractSpinBox(parent)
{
+ _returnMode = false;
+ cur_minute = cur_sec = cur_frame = cur_subframe = 0;
+ cur_bar = cur_beat = cur_tick = 0;
+
validator = new QIntValidator(this);
initialized = false;
@@ -58,20 +63,6 @@ PosEdit::PosEdit(QWidget* parent)
//connect(this, SIGNAL(returnPressed()), SLOT(enterPressed()));
}
-// What was this for? Tim.
-/*
-void* PosEdit::operator new(size_t n)
- {
- void* p = new char[n];
- memset(p, 0, n);
- return p;
- }
-*/
-
-PosEdit::~PosEdit()
- {
- }
-
QSize PosEdit::sizeHint() const
{
//QFontMetrics fm(font());
@@ -100,7 +91,11 @@ bool PosEdit::event(QEvent* event)
{
//printf("key press event Return\n");
//enterPressed();
- finishEdit();
+ bool changed = finishEdit();
+ if(changed || _returnMode) // Force valueChanged if return mode set, even if not modified.
+ {
+ emit valueChanged(_pos);
+ }
emit returnPressed();
emit editingFinished();
return true;
@@ -191,7 +186,8 @@ bool PosEdit::event(QEvent* event)
{
QFocusEvent* fe = static_cast<QFocusEvent*>(event);
QAbstractSpinBox::focusOutEvent(fe);
- finishEdit();
+ if(finishEdit())
+ emit valueChanged(_pos);
emit lostFocus();
emit editingFinished();
return true;
@@ -221,12 +217,29 @@ void PosEdit::setSmpte(bool f)
//---------------------------------------------------------
void PosEdit::setValue(const MusECore::Pos& time)
- {
+{
if(_pos == time)
- return;
- _pos = time;
- updateValue();
+ {
+ // Must check whether actual values dependent on tempo or sig changed...
+ if (_smpte) {
+ int minute, sec, frame, subframe;
+ time.msf(&minute, &sec, &frame, &subframe);
+ if(minute != cur_minute || sec != cur_sec || frame != cur_frame || subframe != cur_subframe)
+ updateValue();
+ }
+ else {
+ int bar, beat, tick;
+ time.mbt(&bar, &beat, &tick);
+ if(bar != cur_bar || beat != cur_beat || tick != cur_tick)
+ updateValue();
+ }
+ }
+ else
+ {
+ _pos = time;
+ updateValue();
}
+}
void PosEdit::setValue(const QString& s)
{
@@ -248,15 +261,12 @@ void PosEdit::updateValue()
{
char buffer[64];
if (_smpte) {
- int minute, sec, frame, subframe;
- _pos.msf(&minute, &sec, &frame, &subframe);
- sprintf(buffer, "%03d:%02d:%02d:%02d", minute, sec, frame, subframe);
+ _pos.msf(&cur_minute, &cur_sec, &cur_frame, &cur_subframe);
+ sprintf(buffer, "%03d:%02d:%02d:%02d", cur_minute, cur_sec, cur_frame, cur_subframe);
}
else {
- int bar, beat;
- int tick;
- _pos.mbt(&bar, &beat, &tick);
- sprintf(buffer, "%04d.%02d.%03d", bar+1, beat+1, tick);
+ _pos.mbt(&cur_bar, &cur_beat, &cur_tick);
+ sprintf(buffer, "%04d.%02d.%03d", cur_bar+1, cur_beat+1, cur_tick);
}
lineEdit()->setText(buffer);
}
@@ -653,9 +663,10 @@ void PosEdit::paintEvent(QPaintEvent* event)
//---------------------------------------------------------
// finishEdit
+// Return true if position changed.
//---------------------------------------------------------
-void PosEdit::finishEdit()
+bool PosEdit::finishEdit()
{
// If our validator did its job correctly, the entire line edit text should be valid now...
@@ -666,7 +677,7 @@ void PosEdit::finishEdit()
if(sl.size() != 4)
{
printf("finishEdit smpte string:%s sections:%d != 4\n", text().toLatin1().data(), sl.size());
- return;
+ return false;
}
MusECore::Pos newPos(sl[0].toInt(), sl[1].toInt(), sl[2].toInt(), sl[3].toInt());
@@ -681,7 +692,7 @@ void PosEdit::finishEdit()
if(sl.size() != 3)
{
printf("finishEdit bbt string:%s sections:%d != 3\n", text().toLatin1().data(), sl.size());
- return;
+ return false;
}
MusECore::Pos newPos(sl[0].toInt() - 1, sl[1].toInt() - 1, sl[2].toInt());
@@ -692,11 +703,7 @@ void PosEdit::finishEdit()
}
}
- if (changed)
- {
- //updateValue();
- emit valueChanged(_pos);
- }
+ return changed;
}
diff --git a/muse2/awl/posedit.h b/muse2/awl/posedit.h
index 65bc48de..b834be3c 100644
--- a/muse2/awl/posedit.h
+++ b/muse2/awl/posedit.h
@@ -44,7 +44,10 @@ class PosEdit : public QAbstractSpinBox
bool _smpte;
MusECore::Pos _pos;
bool initialized;
-
+ bool _returnMode;
+ int cur_minute, cur_sec, cur_frame, cur_subframe;
+ int cur_bar, cur_beat, cur_tick;
+
QIntValidator* validator;
virtual void paintEvent(QPaintEvent* event);
@@ -52,10 +55,9 @@ class PosEdit : public QAbstractSpinBox
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*);
- void finishEdit();
+ bool finishEdit();
signals:
void valueChanged(const MusECore::Pos&);
@@ -74,13 +76,14 @@ class PosEdit : public QAbstractSpinBox
public:
PosEdit(QWidget* parent = 0);
- ~PosEdit();
QSize sizeHint() const;
MusECore::Pos pos() const { return _pos; }
void setSmpte(bool);
bool smpte() const { return _smpte; }
- // void* operator new(size_t); // What was this for? Tim.
+ void setReturnMode(bool v) { _returnMode = v; }
+ bool returnMode() const { return _returnMode; }
+ void updateValue();
};
}