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 <QDesktopWidget> 26 #include <QApplication> 27 #include <QTimer> 28 29 #include "SnippingAreaAdorner.h" 30 #include "SnippingAreaResizer.h" 31 #include "SnippingAreaSelector.h" 32 #include "SnippingAreaSelectorInfoText.h" 33 #include "SnippingAreaResizerInfoText.h" 34 #include "src/common/helper/MathHelper.h" 35 #include "src/backend/config/KsnipConfigProvider.h" 36 37 class AbstractSnippingArea : public QWidget 38 { 39 Q_OBJECT 40 public: 41 explicit AbstractSnippingArea(); 42 ~AbstractSnippingArea() override; 43 void showWithoutBackground(); 44 void showWithBackground(const QPixmap& background); 45 virtual QRect selectedRectArea() const = 0; 46 virtual QPixmap background() const; 47 bool closeSnippingArea(); 48 49 signals: 50 void finished(); 51 void canceled(); 52 53 protected: 54 QRect mCaptureArea; 55 QRegion mClippingRegion; 56 57 void mousePressEvent(QMouseEvent *event) override; 58 void mouseReleaseEvent(QMouseEvent *event) override; 59 void mouseMoveEvent(QMouseEvent *event) override; 60 void keyPressEvent(QKeyEvent *event) override; 61 void keyReleaseEvent(QKeyEvent *event) override; 62 void paintEvent(QPaintEvent *event) override; 63 virtual bool isBackgroundTransparent() const; 64 virtual void setFullScreen() = 0; 65 virtual QRect getSnippingAreaGeometry() const = 0; 66 virtual QPoint getLocalCursorPosition() const; 67 virtual void grabKeyboardFocus(); 68 69 private: 70 KsnipConfig *mConfig; 71 QPixmap *mBackground; 72 SnippingAreaResizer *mResizer; 73 SnippingAreaSelector *mSelector; 74 SnippingAreaSelectorInfoText *mSelectorInfoText; 75 SnippingAreaResizerInfoText *mResizerInfoText; 76 bool mIsSwitchPressed; 77 QTimer *mTimer; 78 int mUnselectedRegionAlpha; 79 80 void setBackgroundImage(const QPixmap &background); 81 void clearBackgroundImage(); 82 virtual void showSnippingArea(); 83 void finishSelection(); 84 85 private slots: 86 void updateCapturedArea(const QRectF &rect); 87 void updateCursor(const QCursor &cursor); 88 void switchToResizer(QPoint point); 89 void cancelSelection(); 90 bool isResizerSwitchRequired() const; 91 void startTimeout(); 92 void stopTimeout(); 93 }; 94 95 #endif // KSNIP_ABSTRACTSNIPPINGAREA_H 96