7#include "snippetwidget.h"
8#include "ui_snippetwidget.h"
9#include <MessageComposer/ConvertSnippetVariableMenu>
10#include <TextCustomEditor/PlainTextEditor>
12#include <KActionCollection>
14#include <KLocalizedString>
19class Q_DECL_HIDDEN SnippetWidgetPrivate
22 Ui::SnippetWidget mUi;
24 bool isSelectedGroup =
false;
25 bool wasChanged =
false;
28SnippetWidget::SnippetWidget(
QWidget *parent)
30 , d(new SnippetWidgetPrivate)
34 layout->setContentsMargins({});
36 d->mUi.setupUi(d->wdg);
37 layout->addWidget(d->wdg);
40 d->mUi.pushButtonVariables->setMenu(variableMenu->menu());
42 &MessageComposer::ConvertSnippetVariableMenu::insertVariable,
44 [
this](MessageComposer::ConvertSnippetVariablesUtil::VariableType type) {
45 d->mUi.snippetText->editor()->insertPlainText(MessageComposer::ConvertSnippetVariablesUtil::snippetVariableFromEnum(type) +
QLatin1Char(
' '));
48 d->mUi.nameEdit->setTrapReturnKey(
true);
49 d->mUi.keyword->setTrapReturnKey(
true);
50 d->mUi.keyword->setClearButtonEnabled(
true);
51 d->mUi.nameEdit->setClearButtonEnabled(
true);
52 d->mUi.nameEdit->setFocus();
53 d->mUi.snippetText->setMinimumSize(500, 300);
55 d->mUi.keyword->setWhatsThis(
56 i18n(
"Enter a keyword here to enable fast insertion of this snippet while writing "
57 "an email. For instance if you choose \"greeting\" as the keyword, you can then "
58 "type \\greeting in your email and then press the tab key, and it will be "
59 "replaced with the contents of this snippet."));
62 Q_EMIT textChanged(str);
66 Q_EMIT groupChanged(index);
90 connect(d->mUi.attachment, &MailCommon::SnippetAttachmentWidget::wasChanged,
this, [
this]() {
95SnippetWidget::~SnippetWidget() =
default;
97void SnippetWidget::setName(
const QString &name)
99 d->mUi.nameEdit->setText(name);
102QString SnippetWidget::name()
const
104 return d->mUi.nameEdit->text();
107void SnippetWidget::setText(
const QString &text)
109 d->mUi.snippetText->setPlainText(text);
112QString SnippetWidget::text()
const
114 return d->mUi.snippetText->toPlainText();
117void SnippetWidget::setKeySequence(
const QKeySequence &sequence)
119 d->mUi.keyWidget->setKeySequence(sequence);
124 return d->mUi.keyWidget->keySequence();
127void SnippetWidget::setKeyword(
const QString &keyword)
129 d->mUi.keyword->setText(keyword);
132QString SnippetWidget::keyword()
const
134 return d->mUi.keyword->text();
137void SnippetWidget::setTo(
const QString &keyword)
139 d->mUi.to->setText(keyword);
142QString SnippetWidget::to()
const
144 return d->mUi.to->text();
147void SnippetWidget::setCc(
const QString &keyword)
149 d->mUi.cc->setText(keyword);
152QString SnippetWidget::cc()
const
154 return d->mUi.cc->text();
157void SnippetWidget::setBcc(
const QString &keyword)
159 d->mUi.bcc->setText(keyword);
162QString SnippetWidget::bcc()
const
164 return d->mUi.bcc->text();
169 d->mUi.groupBox->setModel(model);
172void SnippetWidget::setGroupIndex(
const QModelIndex &index)
174 d->mUi.groupBox->setCurrentIndex(index.
row());
179 return d->mUi.groupBox->model()->index(d->mUi.groupBox->currentIndex(), 0);
182bool SnippetWidget::snippetIsValid()
const
184 if (d->mUi.nameEdit->text().trimmed().isEmpty()) {
187 if (d->mUi.formLayout->isRowVisible(1)) {
188 return !d->mUi.groupBox->currentText().trimmed().isEmpty();
196 d->mUi.keyWidget->setCheckActionCollections(lst);
199void SnippetWidget::setGroupSelected(
bool inGroupMode)
201 d->isSelectedGroup = inGroupMode;
203 for (
int i = 1; i < d->mUi.formLayout->rowCount(); i++) {
204 d->mUi.formLayout->setRowVisible(i, !inGroupMode);
208bool SnippetWidget::isGroupSelected()
const
210 return d->isSelectedGroup;
213void SnippetWidget::clear()
215 d->mUi.nameEdit->clear();
216 d->mUi.keyword->clear();
217 d->mUi.snippetText->clear();
218 d->mUi.keyWidget->setKeySequence({});
219 d->mUi.subject->clear();
223 d->mUi.attachment->clear();
226bool SnippetWidget::wasChanged()
const
228 return d->wasChanged;
231void SnippetWidget::setWasChanged(
bool b)
236QString SnippetWidget::subject()
const
238 return d->mUi.subject->text();
241void SnippetWidget::setAttachment(
const QString &keyword)
243 d->mUi.attachment->setText(keyword);
246QString SnippetWidget::attachment()
const
248 return d->mUi.attachment->text();
251void SnippetWidget::setSubject(
const QString &text)
253 d->mUi.subject->setText(text);
256#include "moc_snippetwidget.cpp"
QString i18n(const char *text, const TYPE &arg...)
void currentIndexChanged(int index)
void textChanged(const QString &text)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)