]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/util/qvlcframe.hpp
Qt: emit video window resize events
[vlc] / modules / gui / qt4 / util / qvlcframe.hpp
index d8f97ef7e2a6e85ad1dd7054a00be3ce9487148e..3706f4d7f4b0d9d0680055477a8f5e733d4d690a 100644 (file)
 
 #include <QWidget>
 #include <QDialog>
-#include <QSpacerItem>
 #include <QHBoxLayout>
 #include <QApplication>
-#include <QSettings>
 #include <QMainWindow>
-#include <QPushButton>
 #include <QKeyEvent>
 #include <QDesktopWidget>
+#include <QSettings>
+#include <QStyle>
 
 #include "qt4.hpp"
-#include <vlc_common.h>
-#include <vlc_charset.h>
 
 class QVLCTools
 {
@@ -45,20 +42,20 @@ class QVLCTools
        /*
         use this function to save a widgets screen position
         only for windows / dialogs which are floating, if a
-        window is docked into an other - don't all this function
+        window is docked into another - don't all this function
         or it may write garbage to position info!
        */
-       static void saveWidgetPosition(QSettings *settings, QWidget *widget)
+       static void saveWidgetPosition( QSettings *settings, QWidget *widget)
        {
          settings->setValue("geometry", widget->saveGeometry());
        }
-       static void saveWidgetPosition(QString configName, QWidget *widget)
+       static void saveWidgetPosition( intf_thread_t *p_intf,
+                                       const QString& configName,
+                                       QWidget *widget)
        {
-         QSettings *settings = new QSettings("vlc", "vlc-qt-interface");
-         settings->beginGroup( configName );
-         QVLCTools::saveWidgetPosition(settings, widget);
-         settings->endGroup();
-         delete settings;
+         getSettings()->beginGroup( configName );
+         QVLCTools::saveWidgetPosition(getSettings(), widget);
+         getSettings()->endGroup();
        }
 
 
@@ -78,51 +75,33 @@ class QVLCTools
             widget->resize(defSize);
 
             if(defPos.x() == 0 && defPos.y()==0)
-               centerWidgetOnScreen(widget);
+               widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), qApp->desktop()->availableGeometry()));
             return true;
           }
           return false;
        }
 
-       static bool restoreWidgetPosition(QString configName,
+       static bool restoreWidgetPosition( intf_thread_t *p_intf,
+                                           const QString& configName,
                                            QWidget *widget,
                                            QSize defSize = QSize( 0, 0 ),
                                            QPoint defPos = QPoint( 0, 0 ) )
        {
-         QSettings *settings = new QSettings( "vlc", "vlc-qt-interface" );
-         settings->beginGroup( configName );
-         bool defaultUsed = QVLCTools::restoreWidgetPosition(settings,
+         getSettings()->beginGroup( configName );
+         bool defaultUsed = QVLCTools::restoreWidgetPosition( getSettings(),
                                                                    widget,
                                                                    defSize,
                                                                    defPos);
-         settings->endGroup();
-         delete settings;
+         getSettings()->endGroup();
 
          return defaultUsed;
        }
-
-      /*
-        call this method for a window or dialog to show it centred on
-        current screen
-      */
-      static void centerWidgetOnScreen(QWidget *widget)
-      {
-         QDesktopWidget * const desktop = QApplication::desktop();
-         QRect screenRect = desktop->screenGeometry(widget);
-         QPoint p1 = widget->frameGeometry().center();
-
-         widget->move ( screenRect.center() - p1 );
-      }
 };
 
 class QVLCFrame : public QWidget
 {
 public:
-#ifdef __APPLE__
-    QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL, Qt::Window ), p_intf( _p_intf )
-#else
     QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
-#endif
     {};
     virtual ~QVLCFrame()   {};
 
@@ -134,16 +113,16 @@ public:
 protected:
     intf_thread_t *p_intf;
 
-    void readSettings( QString name,
-                       QSize defSize = QSize( 0, 0 ),
+    void restoreWidgetPosition( const QString& name,
+                       QSize defSize = QSize( 1, 1 ),
                        QPoint defPos = QPoint( 0, 0 ) )
     {
-        QVLCTools::restoreWidgetPosition(name, this, defSize, defPos);
+        QVLCTools::restoreWidgetPosition(p_intf, name, this, defSize, defPos);
     }
 
-    void writeSettings( QString name )
+    void saveWidgetPosition( const QString& name )
     {
-        QVLCTools::saveWidgetPosition(name, this);
+        QVLCTools::saveWidgetPosition( p_intf, name, this);
     }
 
     virtual void cancel()
@@ -154,18 +133,17 @@ protected:
     {
         hide();
     }
-    virtual void keyPressEvent( QKeyEvent *keyEvent )
+    void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE
     {
         if( keyEvent->key() == Qt::Key_Escape )
         {
-            msg_Dbg( p_intf, "Escp Key pressed" );
-            cancel();
+            this->cancel();
         }
-        else if( keyEvent->key() == Qt::Key_Return )
+        else if( keyEvent->key() == Qt::Key_Return
+              || keyEvent->key() == Qt::Key_Enter )
         {
-             msg_Dbg( p_intf, "Enter Key pressed" );
-             close();
-         }
+             this->close();
+        }
     }
 };
 
@@ -193,17 +171,16 @@ protected:
     {
         hide();
     }
-    virtual void keyPressEvent( QKeyEvent *keyEvent )
+    void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE
     {
         if( keyEvent->key() == Qt::Key_Escape )
         {
-            msg_Dbg( p_intf, "Escp Key pressed" );
-            cancel();
+            this->cancel();
         }
-        else if( keyEvent->key() == Qt::Key_Return )
+        else if( keyEvent->key() == Qt::Key_Return
+              || keyEvent->key() == Qt::Key_Enter )
         {
-             msg_Dbg( p_intf, "Enter Key pressed" );
-             close();
+            this->close();
         }
     }
 };
@@ -211,9 +188,7 @@ protected:
 class QVLCMW : public QMainWindow
 {
 public:
-    QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
-    {    }
-    virtual ~QVLCMW() {};
+    QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf ){}
     void toggleVisible()
     {
         if( isVisible() ) hide();
@@ -223,16 +198,15 @@ protected:
     intf_thread_t *p_intf;
     QSize mainSize;
 
-    void readSettings( QString name, QSize defSize )
+    void readSettings( const QString& name, QSize defSize )
     {
-        QVLCTools::restoreWidgetPosition(name, this, defSize);
+        QVLCTools::restoreWidgetPosition( p_intf, name, this, defSize);
     }
 
-    void readSettings( QString name )
+    void readSettings( const QString& name )
     {
-        QVLCTools::restoreWidgetPosition(name, this);
+        QVLCTools::restoreWidgetPosition( p_intf, name, this);
     }
-
     void readSettings( QSettings *settings )
     {
         QVLCTools::restoreWidgetPosition(settings, this);
@@ -243,16 +217,14 @@ protected:
         QVLCTools::restoreWidgetPosition(settings, this, defSize);
     }
 
-    void writeSettings(QString name )
+    void writeSettings( const QString& name )
     {
-        QVLCTools::saveWidgetPosition(name, this);
+        QVLCTools::saveWidgetPosition( p_intf, name, this);
     }
-
     void writeSettings(QSettings *settings )
     {
         QVLCTools::saveWidgetPosition(settings, this);
     }
-
 };
 
 #endif