2017-11-21 00:09:47 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 Edouard Griffiths, F4EXB. //
|
|
|
|
// //
|
|
|
|
// Swagger server adapter interface //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 12:43:33 +00:00
|
|
|
// (at your option) any later version. //
|
2017-11-21 00:09:47 +00:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QStylePainter>
|
|
|
|
#include <QStyleOptionSlider>
|
|
|
|
|
2017-11-21 23:40:11 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2017-11-21 00:09:47 +00:00
|
|
|
#include "tickedslider.h"
|
|
|
|
|
|
|
|
TickedSlider::TickedSlider(QWidget* parent) :
|
|
|
|
QSlider(parent),
|
|
|
|
m_tickColor(Qt::white)
|
|
|
|
{ }
|
|
|
|
|
2018-11-12 17:36:27 +00:00
|
|
|
void TickedSlider::paintEvent(QPaintEvent *ev)
|
2017-11-21 00:09:47 +00:00
|
|
|
{
|
2018-11-12 17:36:27 +00:00
|
|
|
(void) ev;
|
2017-11-21 00:09:47 +00:00
|
|
|
QStylePainter p(this);
|
|
|
|
QStyleOptionSlider opt;
|
|
|
|
initStyleOption(&opt);
|
|
|
|
|
|
|
|
QRect handle = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
|
|
|
|
|
|
|
|
// draw tick marks
|
|
|
|
// do this manually because they are very badly behaved with style sheets
|
|
|
|
int interval = tickInterval();
|
|
|
|
if (interval == 0)
|
|
|
|
{
|
|
|
|
interval = pageStep();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tickPosition() != NoTicks)
|
|
|
|
{
|
|
|
|
for (int i = minimum(); i <= maximum(); i += interval)
|
|
|
|
{
|
2017-11-21 23:32:58 +00:00
|
|
|
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;
|
2017-11-21 00:09:47 +00:00
|
|
|
int h = 4;
|
|
|
|
p.setPen(m_tickColor);
|
|
|
|
if (tickPosition() == TicksBothSides || tickPosition() == TicksAbove)
|
|
|
|
{
|
|
|
|
int y = this->rect().top();
|
|
|
|
p.drawLine(x, y, x, y + h);
|
|
|
|
}
|
|
|
|
if (tickPosition() == TicksBothSides || tickPosition() == TicksBelow)
|
|
|
|
{
|
|
|
|
int y = this->rect().bottom();
|
|
|
|
p.drawLine(x, y, x, y - h);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw the slider (this is basically copy/pasted from QSlider::paintEvent)
|
|
|
|
opt.subControls = QStyle::SC_SliderGroove;
|
|
|
|
p.drawComplexControl(QStyle::CC_Slider, opt);
|
|
|
|
|
|
|
|
// draw the slider handle
|
|
|
|
opt.subControls = QStyle::SC_SliderHandle;
|
|
|
|
p.drawComplexControl(QStyle::CC_Slider, opt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|