-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMarkSlider.cpp
112 lines (101 loc) · 2.13 KB
/
MarkSlider.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* MarkSlider.cpp
*
* Created on: Feb 20, 2012
* Author: Selur
*/
#include "MarkSlider.h"
#include <QPaintEvent>
#include <QPainter>
MarkSlider::MarkSlider(QWidget *parent)
: QSlider(parent), m_start(0), m_end(0), m_sections()
{
}
MarkSlider::~MarkSlider()
{
}
void MarkSlider::paintEvent(QPaintEvent *event)
{
QSlider::paintEvent(event);
if (m_start == 0 && m_end == 0) {
return;
}
if (m_start != this->minimum() || m_end != this->maximum()) {
int left = (m_start * width()) / this->maximum();
int right = (m_end * width()) / this->maximum();
QPainter painter(this);
QColor color = Qt::darkBlue;
color.setAlpha(50);
painter.fillRect(left, 1, right - left, height() - 3, color);
painter.end();
}
if (m_sections.isEmpty()) {
return;
}
QStringList elements;
QPainter painter(this);
QColor color = Qt::darkGray;
color.setAlpha(50);
int left, right = (m_end * width()) / this->maximum();
foreach(QString section, m_sections)
{
elements = section.split("-");
left = (elements.at(0).toInt() * width()) / this->maximum();
right = (elements.at(1).toInt() * width()) / this->maximum();
painter.fillRect(left, 1, right - left, height() - 3, color);
}
painter.end();
}
void MarkSlider::multiMark(QStringList sections)
{
if (sections.isEmpty()) {
return;
}
m_sections = sections;
this->repaint();
}
void MarkSlider::resetMarks()
{
m_start = this->minimum();
m_end = this->maximum();
}
int MarkSlider::getEnd() const
{
return m_end;
}
int MarkSlider::getStart() const
{
return m_start;
}
void MarkSlider::setEnd(int end)
{
if (end > this->maximum() || end < this->minimum()) {
return;
}
if (end == m_start && end == m_end) {
return;
}
if (end < m_start) {
m_end = m_start;
m_start = end;
} else {
m_end = end;
}
this->repaint();
}
void MarkSlider::setStart(int start)
{
if (start > this->maximum() || start < this->minimum()) {
return;
}
if (start == m_start && start == m_end) {
return;
}
if (start > m_end) {
m_start = m_end;
m_end = start;
} else {
m_start = start;
}
this->repaint();
}