Mailcommon

snippetattachmentwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2022 Laurent Montel <[email protected]>
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 
15 using namespace MailCommon;
16 
17 SnippetAttachmentWidget::SnippetAttachmentWidget(QWidget *parent)
18  : QWidget(parent)
19  , mLineEdit(new QLineEdit(this))
20 {
21  auto layout = new QHBoxLayout(this);
22  layout->setObjectName(QStringLiteral("layout"));
23  layout->setContentsMargins({});
24 
25  mLineEdit->setObjectName(QStringLiteral("lineedit"));
26  mLineEdit->setPlaceholderText(i18n("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(QStringLiteral("button"));
32  button->setToolTip(i18n("Select Attachments"));
33  button->setText(i18n("..."));
34  layout->addWidget(button);
35  connect(button, &QToolButton::clicked, this, &SnippetAttachmentWidget::slotSelectAttachment);
36 }
37 
38 SnippetAttachmentWidget::~SnippetAttachmentWidget() = default;
39 
40 void SnippetAttachmentWidget::setText(const QString &str)
41 {
42  mLineEdit->setText(str);
43 }
44 
45 QString SnippetAttachmentWidget::text() const
46 {
47  return mLineEdit->text();
48 }
49 
50 void SnippetAttachmentWidget::clear()
51 {
52  mLineEdit->clear();
53 }
54 
55 void 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 }
void clear()
void clicked(bool checked)
QString i18n(const char *text, const TYPE &arg...)
SkipEmptyParts
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Oct 1 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.