From c2a80ce570e79deb88d6da803057f21ae17f86ae Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Wed, 25 May 2016 16:55:06 +0200 Subject: [PATCH] Remember auto-type window size. Resize columns once when the entry list is set. Based on https://github.com/keepassx/keepassx/pull/158 Closes #478 --- src/autotype/AutoTypeSelectDialog.cpp | 18 ++++++++++++++++-- src/autotype/AutoTypeSelectDialog.h | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/autotype/AutoTypeSelectDialog.cpp b/src/autotype/AutoTypeSelectDialog.cpp index 3e7a2476..61b534b9 100644 --- a/src/autotype/AutoTypeSelectDialog.cpp +++ b/src/autotype/AutoTypeSelectDialog.cpp @@ -20,10 +20,12 @@ #include #include #include +#include #include #include #include "autotype/AutoTypeSelectView.h" +#include "core/Config.h" #include "core/FilePath.h" #include "gui/entry/EntryModel.h" @@ -39,11 +41,14 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent) setWindowTitle(tr("Auto-Type - KeePassX")); setWindowIcon(filePath()->applicationIcon()); - QSize size(400, 250); + QRect screenGeometry = QApplication::desktop()->availableGeometry(QCursor::pos()); + QSize size = config()->get("GUI/AutoTypeSelectDialogSize", QSize(400, 250)).toSize(); + size.setWidth(qMin(size.width(), screenGeometry.width())); + size.setHeight(qMin(size.height(), screenGeometry.height())); resize(size); // move dialog to the center of the screen - QPoint screenCenter = QApplication::desktop()->availableGeometry(QCursor::pos()).center(); + QPoint screenCenter = screenGeometry.center(); move(screenCenter.x() - (size.width() / 2), screenCenter.y() - (size.height() / 2)); QVBoxLayout* layout = new QVBoxLayout(this); @@ -65,6 +70,15 @@ void AutoTypeSelectDialog::setEntries(const QList& entries, const QHash< { m_sequences = sequences; m_view->setEntryList(entries); + + m_view->header()->resizeSections(QHeaderView::ResizeToContents); +} + +void AutoTypeSelectDialog::done(int r) +{ + config()->set("GUI/AutoTypeSelectDialogSize", size()); + + QDialog::done(r); } void AutoTypeSelectDialog::emitEntryActivated(const QModelIndex& index) diff --git a/src/autotype/AutoTypeSelectDialog.h b/src/autotype/AutoTypeSelectDialog.h index c0dbfe47..7b3909a1 100644 --- a/src/autotype/AutoTypeSelectDialog.h +++ b/src/autotype/AutoTypeSelectDialog.h @@ -36,6 +36,9 @@ public: Q_SIGNALS: void entryActivated(Entry* entry, const QString& sequence); +public Q_SLOTS: + void done(int r) override; + private Q_SLOTS: void emitEntryActivated(const QModelIndex& index); void entryRemoved();