-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatternSizeEditWidget.cpp
64 lines (57 loc) · 1.66 KB
/
PatternSizeEditWidget.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
#include "PatternSizeEditWidget.h"
PatternSizeEditWidget::PatternSizeEditWidget(QWidget* a_parent)
: QSpinBox(a_parent)
{
setSingleStep(Properties::Core::FramesPerSecond);
setMinimum( Properties::Pattern::MinSize );
setMaximum( Properties::Pattern::MaxSize );
reset();
}
void PatternSizeEditWidget::reset()
{
setValue( Properties::Pattern::DefaultSize );
}
QString PatternSizeEditWidget::textFromValue(int a_value) const
{
int seconds = a_value/Properties::Core::FramesPerSecond;
int frames = a_value-seconds*Properties::Core::FramesPerSecond;
int minutes = seconds/Properties::Core::SecondsInMinute;
seconds -= minutes*Properties::Core::SecondsInMinute;
return QString("%1:%2:%3")
.arg(minutes, 2, 10, QChar{'0'})
.arg(seconds, 2, 10, QChar{'0'})
.arg(frames , 2, 10, QChar{'0'});
}
int PatternSizeEditWidget::valueFromText(const QString& a_text) const
{
int value = 0;
QStringList parts = a_text.split(':');
if (parts.size() == 3)
{
value += parts[0].toInt()*Properties::Core::FramesPerSecond*Properties::Core::SecondsInMinute;
value += parts[1].toInt()*Properties::Core::FramesPerSecond;
value += parts[2].toInt();
}
return value;
}
QValidator::State PatternSizeEditWidget::validate(QString& a_text, int& a_pos) const
{
Q_UNUSED(a_pos);
QStringList parts = a_text.split(':');
if (parts.size() == 3)
return QValidator::Acceptable;
return QValidator::Invalid;
}
void PatternSizeEditWidget::wheelEvent(QWheelEvent* a_event)
{
if (a_event->modifiers() == Qt::ShiftModifier)
{
if (a_event->angleDelta().y() > 0)
setValue(value() + 1);
else
if (a_event->angleDelta().y() < 0)
setValue(value() - 1);
}
else
QSpinBox::wheelEvent(a_event);
}