Skip to content

Commit

Permalink
Remember auto-type window size.
Browse files Browse the repository at this point in the history
Resize columns once when the entry list is set.

Based on keepassx/keepassx#158

Closes keepassxreboot#478
  • Loading branch information
debfx committed May 25, 2016
1 parent 4eea7c8 commit d4ed4f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/autotype/AutoTypeSelectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QDialogButtonBox>
#include <QHeaderView>
#include <QLabel>
#include <QVBoxLayout>

#include "autotype/AutoTypeSelectView.h"
#include "core/Config.h"
#include "core/FilePath.h"
#include "gui/entry/EntryModel.h"

Expand All @@ -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);
Expand All @@ -65,6 +70,15 @@ void AutoTypeSelectDialog::setEntries(const QList<Entry*>& 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)
Expand Down
3 changes: 3 additions & 0 deletions src/autotype/AutoTypeSelectDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class AutoTypeSelectDialog : public QDialog
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();
Expand Down

0 comments on commit d4ed4f9

Please sign in to comment.