auto save configuration
This commit is contained in:
parent
5fc50a524c
commit
152873d860
|
@ -12,6 +12,9 @@ QT_BEGIN_NAMESPACE
|
|||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class QTimer;
|
||||
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -23,6 +26,9 @@ protected:
|
|||
virtual void closeEvent(QCloseEvent* event) override;
|
||||
virtual void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
public slots:
|
||||
void resetSaveTimer();
|
||||
|
||||
private slots:
|
||||
void toggleMainswitch(bool);
|
||||
void aatoggled(bool);
|
||||
|
@ -34,6 +40,8 @@ private slots:
|
|||
void applyRunes();
|
||||
void autoWriteChanged();
|
||||
|
||||
void saveConfig();
|
||||
void initDone();
|
||||
signals:
|
||||
void requestTabChange(int tabindex);
|
||||
|
||||
|
@ -42,7 +50,10 @@ private:
|
|||
void onPosChange(Position newpos); // to trigger the signal from a QObject
|
||||
void onFail(); // get triggerd, when the autoacceptor fails (lost connection)
|
||||
|
||||
bool loading;
|
||||
Ui::MainWindow *ui;
|
||||
QTimer* saveTimer;
|
||||
QTimer* initDoneTimer;
|
||||
std::thread lolaathread;
|
||||
DataDragon dd;
|
||||
Config conf;
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#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)) {
|
||||
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));
|
||||
|
||||
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);
|
||||
tab->setup(*rc.getPositionConfig(tab->getPosition()), &dd);
|
||||
|
||||
QObject::connect(tab, SIGNAL( changed(Position, LolAutoAccept::State) ), this, SLOT( tabchanged(Position, LolAutoAccept::State) ));
|
||||
QObject::connect(tab, SIGNAL( toggled(Position, LolAutoAccept::State, bool) ), this, SLOT( tabtoggled(Position, LolAutoAccept::State, bool) ));
|
||||
QObject::connect(tab, &SettingsTab::changed, this, &MainWindow::tabchanged);
|
||||
QObject::connect(tab, &SettingsTab::toggled, this, &MainWindow::tabtoggled);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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() {
|
||||
|
@ -53,8 +66,13 @@ void MainWindow::resizeEvent([[maybe_unused]] QResizeEvent *event) {
|
|||
ui->verticalLayoutWidget->setMinimumSize(ui->centralwidget->size());
|
||||
}
|
||||
|
||||
void MainWindow::resetSaveTimer() {
|
||||
saveTimer->start();
|
||||
qDebug() << "resetTimer";
|
||||
}
|
||||
|
||||
void MainWindow::toggleMainswitch(bool state) {
|
||||
Log::info << "mainswitch toggled: " << state;
|
||||
qDebug() << "mainswitch toggled: " << state;
|
||||
|
||||
if(state) {
|
||||
if(!lolaa.init()) {
|
||||
|
@ -78,44 +96,73 @@ void MainWindow::toggleMainswitch(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);
|
||||
conf.getConfig().enabledAutoAccept = state;
|
||||
resetSaveTimer();
|
||||
}
|
||||
|
||||
void MainWindow::smitewarntoggled(bool state) {
|
||||
Log::info << "smitewarn checkbox toggled " << state;
|
||||
if( loading ) return;
|
||||
|
||||
qDebug() << "smitewarn checkbox toggled " << state;
|
||||
|
||||
lolaa.setSmiteWarn(state);
|
||||
conf.getConfig().enabledSmiteWarn = state;
|
||||
resetSaveTimer();
|
||||
}
|
||||
|
||||
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.reload();
|
||||
resetSaveTimer();
|
||||
}
|
||||
|
||||
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();
|
||||
resetSaveTimer();
|
||||
}
|
||||
|
||||
void MainWindow::applyRunes() {
|
||||
Log::info << "applyRunes pressed";
|
||||
qDebug() << "applyRunes pressed";
|
||||
|
||||
lolaa.applyRunes();
|
||||
}
|
||||
|
||||
void MainWindow::autoWriteChanged() {
|
||||
if( loading ) return;
|
||||
|
||||
bool enabled = ui->enableAutoWrite->isChecked();
|
||||
const std::string text = ui->autoWriteText->toPlainText().toStdString();
|
||||
|
||||
lolaa.setAutoWriteText(enabled, text);
|
||||
|
||||
conf.getConfig().enabledAutoWrite = enabled;
|
||||
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) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>579</width>
|
||||
<height>633</height>
|
||||
<height>788</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -35,7 +35,7 @@
|
|||
<height>809</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="2,1">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
|
@ -76,7 +76,7 @@
|
|||
<enum>QTabWidget::Rounded</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="elideMode">
|
||||
<enum>Qt::ElideNone</enum>
|
||||
|
|
Loading…
Reference in New Issue