Improve window select combo box.

Create the WindowSelectComboBox subclass that refreshes the window
list whenever the popup is opened.
This commit is contained in:
Felix Geyer 2012-07-20 12:08:09 +02:00
parent b5c3873cfd
commit c7107de2a7
5 changed files with 120 additions and 11 deletions

View File

@ -21,6 +21,7 @@ set(keepassx_SOURCES
autotype/AutoType.cpp
autotype/AutoTypeAction.cpp
autotype/ShortcutWidget.cpp
autotype/WindowSelectComboBox.cpp
core/AutoTypeAssociations.cpp
core/Config.cpp
core/Database.cpp
@ -99,6 +100,7 @@ set(keepassx_SOURCES
set(keepassx_MOC
autotype/AutoType.h
autotype/ShortcutWidget.h
autotype/WindowSelectComboBox.h
core/AutoTypeAssociations.h
core/Config.h
core/Database.h

View File

@ -0,0 +1,68 @@
/*
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "WindowSelectComboBox.h"
#include <QtGui/QLineEdit>
#include "autotype/AutoType.h"
WindowSelectComboBox::WindowSelectComboBox(QWidget* parent)
: QComboBox(parent)
{
setEditable(true);
setInsertPolicy(QComboBox::NoInsert);
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::ComboBox));
// first item is always the current content of the line edit
insertItem(0, "");
}
void WindowSelectComboBox::refreshWindowList()
{
model()->setData(model()->index(0, 0), lineEdit()->text());
while (count() > 1) {
removeItem(1);
}
insertItems(1, autoType()->windowTitles());
}
void WindowSelectComboBox::showPopup()
{
if (lineEdit()->isReadOnly()) {
return;
}
refreshWindowList();
QComboBox::showPopup();
}
QSize WindowSelectComboBox::sizeHint() const
{
QSize size = lineEdit()->sizeHint();
size.setHeight(qMax(size.height(), QComboBox::sizeHint().height()));
return size;
}
QSize WindowSelectComboBox::minimumSizeHint() const
{
QSize size = lineEdit()->minimumSizeHint();
size.setHeight(qMax(size.height(), QComboBox::minimumSizeHint().height()));
return size;
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_WINDOWSELECTCOMBOBOX_H
#define KEEPASSX_WINDOWSELECTCOMBOBOX_H
#include <QtGui/QComboBox>
#include "core/Global.h"
class WindowSelectComboBox : public QComboBox
{
Q_OBJECT
public:
explicit WindowSelectComboBox(QWidget* parent = Q_NULLPTR);
void refreshWindowList();
void showPopup() Q_DECL_OVERRIDE;
QSize sizeHint() const Q_DECL_OVERRIDE;
QSize minimumSizeHint() const Q_DECL_OVERRIDE;
};
#endif // KEEPASSX_WINDOWSELECTCOMBOBOX_H

View File

@ -29,7 +29,6 @@
#include <QtGui/QMessageBox>
#include <QtGui/QSortFilterProxyModel>
#include "autotype/AutoType.h"
#include "core/Database.h"
#include "core/Entry.h"
#include "core/Metadata.h"
@ -280,10 +279,6 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
iconStruct.number = entry->iconNumber();
m_iconsWidget->load(entry->uuid(), m_database, iconStruct);
m_autoTypeUi->windowTitleCombo->clear();
if (!m_history) {
m_autoTypeUi->windowTitleCombo->insertItems(0, autoType()->windowTitles());
}
m_autoTypeUi->windowTitleCombo->lineEdit()->clear();
m_autoTypeAssoc->copyDataFrom(entry->autoTypeAssociations());
m_autoTypeUi->enableButton->setChecked(entry->autoTypeEnabled());
@ -297,6 +292,9 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
if (m_autoTypeAssoc->size() != 0) {
m_autoTypeUi->assocView->setCurrentIndex(m_autoTypeAssocModel->index(0, 0));
}
if (!m_history) {
m_autoTypeUi->windowTitleCombo->refreshWindowList();
}
updateAutoTypeEnabled();
if (!m_history && !restore) {

View File

@ -76,7 +76,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="1,2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
@ -150,11 +150,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="windowTitleCombo">
<property name="editable">
<bool>true</bool>
</property>
</widget>
<widget class="WindowSelectComboBox" name="windowTitleCombo"/>
</item>
<item>
<spacer name="verticalSpacer_3">
@ -232,6 +228,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>WindowSelectComboBox</class>
<extends>QComboBox</extends>
<header>autotype/WindowSelectComboBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>