Add global shortcut widget to SettingsWidget and register shortcut on startup.

This commit is contained in:
Felix Geyer 2012-07-14 19:09:28 +02:00
parent d3af39a7ae
commit 288fa732ca
6 changed files with 53 additions and 2 deletions

View File

@ -21,6 +21,7 @@
#include <QtGui/QTabWidget> #include <QtGui/QTabWidget>
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include "autotype/AutoType.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Database.h" #include "core/Database.h"
#include "core/Group.h" #include "core/Group.h"
@ -52,6 +53,7 @@ DatabaseTabWidget::DatabaseTabWidget(QWidget* parent)
connect(this, SIGNAL(tabCloseRequested(int)), SLOT(closeDatabase(int))); connect(this, SIGNAL(tabCloseRequested(int)), SLOT(closeDatabase(int)));
connect(this, SIGNAL(currentChanged(int)), SLOT(emitEntrySelectionChanged())); connect(this, SIGNAL(currentChanged(int)), SLOT(emitEntrySelectionChanged()));
connect(autoType(), SIGNAL(globalShortcutTriggered()), SLOT(performGlobalAutoType()));
} }
DatabaseTabWidget::~DatabaseTabWidget() DatabaseTabWidget::~DatabaseTabWidget()
@ -604,3 +606,8 @@ void DatabaseTabWidget::connectDatabase(Database* newDb, Database* oldDb)
connect(newDb, SIGNAL(modified()), SLOT(modified())); connect(newDb, SIGNAL(modified()), SLOT(modified()));
newDb->setEmitModified(true); newDb->setEmitModified(true);
} }
void DatabaseTabWidget::performGlobalAutoType()
{
autoType()->performGlobalAutoType(m_dbList.keys());
}

View File

@ -79,6 +79,7 @@ public Q_SLOTS:
void deleteGroup(); void deleteGroup();
void toggleSearch(); void toggleSearch();
bool readOnly(int index = -1); bool readOnly(int index = -1);
void performGlobalAutoType();
Q_SIGNALS: Q_SIGNALS:
void entrySelectionChanged(bool singleEntrySelected); void entrySelectionChanged(bool singleEntrySelected);

View File

@ -20,6 +20,8 @@
#include <QtGui/QCloseEvent> #include <QtGui/QCloseEvent>
#include "autotype/AutoType.h"
#include "core/Config.h"
#include "core/Database.h" #include "core/Database.h"
#include "core/DataPath.h" #include "core/DataPath.h"
#include "core/Metadata.h" #include "core/Metadata.h"
@ -37,6 +39,13 @@ MainWindow::MainWindow()
toggleViewAction->setText(tr("Show toolbar")); toggleViewAction->setText(tr("Show toolbar"));
m_ui->menuView->addAction(toggleViewAction); m_ui->menuView->addAction(toggleViewAction);
Qt::Key globalAutoTypeKey = static_cast<Qt::Key>(config()->get("GlobalAutoTypeKey").toInt());
Qt::KeyboardModifiers globalAutoTypeModifiers = static_cast<Qt::KeyboardModifiers>(
config()->get("GlobalAutoTypeModifiers").toInt());
if (globalAutoTypeKey > 0 && globalAutoTypeModifiers > 0) {
autoType()->registerGlobalShortcut(globalAutoTypeKey, globalAutoTypeModifiers);
}
setShortcut(m_ui->actionDatabaseOpen, QKeySequence::Open, Qt::CTRL + Qt::Key_O); setShortcut(m_ui->actionDatabaseOpen, QKeySequence::Open, Qt::CTRL + Qt::Key_O);
setShortcut(m_ui->actionDatabaseSave, QKeySequence::Save, Qt::CTRL + Qt::Key_S); setShortcut(m_ui->actionDatabaseSave, QKeySequence::Save, Qt::CTRL + Qt::Key_S);
setShortcut(m_ui->actionDatabaseSaveAs, QKeySequence::SaveAs); setShortcut(m_ui->actionDatabaseSaveAs, QKeySequence::SaveAs);

View File

