[vlc-commits] qt: Add toolbar editor (native)
Rohan Rajpal
git at videolan.org
Wed Aug 21 16:26:53 CEST 2019
vlc | branch: master | Rohan Rajpal <rohan17089 at iiitd.ac.in> | Tue Jul 30 16:46:27 2019 +0530| [04c3e28eaa8f1e197d6f98f4a3dd2c5899969c30] | committer: Jean-Baptiste Kempf
qt: Add toolbar editor (native)
Add the native part of the toolbar editor.
This part has the window and a few widgets.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=04c3e28eaa8f1e197d6f98f4a3dd2c5899969c30
---
modules/gui/qt/Makefile.am | 2 +
modules/gui/qt/dialogs/toolbareditor.cpp | 180 +++++++++++++++++++++++++++++++
modules/gui/qt/dialogs/toolbareditor.hpp | 57 ++++++++++
modules/gui/qt/dialogs_provider.cpp | 4 +-
4 files changed, 242 insertions(+), 1 deletion(-)
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 725be269fa..a79ba9c718 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -70,6 +70,7 @@ libqt_plugin_la_SOURCES = \
gui/qt/dialogs/help.cpp gui/qt/dialogs/help.hpp \
gui/qt/dialogs/gototime.cpp gui/qt/dialogs/gototime.hpp \
gui/qt/dialogs/toolbar.cpp gui/qt/dialogs/toolbar.hpp \
+ gui/qt/dialogs/toolbareditor.cpp gui/qt/dialogs/toolbareditor.hpp \
gui/qt/dialogs/open.cpp gui/qt/dialogs/open.hpp \
gui/qt/dialogs/openurl.cpp gui/qt/dialogs/openurl.hpp \
gui/qt/dialogs/vlm.cpp gui/qt/dialogs/vlm.hpp \
@@ -244,6 +245,7 @@ nodist_libqt_plugin_la_SOURCES = \
gui/qt/dialogs/help.moc.cpp \
gui/qt/dialogs/gototime.moc.cpp \
gui/qt/dialogs/toolbar.moc.cpp \
+ gui/qt/dialogs/toolbareditor.moc.cpp \
gui/qt/dialogs/open.moc.cpp \
gui/qt/dialogs/openurl.moc.cpp \
gui/qt/dialogs/podcast_configuration.moc.cpp \
diff --git a/modules/gui/qt/dialogs/toolbareditor.cpp b/modules/gui/qt/dialogs/toolbareditor.cpp
new file mode 100644
index 0000000000..bc44c049bf
--- /dev/null
+++ b/modules/gui/qt/dialogs/toolbareditor.cpp
@@ -0,0 +1,180 @@
+/*****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "dialogs/toolbareditor.hpp"
+#include "components/settings.hpp"
+#include "components/playercontrolbarmodel.hpp"
+#include "main_interface.hpp"
+
+#include <QInputDialog>
+#include <QtQml/QQmlContext>
+
+#define PROFILE_NAME_1 "Minimalist Style"
+#define VALUE_1 "0;64;3;1;4;64;11;64;34;64;9;64;33"
+#define PROFILE_NAME_2 "One-Liner Style"
+#define VALUE_2 "0;64;3;1;4;64;7;9;8;64;64;11;10;12;13;65;33"
+#define PROFILE_NAME_3 "Simplest Style"
+#define VALUE_3 "33;65;0;4;1;65;7"
+
+ToolbarEditorDialog::ToolbarEditorDialog( QWidget *_w, intf_thread_t *_p_intf)
+ : QVLCDialog( _w, _p_intf )
+{
+ setWindowTitle( qtr( "Toolbars Editor" ) );
+ setWindowRole( "vlc-toolbars-editor" );
+ setMinimumWidth( 800 );
+ setMinimumHeight( 500 );
+
+ /* Profile */
+ QGridLayout *mainLayout = new QGridLayout( this );
+ QHBoxLayout *profileBoxLayout = new QHBoxLayout();
+
+ profileCombo = new QComboBox;
+
+ QToolButton *newButton = new QToolButton;
+ newButton->setIcon( QIcon( ":/new.svg" ) );
+ newButton->setToolTip( qtr("New profile") );
+ QToolButton *deleteButton = new QToolButton;
+ deleteButton->setIcon( QIcon( ":/toolbar/clear.svg" ) );
+ deleteButton->setToolTip( qtr( "Delete the current profile" ) );
+
+ profileBoxLayout->addWidget( new QLabel( qtr( "Select profile:" ) ) );
+ profileBoxLayout->addWidget( profileCombo );
+ profileBoxLayout->addWidget( newButton );
+ profileBoxLayout->addWidget( deleteButton );
+
+ mainLayout->addLayout( profileBoxLayout, 0, 0, 1, 9 );
+
+ /* Fill combos */
+ int i_size = getSettings()->beginReadArray( "ToolbarProfiles" );
+ for( int i = 0; i < i_size; i++ )
+ {
+ getSettings()->setArrayIndex(i);
+ profileCombo->addItem( getSettings()->value( "ProfileName" ).toString(),
+ getSettings()->value( "Value" ).toString() );
+ }
+ getSettings()->endArray();
+
+ /* Load defaults ones if we have no combos */
+ if( i_size == 0 )
+ {
+ profileCombo->addItem( PROFILE_NAME_1, QString( VALUE_1 ) );
+ profileCombo->addItem( PROFILE_NAME_2, QString( VALUE_2 ) );
+ profileCombo->addItem( PROFILE_NAME_3, QString( VALUE_3 ) );
+ }
+ profileCombo->setCurrentIndex( -1 );
+
+ /* Drag and Drop */
+ editorView = new QQuickWidget(p_intf->p_sys->p_mi->getEngine(),this);
+ editorView->setClearColor(Qt::transparent);
+ QQmlContext *rootCtx = editorView->rootContext();
+ QQmlContext *p_mi_rootCtx = p_intf->p_sys->p_mi->getRootCtx();
+
+ rootCtx->setContextProperty( "mainctx", p_mi_rootCtx->contextProperty("mainctx"));
+ rootCtx->setContextProperty( "player", p_mi_rootCtx->contextProperty("player") );
+ rootCtx->setContextProperty( "settings", p_mi_rootCtx->contextProperty("settings"));
+ rootCtx->setContextProperty( "medialib", p_mi_rootCtx->contextProperty("medialib"));
+ rootCtx->setContextProperty( "recentsMedias", p_mi_rootCtx->contextProperty("recentsMedias"));
+ rootCtx->setContextProperty( "rootWindow", p_mi_rootCtx->contextProperty("rootWindow"));
+ rootCtx->setContextProperty( "toolbareditor", this);
+
+ editorView->setSource( QUrl ( QStringLiteral("qrc:/dialogs/ToolbarEditor.qml") ) );
+
+ mainLayout->addWidget(editorView, 0, 0);
+
+ editorView->setResizeMode( QQuickWidget::SizeRootObjectToView );
+
+ mainLayout->addWidget( editorView, 1, 0, 1, 9 );
+ editorView->show();
+
+ /* Buttons */
+ QDialogButtonBox *okCancel = new QDialogButtonBox;
+ QPushButton *okButton = new QPushButton( qtr( "Cl&ose" ), this );
+ okButton->setDefault( true );
+ QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ), this );
+ okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
+ okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
+
+ BUTTONACT( deleteButton, deleteProfile() );
+ BUTTONACT( newButton, newProfile() );
+ CONNECT( profileCombo, currentIndexChanged( int ), this, changeProfile( int ) );
+ BUTTONACT( okButton, close() );
+ BUTTONACT( cancelButton, cancel() );
+ mainLayout->addWidget( okCancel, 2, 0, 1, 9 );
+}
+ToolbarEditorDialog::~ToolbarEditorDialog()
+{
+ getSettings()->beginWriteArray( "ToolbarProfiles" );
+ for( int i = 0; i < profileCombo->count(); i++ )
+ {
+ getSettings()->setArrayIndex(i);
+ getSettings()->setValue( "ProfileName", profileCombo->itemText( i ) );
+ getSettings()->setValue( "Value", profileCombo->itemData( i ) );
+ }
+ getSettings()->endArray();
+}
+
+void ToolbarEditorDialog::close()
+{
+ emit saveConfig();
+ accept();
+}
+
+void ToolbarEditorDialog::cancel()
+{
+ reject();
+}
+
+void ToolbarEditorDialog::newProfile()
+{
+ bool ok;
+ QString name = QInputDialog::getText( this, qtr( "Profile Name" ),
+ qtr( "Please enter the new profile name." ), QLineEdit::Normal, 0, &ok );
+ if( !ok ) return;
+
+ QVariant config;
+ QMetaObject::invokeMethod(editorView->rootObject(),"getConfig",
+ Q_RETURN_ARG(QVariant, config));
+
+ profileCombo->addItem( name, config.toString() );
+ profileCombo->setCurrentIndex( profileCombo->count() - 1 );
+}
+
+void ToolbarEditorDialog::deleteProfile()
+{
+ profileCombo->removeItem( profileCombo->currentIndex() );
+}
+
+void ToolbarEditorDialog::changeProfile( int i )
+{
+ QString config = profileCombo->itemData( i ).toString();
+ emit updatePlayerModel(config);
+}
+
+void ToolbarEditorDialog::deleteCursor()
+{
+ QApplication::setOverrideCursor(Qt::ForbiddenCursor);
+}
+
+void ToolbarEditorDialog::restoreCursor()
+{
+ QApplication::restoreOverrideCursor();
+}
diff --git a/modules/gui/qt/dialogs/toolbareditor.hpp b/modules/gui/qt/dialogs/toolbareditor.hpp
new file mode 100644
index 0000000000..be27ff6ac2
--- /dev/null
+++ b/modules/gui/qt/dialogs/toolbareditor.hpp
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifndef QVLC_TOOLBAREDITOR_DIALOG_H_
+#define QVLC_TOOLBAREDITOR_DIALOG_H_ 1
+
+#include "util/qvlcframe.hpp" /* QVLCDialog */
+#include "components/qml_main_context.hpp"
+#include "components/sout/profile_selector.hpp"
+
+#include <QAbstractListModel>
+#include <QVector>
+#include <QQuickWidget>
+
+class ToolbarEditorDialog : public QVLCDialog
+{
+ Q_OBJECT
+public:
+ ToolbarEditorDialog( QWidget *, intf_thread_t *);
+ virtual ~ToolbarEditorDialog();
+
+public slots:
+ Q_INVOKABLE void close();
+ Q_INVOKABLE void cancel();
+ Q_INVOKABLE void deleteCursor();
+ Q_INVOKABLE void restoreCursor();
+
+private slots:
+ void newProfile();
+ void deleteProfile();
+ void changeProfile( int );
+
+private:
+ QComboBox *profileCombo;
+ QQuickWidget *editorView;
+
+signals:
+ void updatePlayerModel(QString config);
+ void saveConfig();
+};
+
+#endif
diff --git a/modules/gui/qt/dialogs_provider.cpp b/modules/gui/qt/dialogs_provider.cpp
index 58c88a7c1f..0603d31707 100644
--- a/modules/gui/qt/dialogs_provider.cpp
+++ b/modules/gui/qt/dialogs_provider.cpp
@@ -52,6 +52,7 @@
#include "dialogs/gototime.hpp"
#include "dialogs/podcast_configuration.hpp"
#include "dialogs/toolbar.hpp"
+#include "dialogs/toolbareditor.hpp"
#include "dialogs/plugins.hpp"
#include "dialogs/epg.hpp"
#include "dialogs/errors.hpp"
@@ -314,9 +315,10 @@ void DialogsProvider::podcastConfigureDialog()
void DialogsProvider::toolbarDialog()
{
- ToolbarEditDialog *toolbarEditor = new ToolbarEditDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
+ ToolbarEditorDialog *toolbarEditor = new ToolbarEditorDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf);
if( toolbarEditor->exec() == QDialog::Accepted )
emit toolBarConfUpdated();
+ delete toolbarEditor;
}
void DialogsProvider::pluginDialog()
More information about the vlc-commits
mailing list