forked from foldynl/QLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFreqQSpinBox.cpp
79 lines (68 loc) · 1.59 KB
/
FreqQSpinBox.cpp
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
78
79
#include "FreqQSpinBox.h"
#include <QKeyEvent>
#include "data/BandPlan.h"
FreqQSpinBox::FreqQSpinBox(QWidget *parent) :
QDoubleSpinBox(parent)
{
loadBands();
}
void FreqQSpinBox::loadBands()
{
enabledBands = BandPlan::bandsList(false, true);
}
void FreqQSpinBox::keyPressEvent(QKeyEvent *event)
{
if ( event->key() == Qt::Key_PageUp )
{
increaseByBand();
event->accept();
return;
}
else if ( event->key() == Qt::Key_PageDown )
{
decreaseByBand();
event->accept();
return;
}
QDoubleSpinBox::keyPressEvent(event);
}
void FreqQSpinBox::wheelEvent(QWheelEvent *event)
{
if ( event->modifiers() & Qt::ControlModifier )
{
if ( event->angleDelta().y() > 0 )
increaseByBand();
else
decreaseByBand();
event->accept();
return;
}
QDoubleSpinBox::wheelEvent(event);
}
void FreqQSpinBox::increaseByBand()
{
if ( enabledBands.size() == 0 )
return;
for ( const Band &band : static_cast<const QList<Band>&>(enabledBands) )
{
if ( band.start > value() )
{
setValue(band.start);
selectAll();
return;
}
}
}
void FreqQSpinBox::decreaseByBand()
{
if ( enabledBands.size() == 0 )
return;
double result = enabledBands.at(0).start;
for ( const Band &band : static_cast<const QList<Band>&>(enabledBands) )
{
if ( band.start < value() )
result = band.start;
}
setValue(result);
selectAll();
}