qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
screengrabberchooserrectitem.h
Go to the documentation of this file.
1 /*
2  Copyright © 2015-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <QGraphicsItemGroup>
23 
24 class ScreenGrabberChooserRectItem final : public QObject, public QGraphicsItemGroup
25 {
26  Q_OBJECT
27 public:
28  explicit ScreenGrabberChooserRectItem(QGraphicsScene* scene);
30 
31  QRectF boundingRect() const final;
32  void beginResize(QPointF mousePos);
33 
34  QRect chosenRect() const;
35 
36  void showHandles();
37  void hideHandles();
38 
39 signals:
40 
41  void doubleClicked();
42  void regionChosen(QRect rect);
43 
44 protected:
45  bool sceneEventFilter(QGraphicsItem* watched, QEvent* event) final;
46 
47 private:
48  enum State
49  {
54  };
55 
57  int rectWidth = 0;
58  int rectHeight = 0;
59  QPointF startPos;
60 
61  void forwardMainRectEvent(QEvent* event);
62  void forwardHandleEvent(QGraphicsItem* watched, QEvent* event);
63 
64  void mousePress(QGraphicsSceneMouseEvent* event);
65  void mouseMove(QGraphicsSceneMouseEvent* event);
66  void mouseRelease(QGraphicsSceneMouseEvent* event);
67  void mouseDoubleClick(QGraphicsSceneMouseEvent* event);
68 
69  void mousePressHandle(int x, int y, QGraphicsSceneMouseEvent* event);
70  void mouseMoveHandle(int x, int y, QGraphicsSceneMouseEvent* event);
71  void mouseReleaseHandle(int x, int y, QGraphicsSceneMouseEvent* event);
72 
73  QPoint getHandleMultiplier(QGraphicsItem* handle);
74 
75  void updateHandlePositions();
76  QGraphicsRectItem* createHandleItem(QGraphicsScene* scene);
77 
78  QGraphicsRectItem* mainRect;
79  QGraphicsRectItem* topLeft;
80  QGraphicsRectItem* topCenter;
81  QGraphicsRectItem* topRight;
82  QGraphicsRectItem* rightCenter;
83  QGraphicsRectItem* bottomRight;
84  QGraphicsRectItem* bottomCenter;
85  QGraphicsRectItem* bottomLeft;
86  QGraphicsRectItem* leftCenter;
87 };
ScreenGrabberChooserRectItem::rightCenter
QGraphicsRectItem * rightCenter
Definition: screengrabberchooserrectitem.h:82
ScreenGrabberChooserRectItem::bottomCenter
QGraphicsRectItem * bottomCenter
Definition: screengrabberchooserrectitem.h:84
ScreenGrabberChooserRectItem::topRight
QGraphicsRectItem * topRight
Definition: screengrabberchooserrectitem.h:81
ScreenGrabberChooserRectItem::None
@ None
Definition: screengrabberchooserrectitem.h:50
ScreenGrabberChooserRectItem::topLeft
QGraphicsRectItem * topLeft
Definition: screengrabberchooserrectitem.h:79
ScreenGrabberChooserRectItem::mouseMoveHandle
void mouseMoveHandle(int x, int y, QGraphicsSceneMouseEvent *event)
Definition: screengrabberchooserrectitem.cpp:193
ScreenGrabberChooserRectItem::Moving
@ Moving
Definition: screengrabberchooserrectitem.h:53
ScreenGrabberChooserRectItem::mousePressHandle
void mousePressHandle(int x, int y, QGraphicsSceneMouseEvent *event)
Definition: screengrabberchooserrectitem.cpp:184
ScreenGrabberChooserRectItem::hideHandles
void hideHandles()
Definition: screengrabberchooserrectitem.cpp:111
ScreenGrabberChooserRectItem::ScreenGrabberChooserRectItem
ScreenGrabberChooserRectItem(QGraphicsScene *scene)
Definition: screengrabberchooserrectitem.cpp:33
ScreenGrabberChooserRectItem::chosenRect
QRect chosenRect() const
Definition: screengrabberchooserrectitem.cpp:83
ScreenGrabberChooserRectItem::sceneEventFilter
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) final
Definition: screengrabberchooserrectitem.cpp:287
ScreenGrabberChooserRectItem::rectHeight
int rectHeight
Definition: screengrabberchooserrectitem.h:58
ScreenGrabberChooserRectItem::mouseReleaseHandle
void mouseReleaseHandle(int x, int y, QGraphicsSceneMouseEvent *event)
Definition: screengrabberchooserrectitem.cpp:224
ScreenGrabberChooserRectItem::bottomRight
QGraphicsRectItem * bottomRight
Definition: screengrabberchooserrectitem.h:83
ScreenGrabberChooserRectItem::boundingRect
QRectF boundingRect() const final
Definition: screengrabberchooserrectitem.cpp:65
ScreenGrabberChooserRectItem::doubleClicked
void doubleClicked()
ScreenGrabberChooserRectItem::forwardMainRectEvent
void forwardMainRectEvent(QEvent *event)
Definition: screengrabberchooserrectitem.cpp:297
ScreenGrabberChooserRectItem::Resizing
@ Resizing
Definition: screengrabberchooserrectitem.h:51
ScreenGrabberChooserRectItem::mouseRelease
void mouseRelease(QGraphicsSceneMouseEvent *event)
Definition: screengrabberchooserrectitem.cpp:151
ScreenGrabberChooserRectItem::mouseDoubleClick
void mouseDoubleClick(QGraphicsSceneMouseEvent *event)
Definition: screengrabberchooserrectitem.cpp:178
ScreenGrabberChooserRectItem::leftCenter
QGraphicsRectItem * leftCenter
Definition: screengrabberchooserrectitem.h:86
ScreenGrabberChooserRectItem::updateHandlePositions
void updateHandlePositions()
Definition: screengrabberchooserrectitem.cpp:262
ScreenGrabberChooserRectItem::mouseMove
void mouseMove(QGraphicsSceneMouseEvent *event)
Definition: screengrabberchooserrectitem.cpp:131
ScreenGrabberChooserRectItem::state
State state
Definition: screengrabberchooserrectitem.h:56
ScreenGrabberChooserRectItem::bottomLeft
QGraphicsRectItem * bottomLeft
Definition: screengrabberchooserrectitem.h:85
ScreenGrabberChooserRectItem::State
State
Definition: screengrabberchooserrectitem.h:48
ScreenGrabberChooserRectItem::createHandleItem
QGraphicsRectItem * createHandleItem(QGraphicsScene *scene)
Definition: screengrabberchooserrectitem.cpp:274
ScreenGrabberChooserRectItem::mousePress
void mousePress(QGraphicsSceneMouseEvent *event)
Definition: screengrabberchooserrectitem.cpp:123
ScreenGrabberChooserRectItem::forwardHandleEvent
void forwardHandleEvent(QGraphicsItem *watched, QEvent *event)
Definition: screengrabberchooserrectitem.cpp:315
ScreenGrabberChooserRectItem::showHandles
void showHandles()
Definition: screengrabberchooserrectitem.cpp:99
ScreenGrabberChooserRectItem::mainRect
QGraphicsRectItem * mainRect
Definition: screengrabberchooserrectitem.h:78
ScreenGrabberChooserRectItem::startPos
QPointF startPos
Definition: screengrabberchooserrectitem.h:59
ScreenGrabberChooserRectItem
Definition: screengrabberchooserrectitem.h:24
ScreenGrabberChooserRectItem::~ScreenGrabberChooserRectItem
~ScreenGrabberChooserRectItem()
Definition: screengrabberchooserrectitem.cpp:61
ScreenGrabberChooserRectItem::topCenter
QGraphicsRectItem * topCenter
Definition: screengrabberchooserrectitem.h:80
ScreenGrabberChooserRectItem::getHandleMultiplier
QPoint getHandleMultiplier(QGraphicsItem *handle)
Definition: screengrabberchooserrectitem.cpp:233
ScreenGrabberChooserRectItem::beginResize
void beginResize(QPointF mousePos)
Definition: screengrabberchooserrectitem.cpp:71
ScreenGrabberChooserRectItem::HandleResizing
@ HandleResizing
Definition: screengrabberchooserrectitem.h:52
ScreenGrabberChooserRectItem::regionChosen
void regionChosen(QRect rect)
ScreenGrabberChooserRectItem::rectWidth
int rectWidth
Definition: screengrabberchooserrectitem.h:57