File indexing completed on 2024-04-28 08:21:12
0001 /* 0002 SPDX-FileCopyrightText: 2000-2008 Till Krech <till@snafu.de> 0003 SPDX-FileCopyrightText: 2009 Mathias Soeken <msoeken@tzi.de> 0004 SPDX-FileCopyrightText: 2017 Aurélien Gâteau <agateau@kde.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KLINEAL_H 0010 #define KLINEAL_H 0011 0012 #include <QWidget> 0013 0014 class QAction; 0015 class QIcon; 0016 class QMenu; 0017 0018 class KActionCollection; 0019 class KRulerSystemTray; 0020 0021 class KLineal : public QWidget 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 explicit KLineal(QWidget *parent = nullptr); 0027 ~KLineal() override; 0028 0029 void move(int x, int y); 0030 void move(const QPoint &p); 0031 QPoint pos() const; 0032 int x() const; 0033 int y() const; 0034 0035 protected: 0036 void keyPressEvent(QKeyEvent *e) override; 0037 void leaveEvent(QEvent *e) override; 0038 void mousePressEvent(QMouseEvent *e) override; 0039 void mouseMoveEvent(QMouseEvent *e) override; 0040 void wheelEvent(QWheelEvent *e) override; 0041 void paintEvent(QPaintEvent *e) override; 0042 0043 void createSystemTray(); 0044 0045 private: 0046 void createCrossCursor(); 0047 QAction *addAction(QMenu *menu, 0048 const QIcon &icon, 0049 const QString &text, 0050 const QObject *receiver, 0051 const char *member, 0052 const QKeySequence &shortcut, 0053 const QString &name); 0054 void drawScale(QPainter &painter); 0055 void drawBackground(QPainter &painter); 0056 void drawScaleText(QPainter &painter, int x, const QString &text); 0057 void drawScaleTick(QPainter &painter, int x, int length); 0058 void drawResizeHandle(QPainter &painter, Qt::Edge edge); 0059 void drawIndicatorOverlay(QPainter &painter, int xy); 0060 void drawIndicatorText(QPainter &painter, int xy); 0061 void updateScaleDirectionMenuItem(); 0062 0063 QRect beginRect() const; 0064 QRect endRect() const; 0065 Qt::CursorShape resizeCursor() const; 0066 QString indicatorText(int xy) const; 0067 0068 QCursor mCrossCursor; 0069 QPoint mCursorPos; // cached cursor pos used between painEvent <-> mouseMoveEvents 0070 QPoint mLastClickGlobalPos; 0071 bool mHorizontal = false; 0072 QMenu *mMenu = nullptr; 0073 QAction *mCloseAction = nullptr; 0074 QAction *mScaleDirectionAction = nullptr; 0075 QAction *mCenterOriginAction = nullptr; 0076 QAction *mOffsetAction = nullptr; 0077 QColor mColor; 0078 QFont mScaleFont; 0079 bool mAlwaysOnTopLayer = false; 0080 bool middleClicked = false; 0081 bool mLeftToRight = false; 0082 int mOffset = 0; 0083 bool mRelativeScale = false; 0084 KActionCollection *mActionCollection = nullptr; 0085 int mOpacity = 0; 0086 KRulerSystemTray *mTrayIcon = nullptr; 0087 0088 void setHorizontal(bool horizontal); 0089 0090 int length() const; 0091 qreal pixelRatio() const; 0092 0093 public Q_SLOTS: 0094 void rotate(); 0095 void showMenu(); 0096 void switchDirection(); 0097 void centerOrigin(); 0098 void slotOffset(); 0099 void slotOpacity(int value); 0100 void slotKeyBindings(); 0101 void slotPreferences(); 0102 void switchRelativeScale(bool checked); 0103 void saveSettings(); 0104 void slotClose(); 0105 void loadConfig(); 0106 }; 0107 #endif