1 | /*************************************************************************** |
2 | * Copyright (C) 2010 by Till Theato (root@ttill.de) * |
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 * |
16 | * Free Software Foundation, Inc., * |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
18 | ***************************************************************************/ |
19 | |
20 | |
21 | #ifndef MONITORSCENE_H |
22 | #define MONITORSCENE_H |
23 | |
24 | #include <QtCore> |
25 | #include <QGraphicsScene> |
26 | |
27 | class Render; |
28 | |
29 | |
30 | class MonitorScene : public QGraphicsScene |
31 | { |
32 | Q_OBJECT |
33 | public: |
34 | explicit MonitorScene(Render *renderer, QObject* parent = 0); |
35 | |
36 | /** @brief Sets m_view to this scenes view. */ |
37 | void setUp(); |
38 | |
39 | /** @brief Enables/Disables the scene for usage (background still updated). |
40 | * @param enabled (default = true) */ |
41 | void setEnabled(bool enabled = true); |
42 | |
43 | /** @brief Makes the background frame fit again after the profile changed (and therefore the resolution might have changed). */ |
44 | void resetProfile(); |
45 | |
46 | /** @brief Reset scene size. */ |
47 | void cleanup(); |
48 | |
49 | /** @brief Center view on frame border. */ |
50 | void centerView(); |
51 | |
52 | protected: |
53 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
54 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
55 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
56 | /** @brief Adds a keyframe if scene is disabled. */ |
57 | void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); |
58 | /** @brief Reimplemented to allow zooming using ctrl + mouse wheel. */ |
59 | void wheelEvent(QGraphicsSceneWheelEvent *event); |
60 | |
61 | public slots: |
62 | /** @brief Sets the backgrounditem's pixmap to m_backgroundImage (only if a certain amount of time has passed since last update). */ |
63 | void slotUpdateBackground(); |
64 | |
65 | /** @brief Sets the scene's zoom level. |
66 | * @param value zoom level with 100 = show frame at original size */ |
67 | void slotZoom(int value); |
68 | /** @brief Makes the zoom level fit the viewport's size. */ |
69 | void slotZoomFit(); |
70 | /** @brief Shows the frame at it's original size and center. */ |
71 | void slotZoomOriginal(); |
72 | /** @brief Zooms in by @param by%. */ |
73 | void slotZoomIn(int by = 1); |
74 | /** @brief Zooms out by @param by%. */ |
75 | void slotZoomOut(int by = 1); |
76 | |
77 | private slots: |
78 | /** @brief Sets m_backgroundImage to @param image and requests updating the background item. */ |
79 | void slotSetBackgroundImage(const QImage &image); |
80 | |
81 | private: |
82 | Render *m_renderer; |
83 | QGraphicsPixmapItem *m_background; |
84 | QGraphicsRectItem *m_frameBorder; |
85 | QTime m_lastUpdate; |
86 | QGraphicsView *m_view; |
87 | QImage m_backgroundImage; |
88 | bool m_enabled; |
89 | qreal m_zoom; |
90 | bool m_groupMove; |
91 | QPointF m_lastPos; |
92 | |
93 | signals: |
94 | void zoomChanged(int); |
95 | void addKeyframe(); |
96 | }; |
97 | |
98 | #endif |
99 | |