Added a SettingsDialog with a "Server" tab to configure the server settings.
This commit is contained in:
61
dialogs/settingsdialog.cpp
Normal file
61
dialogs/settingsdialog.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include "settingsdialog.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QTabWidget>
|
||||
|
||||
SettingsDialog::SettingsDialog(QWidget* parent)
|
||||
: AbstractDialog(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, parent) {}
|
||||
|
||||
void SettingsDialog::createContent() {
|
||||
if (m_contentContainer) {
|
||||
delete m_contentContainer;
|
||||
}
|
||||
|
||||
const QString dialogTitle = tr("Settings - ");
|
||||
const QString applicationName = QCoreApplication::applicationName();
|
||||
|
||||
setWindowTitle(dialogTitle + applicationName);
|
||||
setModal(true);
|
||||
setGeometry(0, 0, 350, 250);
|
||||
QGridLayout* serverLayout = new QGridLayout();
|
||||
QLabel* urlLabel = new QLabel("Server URL:");
|
||||
m_urlEdit = new QLineEdit();
|
||||
serverLayout->addWidget(urlLabel, 0, 0);
|
||||
serverLayout->addWidget(m_urlEdit, 0, 1);
|
||||
QLabel* emailLabel = new QLabel("Email:");
|
||||
m_emailEdit = new QLineEdit();
|
||||
serverLayout->addWidget(emailLabel, 1, 0);
|
||||
serverLayout->addWidget(m_emailEdit, 1, 1);
|
||||
QLabel* passwordLabel = new QLabel("Password:");
|
||||
m_passwordEdit = new QLineEdit();
|
||||
m_passwordEdit->setEchoMode(QLineEdit::Password);
|
||||
serverLayout->addWidget(passwordLabel, 2, 0);
|
||||
serverLayout->addWidget(m_passwordEdit, 2, 1);
|
||||
|
||||
QWidget* serverTab = new QWidget();
|
||||
serverTab->setLayout(serverLayout);
|
||||
|
||||
QTabWidget* widget = new QTabWidget();
|
||||
widget->addTab(serverTab, "Server");
|
||||
|
||||
m_contentContainer = widget;
|
||||
m_outerLayout->insertWidget(0, m_contentContainer);
|
||||
}
|
||||
|
||||
void SettingsDialog::fillContent(const QVariantMap& settings) {
|
||||
m_urlEdit->setText(settings.value("url").toString());
|
||||
m_emailEdit->setText(settings.value("email").toString());
|
||||
m_passwordEdit->setText(settings.value("password").toString());
|
||||
}
|
||||
|
||||
QVariantMap SettingsDialog::getSettings() const {
|
||||
QVariantMap result;
|
||||
result.insert("url", m_urlEdit->text());
|
||||
result.insert("email", m_emailEdit->text());
|
||||
result.insert("password", m_passwordEdit->text());
|
||||
|
||||
return result;
|
||||
}
|
||||
23
dialogs/settingsdialog.h
Normal file
23
dialogs/settingsdialog.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef SETTINGSDIALOG_H
|
||||
#define SETTINGSDIALOG_H
|
||||
|
||||
#include "abstractdialog.h"
|
||||
|
||||
class QLineEdit;
|
||||
|
||||
class SettingsDialog : public AbstractDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SettingsDialog(QWidget* parent = nullptr);
|
||||
|
||||
void createContent() override;
|
||||
void fillContent(const QVariantMap& settings);
|
||||
QVariantMap getSettings() const;
|
||||
|
||||
private:
|
||||
QLineEdit* m_urlEdit = nullptr;
|
||||
QLineEdit* m_emailEdit = nullptr;
|
||||
QLineEdit* m_passwordEdit = nullptr;
|
||||
};
|
||||
|
||||
#endif // SETTINGSDIALOG_H
|
||||
Reference in New Issue
Block a user