Changeset View
Changeset View
Standalone View
Standalone View
src/panelplugins/helppanel/helppanelplugin.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #include "helppanelplugin.h" | 21 | #include "helppanelplugin.h" | ||
22 | 22 | | |||
23 | #include <KLocalizedString> | 23 | #include <KLocalizedString> | ||
24 | 24 | | |||
25 | #include <KTextEdit> | 25 | #include <KTextEdit> | ||
26 | #include "cantor_macros.h" | 26 | #include "cantor_macros.h" | ||
27 | 27 | | |||
28 | #include <QDebug> | ||||
29 | | ||||
28 | HelpPanelPlugin::HelpPanelPlugin(QObject* parent, QList<QVariant> args) : Cantor::PanelPlugin(parent) | 30 | HelpPanelPlugin::HelpPanelPlugin(QObject* parent, QList<QVariant> args) : Cantor::PanelPlugin(parent) | ||
29 | { | 31 | { | ||
30 | Q_UNUSED(args); | 32 | Q_UNUSED(args); | ||
31 | m_edit=nullptr; | 33 | m_edit=nullptr; | ||
32 | } | 34 | } | ||
33 | 35 | | |||
34 | HelpPanelPlugin::~HelpPanelPlugin() | 36 | HelpPanelPlugin::~HelpPanelPlugin() | ||
35 | { | 37 | { | ||
36 | delete m_edit; | 38 | delete m_edit; | ||
37 | } | 39 | } | ||
38 | 40 | | |||
39 | QWidget* HelpPanelPlugin::widget() | 41 | QWidget* HelpPanelPlugin::widget() | ||
40 | { | 42 | { | ||
41 | if(m_edit==nullptr) | 43 | if(m_edit==nullptr) | ||
42 | { | 44 | { | ||
43 | m_edit=new KTextEdit(parentWidget()); | 45 | m_edit=new KTextEdit(parentWidget()); | ||
44 | setHelpHtml(i18n("<h1>Cantor</h1>The KDE way to do Mathematics")); | 46 | | ||
47 | QTextDocument* doc = new QTextDocument; | ||||
48 | doc->setHtml(i18n("<h1>Cantor</h1>The KDE way to do Mathematics")); | ||||
49 | setHelp(doc); | ||||
50 | | ||||
45 | m_edit->setTextInteractionFlags(Qt::TextBrowserInteraction); | 51 | m_edit->setTextInteractionFlags(Qt::TextBrowserInteraction); | ||
46 | 52 | | |||
47 | connect(parent()->parent(), SIGNAL(showHelp(QString)), this, SLOT(setHelpHtml(QString))); | 53 | connect(parent()->parent(), SIGNAL(showHelp(QTextDocument*)), this, SLOT(setHelp(QTextDocument*))); | ||
48 | connect(parent()->parent(), SIGNAL(showHelp(QString)), this, SIGNAL(visibilityRequested())); | 54 | connect(parent()->parent(), SIGNAL(showHelp(QTextDocument*)), this, SIGNAL(visibilityRequested())); | ||
49 | } | 55 | } | ||
50 | 56 | | |||
51 | return m_edit; | 57 | return m_edit; | ||
52 | } | 58 | } | ||
53 | 59 | | |||
54 | void HelpPanelPlugin::setHelpHtml(const QString& help) | 60 | void HelpPanelPlugin::setHelp(QTextDocument* doc) | ||
55 | { | 61 | { | ||
56 | if(!m_edit) | 62 | if(!m_edit) | ||
63 | { | ||||
64 | doc->deleteLater(); | ||||
57 | return; | 65 | return; | ||
66 | } | ||||
58 | 67 | | |||
59 | m_edit->setHtml(help); | 68 | if (m_edit->document()) | ||
69 | m_edit->document()->deleteLater(); | ||||
70 | | ||||
71 | m_edit->setDocument(doc); | ||||
60 | m_edit->selectAll(); | 72 | m_edit->selectAll(); | ||
61 | m_edit->setFontFamily(QLatin1String("Monospace")); | 73 | m_edit->setFontFamily(QLatin1String("Monospace")); | ||
62 | m_edit->moveCursor(QTextCursor::Start); | 74 | m_edit->moveCursor(QTextCursor::Start); | ||
63 | } | 75 | } | ||
64 | 76 | | |||
65 | void HelpPanelPlugin::showHelp(const QString& help) | | |||
66 | { | | |||
67 | if(m_edit) | | |||
68 | m_edit->setHtml(help); | | |||
69 | } | | |||
70 | | ||||
71 | | ||||
72 | 77 | | |||
73 | K_PLUGIN_FACTORY_WITH_JSON(helppanelplugin, "helppanelplugin.json", registerPlugin<HelpPanelPlugin>();) | 78 | K_PLUGIN_FACTORY_WITH_JSON(helppanelplugin, "helppanelplugin.json", registerPlugin<HelpPanelPlugin>();) | ||
74 | #include "helppanelplugin.moc" | 79 | #include "helppanelplugin.moc" |