8#include "incidencedescription.h"
11#include "ui_dialogdesktop.h"
12#include <KPIMTextEdit/RichTextComposer>
14#include "incidenceeditor_debug.h"
15#include <KActionCollection>
16#include <KLocalizedString>
19using namespace IncidenceEditorNG;
21namespace IncidenceEditorNG
23class IncidenceDescriptionPrivate
26 IncidenceDescriptionPrivate() =
default;
28 QString mRealOriginalDescriptionEditContents;
29 bool mRichTextEnabled =
false;
33IncidenceDescription::IncidenceDescription(Ui::EventOrTodoDesktop *ui)
36 , d(new IncidenceDescriptionPrivate())
38 setObjectName(
"IncidenceDescription"_L1);
45IncidenceDescription::~IncidenceDescription() =
default;
51 d->mRealOriginalDescriptionEditContents.clear();
54 enableRichTextDescription(
incidence->descriptionIsRich());
56 mUi->mDescriptionEdit->richTextComposer()->setHtml(
incidence->richDescription());
57 d->mRealOriginalDescriptionEditContents = mUi->mDescriptionEdit->richTextComposer()->toHtml();
59 mUi->mDescriptionEdit->richTextComposer()->setPlainText(
incidence->description());
60 d->mRealOriginalDescriptionEditContents = mUi->mDescriptionEdit->richTextComposer()->toPlainText();
63 enableRichTextDescription(
false);
64 mUi->mDescriptionEdit->richTextComposer()->clear();
72 if (d->mRichTextEnabled) {
73 incidence->setDescription(mUi->mDescriptionEdit->richTextComposer()->toHtml(),
true);
75 incidence->setDescription(mUi->mDescriptionEdit->richTextComposer()->toPlainText(),
false);
90 if (d->mRichTextEnabled) {
91 return !mLoadedIncidence->descriptionIsRich() || d->mRealOriginalDescriptionEditContents != mUi->mDescriptionEdit->richTextComposer()->toHtml();
93 return mLoadedIncidence->descriptionIsRich() || d->mRealOriginalDescriptionEditContents != mUi->mDescriptionEdit->richTextComposer()->toPlainText();
97void IncidenceDescription::enableRichTextDescription(
bool enable)
99 d->mRichTextEnabled = enable;
101 QString rt(
i18nc(
"@action Enable or disable rich text editing",
"Enable rich text"));
102 QString placeholder(QStringLiteral(
"<a href=\"show\">%1 >></a>"));
105 rt =
i18nc(
"@action Enable or disable rich text editing",
"Disable rich text");
106 placeholder = QStringLiteral(
"<a href=\"show\"><< %1</a>");
107 mUi->mDescriptionEdit->richTextComposer()->activateRichText();
108 d->mRealOriginalDescriptionEditContents = mUi->mDescriptionEdit->richTextComposer()->toHtml();
110 mUi->mDescriptionEdit->richTextComposer()->switchToPlainText();
111 d->mRealOriginalDescriptionEditContents = mUi->mDescriptionEdit->richTextComposer()->toPlainText();
114 placeholder = placeholder.arg(rt);
115 mUi->mRichTextLabel->setText(placeholder);
116 mUi->mDescriptionEdit->richTextComposer()->setEnableActions(enable);
117 mUi->mEditToolBarPlaceHolder->setVisible(enable);
121void IncidenceDescription::toggleRichTextDescription()
123 enableRichTextDescription(!d->mRichTextEnabled);
126void IncidenceDescription::setupToolBar()
130 mUi->mDescriptionEdit->richTextComposer()->createActions(collection);
132 auto mEditToolBar =
new KToolBar(mUi->mEditToolBarPlaceHolder);
134 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_text_bold")));
135 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_text_italic")));
136 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_text_underline")));
137 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_text_strikeout")));
138 mEditToolBar->addSeparator();
140 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_font_family")));
141 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_font_size")));
142 mEditToolBar->addSeparator();
144 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_text_foreground_color")));
145 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_text_background_color")));
146 mEditToolBar->addSeparator();
148 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_list_style")));
149 mEditToolBar->addSeparator();
151 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_align_left")));
152 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_align_center")));
153 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_align_right")));
154 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_align_justify")));
155 mEditToolBar->addSeparator();
157 mEditToolBar->addAction(collection->action(QStringLiteral(
"format_painter")));
158 mEditToolBar->addSeparator();
159 mEditToolBar->addAction(collection->action(QStringLiteral(
"manage_link")));
160 mUi->mDescriptionEdit->richTextComposer()->setEnableActions(
false);
162 auto layout =
new QGridLayout(mUi->mEditToolBarPlaceHolder);
163 layout->addWidget(mEditToolBar);
167 mUi->mEditToolBarPlaceHolder->setVisible(
false);
168 d->mRichTextEnabled =
false;
174 qCDebug(INCIDENCEEDITOR_LOG) <<
"RichText enabled " << d->mRichTextEnabled;
176 if (mLoadedIncidence) {
177 qCDebug(INCIDENCEEDITOR_LOG) <<
"Incidence description is rich " << mLoadedIncidence->descriptionIsRich();
179 if (mLoadedIncidence->descriptionIsRich()) {
180 qCDebug(INCIDENCEEDITOR_LOG) <<
"desc is rich, and it is <desc>" << mLoadedIncidence->richDescription() <<
"</desc>; "
181 <<
"widget has <desc>" << mUi->mDescriptionEdit->richTextComposer()->toHtml() <<
"</desc>; "
182 <<
"expr mLoadedIncidence->richDescription() != mUi->mDescriptionEdit->toHtml() is "
183 << (mLoadedIncidence->richDescription() != mUi->mDescriptionEdit->richTextComposer()->toHtml());
185 qCDebug(INCIDENCEEDITOR_LOG) <<
"desc is not rich, and it is <desc>" << mLoadedIncidence->description() <<
"</desc>; "
186 <<
"widget has <desc>" << mUi->mDescriptionEdit->richTextComposer()->toPlainText() <<
"</desc>; "
187 <<
"expr mLoadedIncidence->description() != mUi->mDescriptionEdit->toPlainText() is "
188 << (mLoadedIncidence->description() != mUi->mDescriptionEdit->richTextComposer()->toPlainText());
191 qCDebug(INCIDENCEEDITOR_LOG) <<
"Incidence is invalid";
195#include "moc_incidencedescription.cpp"
bool isDirty() const override
Returns whether or not the current values in the editor differ from the initial values.
void save(const KCalendarCore::Incidence::Ptr &incidence) override
Store the current values of the editor into.
void load(const KCalendarCore::Incidence::Ptr &incidence) override
Load the values of.
void printDebugInfo() const override
Re-implement this and print important member values and widget enabled/disabled states that could hav...
KCal Incidences are complicated objects.
void checkDirtyStatus()
Checks if the dirty status has changed until last check and emits the dirtyStatusChanged signal if ne...
QSharedPointer< IncidenceT > incidence() const
Convenience method to get a pointer for a specific const Incidence Type.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void linkActivated(const QString &link)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)