summaryrefslogtreecommitdiff
path: root/muse2/awl/sigspinbox.cpp
blob: 6e38b164e43fd0eae17d32dc2b7bb662a906b506 (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
#include "sigspinbox.h"
#include "al/sig.h"
#include <QKeyEvent>
#include <stdio.h>

SigSpinBox::SigSpinBox(QWidget *parent) :
    QSpinBox(parent)
{
  _denominator=false;
}
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);
    }
  }
}