From c88b4129ffd06b9a230a2621cbcf3610905fc15c Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 1 Jun 2018 16:25:09 +0200 Subject: Add ProfileManagerDialog --- plugins/ProfileEditor/CMakeLists.txt | 6 +- .../ProfileEditor/forms/profilemanagerdialog.cpp | 45 +++++++++++ plugins/ProfileEditor/forms/profilemanagerdialog.h | 31 ++++++++ .../ProfileEditor/forms/profilemanagerdialog.ui | 89 ++++++++++++++++++++++ plugins/ProfileEditor/profileeditorplugin.cpp | 8 +- plugins/ProfileEditor/profileeditorplugin.h | 2 +- plugins/interfaces.h | 2 +- 7 files changed, 178 insertions(+), 5 deletions(-) create mode 100644 plugins/ProfileEditor/forms/profilemanagerdialog.cpp create mode 100644 plugins/ProfileEditor/forms/profilemanagerdialog.h create mode 100644 plugins/ProfileEditor/forms/profilemanagerdialog.ui (limited to 'plugins') diff --git a/plugins/ProfileEditor/CMakeLists.txt b/plugins/ProfileEditor/CMakeLists.txt index ad4c457..2fa3ba8 100644 --- a/plugins/ProfileEditor/CMakeLists.txt +++ b/plugins/ProfileEditor/CMakeLists.txt @@ -10,7 +10,11 @@ add_library(ProfileEditorPlugin SHARED profileeditorplugin.h forms/profileview.cpp forms/profileview.h - forms/profileview.ui) + forms/profileview.ui + forms/profilemanagerdialog.cpp + forms/profilemanagerdialog.h + forms/profilemanagerdialog.ui +) target_include_directories(ProfileEditorPlugin PRIVATE ..) diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp new file mode 100644 index 0000000..c5fec2b --- /dev/null +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp @@ -0,0 +1,45 @@ +#include "profilemanagerdialog.h" +#include "ui_profilemanagerdialog.h" +#include +#include +#include "profileview.h" + +ProfileManagerDialog::ProfileManagerDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ProfileManagerDialog) +{ + ui->setupUi(this); + + connect(ui->listWidget, &QListWidget::itemPressed, this, &ProfileManagerDialog::showProfile); + showProfile(nullptr); +} + +ProfileManagerDialog::~ProfileManagerDialog() +{ + delete ui; +} + +void ProfileManagerDialog::addProfile(const QString &name, QWebEngineProfile *profile) +{ + profiles.insert(name, profile); + ui->listWidget->addItem(name); +} + +void ProfileManagerDialog::showProfile(QListWidgetItem *item) +{ + // clear out groupbox layout + QLayoutItem *i; + while((i = ui->groupBox->layout()->takeAt(0)) != nullptr) { + delete i->widget(); + delete i; + } + + if(item == nullptr) { + ui->groupBox->setVisible(false); + return; + } + ui->groupBox->setVisible(true); + + auto *v = new ProfileView(profiles.value(item->text()), this); + ui->groupBox->layout()->addWidget(v); +} diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.h b/plugins/ProfileEditor/forms/profilemanagerdialog.h new file mode 100644 index 0000000..ed79824 --- /dev/null +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.h @@ -0,0 +1,31 @@ +#ifndef PROFILEMANAGERDIALOG_H +#define PROFILEMANAGERDIALOG_H + +#include +#include + +namespace Ui { +class ProfileManagerDialog; +} + +class QWebEngineProfile; +class QListWidgetItem; +class ProfileManagerDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ProfileManagerDialog(QWidget *parent = 0); + ~ProfileManagerDialog(); + + void addProfile(const QString &name, QWebEngineProfile *profile); + +private slots: + void showProfile(QListWidgetItem *item); + +private: + Ui::ProfileManagerDialog *ui; + QHash profiles; +}; + +#endif // PROFILEMANAGERDIALOG_H diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.ui b/plugins/ProfileEditor/forms/profilemanagerdialog.ui new file mode 100644 index 0000000..ae3829a --- /dev/null +++ b/plugins/ProfileEditor/forms/profilemanagerdialog.ui @@ -0,0 +1,89 @@ + + + ProfileManagerDialog + + + + 0 + 0 + 400 + 300 + + + + Profile Manager + + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + buttonBox + accepted() + ProfileManagerDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ProfileManagerDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/plugins/ProfileEditor/profileeditorplugin.cpp b/plugins/ProfileEditor/profileeditorplugin.cpp index b5e772f..041dbe7 100644 --- a/plugins/ProfileEditor/profileeditorplugin.cpp +++ b/plugins/ProfileEditor/profileeditorplugin.cpp @@ -8,6 +8,7 @@ #include "profileeditorplugin.h" #include "forms/profileview.h" +#include "forms/profilemanagerdialog.h" #include QHash > ProfileEditorPlugin::commands() @@ -20,9 +21,12 @@ QHash > ProfileEditorPlugin::commands() return hash; } -QDialog *ProfileEditorPlugin::createWidget(QWebEngineProfile *profile, QWidget *parent) +QDialog *ProfileEditorPlugin::createWidget(QHash profiles, QWidget *parent) { - auto *widget = new ProfileView(profile, parent); + auto *widget = new ProfileManagerDialog(parent); + for(const QString &name : profiles.keys()) { + widget->addProfile(name, profiles.value(name)); + } widget->setAttribute(Qt::WA_DeleteOnClose, true); return widget; } diff --git a/plugins/ProfileEditor/profileeditorplugin.h b/plugins/ProfileEditor/profileeditorplugin.h index 4f88e1b..e026bbe 100644 --- a/plugins/ProfileEditor/profileeditorplugin.h +++ b/plugins/ProfileEditor/profileeditorplugin.h @@ -24,7 +24,7 @@ public: QHash> commands() override; // ProfileInterface - QDialog *createWidget(QWebEngineProfile *profile, QWidget *parent) override; + QDialog *createWidget(QHash profiles, QWidget *parent) override; }; #endif //PROFILEEDITOR_PLUGIN_H diff --git a/plugins/interfaces.h b/plugins/interfaces.h index 196da0b..4e361ab 100644 --- a/plugins/interfaces.h +++ b/plugins/interfaces.h @@ -34,7 +34,7 @@ class ProfileInterface { public: virtual ~ProfileInterface() = default; - virtual QDialog *createWidget(QWebEngineProfile *profile, QWidget *parent) = 0; + virtual QDialog *createWidget(QHash profiles, QWidget *parent) = 0; }; #define PluginInterfaceIid "net.iserlohn-fortress.smolbote.PluginInterface" -- cgit v1.2.1