File indexing completed on 2024-12-29 05:06:05
0001 // SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include <QMouseEvent> 0007 #include <QQuickItem> 0008 #include <QTimer> 0009 0010 class WidgetContainer : public QQuickItem 0011 { 0012 Q_OBJECT 0013 Q_PROPERTY(bool editMode READ editMode WRITE setEditMode NOTIFY editModeChanged) 0014 0015 QML_NAMED_ELEMENT(WidgetContainer) 0016 0017 public: 0018 WidgetContainer(QQuickItem *parent = nullptr); 0019 0020 bool editMode() const; 0021 void setEditMode(bool editMode); 0022 0023 Q_SIGNALS: 0024 void editModeChanged(); 0025 void pressReleased(); 0026 void startEditMode(QPointF pressPoint); 0027 0028 protected: 0029 bool childMouseEventFilter(QQuickItem *item, QEvent *event) override; 0030 void mousePressEvent(QMouseEvent *event) override; 0031 void mouseMoveEvent(QMouseEvent *event) override; 0032 void mouseReleaseEvent(QMouseEvent *event) override; 0033 void mouseUngrabEvent() override; 0034 0035 private Q_SLOTS: 0036 void startPressAndHold(); 0037 void onActiveFocusChanged(bool activeFocus); 0038 0039 private: 0040 bool m_pressed{false}; 0041 bool m_editMode{false}; 0042 QTimer *m_pressAndHoldTimer{nullptr}; 0043 QPointF m_mouseDownPosition{}; 0044 }; 0045 0046 QML_DECLARE_TYPE(WidgetContainer)