Debian Codegraph @

src/gui/snippingArea/AbstractSnippingArea.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 Damir Porobic <https://github.com/damirporobic>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef KSNIP_ABSTRACTSNIPPINGAREA_H
21 #define KSNIP_ABSTRACTSNIPPINGAREA_H
22
23 #include <QWidget>
24 #include <QMouseEvent>
25 #include <QApplication>
26 #include <QTimer>
27
28 #include "SnippingAreaAdorner.h"
29 #include "SnippingAreaResizer.h"
30 #include "SnippingAreaSelector.h"
31 #include "SnippingAreaSelectorInfoText.h"
32 #include "SnippingAreaResizerInfoText.h"
33 #include "src/common/helper/MathHelper.h"
34 #include "src/backend/config/IConfig.h"
35
36 class AbstractSnippingArea : public QWidget
37 {
38 Q_OBJECT
39 public:
40 explicit AbstractSnippingArea(const QSharedPointer<IConfig> &config);
41 ~AbstractSnippingArea() override;
42 void showWithoutBackground();
43 void showWithBackground(const QPixmap& background);
44 virtual QRect selectedRectArea() const = 0;
45 virtual QPixmap background() const;
46 bool closeSnippingArea();
47
48 signals:
49 void finished();
50 void canceled();
51
52 protected:
53 QRegion mClippingRegion;
54
55 void mousePressEvent(QMouseEvent *event) override;
56 void mouseReleaseEvent(QMouseEvent *event) override;
57 void mouseMoveEvent(QMouseEvent *event) override;
58 void mouseDoubleClickEvent(QMouseEvent *event) override;
59 void keyPressEvent(QKeyEvent *event) override;
60 void keyReleaseEvent(QKeyEvent *event) override;
61 void paintEvent(QPaintEvent *event) override;
62 virtual bool isBackgroundTransparent() const;
63 virtual void setFullScreen() = 0;
64 virtual QSizeF getSize() const = 0;
65 virtual QPoint getGlobalCursorPosition() const;
66 virtual void grabKeyboardFocus();
67 virtual QPointF getPosition() const;
68 virtual QRectF getGeometry() const;
69 virtual void showSnippingArea();
70 QRect getCaptureArea() const;
71 QRect getGlobalCaptureArea() const;
72
73 private:
74 QRect mCaptureArea;
75 QSharedPointer<IConfig> mConfig;
76 QPixmap *mBackground;
77 SnippingAreaResizer *mResizer;
78 SnippingAreaSelector *mSelector;
79 SnippingAreaSelectorInfoText *mSelectorInfoText;
80 SnippingAreaResizerInfoText *mResizerInfoText;
81 bool mIsSwitchPressed;
82 QTimer *mTimer;
83 int mUnselectedRegionAlpha;
84 QPointF mPosition;
85
86 void setBackgroundImage(const QPixmap &background);
87 void clearBackgroundImage();
88 void finishSelection();
89
90 private slots:
91 void updateCapturedArea(const QRectF &rect);
92 void updateCursor(const QCursor &cursor);
93 void switchToResizer(const QPointF &pos);
94 void cancelSelection();
95 bool isResizerSwitchRequired() const;
96 void startTimeout();
97 void stopTimeout();
98 void updatePosition();
99 };
100
101 #endif // KSNIP_ABSTRACTSNIPPINGAREA_H