mirror of
https://github.com/FAUSheppy/speech-server-client-qt
synced 2025-12-06 00:41:35 +01:00
implement configuration window
This commit is contained in:
92
settings.cpp
Normal file
92
settings.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "settings.h"
|
||||
#include "ui_settings.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
#include <settingkeys.h>
|
||||
|
||||
Settings::Settings(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::settings)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
configLineEditMap = new QHash<QString, QLineEdit*>();
|
||||
QSettings mySettings;
|
||||
|
||||
/* config options */
|
||||
QStringList *configOptions = new QStringList();
|
||||
configOptions->append("Host");
|
||||
configOptions->append("Port");
|
||||
configOptions->append("Protokoll");
|
||||
configOptions->append("Transcript Ordner");
|
||||
configOptions->append("Username");
|
||||
configOptions->append("Passwort");
|
||||
|
||||
/* config option keys */
|
||||
QStringList *configOptionsKeys = new QStringList();
|
||||
configOptionsKeys->append(SETTING_HOST);
|
||||
configOptionsKeys->append(SETTING_PORT);
|
||||
configOptionsKeys->append(SETTING_PROTO);
|
||||
configOptionsKeys->append(SETTING_SAVE_DIR);
|
||||
configOptionsKeys->append(SETTING_USER);
|
||||
configOptionsKeys->append(SETTING_PASS);
|
||||
|
||||
/* config options layout */
|
||||
auto cw = this->findChild<QWidget*>("centralwidget");
|
||||
QGridLayout *layout = static_cast<QGridLayout*>(cw->layout());
|
||||
|
||||
for(int i = 0; i < configOptions->length(); i++){
|
||||
|
||||
/* create widgets */
|
||||
QLabel *label = new QLabel(this);
|
||||
label->setText(configOptions->at(i));
|
||||
QLineEdit *edit = new QLineEdit();
|
||||
edit->setText(mySettings.value(configOptionsKeys->at(i)).toString());
|
||||
|
||||
/* add widgets to layout */
|
||||
layout->addWidget(label, i, 0);
|
||||
layout->addWidget(edit, i, 1);
|
||||
|
||||
/* set stretch factors */
|
||||
layout->setColumnStretch(0, 1);
|
||||
layout->setColumnStretch(1, 1);
|
||||
|
||||
/* remeber options for laters save */
|
||||
configLineEditMap->insert(configOptionsKeys->at(i), edit);
|
||||
}
|
||||
|
||||
/* buttons */
|
||||
auto ok = new QPushButton("Ok");
|
||||
auto cancle = new QPushButton("Cancle");
|
||||
|
||||
layout->addWidget(ok, configOptions->length(), 0);
|
||||
layout->addWidget(cancle, configOptions->length(), 1);
|
||||
|
||||
connect(ok, SIGNAL(released()), this, SLOT(okClose()));
|
||||
connect(cancle, SIGNAL(released()), this, SLOT(cancleClose()));
|
||||
}
|
||||
|
||||
void Settings::cancleClose(){
|
||||
if(false){
|
||||
// TODO warning
|
||||
}
|
||||
this->close();
|
||||
}
|
||||
|
||||
void Settings::okClose(){
|
||||
QSettings mySettings;
|
||||
for(auto key : configLineEditMap->keys()){
|
||||
QString input = configLineEditMap->take(key)->text();
|
||||
if(input.compare("") != 0){
|
||||
mySettings.setValue(key, input);
|
||||
}
|
||||
}
|
||||
this->close();
|
||||
}
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
Reference in New Issue
Block a user