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 
9 namespace score
10 {
11 template <typename T>
12 QGraphicsSliderBase<T>::QGraphicsSliderBase(QGraphicsItem* parent)
13  : QGraphicsItem{parent}
14  , impl{new RightClickImpl}
15 {
16  this->setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
17 }
18 
19 template <typename T>
20 QGraphicsSliderBase<T>::~QGraphicsSliderBase()
21 {
22  if(this->impl->spinbox || this->impl->spinboxProxy)
23  delete this->impl->spinboxProxy;
24  delete impl;
25 }
26 
27 template <typename T>
28 QRectF QGraphicsSliderBase<T>::boundingRect() const
29 {
30  return m_rect;
31 }
32 
33 template <typename T>
34 bool QGraphicsSliderBase<T>::isInHandle(QPointF p)
35 {
36  return m_rect.contains(p);
37 }
38 
39 template <typename T>
40 double QGraphicsSliderBase<T>::getHandleX() const
41 {
42  return sliderRect().width() * static_cast<const T&>(*this).m_value;
43 }
44 
45 template <typename T>
46 double QGraphicsSliderBase<T>::getExecHandleX() const
47 {
48  return sliderRect().width() * static_cast<const T&>(*this).m_execValue;
49 }
50 
51 template <typename T>
52 QRectF QGraphicsSliderBase<T>::sliderRect() const
53 {
54  return QRectF{0, 0, m_rect.width(), 8};
55 }
56 
57 template <typename T>
58 QRectF 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 }
64 template <typename T>
65 QRectF QGraphicsSliderBase<T>::execHandleRect() const
66 {
67  return {0, 6, static_cast<const T&>(*this).getExecHandleX(), 2};
68 }
69 
70 template <typename T>
71 void 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