@ -19,6 +19,7 @@
#include "ui_SettingsWidgetGeneral.h" #include "ui_SettingsWidgetGeneral.h"
#include "ui_SettingsWidgetSecurity.h" #include "ui_SettingsWidgetSecurity.h"
#include "autotype/AutoType.h"
#include "core/Config.h" #include "core/Config.h"
SettingsWidget::SettingsWidget(QWidget* parent) SettingsWidget::SettingsWidget(QWidget* parent)
@ -55,6 +56,13 @@ void SettingsWidget::loadSettings()
m_generalUi->modifiedExpandedChangedCheckBox->setChecked(config()->get("ModifiedOnExpandedStateChanges").toBool()); m_generalUi->modifiedExpandedChangedCheckBox->setChecked(config()->get("ModifiedOnExpandedStateChanges").toBool());
m_generalUi->autoSaveAfterEveryChangeCheckBox->setChecked(config()->get("AutoSaveAfterEveryChange").toBool()); m_generalUi->autoSaveAfterEveryChangeCheckBox->setChecked(config()->get("AutoSaveAfterEveryChange").toBool());
m_generalUi->autoSaveOnExitCheckBox->setChecked(config()->get("AutoSaveOnExit").toBool()); m_generalUi->autoSaveOnExitCheckBox->setChecked(config()->get("AutoSaveOnExit").toBool());
m_globalAutoTypeKey = static_cast<Qt::Key>(config()->get("GlobalAutoTypeKey").toInt());
m_globalAutoTypeModifiers = static_cast<Qt::KeyboardModifiers>(config()->get("GlobalAutoTypeModifiers").toInt());
if (m_globalAutoTypeKey > 0 && m_globalAutoTypeModifiers > 0) {
m_generalUi->autoTypeShortcutWidget->setShortcut(m_globalAutoTypeKey, m_globalAutoTypeModifiers);
}
m_secUi->clearClipboardCheckBox->setChecked(config()->get("security/clearclipboard").toBool()); m_secUi->clearClipboardCheckBox->setChecked(config()->get("security/clearclipboard").toBool());
m_secUi->clearClipboardSpinBox->setValue(config()->get("security/clearclipboardtimeout").toInt()); m_secUi->clearClipboardSpinBox->setValue(config()->get("security/clearclipboardtimeout").toInt());
@ -67,6 +75,8 @@ void SettingsWidget::saveSettings()
config()->set("ModifiedOnExpandedStateChanges", m_generalUi->modifiedExpandedChangedCheckBox->isChecked()); config()->set("ModifiedOnExpandedStateChanges", m_generalUi->modifiedExpandedChangedCheckBox->isChecked());
config()->set("AutoSaveAfterEveryChange", m_generalUi->autoSaveAfterEveryChangeCheckBox->isChecked()); config()->set("AutoSaveAfterEveryChange", m_generalUi->autoSaveAfterEveryChangeCheckBox->isChecked());
config()->set("AutoSaveOnExit", m_generalUi->autoSaveOnExitCheckBox->isChecked()); config()->set("AutoSaveOnExit", m_generalUi->autoSaveOnExitCheckBox->isChecked());
config()->set("GlobalAutoTypeKey", m_generalUi->autoTypeShortcutWidget->key());
config()->set("GlobalAutoTypeModifiers", static_cast<int>(m_generalUi->autoTypeShortcutWidget->modifiers()));
config()->set("security/clearclipboard", m_secUi->clearClipboardCheckBox->isChecked()); config()->set("security/clearclipboard", m_secUi->clearClipboardCheckBox->isChecked());
config()->set("security/clearclipboardtimeout", m_secUi->clearClipboardSpinBox->value()); config()->set("security/clearclipboardtimeout", m_secUi->clearClipboardSpinBox->value());
@ -75,6 +85,11 @@ void SettingsWidget::saveSettings()
void SettingsWidget::reject() void SettingsWidget::reject()
{ {
// register the old key again as it might have changed
if (m_globalAutoTypeKey > 0 && m_globalAutoTypeModifiers > 0) {
autoType()->registerGlobalShortcut(m_globalAutoTypeKey, m_globalAutoTypeModifiers);
}
Q_EMIT editFinished(false); Q_EMIT editFinished(false);
} }

View File

@ -47,6 +47,8 @@ private:
QWidget* const m_generalWidget; QWidget* const m_generalWidget;
const QScopedPointer<Ui::SettingsWidgetSecurity> m_secUi; const QScopedPointer<Ui::SettingsWidgetSecurity> m_secUi;
const QScopedPointer<Ui::SettingsWidgetGeneral> m_generalUi; const QScopedPointer<Ui::SettingsWidgetGeneral> m_generalUi;
Qt::Key m_globalAutoTypeKey;
Qt::KeyboardModifiers m_globalAutoTypeModifiers;
}; };
#endif // KEEPASSX_SETTINGSWIDGET_H #endif // KEEPASSX_SETTINGSWIDGET_H

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>354</width> <width>456</width>
<height>104</height> <height>146</height>
</rect> </rect>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
@ -45,8 +45,25 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Global Auto-Type shortcut</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="ShortcutWidget" name="autoTypeShortcutWidget"/>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>ShortcutWidget</class>
<extends>QLineEdit</extends>
<header>autotype/ShortcutWidget.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>