File indexing completed on 2024-05-05 15:58:11

0001 /*
0002     This program is free software; you can redistribute it and/or
0003     modify it under the terms of the GNU General Public License
0004     as published by the Free Software Foundation; either version 2
0005     of the License, or (at your option) any later version.
0006 
0007     This program is distributed in the hope that it will be useful,
0008     but WITHOUT ANY WARRANTY; without even the implied warranty of
0009     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0010     GNU General Public License for more details.
0011 
0012     You should have received a copy of the GNU General Public License
0013     along with this program; if not, write to the Free Software
0014     Foundation, Inc., 51 Franklin Street, Fifth Floor,
0015     Boston, MA  02110-1301, USA.
0016 
0017     ---
0018     Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
0019 */
0020 
0021 #ifndef CANTORPART_H
0022 #define CANTORPART_H
0023 
0024 #include <QPointer>
0025 
0026 #include <KParts/ReadWritePart>
0027 #include <cantor/session.h>
0028 
0029 class QWidget;
0030 class Worksheet;
0031 class WorksheetView;
0032 class SarchBar;
0033 class SearchBar;
0034 class ScriptEditorWidget;
0035 class KAboutData;
0036 class QAction;
0037 class KToggleAction;
0038 class KProgressDialog;
0039 
0040 namespace Cantor {
0041     class PanelPluginHandler;
0042 }
0043 
0044 /**
0045  * This is a "Part".  It that does all the real work in a KPart
0046  * application.
0047  *
0048  * @short Main Part
0049  * @author Alexander Rieder <alexanderrieder@gmail.com>
0050  */
0051 class CantorPart : public KParts::ReadWritePart
0052 {
0053     Q_OBJECT
0054 public:
0055     /**
0056      * Default constructor
0057      */
0058     CantorPart(QWidget *parentWidget,QObject *parent, const QVariantList &args);
0059 
0060     /**
0061      * Destructor
0062      */
0063     ~CantorPart() override;
0064 
0065     /**
0066      * This is a virtual function inherited from KParts::ReadWritePart.
0067      * A shell will use this to inform this Part if it should act
0068      * read-only
0069      */
0070     void setReadWrite(bool rw) override;
0071 
0072     /**
0073      * Reimplemented to disable and enable Save action
0074      */
0075     void setModified(bool modified) override;
0076 
0077     KAboutData& createAboutData();
0078 
0079     Worksheet* worksheet();
0080 
0081 Q_SIGNALS:
0082     void setCaption(const QString& caption);
0083     void showHelp(const QString& help);
0084 
0085 protected:
0086     /**
0087      * This must be implemented by each part
0088      */
0089     bool openFile() override;
0090 
0091     /**
0092      * This must be implemented by each read-write part
0093      */
0094     bool saveFile() override;
0095 
0096     /**
0097      * Called when this part becomes the active one,
0098      * or if it looses activity
0099      **/
0100     void guiActivateEvent( KParts::GUIActivateEvent * event ) override;
0101 
0102 
0103     void loadAssistants();
0104     void adjustGuiToSession();
0105 
0106 protected Q_SLOTS:
0107     void fileSaveAs();
0108     void fileSavePlain();
0109     void exportToLatex();
0110     void evaluateOrInterrupt();
0111     void restartBackend();
0112     void enableTypesetting(bool enable);
0113     void showBackendHelp();
0114     void print();
0115     void printPreview();
0116 
0117     void worksheetStatusChanged(Cantor::Session::Status stauts);
0118     void showSessionError(const QString& error);
0119     void worksheetSessionChanged();
0120     void initialized();
0121     void updateCaption();
0122 
0123     void pluginsChanged();
0124     void runCommand(const QString& value);
0125 
0126     void runAssistant();
0127     void publishWorksheet();
0128 
0129     void showScriptEditor(bool show);
0130     void scriptEditorClosed();
0131     void runScript(const QString& file);
0132 
0133     void showSearchBar();
0134     void showExtendedSearchBar();
0135     void findNext();
0136     void findPrev();
0137     void searchBarDeleted();
0138 
0139     /** sets the status message, or cached it, if the StatusBar is blocked.
0140      *  Use this method instead of "emit setStatusBarText"
0141      */
0142     void setStatusMessage(const QString& message);
0143     /** Shows an important status message. It makes sure the message is displayed,
0144      *  by blocking the statusbarText for 3 seconds
0145      */
0146     void showImportantStatusMessage(const QString& message);
0147     /** Blocks the StatusBar for new messages, so the currently shown one won't be overridden
0148      */
0149     void blockStatusBar();
0150     /** Removes the block from the StatusBar, and shows the last one of the StatusMessages that
0151         where set during the block
0152     **/
0153     void unblockStatusBar();
0154 private:
0155     Worksheet *m_worksheet;
0156     WorksheetView *m_worksheetview;
0157     SearchBar *m_searchBar;
0158     QPointer<ScriptEditorWidget> m_scriptEditor;
0159     Cantor::PanelPluginHandler* m_panelHandler;
0160 
0161     KProgressDialog* m_initProgressDlg;
0162     QAction * m_evaluate;
0163     QAction * m_save;
0164     QAction * m_findNext;
0165     QAction * m_findPrev;
0166     KToggleAction* m_typeset;
0167     KToggleAction* m_highlight;
0168     KToggleAction* m_completion;
0169     KToggleAction* m_exprNumbering;
0170     KToggleAction* m_animateWorksheet;
0171     QAction * m_showBackendHelp;
0172 
0173     QString m_cachedStatusMessage;
0174     bool m_statusBarBlocked;
0175 };
0176 
0177 #endif // CANTORPART_H