summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-08-05 10:23:04 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-08-05 10:23:04 (GMT)
commit4bd90c0c554c80101300b656cddf88c788b5e40d (patch)
treeb0a782511c2779212c426fa94a5befbc3c9ffc99
parent9b853c1498758149b05c2bafe3f38de5d3d88a5d (diff)
Let certificatelineedit inherit QLineEdit
Using QWidget as a base was a relic from the past where the lineedit was a widget with extra buttons and labels.
-rw-r--r--src/crypto/gui/certificatelineedit.cpp38
-rw-r--r--src/crypto/gui/certificatelineedit.h7
2 files changed, 20 insertions, 25 deletions
diff --git a/src/crypto/gui/certificatelineedit.cpp b/src/crypto/gui/certificatelineedit.cpp
index a700f5a..0a82760 100644
--- a/src/crypto/gui/certificatelineedit.cpp
+++ b/src/crypto/gui/certificatelineedit.cpp
@@ -63,27 +63,21 @@ using namespace GpgME;
Q_DECLARE_METATYPE(GpgME::Key);
-#define MINIMUM_WIDTH_STR "Short Short<LongLong@MiddleDomain.co.uk> (12345678 - OpenPGP)"
-
CertificateLineEdit::CertificateLineEdit(AbstractKeyListModel *model,
QWidget *parent,
KeyFilter *filter)
- : QWidget(parent),
- mEdit(new QLineEdit()),
+ : QLineEdit(parent),
mFilterModel(new KeyListSortFilterProxyModel(this)),
mFilter(boost::shared_ptr<KeyFilter>(filter)),
mEditStarted(false),
mEditFinished(false),
mLineAction(new QAction(Q_NULLPTR))
{
- auto *hLay = new QHBoxLayout;
- mEdit->setPlaceholderText(i18n("Please enter a name or email address..."));
- mEdit->setClearButtonEnabled(true);
- hLay->addWidget(mEdit, -1);
- mEdit->addAction(mLineAction, QLineEdit::LeadingPosition);
+ setPlaceholderText(i18n("Please enter a name or email address..."));
+ setClearButtonEnabled(true);
+ addAction(mLineAction, QLineEdit::LeadingPosition);
QFontMetrics fm(font());
- mEdit->setMinimumWidth(fm.width(QStringLiteral(MINIMUM_WIDTH_STR)));
auto *completer = new QCompleter(this);
auto *completeFilterModel = new KeyListSortFilterProxyModel(completer);
@@ -93,7 +87,7 @@ CertificateLineEdit::CertificateLineEdit(AbstractKeyListModel *model,
completer->setCompletionColumn(KeyListModelInterface::Summary);
completer->setFilterMode(Qt::MatchContains);
completer->setCaseSensitivity(Qt::CaseInsensitive);
- mEdit->setCompleter(completer);
+ setCompleter(completer);
mFilterModel->setSourceModel(model);
mFilterModel->setFilterKeyColumn(KeyListModelInterface::Summary);
if (filter) {
@@ -102,14 +96,13 @@ CertificateLineEdit::CertificateLineEdit(AbstractKeyListModel *model,
connect(model, &QAbstractItemModel::dataChanged,
this, &CertificateLineEdit::updateKey);
- connect(mEdit, &QLineEdit::editingFinished,
+ connect(this, &QLineEdit::editingFinished,
this, &CertificateLineEdit::updateKey);
- connect(mEdit, &QLineEdit::textChanged,
+ connect(this, &QLineEdit::textChanged,
this, &CertificateLineEdit::editChanged);
connect(mLineAction, &QAction::triggered,
this, &CertificateLineEdit::dialogRequested);
- setLayout(hLay);
updateKey();
/* Take ownership of the model to prevent double deletion when the
@@ -129,7 +122,7 @@ void CertificateLineEdit::editChanged()
void CertificateLineEdit::updateKey()
{
- const auto mailText = mEdit->text();
+ const auto mailText = text();
auto newKey = Key();
if (mailText.isEmpty()) {
Q_EMIT wantsRemoval(this);
@@ -156,9 +149,9 @@ void CertificateLineEdit::updateKey()
mKey = newKey;
if (mKey.isNull()) {
- mEdit->setToolTip(QString());
+ setToolTip(QString());
} else {
- mEdit->setToolTip(Formatting::toolTip(newKey, Formatting::ToolTipOption::AllOptions));
+ setToolTip(Formatting::toolTip(newKey, Formatting::ToolTipOption::AllOptions));
}
Q_EMIT keyChanged();
@@ -166,7 +159,11 @@ void CertificateLineEdit::updateKey()
Key CertificateLineEdit::key() const
{
- return mKey;
+ if (isEnabled()) {
+ return mKey;
+ } else {
+ return Key();
+ }
}
void CertificateLineEdit::dialogRequested()
@@ -201,10 +198,11 @@ void CertificateLineEdit::setKey(const Key &k)
{
QSignalBlocker blocky(this);
qCDebug(KLEOPATRA_LOG) << "Setting Key. " << Formatting::summaryLine(k);
- mEdit->setText(Formatting::summaryLine(k));
+ setText(Formatting::summaryLine(k));
+ updateKey();
}
bool CertificateLineEdit::isEmpty() const
{
- return mEdit->text().isEmpty();
+ return text().isEmpty();
}
diff --git a/src/crypto/gui/certificatelineedit.h b/src/crypto/gui/certificatelineedit.h
index 35f1757..9915ac7 100644
--- a/src/crypto/gui/certificatelineedit.h
+++ b/src/crypto/gui/certificatelineedit.h
@@ -31,9 +31,7 @@
#ifndef CRYPTO_GUI_CERTIFICATELINEEDIT_H
#define CRYPTO_GUI_CERTIFICATELINEEDIT_H
-class QLineEdit;
-
-#include <QWidget>
+#include <QLineEdit>
#include <QString>
#include <gpgme++/key.h>
@@ -57,7 +55,7 @@ class KeyListSortFilterProxyModel;
* The widget will use a single line HBox Layout. For larger dialog
* see certificateslectiondialog.
*/
-class CertificateLineEdit: public QWidget
+class CertificateLineEdit: public QLineEdit
{
Q_OBJECT
public:
@@ -102,7 +100,6 @@ private Q_SLOTS:
void editChanged();
private:
- QLineEdit *mEdit;
KeyListSortFilterProxyModel *mFilterModel;
QLabel *mStatusLabel,
*mStatusIcon;