diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2020-10-19 20:36:51 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2020-10-19 20:36:51 +0000 |
| commit | 6baa843a2a0bdf143617df269129d81dae0a3a38 (patch) | |
| tree | 9a650b4349c1129c8c20b4536228bb838eb9ee67 /src/qmmpui | |
| parent | b0ab8e75df1bb8c5752ebf3ed60334f1134b04f3 (diff) | |
| download | qmmp-6baa843a2a0bdf143617df269129d81dae0a3a38.tar.gz qmmp-6baa843a2a0bdf143617df269129d81dae0a3a38.tar.bz2 qmmp-6baa843a2a0bdf143617df269129d81dae0a3a38.zip | |
qsui: added feature to add dock widgets from plugins
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9509 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui')
| -rw-r--r-- | src/qmmpui/general.cpp | 66 | ||||
| -rw-r--r-- | src/qmmpui/general.h | 9 | ||||
| -rw-r--r-- | src/qmmpui/generalfactory.cpp | 10 | ||||
| -rw-r--r-- | src/qmmpui/generalfactory.h | 13 | ||||
| -rw-r--r-- | src/qmmpui/qmmpui.pro | 3 | ||||
| -rw-r--r-- | src/qmmpui/uihelper.cpp | 17 | ||||
| -rw-r--r-- | src/qmmpui/uihelper.h | 9 |
7 files changed, 116 insertions, 11 deletions
diff --git a/src/qmmpui/general.cpp b/src/qmmpui/general.cpp index a9c0a766f..8015dfb8c 100644 --- a/src/qmmpui/general.cpp +++ b/src/qmmpui/general.cpp @@ -22,6 +22,7 @@ #include <QDir> #include <QDialog> #include <qmmp/qmmp.h> +#include "uihelper.h" #include "qmmpuiplugincache_p.h" #include "general.h" @@ -98,6 +99,46 @@ QList<GeneralFactory *> General::enabledFactories() return list; } +QStringList General::enabledWidgets() +{ + QStringList out; + for(const GeneralFactory *f : General::enabledFactories()) + { + for(const WidgetDescription &desc : f->properties().widgets) + out << QString("%1_%2").arg(f->properties().shortName).arg(desc.id); + } + + return out; +} + +WidgetDescription General::widgetDescription(const QString &id) +{ + for(const GeneralFactory *f : General::enabledFactories()) + { + for(const WidgetDescription &desc : f->properties().widgets) + { + if(id == QString("%1_%2").arg(f->properties().shortName).arg(desc.id)) + return desc; + } + } + + return { -1, QString(), Qt::NoDockWidgetArea }; +} + +QWidget *General::createWidget(const QString &id, QWidget *parent) +{ + for(GeneralFactory *f : General::enabledFactories()) + { + for(const WidgetDescription &desc : f->properties().widgets) + { + if(id == QString("%1_%2").arg(f->properties().shortName).arg(desc.id)) + return f->createWidget(desc.id, parent); + } + } + + return nullptr; +} + QString General::file(const GeneralFactory *factory) { loadPlugins(); @@ -106,7 +147,7 @@ QString General::file(const GeneralFactory *factory) return it == m_cache->cend() ? QString() : (*it)->file(); } -void General::setEnabled(GeneralFactory* factory, bool enable) +void General::setEnabled(GeneralFactory *factory, bool enable) { loadPlugins(); if (!factories().contains(factory)) @@ -129,30 +170,43 @@ void General::setEnabled(GeneralFactory* factory, bool enable) if (enable == m_generals->keys().contains(factory)) return; + if (enable) { QObject *general = factory->create(m_parent); if(general) m_generals->insert(factory, general); + + for(const WidgetDescription &d : factory->properties().widgets) + UiHelper::instance()->addWidget(QString("%1_%2").arg(factory->properties().shortName).arg(d.id)); } - else if(m_generals->value(factory)) + else { - delete m_generals->take(factory); + for(const WidgetDescription &d : factory->properties().widgets) + UiHelper::instance()->removeWidget(QString("%1_%2").arg(factory->properties().shortName).arg(d.id)); + + if(m_generals->value(factory)) + delete m_generals->take(factory); } } -void General::showSettings(GeneralFactory* factory, QWidget* parentWidget) +void General::showSettings(GeneralFactory *factory, QWidget *parentWidget) { QDialog *dialog = factory->createConfigDialog(parentWidget); if (!dialog) return; - if (m_generals && dialog->exec() == QDialog::Accepted && m_generals->keys().contains(factory)) + if (m_generals && dialog->exec() == QDialog::Accepted) { - delete m_generals->take(factory); + if(m_generals->keys().contains(factory)) + delete m_generals->take(factory); + QObject *general = factory->create(m_parent); if(general) m_generals->insert(factory, general); + + for(const WidgetDescription &d : factory->properties().widgets) + UiHelper::instance()->updateWidget(QString("%1_%2").arg(factory->properties().shortName).arg(d.id)); } dialog->deleteLater(); } diff --git a/src/qmmpui/general.h b/src/qmmpui/general.h index 14b1af26a..9e4bc0d01 100644 --- a/src/qmmpui/general.h +++ b/src/qmmpui/general.h @@ -47,6 +47,9 @@ public: * Returns a list of the enabled general plugin factories. */ static QList<GeneralFactory *> enabledFactories(); + static QStringList enabledWidgets(); + static WidgetDescription widgetDescription(const QString &id); + static QWidget *createWidget(const QString &id, QWidget *parent); /*! * Returns plugin file path. * @param factory General plugin factory. @@ -57,13 +60,13 @@ public: * @param factory General plugin factory. * @param enable Plugin enable state (\b true - enable, \b false - disable) */ - static void setEnabled(GeneralFactory* factory, bool enable = true); + static void setEnabled(GeneralFactory *factory, bool enable = true); /*! * Shows configuration dialog and updates settings automatically. * @param factory General plugin factory. * @param parentWidget Parent widget. */ - static void showSettings(GeneralFactory* factory, QWidget* parentWidget); + static void showSettings(GeneralFactory *factory, QWidget *parentWidget); /*! * Returns \b true if general plugin is enabled, otherwise returns \b false * @param factory General plugin factory. @@ -71,6 +74,8 @@ public: static bool isEnabled(const GeneralFactory* factory); private: + General() {} + ~General() {} static void loadPlugins(); static QHash <GeneralFactory*, QObject*> *m_generals; static QObject *m_parent; diff --git a/src/qmmpui/generalfactory.cpp b/src/qmmpui/generalfactory.cpp new file mode 100644 index 000000000..d657dab64 --- /dev/null +++ b/src/qmmpui/generalfactory.cpp @@ -0,0 +1,10 @@ +#include <QString> +#include <QList> +#include <QtGlobal> +#include <QWidget> +#include "generalfactory.h" + +QWidget *GeneralFactory::createWidget(int, QWidget *) +{ + return nullptr; +} diff --git a/src/qmmpui/generalfactory.h b/src/qmmpui/generalfactory.h index 63a8a80fc..404663792 100644 --- a/src/qmmpui/generalfactory.h +++ b/src/qmmpui/generalfactory.h @@ -29,6 +29,14 @@ class QWidget; class Control; class General; +struct WidgetDescription +{ + int id; + QString name; + Qt::DockWidgetAreas allowedAreas; +}; + + /*! @brief Structure to store general plugin properies. */ struct GeneralProperties @@ -39,11 +47,13 @@ struct GeneralProperties bool hasSettings = false; /*!< Should be \b true if plugin has settings dialog, and \b false otherwise */ bool visibilityControl = false; /*!< Should be \b true if plugin can show/hide main window of the player, * and \b false otherwise */ + QList<WidgetDescription> widgets; }; + /*! @brief %General plugin interface. * @author Ilya Kotov <forkotov02@ya.ru> */ -class GeneralFactory +class QMMPUI_EXPORT GeneralFactory { public: /*! @@ -58,6 +68,7 @@ public: * Creates object of the General class. */ virtual QObject *create(QObject *parent) = 0; + virtual QWidget *createWidget(int id, QWidget *parent); /*! * Creates configuration dialog. * @param parent Parent widget. diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro index 7ed777761..41f2a2a03 100644 --- a/src/qmmpui/qmmpui.pro +++ b/src/qmmpui/qmmpui.pro @@ -115,7 +115,8 @@ SOURCES += general.cpp \ coverviewer.cpp \ metadataformattermenu.cpp \ covereditor.cpp \ - commandlinehandler.cpp + commandlinehandler.cpp \ + generalfactory.cpp FORMS += forms/detailsdialog.ui \ forms/tageditor.ui \ diff --git a/src/qmmpui/uihelper.cpp b/src/qmmpui/uihelper.cpp index 6e800b831..c01ff17bb 100644 --- a/src/qmmpui/uihelper.cpp +++ b/src/qmmpui/uihelper.cpp @@ -129,7 +129,22 @@ void UiHelper::registerMenu(UiHelper::MenuType type, QMenu *menu, bool autoHide, m_menus[type].menu->insertActions(before, m_menus[type].actions); else m_menus[type].menu->addActions(m_menus[type].actions); - m_menus[type].menu->menuAction()->setVisible(!autoHide || !m_menus[type].actions.isEmpty()); + m_menus[type].menu->menuAction()->setVisible(!autoHide || !m_menus[type].actions.isEmpty()); +} + +void UiHelper::addWidget(const QString &id) +{ + emit widgetAdded(id); +} + +void UiHelper::removeWidget(const QString &id) +{ + emit widgetRemoved(id); +} + +void UiHelper::updateWidget(const QString &id) +{ + emit widgetUpdated(id); } void UiHelper::addFiles(QWidget *parent, PlayListModel *model) diff --git a/src/qmmpui/uihelper.h b/src/qmmpui/uihelper.h index 1b1f76f69..9d31443bf 100644 --- a/src/qmmpui/uihelper.h +++ b/src/qmmpui/uihelper.h @@ -98,6 +98,11 @@ public: * @param before An action, after which the rest are added. */ void registerMenu(MenuType type, QMenu *menu, bool autoHide = false, QAction *before = nullptr); + + void addWidget(const QString &id); + void removeWidget(const QString &id); + void updateWidget(const QString &id); + /*! * Opens 'Add Files' dialog * @param parent Parent widget @@ -183,6 +188,10 @@ signals: */ void showMainWindowCalled(); + void widgetAdded(const QString &id); + void widgetRemoved(const QString &id); + void widgetUpdated(const QString &id); + private slots: void removeAction(QObject *action); void addSelectedFiles(const QStringList &files, bool play); |
