From 9bee11c5b8e2d4f5845036019918acc38b87c746 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 10 Jun 2017 20:19:22 +0200 Subject: Added new profile button --- src/forms/profilesdialog.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/forms/profilesdialog.cpp') diff --git a/src/forms/profilesdialog.cpp b/src/forms/profilesdialog.cpp index ed4c871..34bd063 100644 --- a/src/forms/profilesdialog.cpp +++ b/src/forms/profilesdialog.cpp @@ -24,6 +24,9 @@ #include "browser.h" #include #include +#include +#include +#include ProfilesDialog::ProfilesDialog(MainWindow *window, QWidget *parent) : QDialog(parent), @@ -34,8 +37,8 @@ ProfilesDialog::ProfilesDialog(MainWindow *window, QWidget *parent) : m_view = new ProfileView(0, this); // Hide the profile view because we're fancy - // Give focus to the widget because otherwise the listwidget gains focus - // this causes it to select the first item in it, which in turn triggers the signal + // Give focus to the top widget because otherwise the listwidget gains focus + // which causes it to select the first item in it, which in turn triggers the signal // and so the profile view gets shown even though the user hasn't selected anything // and so we get to be less fancy, defeating the point of the exercise // [on linux; other OS's not checked] @@ -44,9 +47,13 @@ ProfilesDialog::ProfilesDialog(MainWindow *window, QWidget *parent) : ui->setupUi(this); ui->horizontalLayout->addWidget(m_view); + ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Load")); connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(viewProfile(int))); + connect(ui->new_toolButton, SIGNAL(released()), this, SLOT(newProfile())); connect(this, SIGNAL(accepted()), this, SLOT(loadSelectedProfile())); + + loadProfiles(); } ProfilesDialog::~ProfilesDialog() @@ -54,14 +61,25 @@ ProfilesDialog::~ProfilesDialog() delete ui; } -int ProfilesDialog::exec() +void ProfilesDialog::loadProfiles() { - qDebug("Showing..."); + ui->listWidget->clear(); + for(QString name : qApp->profiles()) { QListWidgetItem *item = new QListWidgetItem(qApp->profile(name)->name(), ui->listWidget); item->setData(Qt::UserRole, name); } - return QDialog::exec(); +} + +void ProfilesDialog::newProfile() +{ + bool ok; + QString name = QInputDialog::getText(this, tr("Profile Name"), tr("Profile Name:"), QLineEdit::Normal, tr("Default"), &ok); + + if(ok) { + qApp->profile(name); + loadProfiles(); + } } void ProfilesDialog::loadSelectedProfile() -- cgit v1.2.1