Warning, file /education/cantor/src/panelplugins/helppanel/helppanelplugin.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-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2010 Alexander Rieder <alexanderrieder@gmail.com> 0004 */ 0005 0006 #include "helppanelplugin.h" 0007 0008 #include <KLocalizedString> 0009 #include <KTextEdit> 0010 #include <KPluginFactory> 0011 0012 HelpPanelPlugin::HelpPanelPlugin(QObject* parent, const QList<QVariant>& args) : Cantor::PanelPlugin(parent), m_edit(nullptr) 0013 { 0014 Q_UNUSED(args); 0015 } 0016 0017 HelpPanelPlugin::~HelpPanelPlugin() 0018 { 0019 delete m_edit; 0020 } 0021 0022 QWidget* HelpPanelPlugin::widget() 0023 { 0024 if(!m_edit) 0025 { 0026 m_edit = new KTextEdit(parentWidget()); 0027 setHelpHtml(QString()); 0028 m_edit->setTextInteractionFlags(Qt::TextBrowserInteraction); 0029 } 0030 0031 return m_edit; 0032 } 0033 0034 void HelpPanelPlugin::setHelpHtml(const QString& help) 0035 { 0036 if(!m_edit) 0037 return; 0038 0039 m_edit->setHtml(help); 0040 m_edit->selectAll(); 0041 m_edit->setFontFamily(QLatin1String("Monospace")); 0042 m_edit->moveCursor(QTextCursor::Start); 0043 } 0044 0045 void HelpPanelPlugin::showHelp(const QString& help) 0046 { 0047 if(m_edit) 0048 m_edit->setHtml(help); 0049 } 0050 0051 bool HelpPanelPlugin::showOnStartup() 0052 { 0053 return false; 0054 } 0055 0056 void HelpPanelPlugin::connectToShell(QObject* cantorShell) 0057 { 0058 //using old-style syntax here, otherwise we'd need to include and link to CantorPart and KParts 0059 connect(cantorShell, SIGNAL(showHelp(QString)), this, SLOT(setHelpHtml(QString))); 0060 connect(cantorShell, SIGNAL(showHelp(QString)), this, SIGNAL(visibilityRequested())); 0061 } 0062 0063 Cantor::PanelPlugin::State HelpPanelPlugin::saveState() 0064 { 0065 auto state = PanelPlugin::saveState(); 0066 state.inners.append(m_edit->toHtml()); 0067 return state; 0068 } 0069 0070 void HelpPanelPlugin::restoreState(const Cantor::PanelPlugin::State& state) 0071 { 0072 PanelPlugin::restoreState(state); 0073 if(state.inners.size() > 0) 0074 setHelpHtml(state.inners.first().toString()); 0075 else 0076 setHelpHtml(QString()); 0077 } 0078 0079 K_PLUGIN_FACTORY_WITH_JSON(helppanelplugin, "helppanelplugin.json", registerPlugin<HelpPanelPlugin>();) 0080 #include "helppanelplugin.moc"