Loading...
Searching...
No Matches
GraphicsSliderBaseImpl.hpp
1#pragma once
2#include <score/graphics/DefaultGraphicsSliderImpl.hpp>
3#include <score/graphics/GraphicWidgets.hpp>
4#include <score/widgets/DoubleSpinBox.hpp>
5#include <score/widgets/SignalUtils.hpp>
6
7#include <QGraphicsProxyWidget>
8
9namespace score
10{
11template <typename T>
12QGraphicsSliderBase<T>::QGraphicsSliderBase(QGraphicsItem* parent)
13 : QGraphicsItem{parent}
14 , impl{new RightClickImpl}
15{
16 this->setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
17}
18
19template <typename T>
20QGraphicsSliderBase<T>::~QGraphicsSliderBase()
21{
22 if(this->impl->spinbox || this->impl->spinboxProxy)
23 delete this->impl->spinboxProxy;
24 delete impl;
25}
26
27template <typename T>
28QRectF QGraphicsSliderBase<T>::boundingRect() const
29{
30 return m_rect;
31}
32
33template <typename T>
34bool QGraphicsSliderBase<T>::isInHandle(QPointF p)
35{
36 return m_rect.contains(p);
37}
38
39template <typename T>
40double QGraphicsSliderBase<T>::getHandleX() const
41{
42 return sliderRect().width() * static_cast<const T&>(*this).m_value;
43}
44
45template <typename T>
46double QGraphicsSliderBase<T>::getExecHandleX() const
47{
48 return sliderRect().width() * static_cast<const T&>(*this).m_execValue;
49}
50
51template <typename T>
52QRectF QGraphicsSliderBase<T>::sliderRect() const
53{
54 return QRectF{0, 0, m_rect.width(), 8};
55}
56
57template <typename T>
58QRectF QGraphicsSliderBase<T>::handleRect() const
59{
60 auto r = sliderRect();
61 r.setWidth(std::max(0., static_cast<const T&>(*this).getHandleX()));
62 return r;
63}
64template <typename T>
65QRectF QGraphicsSliderBase<T>::execHandleRect() const
66{
67 return {0, 6, static_cast<const T&>(*this).getExecHandleX(), 2};
68}
69
70template <typename T>
71void QGraphicsSliderBase<T>::setRect(const QRectF& r)
72{
73 prepareGeometryChange();
74 m_rect = r;
75}
76
77}
Base toolkit upon which the software is built.
Definition Application.cpp:90