1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2013 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 | #ifndef MPLAYERWINDOW_H
|
---|
21 | #define MPLAYERWINDOW_H
|
---|
22 |
|
---|
23 | #include <QWidget>
|
---|
24 | #include <QSize>
|
---|
25 | #include <QPoint>
|
---|
26 |
|
---|
27 | #include <QResizeEvent>
|
---|
28 | #include <QWheelEvent>
|
---|
29 | #include <QMouseEvent>
|
---|
30 | #include <QKeyEvent>
|
---|
31 | #include <QPaintEvent>
|
---|
32 |
|
---|
33 | #include "config.h"
|
---|
34 |
|
---|
35 | class QWidget;
|
---|
36 | class QLabel;
|
---|
37 | class QKeyEvent;
|
---|
38 | class QTimer;
|
---|
39 |
|
---|
40 | #define ZOOM_STEP 0.05
|
---|
41 | #define ZOOM_MIN 0.5
|
---|
42 |
|
---|
43 | #define DELAYED_RESIZE 0
|
---|
44 |
|
---|
45 | //! Screen is a widget that hides the mouse cursor after some seconds if not moved.
|
---|
46 |
|
---|
47 | class Screen : public QWidget
|
---|
48 | {
|
---|
49 | Q_OBJECT
|
---|
50 |
|
---|
51 | public:
|
---|
52 | Screen(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
---|
53 | ~Screen();
|
---|
54 |
|
---|
55 | void setAutoHideCursor(bool b);
|
---|
56 | bool autoHideCursor() { return autohide_cursor; };
|
---|
57 |
|
---|
58 | void setAutoHideInterval(int milliseconds) { autohide_interval = milliseconds; };
|
---|
59 | int autoHideInterval() { return autohide_interval; };
|
---|
60 |
|
---|
61 | public slots:
|
---|
62 | //! Should be called when a file has started.
|
---|
63 | virtual void playingStarted();
|
---|
64 |
|
---|
65 | //! Should be called when a file has stopped.
|
---|
66 | virtual void playingStopped();
|
---|
67 |
|
---|
68 | protected:
|
---|
69 | virtual void mouseMoveEvent( QMouseEvent * e );
|
---|
70 | virtual void paintEvent ( QPaintEvent * e );
|
---|
71 |
|
---|
72 | protected slots:
|
---|
73 | virtual void checkMousePos();
|
---|
74 |
|
---|
75 | private:
|
---|
76 | QTimer * check_mouse_timer;
|
---|
77 | QPoint mouse_last_position;
|
---|
78 | bool autohide_cursor;
|
---|
79 | int autohide_interval;
|
---|
80 | };
|
---|
81 |
|
---|
82 | //! MplayerLayer can be instructed to not delete the background.
|
---|
83 |
|
---|
84 | class MplayerLayer : public Screen
|
---|
85 | {
|
---|
86 | Q_OBJECT
|
---|
87 |
|
---|
88 | public:
|
---|
89 | MplayerLayer(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
---|
90 | ~MplayerLayer();
|
---|
91 |
|
---|
92 | #if REPAINT_BACKGROUND_OPTION
|
---|
93 | //! If b is true, the background of the widget will be repainted as usual.
|
---|
94 | /*! Otherwise the background will not repainted when a video is playing. */
|
---|
95 | void setRepaintBackground(bool b);
|
---|
96 |
|
---|
97 | //! Return true if repainting the background is allowed.
|
---|
98 | bool repaintBackground() { return repaint_background; };
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | public slots:
|
---|
102 | //! Should be called when a file has started.
|
---|
103 | /*! It's needed to know if the background has to be cleared or not. */
|
---|
104 | virtual void playingStarted();
|
---|
105 | //! Should be called when a file has stopped.
|
---|
106 | virtual void playingStopped();
|
---|
107 |
|
---|
108 | #if REPAINT_BACKGROUND_OPTION
|
---|
109 | protected:
|
---|
110 | virtual void paintEvent ( QPaintEvent * e );
|
---|
111 | #endif
|
---|
112 |
|
---|
113 | private:
|
---|
114 | #if REPAINT_BACKGROUND_OPTION
|
---|
115 | bool repaint_background;
|
---|
116 | #endif
|
---|
117 | bool playing;
|
---|
118 | };
|
---|
119 |
|
---|
120 |
|
---|
121 | class MplayerWindow : public Screen
|
---|
122 | {
|
---|
123 | Q_OBJECT
|
---|
124 |
|
---|
125 | public:
|
---|
126 | MplayerWindow( QWidget* parent = 0, Qt::WindowFlags f = 0);
|
---|
127 | ~MplayerWindow();
|
---|
128 |
|
---|
129 | MplayerLayer * videoLayer() { return mplayerlayer; };
|
---|
130 |
|
---|
131 | void setResolution( int w, int h);
|
---|
132 | void setAspect( double asp);
|
---|
133 | void setMonitorAspect(double asp);
|
---|
134 | void updateVideoWindow();
|
---|
135 |
|
---|
136 | #if USE_COLORKEY
|
---|
137 | void setColorKey(QColor c);
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | void setOffsetX( int );
|
---|
141 | int offsetX();
|
---|
142 |
|
---|
143 | void setOffsetY( int );
|
---|
144 | int offsetY();
|
---|
145 |
|
---|
146 | void setZoom( double );
|
---|
147 | double zoom();
|
---|
148 |
|
---|
149 | void allowVideoMovement(bool b) { allow_video_movement = b; };
|
---|
150 | bool isVideoMovementAllowed() { return allow_video_movement; };
|
---|
151 |
|
---|
152 | virtual QSize sizeHint () const;
|
---|
153 | virtual QSize minimumSizeHint() const;
|
---|
154 |
|
---|
155 | virtual bool eventFilter( QObject * watched, QEvent * event );
|
---|
156 |
|
---|
157 | #if LOGO_ANIMATION
|
---|
158 | bool animatedLogo() { return animated_logo; }
|
---|
159 | #endif
|
---|
160 |
|
---|
161 | public slots:
|
---|
162 | void setLogoVisible(bool b);
|
---|
163 | void showLogo() { setLogoVisible(true); };
|
---|
164 | void hideLogo() { setLogoVisible(false); };
|
---|
165 |
|
---|
166 | #if LOGO_ANIMATION
|
---|
167 | void setAnimatedLogo(bool b) { animated_logo = b; };
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | void moveLeft();
|
---|
171 | void moveRight();
|
---|
172 | void moveUp();
|
---|
173 | void moveDown();
|
---|
174 | void incZoom();
|
---|
175 | void decZoom();
|
---|
176 |
|
---|
177 | #if DELAYED_RESIZE
|
---|
178 | protected slots:
|
---|
179 | void resizeLater();
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | protected:
|
---|
183 | virtual void retranslateStrings();
|
---|
184 | virtual void changeEvent ( QEvent * event ) ;
|
---|
185 |
|
---|
186 | virtual void resizeEvent( QResizeEvent * e);
|
---|
187 | virtual void mouseReleaseEvent( QMouseEvent * e);
|
---|
188 | virtual void mouseDoubleClickEvent( QMouseEvent * e );
|
---|
189 | virtual void wheelEvent( QWheelEvent * e );
|
---|
190 | void moveLayer( int offset_x, int offset_y );
|
---|
191 |
|
---|
192 | signals:
|
---|
193 | //void rightButtonReleased( QPoint p );
|
---|
194 | void doubleClicked();
|
---|
195 | void leftClicked();
|
---|
196 | void rightClicked();
|
---|
197 | void middleClicked();
|
---|
198 | void xbutton1Clicked(); // first X button
|
---|
199 | void xbutton2Clicked(); // second X button
|
---|
200 | void keyPressed(QKeyEvent * e);
|
---|
201 | void wheelUp();
|
---|
202 | void wheelDown();
|
---|
203 | void mouseMoved(QPoint);
|
---|
204 | void mouseMovedDiff(QPoint);
|
---|
205 |
|
---|
206 | protected:
|
---|
207 | int video_width, video_height;
|
---|
208 | double aspect;
|
---|
209 | double monitoraspect;
|
---|
210 |
|
---|
211 | MplayerLayer * mplayerlayer;
|
---|
212 | QLabel * logo;
|
---|
213 |
|
---|
214 | // Zoom and moving
|
---|
215 | int offset_x, offset_y;
|
---|
216 | double zoom_factor;
|
---|
217 |
|
---|
218 | // Original pos and dimensions of the mplayerlayer
|
---|
219 | // before zooming or moving
|
---|
220 | int orig_x, orig_y;
|
---|
221 | int orig_width, orig_height;
|
---|
222 |
|
---|
223 | bool allow_video_movement;
|
---|
224 | QPoint mouse_press_pos;
|
---|
225 |
|
---|
226 | #if DELAYED_RESIZE
|
---|
227 | QTimer * resize_timer;
|
---|
228 | #endif
|
---|
229 |
|
---|
230 | #if LOGO_ANIMATION
|
---|
231 | bool animated_logo;
|
---|
232 | #endif
|
---|
233 | };
|
---|
234 |
|
---|
235 |
|
---|
236 | #endif
|
---|
237 |
|
---|