Skip to content

Commit

Permalink
Added ability to save/restore scripting window size and location
Browse files Browse the repository at this point in the history
  • Loading branch information
collin80 committed Dec 3, 2015
1 parent d324177 commit 0d7490a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
34 changes: 34 additions & 0 deletions scriptingwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ ScriptingWindow::ScriptingWindow(const QVector<CANFrame> *frames, QWidget *paren
{
ui->setupUi(this);

readSettings();

modelFrames = frames;

connect(ui->btnLoadScript, &QAbstractButton::pressed, this, &ScriptingWindow::loadNewScript);
Expand Down Expand Up @@ -48,6 +50,38 @@ void ScriptingWindow::updatedFrames(int numFrames)
}
}

void ScriptingWindow::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event);
writeSettings();
}

void ScriptingWindow::readSettings()
{
QSettings settings;
if (settings.value("Main/SaveRestorePositions", false).toBool())
{
resize(settings.value("ScriptingWindow/WindowSize", QSize(860, 650)).toSize());
move(settings.value("ScriptingWindow/WindowPos", QPoint(100, 100)).toPoint());
}
}

void ScriptingWindow::writeSettings()
{
QSettings settings;

if (settings.value("Main/SaveRestorePositions", false).toBool())
{
settings.setValue("ScriptingWindow/WindowSize", size());
settings.setValue("ScriptingWindow/WindowPos", pos());
}
}

void ScriptingWindow::showEvent(QShowEvent* event)
{
QDialog::showEvent(event);
}

void ScriptingWindow::loadNewScript()
{
QString filename;
Expand Down
6 changes: 5 additions & 1 deletion scriptingwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ScriptingWindow : public QDialog

public:
explicit ScriptingWindow(const QVector<CANFrame> *frames, QWidget *parent = 0);
void showEvent(QShowEvent*);
~ScriptingWindow();

private slots:
Expand All @@ -35,8 +36,11 @@ public slots:
void sendCANFrame(const CANFrame *, int);

private:
Ui::ScriptingWindow *ui;
void closeEvent(QCloseEvent *event);
void readSettings();
void writeSettings();

Ui::ScriptingWindow *ui;
QList<ScriptContainer *> scripts;
ScriptContainer *currentScript;
const QVector<CANFrame> *modelFrames;
Expand Down
4 changes: 2 additions & 2 deletions scriptingwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>994</width>
<height>858</height>
<width>862</width>
<height>651</height>
</rect>
</property>
<property name="windowTitle">
Expand Down

0 comments on commit 0d7490a

Please sign in to comment.