File indexing completed on 2024-05-05 05:46:21

0001 /***************************************************************************
0002  *   Copyright (C) 2003-2006 by David Saxton                               *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef CONTEXTHELP_H
0012 #define CONTEXTHELP_H
0013 
0014 #include <ui_contexthelpwidget.h>
0015 
0016 #include <QPointer>
0017 
0018 class Item;
0019 class ContextHelp;
0020 class RichTextEditor;
0021 
0022 class QTextBRowser;
0023 class QUrl;
0024 class QLabel;
0025 class QTextBrowser;
0026 class QWidgetStack;
0027 
0028 namespace KateMDI
0029 {
0030 class ToolView;
0031 }
0032 namespace KParts
0033 {
0034 class URLArgs;
0035 }
0036 
0037 /**
0038 Sidebar that provides context-sensitive help for whatever the user is currently
0039 helping (e.g. pinouts, command references, etc). Not to be confused with
0040 ItemEditor, which which allows editing of data specific to the selected CNItem
0041 in a ICNDocument.
0042 
0043 @author David Saxton
0044 */
0045 class ContextHelp : public QWidget, public Ui::ContextHelpWidget
0046 {
0047     Q_OBJECT
0048 public:
0049     static ContextHelp *self(KateMDI::ToolView *parent = nullptr);
0050     static QString toolViewIdentifier()
0051     {
0052         return "ContextHelp";
0053     }
0054 
0055     ~ContextHelp() override;
0056     /**
0057      * Replace special tags with appropriate html formatting code.
0058      */
0059     void parseInfo(QString &info);
0060     /**
0061      * Used as an event filter in context help.
0062      */
0063     bool eventFilter(QObject *watched, QEvent *e) override;
0064 
0065 public slots:
0066     void slotClear();
0067     void slotMultipleSelected();
0068     void slotUpdate(Item *item);
0069     void setContextHelp(QString name, QString help);
0070     /**
0071      * Set the help browser to the given location.
0072      */
0073     void setBrowserItem(const QString &type);
0074     void openURL(const QUrl &url /*, const KParts::OpenUrlArguments& */);
0075 
0076 protected slots:
0077     /**
0078      * Called when the user clicks the "Edit" button.
0079      */
0080     void slotEdit();
0081     /**
0082      * Called when the user clicks the "Save" button.
0083      */
0084     void slotSave();
0085     /**
0086      * Called when the user clicks the "Reset" button.
0087      */
0088     void slotEditReset();
0089     /**
0090      * Called from the language select combo when the current selection
0091      * changes.
0092      */
0093     void setCurrentLanguage(int languageIndex);
0094     /**
0095      * Request a directory from the user for storing the context help in.
0096      */
0097     void requestItemDescriptionsDirectory();
0098 
0099 protected:
0100     enum LinkType {
0101         HelpLink,    ///< Context help item (that exists)
0102         NewHelpLink, ///< Context help item that doesn't yet exist
0103         ExampleLink, ///< Example circuit or flowcode
0104         ExternalLink ///< External website, etc
0105     };
0106     /**
0107      * Looks at url and tries to determine the link type. Will return
0108      * ExternalLink if the url can not be identified as any other type.
0109      */
0110     static LinkType extractLinkType(const QUrl &url);
0111     /**
0112      * Adjusts the appearance of links depending on their LinkType (e.g
0113      * external links are given an "external" icon, and new help links are
0114      * colored in red.
0115      */
0116     static void addLinkTypeAppearances(QString *html);
0117     /**
0118      * @return the physical location of the example file from an example url
0119      * (e.g. "/mosfets/and.circuit" might return
0120      * "/usr/share/apps/ktechlab/mosfets/and.circuit").
0121      */
0122     static QString examplePathToFullPath(QString path);
0123 
0124     /**
0125      * Saves the current editor text for the given language.
0126      * @return if all ok (e.g. if the file could be written successfully).
0127      */
0128     bool saveDescription(const QString &language);
0129     bool isEditChanged();
0130     QString m_currentLanguage;
0131     QString m_lastItemType;
0132     QTextBrowser *m_pBrowserView;
0133     RichTextEditor *m_pEditor;
0134 
0135 private slots:
0136     /**
0137      * This has to be called after itemlibrary has constructed itself
0138      * and a list of languages (i.e. a little bit after the constructor).
0139      */
0140     void slotInitializeLanguageList();
0141 
0142 private:
0143     ContextHelp(KateMDI::ToolView *parent);
0144 
0145     static ContextHelp *m_pSelf;
0146 };
0147 
0148 #endif