summaryrefslogtreecommitdiff
path: root/muse2/awl/sigspinbox.cpp
blob: a4e4b21ffc3459cbb925a5b3d1e066a674fd7368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "sigspinbox.h"
#include "al/sig.h"
#include <QKeyEvent>
#include <QMouseEvent>
#include <stdio.h>
#include <QLineEdit>

class MyLineEdit : public QLineEdit
{
  public:
    MyLineEdit() : QLineEdit() {};
    MyLineEdit(QWidget* parent) : QLineEdit(parent) {};
    
  protected:
    virtual void mousePressEvent (QMouseEvent* e)
    {
      QLineEdit::mousePressEvent(e);
      printf("!!!\n");
      selectAll();
    }
};


SigSpinBox::SigSpinBox(QWidget *parent) :
    QSpinBox(parent)
{
  _denominator=false;
  setLineEdit(new MyLineEdit(this));
}

void SigSpinBox::keyPressEvent(QKeyEvent* ev)
{
    switch (ev->key()) {
      case Qt::Key_Return:
        emit returnPressed();
        return;
        break;
      case Qt::Key_Left:
      case Qt::Key_Right:
      case Qt::Key_Slash:
        emit moveFocus();
        return;
        break;
      default:
        break;
    }
    QSpinBox::keyPressEvent(ev);
}

void SigSpinBox::setDenominator()
{
  _denominator=true;
}

void SigSpinBox::stepBy(int step)
{
  if (!_denominator) {
    setValue(value() + step);
    return;
  }

  AL::TimeSignature sig(4, value());
  if (step == 1) {
    // make sure that sig is valid then increase
    if (sig.isValid())
      setValue(value() * 2);
  }
  else if (step == -1) {
    // make sure that sig is valid then increase
    if (sig.isValid()) {
      int v = value() / 2;
      if (v < 2)
        v = 2;
      setValue(v);
    }
  }
}