Libksieve

addresslineedit.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "addresslineedit.h"
7#include <KStatefulBrush>
8
9#include <KColorScheme>
10#include <KLineEditEventHandler>
11#include <KLocalizedString>
12#include <PimCommon/LineEditWithCompleterNg>
13#include <QHBoxLayout>
14#include <QLineEdit>
15
16using namespace KSieveUi;
17
18AddressLineEdit::AddressLineEdit(QWidget *parent)
20 , mLineEdit(new QLineEdit(this))
21{
22 auto mainLayout = new QHBoxLayout(this);
23 mainLayout->setContentsMargins({});
25 mainLayout->addWidget(mLineEdit);
26 mLineEdit->setClearButtonEnabled(true);
27 mLineEdit->setPlaceholderText(i18nc("@info:placeholder", "Define Email Address…"));
28 connect(mLineEdit, &QLineEdit::textChanged, this, &AddressLineEdit::slotTextChanged);
29 verifyAddress();
30}
31
32AddressLineEdit::~AddressLineEdit() = default;
33
34void AddressLineEdit::slotTextChanged()
35{
36 verifyAddress();
37 Q_EMIT valueChanged();
38}
39
40void AddressLineEdit::verifyAddress()
41{
42#ifndef QT_NO_STYLE_STYLESHEET
44 const QString lineEditText = text();
45 mEmailIsInvalid = !lineEditText.contains(QLatin1Char('@'));
46 // Fix check multi address
47 if (mNegativeBackground.isEmpty()) {
49 mNegativeBackground = QStringLiteral("QLineEdit{ background-color:%1 }").arg(bgBrush.brush(palette()).color().name());
50 }
51 if (mEmailIsInvalid) {
52 styleSheet = mNegativeBackground;
53 }
54 mLineEdit->setStyleSheet(styleSheet);
55#endif
56}
57
58void AddressLineEdit::focusOutEvent(QFocusEvent *ev)
59{
60 verifyAddress();
62}
63
64void AddressLineEdit::setText(const QString &str)
65{
66 mLineEdit->setText(str);
67}
68
69QString AddressLineEdit::text() const
70{
71 return mLineEdit->text();
72}
73
74bool AddressLineEdit::isValid() const
75{
76 return !mEmailIsInvalid;
77}
78
79#include "moc_addresslineedit.cpp"
The AbstractSelectEmailLineEdit class.
QBrush brush(const QPalette &) const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void catchReturnKey(QObject *lineEdit)
QString name(StandardAction id)
void setText(const QString &)
void textChanged(const QString &text)
Q_EMITQ_EMIT
QString arg(Args &&... args) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
virtual void focusOutEvent(QFocusEvent *event)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.