127 QWidget *canvasWidget =
dynamic_cast<QWidget *
>(
d->m_viewManager->canvas());
132 p_visible &=
d->m_enabled;
134 const bool VISIBILITY_CHANGED =
d->m_visible != p_visible;
135 if (!VISIBILITY_CHANGED) {
139 if (
d->m_viewManager->selection() && p_visible) {
140 canvasWidget->installEventFilter(
this);
142 if (!
d->m_dragHandle) {
147 canvasWidget->removeEventFilter(
this);
149 for (QPushButton *
button :
d->m_buttons) {
153 d->m_pressed =
false;
154 d->m_dragHandle.reset();
157 d->m_visible = p_visible;
172 switch (event->type()) {
173 case QEvent::FocusIn:
177 case QEvent::MouseButtonPress: {
178 const QMouseEvent *mouseEvent =
static_cast<QMouseEvent *
>(event);
181 case QEvent::TabletPress: {
182 const QTabletEvent *tabletEvent =
static_cast<QTabletEvent *
>(event);
185 case QEvent::TouchBegin: {
186 const QTouchEvent *touchEvent =
static_cast<QTouchEvent *
>(event);
194 case QEvent::MouseMove:
196 const QMouseEvent *mouseEvent =
static_cast<QMouseEvent *
>(event);
200 case QEvent::TabletMove:
202 const QTabletEvent *tabletEvent =
static_cast<QTabletEvent *
>(event);
206 case QEvent::TouchUpdate:
208 const QTouchEvent *touchEvent =
static_cast<QTouchEvent *
>(event);
216 case QEvent::MouseButtonRelease:
217 case QEvent::TabletRelease:
218 case QEvent::TouchEnd:
219 case QEvent::TouchCancel:
221 if (
d->m_pressedIndex >= 0 &&
d->m_pressedIndex <
d->m_buttons.size()) {
223 QTimer::singleShot(0,
d->m_buttons[
d->m_pressedIndex], &QPushButton::click);
225 d->m_pressed =
false;
226 d->m_pressedIndex = -1;
240 QRect canvasBounds = canvasWidget->rect();
242 const int ACTION_BAR_WIDTH =
d->m_actionBarWidth;
246 int pos_x_max = canvasBounds.right() - ACTION_BAR_WIDTH -
BUFFER_SPACE;
249 int pos_y_max = canvasBounds.bottom() - ACTION_BAR_HEIGHT -
BUFFER_SPACE;
253 if (pos_x_max < pos_x_min) {
254 pos_x_max = pos_x_min;
258 if (pos_y_max < pos_y_min) {
259 pos_y_max = pos_y_min;
262 position.setX(qBound(pos_x_min, position.x(), pos_x_max));
263 position.setY(qBound(pos_y_min, position.y(), pos_y_max));
276 int selectionBottom = selectionBounds.bottom();
277 QPointF selectionCenter = selectionBounds.center();
278 QPointF bottomCenter(selectionCenter.x(), selectionBottom);
282 widgetBottomCenter.setX(widgetBottomCenter.x() - (
d->m_actionBarWidth / 2));
283 widgetBottomCenter.setY(widgetBottomCenter.y() +
BUFFER_SPACE);
299 const int CORNER_RADIUS = 4;
300 const int PEN_WIDTH = 5;
301 const QColor BACKGROUND_COLOR = Qt::darkGray;
302 const QColor OUTLINE_COLOR(60, 60, 60, 80);
303 const QColor DOT_COLOR = Qt::lightGray;
304 const int DOT_SIZE = 4;
305 const int DOT_SPACING = 5;
306 const QPoint DRAG_HANDLE_RECT_DOTS_OFFSET(10, 10);
308 QRectF actionBarRect(
d->m_dragHandle->position, QSize(
d->m_actionBarWidth,
BUTTON_SIZE));
310 bgPath.addRoundedRect(actionBarRect, CORNER_RADIUS, CORNER_RADIUS);
311 painter.fillPath(bgPath, BACKGROUND_COLOR);
313 QPen pen(OUTLINE_COLOR);
314 pen.setWidth(PEN_WIDTH);
316 painter.drawPath(bgPath);
318 QRectF dragHandleRect(
319 QPoint(
d->m_dragHandle->position.x() +
d->m_actionBarWidth -
BUTTON_SIZE,
d->m_dragHandle->position.y()),
321 QPainterPath dragHandlePath;
322 dragHandlePath.addRect(dragHandleRect);
323 painter.fillPath(dragHandlePath, BACKGROUND_COLOR);
325 const std::list<std::pair<int, int>> DOT_OFFSETS = {{0, 0},
330 {DOT_SPACING, DOT_SPACING},
331 {DOT_SPACING, -DOT_SPACING},
332 {-DOT_SPACING, DOT_SPACING},
333 {-DOT_SPACING, -DOT_SPACING}};
335 QPainterPath dragHandleRectDots;
336 for (
const std::pair<int, int> &offset : DOT_OFFSETS) {
337 dragHandleRectDots.addEllipse(offset.first, offset.second, DOT_SIZE, DOT_SIZE);
340 dragHandleRectDots.translate(dragHandleRect.topLeft() + DRAG_HANDLE_RECT_DOTS_OFFSET);
341 painter.fillPath(dragHandleRectDots, DOT_COLOR);
351 if (
button == Qt::LeftButton) {
353 if (targetRect.contains(pos)) {
356 d->m_pressedIndex = (pos.x() - targetRect.left()) /
BUTTON_SIZE;
357 if (
d->m_pressedIndex < 0 ||
d->m_pressedIndex >=
d->m_buttons.size()) {
358 d->m_dragHandle->dragOrigin = pos -
d->m_dragHandle->position;
414#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
415 if (touchEvent->pointCount() < 1) {
418 outPos = touchEvent->points().first().position().toPoint();
423 if (touchPoints.isEmpty()) {
426 outPos = touchPoints.first().pos().toPoint();