KPimTextEdit

inserthtmldialog.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5
6*/
7
8#include "inserthtmldialog.h"
9#include "inserthtmleditor.h"
10#include <KLocalizedString>
11
12#include <TextCustomEditor/PlainTextEditorWidget>
13
14#include <KConfigGroup>
15#include <KSharedConfig>
16#include <KWindowConfig>
17#include <QDialogButtonBox>
18#include <QLabel>
19#include <QPushButton>
20#include <QVBoxLayout>
21#include <QWindow>
22namespace
23{
24static const char myInsertHtmlDialogConfigGroupName[] = "InsertHtmlDialog";
25}
26namespace KPIMTextEdit
27{
28class InsertHtmlDialogPrivate
29{
30public:
31 explicit InsertHtmlDialogPrivate(InsertHtmlDialog *qq)
32 : q(qq)
33 {
34 q->setWindowTitle(i18nc("@title:window", "Insert HTML"));
35 auto lay = new QVBoxLayout(q);
36 auto label = new QLabel(i18nc("@label:textbox", "Insert HTML tags and texts:"));
37 lay->addWidget(label);
38 editor = new InsertHtmlEditor;
39 editor->setSpellCheckingSupport(false);
40 auto editorWidget = new TextCustomEditor::PlainTextEditorWidget(editor);
41 lay->addWidget(editorWidget);
42 label = new QLabel(i18nc("@label:textbox", "Example: <i> Hello word </i>"));
43 QFont font = label->font();
44 font.setBold(true);
45 label->setFont(font);
46 label->setTextFormat(Qt::PlainText);
47 lay->addWidget(label);
49 okButton = buttonBox->button(QDialogButtonBox::Ok);
51 okButton->setText(i18nc("@action:button", "Insert"));
52
55
56 lay->addWidget(buttonBox);
57 q->connect(editor, &InsertHtmlEditor::textChanged, q, [this]() {
58 _k_slotTextChanged();
59 });
60 okButton->setEnabled(false);
61 }
62
63 void _k_slotTextChanged();
64 QPushButton *okButton = nullptr;
65 InsertHtmlEditor *editor = nullptr;
66 InsertHtmlDialog *const q;
67};
68
69void InsertHtmlDialogPrivate::_k_slotTextChanged()
70{
71 okButton->setEnabled(!editor->document()->isEmpty());
72}
73
74InsertHtmlDialog::InsertHtmlDialog(QWidget *parent)
75 : QDialog(parent)
76 , d(new InsertHtmlDialogPrivate(this))
77{
78 readConfig();
79}
80
81InsertHtmlDialog::~InsertHtmlDialog()
82{
83 writeConfig();
84}
85
86void InsertHtmlDialog::setSelectedText(const QString &str)
87{
88 d->editor->setPlainText(str);
89}
90
91QString InsertHtmlDialog::html() const
92{
93 return d->editor->toPlainText();
94}
95
96void InsertHtmlDialog::readConfig()
97{
98 create(); // ensure a window is created
99 windowHandle()->resize(QSize(640, 480));
100 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myInsertHtmlDialogConfigGroupName));
102 resize(windowHandle()->size()); // workaround for QTBUG-40584
103}
104
105void InsertHtmlDialog::writeConfig()
106{
107 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myInsertHtmlDialogConfigGroupName));
109}
110}
111
112#include "moc_inserthtmldialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QWindow * windowHandle(QObject *job)
QAction * create(StandardAction id, const Receiver *recvr, Func slot, QObject *parent, std::optional< Qt::ConnectionType > connectionType=std::nullopt)
QString label(StandardShortcut id)
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
void setShortcut(const QKeySequence &key)
void setText(const QString &text)
virtual void accept()
virtual void reject()
void setBold(bool enable)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QTextDocument * document() const const
void textChanged()
Key_Return
PlainText
bool isEmpty() const const
void setEnabled(bool)
void setWindowTitle(const QString &)
void resize(const QSize &newSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.