[vlc-devel] [PATCH] Qt: Add moving main window on any part of a window

Alexander Terentyev lex.terentyev at gmail.com
Wed Dec 5 01:00:04 CET 2012


---
 modules/gui/qt4/main_interface.cpp |   35 +++++++++++++++++++++++++++++++++++
 modules/gui/qt4/main_interface.hpp |    9 +++++++++
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 05f5888..d5dcc94 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -326,6 +326,11 @@ void MainInterface::computeMinimumSize()
     setMinimumWidth( minWidth );
 }
 
+inline void MainInterface::moveWindow( int offsetX, int offsetY )
+{
+    move( x() + offsetX, y() + offsetY );
+}
+
 /*****************************
  *   Main UI handling        *
  *****************************/
@@ -1359,6 +1364,36 @@ bool MainInterface::eventFilter( QObject *obj, QEvent *event )
     }
 }
 
+void MainInterface::mousePressEvent( QMouseEvent *event )
+{
+    b_customMoving = Qt::LeftButton == event->button();
+    lastCustomMovePos = event->globalPos();
+}
+
+void MainInterface::mouseMoveEvent( QMouseEvent *event )
+{
+    if( b_customMoving )
+    {
+        moveWindow(
+            event->globalX() - lastCustomMovePos.x(),
+            event->globalY() - lastCustomMovePos.y()
+        );
+        lastCustomMovePos = event->globalPos();
+    }
+}
+
+void MainInterface::mouseReleaseEvent( QMouseEvent *event )
+{
+    if( b_customMoving )
+    {
+        moveWindow(
+            event->globalX() - lastCustomMovePos.x(),
+            event->globalY() - lastCustomMovePos.y()
+        );
+    }
+    b_customMoving = false;
+}
+
 void MainInterface::toolBarConfUpdated()
 {
     QApplication::postEvent( this, new QEvent( MainInterface::ToolbarsNeedRebuild ) );
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index ae0a624..9d60781 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -105,6 +105,9 @@ protected:
     virtual void keyPressEvent( QKeyEvent *);
     virtual void wheelEvent( QWheelEvent * );
     virtual bool eventFilter(QObject *, QEvent *);
+    virtual void mousePressEvent( QMouseEvent * );
+    virtual void mouseMoveEvent( QMouseEvent * );
+    virtual void mouseReleaseEvent( QMouseEvent * );
 
 private:
     /* Main Widgets Creation */
@@ -128,6 +131,9 @@ private:
     void computeMinimumSize();
 
     /* */
+    inline void moveWindow( int offsetX, int offsetY );
+
+    /* */
     QSettings           *settings;
     QSystemTrayIcon     *sysTray;
     QMenu               *systrayMenu;
@@ -155,6 +161,8 @@ private:
 
     QMap<QWidget *, QSize> stackWidgetsSizes;
 
+    QPoint              lastCustomMovePos;
+
     /* Flags */
     unsigned             i_notificationSetting; /// Systray Notifications
     bool                 b_autoresize;          ///< persistent resizable window
@@ -173,6 +181,7 @@ private:
 
     bool                 b_hasPausedWhenMinimized;
     bool                 b_statusbarVisible;
+    bool                 b_customMoving;        ///< Is the window moving by dragging ?
 
 #ifdef WIN32
     HIMAGELIST himl;
-- 
1.7.8.6




More information about the vlc-devel mailing list