SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
tickedslider.cpp
Go to the documentation of this file.
1 // Copyright (C) 2017 Edouard Griffiths, F4EXB. //
3 // //
4 // Swagger server adapter interface //
5 // //
6 // This program is free software; you can redistribute it and/or modify //
7 // it under the terms of the GNU General Public License as published by //
8 // the Free Software Foundation as version 3 of the License, or //
9 // (at your option) any later version. //
10 // //
11 // This program is distributed in the hope that it will be useful, //
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
14 // GNU General Public License V3 for more details. //
15 // //
16 // You should have received a copy of the GNU General Public License //
17 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
19 
20 #include <QStylePainter>
21 #include <QStyleOptionSlider>
22 
23 #include <math.h>
24 
25 #include "tickedslider.h"
26 
27 TickedSlider::TickedSlider(QWidget* parent) :
28  QSlider(parent),
29  m_tickColor(Qt::white)
30 { }
31 
32 void TickedSlider::paintEvent(QPaintEvent *ev)
33 {
34  (void) ev;
35  QStylePainter p(this);
36  QStyleOptionSlider opt;
37  initStyleOption(&opt);
38 
39  QRect handle = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
40 
41  // draw tick marks
42  // do this manually because they are very badly behaved with style sheets
43  int interval = tickInterval();
44  if (interval == 0)
45  {
46  interval = pageStep();
47  }
48 
49  if (tickPosition() != NoTicks)
50  {
51  for (int i = minimum(); i <= maximum(); i += interval)
52  {
53  int x = roundf((double)((double)((double)(i - this->minimum()) / (double)(this->maximum() - this->minimum())) * (double)(this->width() - handle.width()) + (double)(handle.width() / 2.0))) - 1;
54  int h = 4;
55  p.setPen(m_tickColor);
56  if (tickPosition() == TicksBothSides || tickPosition() == TicksAbove)
57  {
58  int y = this->rect().top();
59  p.drawLine(x, y, x, y + h);
60  }
61  if (tickPosition() == TicksBothSides || tickPosition() == TicksBelow)
62  {
63  int y = this->rect().bottom();
64  p.drawLine(x, y, x, y - h);
65  }
66 
67  }
68  }
69 
70  // draw the slider (this is basically copy/pasted from QSlider::paintEvent)
71  opt.subControls = QStyle::SC_SliderGroove;
72  p.drawComplexControl(QStyle::CC_Slider, opt);
73 
74  // draw the slider handle
75  opt.subControls = QStyle::SC_SliderHandle;
76  p.drawComplexControl(QStyle::CC_Slider, opt);
77 }
78 
79 
80 
81 
QColor m_tickColor
Definition: tickedslider.h:38
int32_t i
Definition: decimators.h:244
virtual void paintEvent(QPaintEvent *ev)
TickedSlider(QWidget *parent=0)