1 /* smplayer, GUI front-end for mplayer. 2 Copyright (C) 2006-2021 Ricardo Villalba <ricardo@smplayer.info> 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 "videolayer.h" 34 #include "config.h" 35 36 class QWidget; 37 class QLabel; 38 class QKeyEvent; 39 class QTimer; 40 class ScreenHelper; 41 class VideoLayerShm; 42 class VideoLayerCV; 43 44 #define ZOOM_STEP 0.05 45 #define ZOOM_MIN 0.5 46 47 #define DELAYED_RESIZE 0 48 49 // Number of pixels the window has to be dragged at least before dragging starts 50 #define DRAG_THRESHOLD 4 51 52 enum TDragState {NOT_DRAGGING, START_DRAGGING, DRAGGING}; 53 54 class MplayerWindow : public QWidget 55 { 56 Q_OBJECT 57 58 public: 59 MplayerWindow(QWidget* parent = 0, Qt::WindowFlags f = QFlag(0)); 60 ~MplayerWindow(); 61 videoLayer()62 QWidget * videoLayer() { return videolayer; }; 63 64 void setResolution( int w, int h); 65 void setAspect( double asp); 66 void setMonitorAspect(double asp); 67 void updateVideoWindow(); 68 69 #if USE_COLORKEY 70 void setColorKey(QColor c); 71 #endif 72 73 void setOffsetX( int ); 74 int offsetX(); 75 76 void setOffsetY( int ); 77 int offsetY(); 78 79 void setZoom( double ); 80 double zoom(); 81 allowVideoMovement(bool b)82 void allowVideoMovement(bool b) { allow_video_movement = b; }; isVideoMovementAllowed()83 bool isVideoMovementAllowed() { return allow_video_movement; }; 84 delayLeftClick(bool b)85 void delayLeftClick(bool b) { delay_left_click = b; }; isLeftClickDelayed()86 bool isLeftClickDelayed() { return delay_left_click; }; 87 88 virtual QSize sizeHint () const; 89 virtual QSize minimumSizeHint() const; 90 91 virtual bool eventFilter(QObject *, QEvent *); 92 93 #if LOGO_ANIMATION animatedLogo()94 bool animatedLogo() { return animated_logo; } 95 #endif 96 97 void setCornerWidget(QWidget * w); cornerWidget()98 QWidget * cornerWidget() { return corner_widget; }; 99 100 #if REPAINT_BACKGROUND_OPTION 101 void setRepaintBackground(bool b); repaintBackground()102 bool repaintBackground() { return repaint_background; } 103 #endif 104 105 public slots: 106 //! Should be called when a file has started. 107 virtual void playingStarted(); 108 109 //! Should be called when a file has stopped. 110 virtual void playingStopped(); 111 112 virtual void gotVO(QString); 113 114 void setLogoVisible(bool b); showLogo()115 void showLogo() { setLogoVisible(true); }; hideLogo()116 void hideLogo() { setLogoVisible(false); }; 117 118 #if LOGO_ANIMATION setAnimatedLogo(bool b)119 void setAnimatedLogo(bool b) { animated_logo = b; }; 120 #endif 121 122 void moveLeft(); 123 void moveRight(); 124 void moveUp(); 125 void moveDown(); 126 void incZoom(); 127 void decZoom(); 128 activateMouseDragTracking(bool active)129 void activateMouseDragTracking(bool active) { mouse_drag_tracking = active; } 130 131 #if DELAYED_RESIZE 132 protected slots: 133 void resizeLater(); 134 #endif 135 136 protected: 137 virtual void retranslateStrings(); 138 virtual void changeEvent ( QEvent * event ) ; 139 140 virtual void resizeEvent( QResizeEvent * e); 141 virtual void mouseReleaseEvent( QMouseEvent * e); 142 virtual void mouseDoubleClickEvent( QMouseEvent * e ); 143 virtual void wheelEvent( QWheelEvent * e ); 144 void moveLayer( int offset_x, int offset_y ); 145 146 signals: 147 //void rightButtonReleased( QPoint p ); 148 void doubleClicked(); 149 void leftClicked(); 150 void rightClicked(); 151 void middleClicked(); 152 void xbutton1Clicked(); // first X button 153 void xbutton2Clicked(); // second X button 154 void keyPressed(QKeyEvent * e); 155 void wheelUp(); 156 void wheelDown(); 157 void mouseMovedDiff(QPoint); 158 void mouseMoved(QPoint); 159 160 protected: 161 int video_width, video_height; 162 double aspect; 163 double monitoraspect; 164 165 ScreenHelper * helper; 166 QLabel * logo; 167 168 VideoLayer * videolayer; 169 170 // Zoom and moving 171 int offset_x, offset_y; 172 double zoom_factor; 173 174 // Original pos and dimensions of the videolayer 175 // before zooming or moving 176 int orig_x, orig_y; 177 int orig_width, orig_height; 178 179 bool allow_video_movement; 180 181 #if DELAYED_RESIZE 182 QTimer * resize_timer; 183 #endif 184 185 // Delay left click event 186 bool delay_left_click; 187 QTimer * left_click_timer; 188 bool double_clicked; 189 190 #if LOGO_ANIMATION 191 bool animated_logo; 192 #endif 193 194 QWidget * corner_widget; 195 196 #if REPAINT_BACKGROUND_OPTION 197 bool repaint_background; 198 #endif 199 200 private: 201 TDragState drag_state; 202 QPoint start_drag; 203 bool mouse_drag_tracking; 204 }; 205 206 #endif 207 208