| 1 | /* |
| 2 | * Copyright (C) 2019 Damir Porobic <[email protected]> |
| 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 | #include "SnippingAreaAdorner.h" |
| 21 | |
| 22 | SnippingAreaAdorner::SnippingAreaAdorner() : |
| 23 | mMouseIsDown(false), |
| 24 | mRulerEnabled(false), |
| 25 | mPositionAndSizeInfoEnabled(false), |
| 26 | mMagnifyingGlassEnabled(false) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | void SnippingAreaAdorner::setRulersEnabled(bool enabled) |
| 31 | { |
| 32 | mRulerEnabled = enabled; |
| 33 | } |
| 34 | |
| 35 | void SnippingAreaAdorner::setPositionAndSizeInfoEnabled(bool enabled) |
| 36 | { |
| 37 | mPositionAndSizeInfoEnabled = enabled; |
| 38 | } |
| 39 | |
| 40 | void SnippingAreaAdorner::setMagnifyingGlassEnabled(bool enabled) |
| 41 | { |
| 42 | mMagnifyingGlassEnabled = enabled; |
| 43 | } |
| 44 | |
| 45 | void SnippingAreaAdorner::setIsMouseDown(bool isDown) |
| 46 | { |
| 47 | mMouseIsDown = isDown; |
| 48 | } |
| 49 | |
| 50 | void SnippingAreaAdorner::setBackgroundImage(const QPixmap *background) |
| 51 | { |
| 52 | mMagnifyingGlass.setBackgroundImage(background); |
| 53 | } |
| 54 | |
| 55 | void SnippingAreaAdorner::update(const QPoint &mousePosition, const QRect &screenRect, const QRect &captureRect) |
| 56 | { |
| 57 | if (mRulerEnabled && !mMouseIsDown) { |
| 58 | mRulers.update(mousePosition, screenRect); |
| 59 | } |
| 60 | |
| 61 | if (mPositionAndSizeInfoEnabled) { |
| 62 | if (mMouseIsDown) { |
| 63 | mSizeInfo.update(captureRect); |
| 64 | } else { |
| 65 | mPositionInfo.update(mousePosition, screenRect); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if (mMagnifyingGlassEnabled) { |
| 70 | mMagnifyingGlass.update(mousePosition, screenRect); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | void SnippingAreaAdorner::paint(QPainter *painter, const QColor &adornerColor, const QColor &cursorColor) |
| 75 | { |
| 76 | if (mRulerEnabled && !mMouseIsDown) { |
| 77 | mRulers.paint(painter, adornerColor); |
| 78 | } |
| 79 | |
| 80 | if (mPositionAndSizeInfoEnabled) { |
| 81 | if (mMouseIsDown) { |
| 82 | mSizeInfo.paint(painter, adornerColor); |
| 83 | } else { |
| 84 | mPositionInfo.paint(painter, adornerColor); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (mMagnifyingGlassEnabled) { |
| 89 | mMagnifyingGlass.paint(painter, cursorColor); |
| 90 | } |
| 91 | } |