Mailcommon

filteractionwithurl.cpp
1/*
2 * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 *
6 */
7
8#include "filteractionwithurl.h"
9
10#include <KLocalizedString>
11#include <KUrlRequester>
12#include <QUrl>
13
14#include <QHBoxLayout>
15#include <QWhatsThis>
16
17using namespace MailCommon;
18
19FilterActionWithUrlHelpButton::FilterActionWithUrlHelpButton(QWidget *parent)
20 : QToolButton(parent)
21{
22 setToolTip(i18nc("@info:tooltip", "Help"));
23 setIcon(QIcon::fromTheme(QStringLiteral("help-hint")));
24}
25
26FilterActionWithUrlHelpButton::~FilterActionWithUrlHelpButton() = default;
27
28FilterActionWithUrl::FilterActionWithUrl(const QString &name, const QString &label, QObject *parent)
29 : FilterAction(name, label, parent)
30 , mHelpButton(nullptr)
31{
32}
33
34FilterActionWithUrl::~FilterActionWithUrl() = default;
35
36bool FilterActionWithUrl::isEmpty() const
37{
38 return mParameter.trimmed().isEmpty();
39}
40
41QWidget *FilterActionWithUrl::createParamWidget(QWidget *parent) const
42{
43 auto widget = new QWidget(parent);
44 auto layout = new QHBoxLayout;
45 layout->setContentsMargins({});
46 layout->setSpacing(0);
47 widget->setLayout(layout);
48 auto requester = new KUrlRequester(parent);
49 requester->setUrl(QUrl::fromLocalFile(mParameter));
50 requester->setObjectName(QLatin1StringView("requester"));
51 layout->addWidget(requester);
52 mHelpButton = new FilterActionWithUrlHelpButton(parent);
53 mHelpButton->setObjectName(QLatin1StringView("helpbutton"));
54 connect(mHelpButton, &QAbstractButton::clicked, this, &FilterActionWithUrl::slotHelp);
55 layout->addWidget(mHelpButton);
56
58
59 return widget;
60}
61
62void FilterActionWithUrl::slotHelp()
63{
64 const QString fullWhatsThis = i18n("You can get specific header when you use %{headername}.");
65 QWhatsThis::showText(QCursor::pos(), fullWhatsThis, mHelpButton);
66}
67
68void FilterActionWithUrl::applyParamWidgetValue(QWidget *paramWidget)
69{
70 auto requester = paramWidget->findChild<KUrlRequester *>(QStringLiteral("requester"));
71 Q_ASSERT(requester);
72
73 mParameter = requester->text();
74}
75
76void FilterActionWithUrl::setParamWidgetValue(QWidget *paramWidget) const
77{
78 auto requester = paramWidget->findChild<KUrlRequester *>(QStringLiteral("requester"));
79 Q_ASSERT(requester);
80
81 requester->setText(mParameter);
82}
83
84void FilterActionWithUrl::clearParamWidget(QWidget *paramWidget) const
85{
86 auto requester = paramWidget->findChild<KUrlRequester *>(QStringLiteral("requester"));
87 Q_ASSERT(requester);
88 requester->clear();
89}
90
91void FilterActionWithUrl::argsFromString(const QString &argsStr)
92{
93 mParameter = argsStr;
94}
95
96QString FilterActionWithUrl::argsAsString() const
97{
98 return mParameter;
99}
100
101QString FilterActionWithUrl::displayString() const
102{
103 return label() + QLatin1StringView(" \"") + argsAsString().toHtmlEscaped() + QLatin1StringView("\"");
104}
105
106#include "moc_filteractionwithurl.cpp"
void textChanged(const QString &)
Abstract base class for filter actions with a command line as parameter.
Abstract base class for mail filter actions.
void filterActionModified()
Called to notify that the current FilterAction has had some value modification.
QString label() const
Returns i18n'd label, ie.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString name(GameStandardAction id)
QString label(StandardShortcut id)
The filter dialog.
void clicked(bool checked)
QPoint pos()
QIcon fromTheme(const QString &name)
void setContentsMargins(const QMargins &margins)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T findChild(const QString &name, Qt::FindChildOptions options) const const
QObject * parent() const const
void setObjectName(QAnyStringView name)
bool isEmpty() const const
QString toHtmlEscaped() const const
QString trimmed() const const
QUrl fromLocalFile(const QString &localFile)
void showText(const QPoint &pos, const QString &text, QWidget *w)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:12:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.