Warning, file /pim/mailcommon/src/snippets/snippetcustomfileattachmentnamewidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "snippetcustomfileattachmentnamewidget.h"
0008 #include <MessageComposer/ConvertSnippetVariableMenu>
0009 #include <QHBoxLayout>
0010 #include <QLineEdit>
0011 #include <QPushButton>
0012 
0013 #include <KLocalizedString>
0014 #include <QLabel>
0015 
0016 using namespace MailCommon;
0017 SnippetCustomFileAttachmentNameWidget::SnippetCustomFileAttachmentNameWidget(QWidget *parent)
0018     : QWidget(parent)
0019     , mLineEdit(new QLineEdit(this))
0020 {
0021     auto mainLayout = new QVBoxLayout(this);
0022     mainLayout->setObjectName(QLatin1StringView("mainLayout"));
0023     mainLayout->setContentsMargins({});
0024 
0025     auto lineEditLayout = new QHBoxLayout;
0026     lineEditLayout->setObjectName(QLatin1StringView("lineEditLayout"));
0027     lineEditLayout->setContentsMargins({});
0028 
0029     auto label = new QLabel(i18n("Filename:"), this);
0030     label->setObjectName(QLatin1StringView("label"));
0031     lineEditLayout->addWidget(label);
0032 
0033     mLineEdit->setObjectName(QLatin1StringView("mLineEdit"));
0034     lineEditLayout->addWidget(mLineEdit);
0035 
0036     mainLayout->addLayout(lineEditLayout);
0037 
0038     auto convertMenuLayout = new QHBoxLayout;
0039     convertMenuLayout->setObjectName(QLatin1StringView("convertMenuLayout"));
0040     convertMenuLayout->setContentsMargins({});
0041     convertMenuLayout->addStretch(1);
0042 
0043     mConvertMenu = new MessageComposer::ConvertSnippetVariableMenu(true, mLineEdit, this);
0044     mConvertMenu->setObjectName(QLatin1StringView("mConvertMenu"));
0045     connect(mConvertMenu, &MessageComposer::ConvertSnippetVariableMenu::insertVariable, this, &SnippetCustomFileAttachmentNameWidget::insertVariable);
0046 
0047     auto selectVariable = new QPushButton(i18n("Insert Variables"), this);
0048     selectVariable->setObjectName(QLatin1StringView("selectVariable"));
0049     selectVariable->setMenu(mConvertMenu->menu());
0050     convertMenuLayout->addWidget(selectVariable);
0051     mainLayout->addLayout(convertMenuLayout);
0052     mainLayout->addStretch(1);
0053 }
0054 
0055 SnippetCustomFileAttachmentNameWidget::~SnippetCustomFileAttachmentNameWidget() = default;
0056 
0057 void SnippetCustomFileAttachmentNameWidget::insertVariable(MessageComposer::ConvertSnippetVariablesUtil::VariableType variable)
0058 {
0059     mLineEdit->insert(MessageComposer::ConvertSnippetVariablesUtil::snippetVariableFromEnum(variable));
0060 }
0061 
0062 QString SnippetCustomFileAttachmentNameWidget::result() const
0063 {
0064     return mLineEdit->text();
0065 }
0066 
0067 void SnippetCustomFileAttachmentNameWidget::setText(const QString &str)
0068 {
0069     mLineEdit->setText(str);
0070 }
0071 
0072 #include "moc_snippetcustomfileattachmentnamewidget.cpp"