Commit ce94cb38 authored by Aleks Kissinger's avatar Aleks Kissinger

set window geometry after showing it for the first time

parent 0755b736
......@@ -46,19 +46,7 @@ MainWindow::MainWindow(QWidget *parent) :
_menu->setParent(this);
setMenuBar(_menu);
QVariant geom = settings.value(QString("geometry-main-qt") + qVersion());
QVariant state = settings.value(QString("windowState-main-qt") + qVersion());
if (geom.isValid()) {
restoreGeometry(geom.toByteArray());
}
if (state.isValid()) {
restoreState(state.toByteArray(), 2);
} else {
addDockWidget(Qt::RightDockWidgetArea, _stylePalette);
resizeDocks({_stylePalette}, {130}, Qt::Horizontal);
}
// initially, the source view should be collapsed
QList<int> sz = ui->splitter->sizes();
......@@ -76,6 +64,15 @@ MainWindow::MainWindow(QWidget *parent) :
#else
ui->tikzSource->setTabStopWidth(20);
#endif
QVariant state = settings.value(QString("windowState-main-qt") + qVersion());
if (state.isValid()) {
restoreState(state.toByteArray(), 2);
} else {
addDockWidget(Qt::RightDockWidgetArea, _stylePalette);
resizeDocks({_stylePalette}, {130}, Qt::Horizontal);
}
}
MainWindow::~MainWindow()
......@@ -84,6 +81,18 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::restorePosition()
{
QSettings settings("tikzit", "tikzit");
QVariant geom = settings.value(QString("geometry-main-qt") + qVersion());
if (geom.isValid()) {
restoreGeometry(geom.toByteArray());
}
}
void MainWindow::open(QString fileName)
{
_tikzDocument->open(fileName);
......
......@@ -29,6 +29,7 @@ public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void restorePosition();
void open(QString fileName);
int windowId() const;
TikzView *tikzView() const;
......
......@@ -41,15 +41,10 @@ PreviewWindow::PreviewWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::PreviewWindow)
{
QSettings settings("tikzit", "tikzit");
ui->setupUi(this);
QVariant geom = settings.value(QString("geometry-preview-qt") + qVersion());
if (geom.isValid()) {
restoreGeometry(geom.toByteArray());
}
ui->setupUi(this);
_positionRestored = false;
_doc = nullptr;
_loader = new QLabel(ui->tabWidget->tabBar());
......@@ -90,6 +85,20 @@ PreviewWindow::~PreviewWindow()
delete ui;
}
void PreviewWindow::restorePosition()
{
// only restore position 1 time
if (_positionRestored) return;
QSettings settings("tikzit", "tikzit");
QVariant geom = settings.value(QString("geometry-preview-qt") + qVersion());
if (geom.isValid()) {
restoreGeometry(geom.toByteArray());
}
_positionRestored = true;
}
void PreviewWindow::setPdf(QString file)
{
// use loadFromData to avoid holding a lock on the PDF file in windows
......
......@@ -46,6 +46,7 @@ public:
};
explicit PreviewWindow(QWidget *parent = nullptr);
~PreviewWindow() override;
void restorePosition();
void setPdf(QString file);
QString preparePreview(QString tikz);
QPlainTextEdit *outputTextEdit();
......@@ -67,6 +68,7 @@ private:
Ui::PreviewWindow *ui;
PdfDocument *_doc;
QLabel *_loader;
bool _positionRestored;
};
#endif // PREVIEWWINDOW_H
......@@ -61,6 +61,7 @@ void Tikzit::init()
//_stylePalette->show();
_windows << new MainWindow();
_windows[0]->show();
_windows[0]->restorePosition();
_styleFile = "";
_styleFilePath = "";
......@@ -187,6 +188,7 @@ void Tikzit::newDoc()
{
MainWindow *w = new MainWindow();
w->show();
w->restorePosition();
_windows << w;
}
......@@ -250,6 +252,7 @@ void Tikzit::open(QString fileName)
MainWindow *w = new MainWindow();
_windows << w;
w->show();
w->restorePosition();
w->open(fileName);
}
}
......@@ -437,7 +440,12 @@ void Tikzit::makePreview()
} else {
_latex->makePreview(activeWindow()->tikzSource());
}
_preview->show();
// restores position from settings the first time this is called, otherwise
// do nothing.
_preview->restorePosition();
_preview->raise();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment