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
This commit is contained in:
Felix Geyer 2016-05-25 16:55:06 +02:00 committed by Jonathan White
parent 3415073051
commit c2a80ce570
2 changed files with 19 additions and 2 deletions

View File

@ -20,10 +20,12 @@
#include <QApplication> #include <QApplication>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QHeaderView>
#include <QLabel> #include <QLabel>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "autotype/AutoTypeSelectView.h" #include "autotype/AutoTypeSelectView.h"
#include "core/Config.h"
#include "core/FilePath.h" #include "core/FilePath.h"
#include "gui/entry/EntryModel.h" #include "gui/entry/EntryModel.h"
@ -39,11 +41,14 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
setWindowTitle(tr("Auto-Type - KeePassX")); setWindowTitle(tr("Auto-Type - KeePassX"));
setWindowIcon(filePath()->applicationIcon()); 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); resize(size);
// move dialog to the center of the screen // 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)); move(screenCenter.x() - (size.width() / 2), screenCenter.y() - (size.height() / 2));
QVBoxLayout* layout = new QVBoxLayout(this); QVBoxLayout* layout = new QVBoxLayout(this);
@ -65,6 +70,15 @@ void AutoTypeSelectDialog::setEntries(const QList<Entry*>& entries, const QHash<
{ {
m_sequences = sequences; m_sequences = sequences;
m_view->setEntryList(entries); 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) void AutoTypeSelectDialog::emitEntryActivated(const QModelIndex& index)

View File

@ -36,6 +36,9 @@ public:
Q_SIGNALS: Q_SIGNALS:
void entryActivated(Entry* entry, const QString& sequence); void entryActivated(Entry* entry, const QString& sequence);
public Q_SLOTS:
void done(int r) override;
private Q_SLOTS: private Q_SLOTS:
void emitEntryActivated(const QModelIndex& index); void emitEntryActivated(const QModelIndex& index);
void entryRemoved(); void entryRemoved();