Mailcommon

snippetattachmentwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "snippetattachmentwidget.h"
8#include "snippetselectattachmentdialog.h"
9#include <KLocalizedString>
10#include <QHBoxLayout>
11#include <QLineEdit>
12#include <QPointer>
13#include <QToolButton>
14
15using namespace MailCommon;
16
17SnippetAttachmentWidget::SnippetAttachmentWidget(QWidget *parent)
18 : QWidget(parent)
19 , mLineEdit(new QLineEdit(this))
20{
21 auto layout = new QHBoxLayout(this);
22 layout->setObjectName(QLatin1StringView("layout"));
23 layout->setContentsMargins({});
24
25 mLineEdit->setObjectName(QLatin1StringView("lineedit"));
26 mLineEdit->setPlaceholderText(i18nc("@info:placeholder", "Click on button for selecting attachment file"));
27 layout->addWidget(mLineEdit);
28 mLineEdit->setReadOnly(true);
29
30 auto button = new QToolButton(this);
31 button->setObjectName(QLatin1StringView("button"));
32 button->setToolTip(i18nc("@info:tooltip", "Select Attachments"));
33 button->setText(i18n("…"));
34 layout->addWidget(button);
35 connect(button, &QToolButton::clicked, this, &SnippetAttachmentWidget::slotSelectAttachment);
36}
37
38SnippetAttachmentWidget::~SnippetAttachmentWidget() = default;
39
40void SnippetAttachmentWidget::setText(const QString &str)
41{
42 mLineEdit->setText(str);
43}
44
45QString SnippetAttachmentWidget::text() const
46{
47 return mLineEdit->text();
48}
49
50void SnippetAttachmentWidget::clear()
51{
52 mLineEdit->clear();
53}
54
55void SnippetAttachmentWidget::slotSelectAttachment()
56{
57 QPointer<MailCommon::SnippetSelectAttachmentDialog> dlg = new MailCommon::SnippetSelectAttachmentDialog(this);
58 dlg->setAttachments(mLineEdit->text().split(QLatin1Char(','), Qt::SkipEmptyParts));
59 if (dlg->exec()) {
60 mLineEdit->setText(dlg->attachments().join(QLatin1Char(',')));
61 Q_EMIT wasChanged();
62 }
63 delete dlg;
64}
65
66#include "moc_snippetattachmentwidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
The filter dialog.
void clicked(bool checked)
void clear()
void setText(const QString &)
Q_EMITQ_EMIT
SkipEmptyParts
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:02:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.