File indexing completed on 2022-09-27 12:31:12

0001 /*
0002     SPDX-FileCopyrightText: 2003-2009 Cies Breijs <cies AT kde DOT nl>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef _MAINWINDOW_H_
0008 #define _MAINWINDOW_H_
0009 
0010 #include <QDockWidget>
0011 
0012 #include <KXmlGuiWindow>
0013 
0014 #include "interpreter/interpreter.h"
0015 #include "canvas.h"
0016 #include "colorpicker.h"
0017 #include "directiondialog.h"
0018 #include "console.h"
0019 #include "editor.h"
0020 #include "errordialog.h"
0021 #include "inspector.h"
0022 
0023 class QStackedWidget;
0024 
0025 class KRecentFilesAction;
0026 
0027 
0028 // extends the QDockWidget with an extra signal
0029 class LocalDockWidget : public QDockWidget {
0030     Q_OBJECT
0031     public:
0032         LocalDockWidget(const QString& title, QWidget* parent) : QDockWidget(parent) { setWindowTitle(title); }
0033         void setVisible(bool b) override { QDockWidget::setVisible(b); Q_EMIT visibilityChanged(b); }
0034         void show() { QDockWidget::show(); Q_EMIT visibilityChanged(true); }
0035         void hide() { QDockWidget::hide(); Q_EMIT visibilityChanged(false); }
0036     Q_SIGNALS:
0037         void visibilityChanged(bool);
0038 };
0039 
0040 
0041 
0042 class MainWindow : public KXmlGuiWindow
0043 {
0044     Q_OBJECT
0045 
0046     public:
0047         MainWindow();
0048         ~MainWindow() override;
0049         void open(const QString& pathOrUrl) { editor->openFile(QUrl(pathOrUrl)); }  // for main.cpp
0050 
0051 //  public Q_SLOTS:
0052 
0053     private Q_SLOTS:
0054         void addToRecentFilesList(const QUrl&);
0055         void showErrorDialog(bool show = false);
0056         void openExample();
0057         void openDownloadedExample();
0058         void filePrintDialog();
0059         void canvasPrintDialog();
0060         void exportToPng();
0061         void exportToSvg();
0062         void exportToHtml();
0063 
0064         void contextHelp();
0065         //void whatsThis();
0066         void documentWasModified();
0067 
0068         void showDirectionDialog();
0069         void showColorPicker();
0070 
0071         void setRunSpeed(int);
0072         void run();
0073         void pause();
0074         void abort();
0075         void iterate();
0076         QString execute(const QString&);  // for single command execution as by the console
0077         void setDedicatedSpeed() { setRunSpeed(0); }
0078         void setFullSpeed()      { setRunSpeed(1); }
0079         void setSlowSpeed()      { setRunSpeed(2); }
0080         void setSlowerSpeed()    { setRunSpeed(3); }
0081         void setSlowestSpeed()   { setRunSpeed(4); }
0082         void setStepSpeed()      { setRunSpeed(5); }
0083 
0084         void slotInputDialog(QString& value);
0085         void slotMessageDialog(const QString& text);
0086 
0087         bool setCurrentLanguage(const QString&);
0088         void setLanguage(QAction*);
0089         void updateContentName(const QString& str = QString());
0090         void updateModificationState() { setCaption(editor->currentUrl().fileName()); }
0091         void addToRecentFiles(const QUrl&);
0092         void toggleOverwriteMode(bool b);
0093         void updateOnCursorPositionChange();
0094 
0095     protected Q_SLOTS:
0096         void saveNewToolbarConfig() override;
0097 
0098     protected:
0099         void closeEvent(QCloseEvent *event) override;
0100 
0101     private:
0102         void setupActions();
0103         void setupCanvas();
0104         void setupDockWindows();
0105         void setupEditor();
0106         void setupInterpreter();
0107         void setupStatusBar();
0108 
0109         void readConfig();
0110         void writeConfig();
0111 
0112         void updateContextHelpAction(const QString& s = QString(), const QString& anchor = QString());
0113         QString codeToFullName(const QString&);
0114 
0115         void updateExamplesMenu();
0116         void updateLanguagesMenu();
0117         void toggleGuiFeedback(bool b);
0118 
0119         Canvas          *canvas;
0120         Console         *console;
0121         Editor          *editor;
0122         Interpreter     *interpreter;
0123         Inspector       *inspector;
0124         ErrorDialog     *errorDialog;
0125         DirectionDialog *directionDialog;
0126         ColorPicker     *colorPicker;
0127         QTabWidget      *canvasTabWidget;
0128         QWidget         *canvasTab;
0129         QStackedWidget  *stackedWidget;
0130         LocalDockWidget *editorDock;
0131         LocalDockWidget *inspectorDock;
0132         QTimer          *iterationTimer;
0133         int              runSpeed;
0134         bool             currentlyRunningConsole;
0135 
0136         QString currentLanguageCode;
0137 
0138         QString contextHelpString;
0139         QString contextHelpAnchor;
0140     
0141         QMenu *examplesMenu;
0142 
0143         KRecentFilesAction *recentFilesAction;
0144 
0145         QAction *newAct;
0146         QAction *openAct;
0147         QAction *saveAct;
0148         QAction *saveAsAct;
0149         QAction *exportToPngAct;
0150         QAction *exportToSvgAct;
0151         QAction *exportToHtmlAct;
0152         QAction *printCanvasAct;
0153         QAction *runAct;
0154         QAction *pauseAct;
0155         QAction *abortAct;
0156         QAction *executeConsoleAct;
0157         QAction *quitAct;
0158         QAction *contextHelpAct;
0159         QAction *dedicatedSpeedAct;
0160         QAction *fullSpeedAct;
0161         QAction *slowSpeedAct;
0162         QAction *slowerSpeedAct;
0163         QAction *slowestSpeedAct;
0164         QAction *stepSpeedAct;
0165 
0166         QActionGroup *runSpeedGroup;
0167         QComboBox *runOptionBox;
0168 
0169         QLabel *statusBarMessageLabel;
0170         QLabel *statusBarLanguageLabel;
0171         QLabel *statusBarPositionLabel;
0172         QLabel *statusBarOverwriteModeLabel;
0173         QLabel *statusBarFileNameLabel;
0174 };
0175 
0176 #endif  // _MAINWINDOW_H_