[vlc-devel] [PATCH] qt: qvlcframe: move functions to source file

Alexandre Janniaux ajanni at videolabs.io
Tue Oct 8 21:18:50 CEST 2019


The file is included almost everywhere and has deprecation warnings.
In addition, it prepares future refactoring of these utility class.
---
 modules/gui/qt/Makefile.am        |  1 +
 modules/gui/qt/util/qvlcframe.cpp | 91 +++++++++++++++++++++++++++++++
 modules/gui/qt/util/qvlcframe.hpp | 67 +++--------------------
 3 files changed, 99 insertions(+), 60 deletions(-)
 create mode 100644 modules/gui/qt/util/qvlcframe.cpp

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index af4a5d05cc..78b8d965e4 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -194,6 +194,7 @@ libqt_plugin_la_SOURCES = \
 	gui/qt/util/buttons/DeckButtonsLayout.hpp \
 	gui/qt/util/buttons/RoundButton.cpp \
 	gui/qt/util/buttons/RoundButton.hpp \
+	gui/qt/util/qvlcframe.cpp \
 	gui/qt/util/qvlcframe.hpp \
 	gui/qt/util/qvlcapp.hpp \
 	gui/qt/util/qmleventfilter.cpp \
diff --git a/modules/gui/qt/util/qvlcframe.cpp b/modules/gui/qt/util/qvlcframe.cpp
new file mode 100644
index 0000000000..690f82f8f9
--- /dev/null
+++ b/modules/gui/qt/util/qvlcframe.cpp
@@ -0,0 +1,91 @@
+/*****************************************************************************
+ * qvlcframe.cpp : A few helpers
+ *****************************************************************************
+ * Copyright (C) 2006-2007 the VideoLAN team
+ *
+ * Authors: Clément Stenac <zorglub at videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "qvlcframe.hpp"
+
+void QVLCTools::saveWidgetPosition(QSettings *settings, QWidget *widget)
+{
+    settings->setValue("geometry", widget->saveGeometry());
+}
+
+void QVLCTools::saveWidgetPosition(intf_thread_t *p_intf,
+                                   const QString& configName,
+                                   QWidget *widget)
+{
+    getSettings()->beginGroup(configName);
+    QVLCTools::saveWidgetPosition(getSettings(), widget);
+    getSettings()->endGroup();
+}
+
+bool QVLCTools::restoreWidgetPosition(QSettings *settings, QWidget *widget,
+                                      QSize defSize, QPoint defPos)
+{
+    if (!widget->restoreGeometry(settings->value("geometry").toByteArray()))
+    {
+        widget->move(defPos);
+        widget->resize(defSize);
+
+        if (defPos.x() == 0 && defPos.y()==0)
+            widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), qApp->desktop()->availableGeometry()));
+        return true;
+    }
+    return false;
+}
+
+bool QVLCTools::restoreWidgetPosition(intf_thread_t *p_intf,
+                                      const QString& configName,
+                                      QWidget *widget, QSize defSize,
+                                      QPoint defPos)
+{
+    getSettings()->beginGroup(configName);
+    bool defaultUsed =
+        QVLCTools::restoreWidgetPosition(getSettings(), widget, defSize, defPos);
+    getSettings()->endGroup();
+
+    return defaultUsed;
+}
+
+void QVLCFrame::keyPressEvent(QKeyEvent *keyEvent)
+{
+    if (keyEvent->key() == Qt::Key_Escape)
+    {
+        this->cancel();
+    }
+    else if (keyEvent->key() == Qt::Key_Return ||
+             keyEvent->key() == Qt::Key_Enter)
+    {
+        this->close();
+    }
+}
+
+void QVLCDialog::keyPressEvent(QKeyEvent *keyEvent)
+{
+    if (keyEvent->key() == Qt::Key_Escape)
+    {
+        this->cancel();
+    }
+    else if (keyEvent->key() == Qt::Key_Return ||
+             keyEvent->key() == Qt::Key_Enter)
+    {
+        this->close();
+    }
+}
diff --git a/modules/gui/qt/util/qvlcframe.hpp b/modules/gui/qt/util/qvlcframe.hpp
index a516c7b285..5ddd024813 100644
--- a/modules/gui/qt/util/qvlcframe.hpp
+++ b/modules/gui/qt/util/qvlcframe.hpp
@@ -44,19 +44,11 @@ class QVLCTools
         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)
-       {
-         settings->setValue("geometry", widget->saveGeometry());
-       }
+       static void saveWidgetPosition( QSettings *settings, QWidget *widget);
+
        static void saveWidgetPosition( intf_thread_t *p_intf,
                                        const QString& configName,
-                                       QWidget *widget)
-       {
-         getSettings()->beginGroup( configName );
-         QVLCTools::saveWidgetPosition(getSettings(), widget);
-         getSettings()->endGroup();
-       }
-
+                                       QWidget *widget);

        /*
          use this method only for restoring window state of non docked
@@ -65,36 +57,13 @@ class QVLCTools
        static bool restoreWidgetPosition(QSettings *settings,
                                            QWidget *widget,
                                            QSize defSize = QSize( 0, 0 ),
-                                           QPoint defPos = QPoint( 0, 0 ))
-       {
-          if(!widget->restoreGeometry(settings->value("geometry")
-                                      .toByteArray()))
-          {
-            widget->move(defPos);
-            widget->resize(defSize);
-
-            if(defPos.x() == 0 && defPos.y()==0)
-               widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), qApp->desktop()->availableGeometry()));
-            return true;
-          }
-          return false;
-       }
+                                           QPoint defPos = QPoint( 0, 0 ));

        static bool restoreWidgetPosition( intf_thread_t *p_intf,
                                            const QString& configName,
                                            QWidget *widget,
                                            QSize defSize = QSize( 0, 0 ),
-                                           QPoint defPos = QPoint( 0, 0 ) )
-       {
-         getSettings()->beginGroup( configName );
-         bool defaultUsed = QVLCTools::restoreWidgetPosition( getSettings(),
-                                                                   widget,
-                                                                   defSize,
-                                                                   defPos);
-         getSettings()->endGroup();
-
-         return defaultUsed;
-       }
+                                           QPoint defPos = QPoint( 0, 0 ) );
 };

 class QVLCFrame : public QWidget
@@ -132,18 +101,7 @@ protected:
     {
         hide();
     }
-    void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE
-    {
-        if( keyEvent->key() == Qt::Key_Escape )
-        {
-            this->cancel();
-        }
-        else if( keyEvent->key() == Qt::Key_Return
-              || keyEvent->key() == Qt::Key_Enter )
-        {
-             this->close();
-        }
-    }
+    void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE;
 };

 class QVLCDialog : public QDialog
@@ -173,18 +131,7 @@ protected:
     {
         hide();
     }
-    void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE
-    {
-        if( keyEvent->key() == Qt::Key_Escape )
-        {
-            this->cancel();
-        }
-        else if( keyEvent->key() == Qt::Key_Return
-              || keyEvent->key() == Qt::Key_Enter )
-        {
-            this->close();
-        }
-    }
+    void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE;
 };

 class QVLCMW : public QMainWindow
--
2.23.0



More information about the vlc-devel mailing list