auto save configuration
This commit is contained in:
parent
5fc50a524c
commit
152873d860
|
@ -12,6 +12,9 @@ QT_BEGIN_NAMESPACE
|
||||||
namespace Ui { class MainWindow; }
|
namespace Ui { class MainWindow; }
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow {
|
class MainWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -23,6 +26,9 @@ protected:
|
||||||
virtual void closeEvent(QCloseEvent* event) override;
|
virtual void closeEvent(QCloseEvent* event) override;
|
||||||
virtual void resizeEvent(QResizeEvent *event) override;
|
virtual void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void resetSaveTimer();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void toggleMainswitch(bool);
|
void toggleMainswitch(bool);
|
||||||
void aatoggled(bool);
|
void aatoggled(bool);
|
||||||
|
@ -34,6 +40,8 @@ private slots:
|
||||||
void applyRunes();
|
void applyRunes();
|
||||||
void autoWriteChanged();
|
void autoWriteChanged();
|
||||||
|
|
||||||
|
void saveConfig();
|
||||||
|
void initDone();
|
||||||
signals:
|
signals:
|
||||||
void requestTabChange(int tabindex);
|
void requestTabChange(int tabindex);
|
||||||
|
|
||||||
|
@ -42,7 +50,10 @@ private:
|
||||||
void onPosChange(Position newpos); // to trigger the signal from a QObject
|
void onPosChange(Position newpos); // to trigger the signal from a QObject
|
||||||
void onFail(); // get triggerd, when the autoacceptor fails (lost connection)
|
void onFail(); // get triggerd, when the autoacceptor fails (lost connection)
|
||||||
|
|
||||||
|
bool loading;
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
QTimer* saveTimer;
|
||||||
|
QTimer* initDoneTimer;
|
||||||
std::thread lolaathread;
|
std::thread lolaathread;
|
||||||
DataDragon dd;
|
DataDragon dd;
|
||||||
Config conf;
|
Config conf;
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include <Log.h>
|
#include <Log.h>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), dd(QLocale().name().toStdString()),
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui(new Ui::MainWindow), saveTimer(new QTimer(this)), dd(QLocale().name().toStdString()),
|
||||||
lolaa(conf.getConfig(), dd, std::bind(&MainWindow::onFail, this), std::bind(&MainWindow::onPosChange, this, std::placeholders::_1)) {
|
lolaa(conf.getConfig(), dd, std::bind(&MainWindow::onFail, this), std::bind(&MainWindow::onPosChange, this, std::placeholders::_1)) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
saveTimer->setInterval(std::chrono::minutes(1));
|
||||||
|
saveTimer->setSingleShot(true);
|
||||||
|
QObject::connect(saveTimer, &QTimer::timeout, this, &MainWindow::saveConfig);
|
||||||
|
|
||||||
ui->copyrightlabel->setText(ui->copyrightlabel->text().arg(LOLAA_VERSION));
|
ui->copyrightlabel->setText(ui->copyrightlabel->text().arg(LOLAA_VERSION));
|
||||||
|
|
||||||
lolaa.setOnRuneChangeFunc(std::bind(&RuneDisplay::setRunes, ui->runedisplay, std::placeholders::_1));
|
lolaa.setOnRuneChangeFunc(std::bind(&RuneDisplay::setRunes, ui->runedisplay, std::placeholders::_1));
|
||||||
|
@ -19,8 +25,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||||
SettingsTab* tab = (SettingsTab*) ui->tabWidget->widget(tabnr);
|
SettingsTab* tab = (SettingsTab*) ui->tabWidget->widget(tabnr);
|
||||||
tab->setup(*rc.getPositionConfig(tab->getPosition()), &dd);
|
tab->setup(*rc.getPositionConfig(tab->getPosition()), &dd);
|
||||||
|
|
||||||
QObject::connect(tab, SIGNAL( changed(Position, LolAutoAccept::State) ), this, SLOT( tabchanged(Position, LolAutoAccept::State) ));
|
QObject::connect(tab, &SettingsTab::changed, this, &MainWindow::tabchanged);
|
||||||
QObject::connect(tab, SIGNAL( toggled(Position, LolAutoAccept::State, bool) ), this, SLOT( tabtoggled(Position, LolAutoAccept::State, bool) ));
|
QObject::connect(tab, &SettingsTab::toggled, this, &MainWindow::tabtoggled);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->enableAll->setChecked(rc.enabledAutoAccept);
|
ui->enableAll->setChecked(rc.enabledAutoAccept);
|
||||||
|
@ -34,6 +40,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||||
lolaa.setAutoWriteText(rc.enabledAutoWrite, rc.autoWriteText);
|
lolaa.setAutoWriteText(rc.enabledAutoWrite, rc.autoWriteText);
|
||||||
|
|
||||||
resizeEvent(nullptr);
|
resizeEvent(nullptr);
|
||||||
|
|
||||||
|
// a timer to delay the loading flag a short time until all other signals are processed
|
||||||
|
initDoneTimer = new QTimer(this);
|
||||||
|
initDoneTimer->setSingleShot(true);
|
||||||
|
initDoneTimer->setInterval(std::chrono::milliseconds(1)); // schedule for first event loop
|
||||||
|
QObject::connect(initDoneTimer, &QTimer::timeout, this, &MainWindow::initDone, Qt::QueuedConnection);
|
||||||
|
initDoneTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
|
@ -53,8 +66,13 @@ void MainWindow::resizeEvent([[maybe_unused]] QResizeEvent *event) {
|
||||||
ui->verticalLayoutWidget->setMinimumSize(ui->centralwidget->size());
|
ui->verticalLayoutWidget->setMinimumSize(ui->centralwidget->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::resetSaveTimer() {
|
||||||
|
saveTimer->start();
|
||||||
|
qDebug() << "resetTimer";
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::toggleMainswitch(bool state) {
|
void MainWindow::toggleMainswitch(bool state) {
|
||||||
Log::info << "mainswitch toggled: " << state;
|
qDebug() << "mainswitch toggled: " << state;
|
||||||
|
|
||||||
if(state) {
|
if(state) {
|
||||||
if(!lolaa.init()) {
|
if(!lolaa.init()) {
|
||||||
|
@ -78,44 +96,73 @@ void MainWindow::toggleMainswitch(bool state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::aatoggled(bool state) {
|
void MainWindow::aatoggled(bool state) {
|
||||||
Log::info << "enableAll checkbox toggled " << state;
|
if( loading ) return;
|
||||||
|
|
||||||
|
qDebug() << "enableAll checkbox toggled " << state;
|
||||||
|
|
||||||
lolaa.setEnabled(state, LolAutoAccept::State::LOBBY);
|
lolaa.setEnabled(state, LolAutoAccept::State::LOBBY);
|
||||||
conf.getConfig().enabledAutoAccept = state;
|
conf.getConfig().enabledAutoAccept = state;
|
||||||
|
resetSaveTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::smitewarntoggled(bool state) {
|
void MainWindow::smitewarntoggled(bool state) {
|
||||||
Log::info << "smitewarn checkbox toggled " << state;
|
if( loading ) return;
|
||||||
|
|
||||||
|
qDebug() << "smitewarn checkbox toggled " << state;
|
||||||
|
|
||||||
lolaa.setSmiteWarn(state);
|
lolaa.setSmiteWarn(state);
|
||||||
conf.getConfig().enabledSmiteWarn = state;
|
conf.getConfig().enabledSmiteWarn = state;
|
||||||
|
resetSaveTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::tabtoggled(Position p, LolAutoAccept::State s, bool state) {
|
void MainWindow::tabtoggled(Position p, LolAutoAccept::State s, bool state) {
|
||||||
Log::info << "checkbox toggled " << state << " position: " << p << " state: " << (int) s;
|
if( loading ) return;
|
||||||
|
|
||||||
|
qDebug() << "checkbox toggled " << state << " position: " << p << " state: " << (int) s;
|
||||||
|
|
||||||
lolaa.setEnabled(state, s);
|
lolaa.setEnabled(state, s);
|
||||||
lolaa.reload();
|
lolaa.reload();
|
||||||
|
resetSaveTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::tabchanged(Position p, LolAutoAccept::State s) {
|
void MainWindow::tabchanged(Position p, LolAutoAccept::State s) {
|
||||||
Log::info << "edited position: " << p << " state: " << (int) s;
|
if( loading ) return;
|
||||||
|
|
||||||
|
qDebug() << "edited position: " << p << " state: " << (int) s;
|
||||||
|
|
||||||
lolaa.reload();
|
lolaa.reload();
|
||||||
|
resetSaveTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::applyRunes() {
|
void MainWindow::applyRunes() {
|
||||||
Log::info << "applyRunes pressed";
|
qDebug() << "applyRunes pressed";
|
||||||
|
|
||||||
lolaa.applyRunes();
|
lolaa.applyRunes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::autoWriteChanged() {
|
void MainWindow::autoWriteChanged() {
|
||||||
|
if( loading ) return;
|
||||||
|
|
||||||
bool enabled = ui->enableAutoWrite->isChecked();
|
bool enabled = ui->enableAutoWrite->isChecked();
|
||||||
const std::string text = ui->autoWriteText->toPlainText().toStdString();
|
const std::string text = ui->autoWriteText->toPlainText().toStdString();
|
||||||
|
|
||||||
lolaa.setAutoWriteText(enabled, text);
|
lolaa.setAutoWriteText(enabled, text);
|
||||||
|
|
||||||
conf.getConfig().enabledAutoWrite = enabled;
|
conf.getConfig().enabledAutoWrite = enabled;
|
||||||
conf.getConfig().autoWriteText = text;
|
conf.getConfig().autoWriteText = text;
|
||||||
|
|
||||||
|
resetSaveTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::saveConfig() {
|
||||||
|
conf.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::initDone() {
|
||||||
|
loading = false;
|
||||||
|
initDoneTimer->deleteLater();
|
||||||
|
initDoneTimer = nullptr;
|
||||||
|
qDebug() << "loading done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onPosChange(Position newpos) {
|
void MainWindow::onPosChange(Position newpos) {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>579</width>
|
<width>579</width>
|
||||||
<height>633</height>
|
<height>788</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
<height>809</height>
|
<height>809</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout" columnstretch="2,1">
|
||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
<enum>QLayout::SetDefaultConstraint</enum>
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
<enum>QTabWidget::Rounded</enum>
|
<enum>QTabWidget::Rounded</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>4</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="elideMode">
|
<property name="elideMode">
|
||||||
<enum>Qt::ElideNone</enum>
|
<enum>Qt::ElideNone</enum>
|
||||||
|
|
Loading…
Reference in New Issue