Libksieve

addresslineedit.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "addresslineedit.h"
7 #include <KColorScheme>
8 #include <KLocalizedString>
9 #include <Libkdepim/LineEditCatchReturnKey>
10 #include <QHBoxLayout>
11 
12 using namespace KSieveUi;
13 
14 AddressLineEdit::AddressLineEdit(QWidget *parent)
16 {
17  auto mainLayout = new QHBoxLayout(this);
18  mainLayout->setContentsMargins({});
19  mLineEdit = new QLineEdit(this);
20  new KPIM::LineEditCatchReturnKey(mLineEdit, this);
21  mainLayout->addWidget(mLineEdit);
22  mLineEdit->setClearButtonEnabled(true);
23  mLineEdit->setPlaceholderText(i18n("Define Email Address..."));
24  connect(mLineEdit, &QLineEdit::textChanged, this, &AddressLineEdit::slotTextChanged);
25  verifyAddress();
26 }
27 
28 AddressLineEdit::~AddressLineEdit()
29 {
30 }
31 
32 void AddressLineEdit::slotTextChanged()
33 {
34  verifyAddress();
35  Q_EMIT valueChanged();
36 }
37 
38 void AddressLineEdit::verifyAddress()
39 {
40 #ifndef QT_NO_STYLE_STYLESHEET
42  const QString lineEditText = text();
43  mEmailIsInvalid = !lineEditText.contains(QLatin1Char('@'));
44  // Fix check multi address
45  if (mNegativeBackground.isEmpty()) {
47  mNegativeBackground = QStringLiteral("QLineEdit{ background-color:%1 }").arg(bgBrush.brush(this).color().name());
48  }
49  if (mEmailIsInvalid) {
50  styleSheet = mNegativeBackground;
51  }
52  mLineEdit->setStyleSheet(styleSheet);
53 #endif
54 }
55 
56 void AddressLineEdit::focusOutEvent(QFocusEvent *ev)
57 {
58  verifyAddress();
60 }
61 
62 void AddressLineEdit::setText(const QString &str)
63 {
64  mLineEdit->setText(str);
65 }
66 
67 QString AddressLineEdit::text() const
68 {
69  return mLineEdit->text();
70 }
71 
72 bool AddressLineEdit::isValid() const
73 {
74  return !mEmailIsInvalid;
75 }
QString styleSheet() const const
QString name() const const
void textChanged(const QString &text)
virtual void focusOutEvent(QFocusEvent *event)
The AbstractSelectEmailLineEdit class.
const QColor & color() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString i18n(const char *text, const TYPE &arg...)
QBrush brush(QPalette::ColorGroup) const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 11 2021 23:09:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.