2 #include <score/model/Skin.hpp>
3 #include <score/widgets/DoubleSpinBox.hpp>
4 #include <score/widgets/SignalUtils.hpp>
6 #include <ossia/detail/math.hpp>
8 #include <QGraphicsProxyWidget>
9 #include <QGraphicsScene>
10 #include <QGraphicsSceneMouseEvent>
16 #include <score_lib_base_export.h>
24 QPointer<DoubleSpinboxWithEnter> spinbox{};
25 QPointer<QGraphicsProxyWidget> spinboxProxy{};
32 T&
self,
const score::Skin& skin,
const QString& text, QPainter* painter,
35 painter->setRenderHint(QPainter::Antialiasing,
false);
37 painter->setPen(skin.NoPen);
38 painter->setBrush(skin.Emphasis2.main.brush);
41 const QRectF brect =
self.boundingRect();
42 const QRectF srect =
self.sliderRect();
43 painter->drawRoundedRect(srect, 1, 1);
46 #if defined(__linux__)
47 static const auto dpi_adjust = widget->devicePixelRatioF() > 1 ? 0 : -1;
49 static const constexpr
auto dpi_adjust = 0;
51 static const constexpr
auto dpi_adjust = -2;
53 painter->setPen(skin.Base4.lighter180.pen1);
54 painter->setFont(skin.Medium8Pt);
55 const auto textrect = brect.adjusted(2, srect.height() + 3 + dpi_adjust, -2, -1);
56 painter->drawText(textrect, text, QTextOption(Qt::AlignCenter));
59 painter->fillRect(
self.handleRect(), skin.Base4);
61 painter->fillRect(
self.execHandleRect(), skin.Base4.lighter180.brush);
72 static void mousePressEvent(T&
self, QGraphicsSceneMouseEvent* event)
74 if(event->button() == Qt::LeftButton &&
self.isInHandle(event->pos()))
78 const auto srect =
self.sliderRect();
79 const auto posX =
event->pos().x() - srect.x();
80 double curPos =
self.from01(ossia::clamp(posX, 0., srect.width()) / srect.width());
81 if(curPos !=
self.m_value)
83 self.m_value = curPos;
93 static void mouseMoveEvent(T&
self, QGraphicsSceneMouseEvent* event)
95 if((event->buttons() & Qt::LeftButton) &&
self.m_grab)
97 const auto srect =
self.sliderRect();
98 const auto posX =
event->pos().x() - srect.x();
99 double curPos =
self.from01(ossia::clamp(posX, 0., srect.width()) / srect.width());
100 if(curPos !=
self.m_value)
102 self.m_value = curPos;
110 template <
typename T>
111 static void mouseReleaseEvent(T&
self, QGraphicsSceneMouseEvent* event)
115 const auto srect =
self.sliderRect();
116 const auto posX =
event->pos().x() - srect.x();
117 double curPos =
self.from01(ossia::clamp(posX, 0., srect.width()) / srect.width());
118 if(curPos !=
self.m_value)
120 self.m_value = curPos;
126 self.sliderReleased();
128 if(event->button() == Qt::RightButton)
130 contextMenuEvent(
self, event->scenePos());
135 template <
typename T>
136 static void contextMenuEvent(T&
self, QPointF pos)
138 QTimer::singleShot(0, &
self, [&, self_p = &
self, pos] {
140 self.impl->spinbox = w;
141 w->setRange(
self.min,
self.max);
144 w->setValue(
self.map(
self.m_value));
145 auto obj =
self.scene()->addWidget(
146 w, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
148 self.impl->spinboxProxy = obj;
150 QTimer::singleShot(0, w, [w] { w->setFocus(); });
152 auto con = QObject::connect(
153 w, SignalUtils::QDoubleSpinBox_valueChanged_double(), &
self,
155 self.m_value =
self.unmap(v);
161 w, &DoubleSpinboxWithEnter::editingFinished, &
self, [obj, con, self_p] {
162 if(self_p->impl->spinbox)
164 self_p->sliderReleased();
165 QObject::disconnect(con);
166 QTimer::singleShot(0, self_p, [self_p, scene = self_p->scene(), obj] {
167 scene->removeItem(obj);
169 self_p->impl->spinbox = nullptr;
170 self_p->impl->spinboxProxy = nullptr;
172 self_p->impl->spinbox =
nullptr;
173 self_p->impl->spinboxProxy =
nullptr;
179 template <
typename T>
180 static void mouseDoubleClickEvent(T&
self, QGraphicsSceneMouseEvent* event)
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: DefaultGraphicsSliderImpl.hpp:29
Definition: DoubleSpinBox.hpp:17
Definition: DefaultGraphicsSliderImpl.hpp:23