File indexing completed on 2022-12-06 18:50:12

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
0004 */
0005 
0006 #ifndef CANTORPART_H
0007 #define CANTORPART_H
0008 
0009 #include <QPointer>
0010 #include <QVector>
0011 
0012 #include <KParts/ReadWritePart>
0013 #include "lib/session.h"
0014 
0015 class QWidget;
0016 class Worksheet;
0017 class WorksheetView;
0018 class SearchBar;
0019 class ScriptEditorWidget;
0020 class KAboutData;
0021 class QAction;
0022 class KToggleAction;
0023 class KSelectAction;
0024 
0025 namespace Cantor{
0026     class PanelPluginHandler;
0027 }
0028 
0029 /**
0030  * This is a "Part".  It that does all the real work in a KPart
0031  * application.
0032  *
0033  * @short Main Part
0034  * @author Alexander Rieder <alexanderrieder@gmail.com>
0035  */
0036 class CantorPart : public KParts::ReadWritePart
0037 {
0038     Q_OBJECT
0039 public:
0040     /**
0041      * Default constructor
0042      */
0043     CantorPart(QWidget* , QObject*, const QVariantList& args);
0044 
0045     /**
0046      * Destructor
0047      */
0048     ~CantorPart() override;
0049 
0050     /**
0051      * This is a virtual function inherited from KParts::ReadWritePart.
0052      * A shell will use this to inform this Part if it should act
0053      * read-only
0054      */
0055     void setReadWrite(bool) override;
0056 
0057     /**
0058      * Reimplemented to disable and enable Save action
0059      */
0060     void setModified(bool) override;
0061 
0062     KAboutData& createAboutData();
0063 
0064     Worksheet* worksheet();
0065 
0066 Q_SIGNALS:
0067     void setCaption(const QString& caption, const QIcon& icon);
0068     void showHelp(const QString&);
0069     void hierarchyChanged(QStringList, QStringList, QList<int>);
0070     void hierarhyEntryNameChange(QString name, QString searchName, int depth);
0071     void worksheetSave(const QUrl&);
0072     void setBackendName(const QString&);
0073     void requestScrollToHierarchyEntry(QString);
0074     void settingsChanges();
0075     void requestDocumentation(const QString& keyword);
0076 
0077 public Q_SLOTS:
0078     void updateCaption();
0079 
0080 protected:
0081     /**
0082      * This must be implemented by each part
0083      */
0084     bool openFile() override;
0085 
0086     /**
0087      * This must be implemented by each read-write part
0088      */
0089     bool saveFile() override;
0090 
0091     /**
0092      * Called when this part becomes the active one,
0093      * or if it looses activity
0094      **/
0095     void guiActivateEvent(KParts::GUIActivateEvent*) override;
0096 
0097     void loadAssistants();
0098     void adjustGuiToSession();
0099 
0100     void setReadOnly();
0101 
0102 protected Q_SLOTS:
0103     void fileSaveAs();
0104     void fileSavePlain();
0105     void exportToLatex();
0106     void evaluateOrInterrupt();
0107     void restartBackend();
0108     void zoomValueEdited(const QString&);
0109     void updateZoomWidgetValue(double);
0110     void enableTypesetting(bool);
0111     void showBackendHelp();
0112     void print();
0113     void printPreview();
0114 
0115     void worksheetStatusChanged(Cantor::Session::Status);
0116     void showSessionError(const QString&);
0117     void worksheetSessionLoginStarted();
0118     void worksheetSessionLoginDone();
0119     void initialized();
0120 
0121     void runCommand(const QString&);
0122 
0123     void runAssistant();
0124     void publishWorksheet();
0125 
0126     void showScriptEditor(bool);
0127     void scriptEditorClosed();
0128     void runScript(const QString&);
0129 
0130     void showSearchBar();
0131     void showExtendedSearchBar();
0132     void findNext();
0133     void findPrev();
0134     void searchBarDeleted();
0135 
0136     /** sets the status message, or cached it, if the StatusBar is blocked.
0137      *  Use this method instead of "emit setStatusBarText"
0138      */
0139     void setStatusMessage(const QString&);
0140     /** Shows an important status message. It makes sure the message is displayed,
0141      *  by blocking the statusbarText for 3 seconds
0142      */
0143     void showImportantStatusMessage(const QString&);
0144     /** Blocks the StatusBar for new messages, so the currently shown one won't be overridden
0145      */
0146     void blockStatusBar();
0147     /** Removes the block from the StatusBar, and shows the last one of the StatusMessages that
0148         where set during the block
0149     **/
0150     void unblockStatusBar();
0151 
0152 private:
0153     Worksheet* m_worksheet{nullptr};
0154     WorksheetView* m_worksheetview{nullptr};
0155     SearchBar* m_searchBar{nullptr};
0156     QPointer<ScriptEditorWidget> m_scriptEditor;
0157 
0158     QAction* m_evaluate;
0159     QAction* m_restart;
0160     KSelectAction* m_zoom;
0161     QAction* m_currectZoomAction{nullptr};
0162     QAction* m_save;
0163     QAction* m_findNext;
0164     QAction* m_findPrev;
0165     KToggleAction* m_typeset;
0166     KToggleAction* m_highlight;
0167     KToggleAction* m_completion;
0168     KToggleAction* m_exprNumbering;
0169     KToggleAction* m_animateWorksheet;
0170     KToggleAction* m_embeddedMath;
0171     QVector<QAction*> m_editActions;
0172 
0173     QString m_cachedStatusMessage;
0174     bool m_statusBarBlocked{false};
0175     unsigned int m_sessionStatusCounter{0};
0176 
0177 private Q_SLOTS:
0178     void documentationRequested(const QString&);
0179 };
0180 
0181 #endif // CANTORPART_H