Mailcommon

snippetcustomfileattachmentnamewidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2022 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "snippetcustomfileattachmentnamewidget.h"
8 #include <MessageComposer/ConvertSnippetVariableMenu>
9 #include <QHBoxLayout>
10 #include <QLineEdit>
11 #include <QPushButton>
12 
13 #include <KLocalizedString>
14 #include <QLabel>
15 
16 using namespace MailCommon;
17 SnippetCustomFileAttachmentNameWidget::SnippetCustomFileAttachmentNameWidget(QWidget *parent)
18  : QWidget(parent)
19  , mLineEdit(new QLineEdit(this))
20 {
21  auto mainLayout = new QVBoxLayout(this);
22  mainLayout->setObjectName(QStringLiteral("mainLayout"));
23  mainLayout->setContentsMargins({});
24 
25  auto lineEditLayout = new QHBoxLayout;
26  lineEditLayout->setObjectName(QStringLiteral("lineEditLayout"));
27  lineEditLayout->setContentsMargins({});
28 
29  auto label = new QLabel(i18n("Filename:"), this);
30  label->setObjectName(QStringLiteral("label"));
31  lineEditLayout->addWidget(label);
32 
33  mLineEdit->setObjectName(QStringLiteral("mLineEdit"));
34  lineEditLayout->addWidget(mLineEdit);
35 
36  mainLayout->addLayout(lineEditLayout);
37 
38  auto convertMenuLayout = new QHBoxLayout;
39  convertMenuLayout->setObjectName(QStringLiteral("convertMenuLayout"));
40  convertMenuLayout->setContentsMargins({});
41  convertMenuLayout->addStretch(1);
42 
43  mConvertMenu = new MessageComposer::ConvertSnippetVariableMenu(true, mLineEdit, this);
44  mConvertMenu->setObjectName(QStringLiteral("mConvertMenu"));
45  connect(mConvertMenu, &MessageComposer::ConvertSnippetVariableMenu::insertVariable, this, &SnippetCustomFileAttachmentNameWidget::insertVariable);
46 
47  auto selectVariable = new QPushButton(i18n("Insert Variables"), this);
48  selectVariable->setObjectName(QStringLiteral("selectVariable"));
49  selectVariable->setMenu(mConvertMenu->menu());
50  convertMenuLayout->addWidget(selectVariable);
51  mainLayout->addLayout(convertMenuLayout);
52  mainLayout->addStretch(1);
53 }
54 
55 SnippetCustomFileAttachmentNameWidget::~SnippetCustomFileAttachmentNameWidget() = default;
56 
57 void SnippetCustomFileAttachmentNameWidget::insertVariable(MessageComposer::ConvertSnippetVariablesUtil::VariableType variable)
58 {
59  mLineEdit->insert(MessageComposer::ConvertSnippetVariablesUtil::snippetVariableFromEnum(variable));
60 }
61 
62 QString SnippetCustomFileAttachmentNameWidget::result() const
63 {
64  return mLineEdit->text();
65 }
66 
67 void SnippetCustomFileAttachmentNameWidget::setText(const QString &str)
68 {
69  mLineEdit->setText(str);
70 }
QString i18n(const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
void setObjectName(const QString &name)
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.