Mailcommon

snippetcustomfileattachmentnamewidget.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
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
16using namespace MailCommon;
17SnippetCustomFileAttachmentNameWidget::SnippetCustomFileAttachmentNameWidget(QWidget *parent)
18 : QWidget(parent)
19 , mLineEdit(new QLineEdit(this))
20{
21 auto mainLayout = new QVBoxLayout(this);
22 mainLayout->setObjectName(QLatin1StringView("mainLayout"));
23 mainLayout->setContentsMargins({});
24
25 auto lineEditLayout = new QHBoxLayout;
26 lineEditLayout->setObjectName(QLatin1StringView("lineEditLayout"));
27 lineEditLayout->setContentsMargins({});
28
29 auto label = new QLabel(i18nc("@label:textbox", "Filename:"), this);
30 label->setObjectName(QLatin1StringView("label"));
31 lineEditLayout->addWidget(label);
32
33 mLineEdit->setObjectName(QLatin1StringView("mLineEdit"));
34 lineEditLayout->addWidget(mLineEdit);
35
36 mainLayout->addLayout(lineEditLayout);
37
38 auto convertMenuLayout = new QHBoxLayout;
39 convertMenuLayout->setObjectName(QLatin1StringView("convertMenuLayout"));
40 convertMenuLayout->setContentsMargins({});
41 convertMenuLayout->addStretch(1);
42
43 mConvertMenu = new MessageComposer::ConvertSnippetVariableMenu(true, mLineEdit, this);
44 mConvertMenu->setObjectName(QLatin1StringView("mConvertMenu"));
45 connect(mConvertMenu, &MessageComposer::ConvertSnippetVariableMenu::insertVariable, this, &SnippetCustomFileAttachmentNameWidget::insertVariable);
46
47 auto selectVariable = new QPushButton(i18nc("@action:button", "Insert Variables"), this);
48 selectVariable->setObjectName(QLatin1StringView("selectVariable"));
49 selectVariable->setMenu(mConvertMenu->menu());
50 convertMenuLayout->addWidget(selectVariable);
51 mainLayout->addLayout(convertMenuLayout);
52 mainLayout->addStretch(1);
53}
54
55SnippetCustomFileAttachmentNameWidget::~SnippetCustomFileAttachmentNameWidget() = default;
56
57void SnippetCustomFileAttachmentNameWidget::insertVariable(MessageComposer::ConvertSnippetVariablesUtil::VariableType variable)
58{
59 mLineEdit->insert(MessageComposer::ConvertSnippetVariablesUtil::snippetVariableFromEnum(variable));
60}
61
62QString SnippetCustomFileAttachmentNameWidget::result() const
63{
64 return mLineEdit->text();
65}
66
67void SnippetCustomFileAttachmentNameWidget::setText(const QString &str)
68{
69 mLineEdit->setText(str);
70}
71
72#include "moc_snippetcustomfileattachmentnamewidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
The filter dialog.
void insert(const QString &newText)
void setObjectName(QAnyStringView name)
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 Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.