File indexing completed on 2024-10-13 08:07:11

0001 /***************************************************************************
0002  *   Copyright (C) 2003-2005 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 KTECHLAB_H
0012 #define KTECHLAB_H
0013 
0014 #include <katemdi.h>
0015 
0016 #include <QList>
0017 #include <QMap>
0018 #include <QPointer>
0019 #include <QUrl>
0020 
0021 class CircuitDocument;
0022 class TextDocument;
0023 class ComponentSelector;
0024 class Document;
0025 class FlowCodeDocument;
0026 class ItemEditor;
0027 class LanguageManager;
0028 class LogView;
0029 class MechanicsDocument;
0030 class ProjectManager;
0031 class View;
0032 class ViewArea;
0033 class ViewContainer;
0034 
0035 typedef QMap<int, QString> IntStringMap;
0036 typedef QList<QPointer<ViewContainer>> ViewContainerList;
0037 
0038 class KRecentFilesAction;
0039 class QTabWidget;
0040 class KToggleAction;
0041 class QLabel;
0042 
0043 /**
0044  * This class serves as the main window for KTechlab.  It handles the
0045  * menus, toolbars, status bars, loading/saving files, config, etc.
0046  *
0047  * @short Main window class
0048  * @author David Saxton
0049  */
0050 class KTechlab : public KateMDI::MainWindow
0051 {
0052     Q_OBJECT
0053 
0054     friend class KtlTestsAppFixture;
0055 
0056 public:
0057     KTechlab();
0058     ~KTechlab() override;
0059 
0060     /**
0061      * @return pointer to the main KTechlab object. This is set to null when
0062      * KTechlab is about to be deleted.
0063      */
0064     static KTechlab *self()
0065     {
0066         return m_pSelf;
0067     }
0068     /**
0069      * The standard item font in use (set to a maximum of 12 pixels).
0070      */
0071     QFont itemFont() const
0072     {
0073         return m_itemFont;
0074     }
0075     /**
0076      * Returns a pointer to an action with the given name.
0077      */
0078     QAction *actionByName(const QString &name) const;
0079     /**
0080      * Returns a URL from a Open File dialog (with all ktechlab related file
0081      * types allowed).
0082      * @param allowMultiple Whether to allow the user to select more than
0083      * one URL.
0084      */
0085     static QList<QUrl> getFileURLs(bool allowMultiple = true);
0086     /**
0087      * Returns a list of the recently opened/saved files
0088      */
0089     QList<QUrl> recentFiles();
0090     /**
0091      * The tab and window captions will get updated when we have re-entered
0092      * the Qt event loop.
0093      */
0094     void requestUpdateCaptions();
0095     /**
0096      * Returns the tabwidget that shows the list of view containers.
0097      */
0098     QTabWidget *tabWidget() const
0099     {
0100         return m_pViewContainerTabWidget;
0101     }
0102     /**
0103      * Registers the viewcontainer with the internal list.
0104      */
0105     void addWindow(ViewContainer *vc);
0106     /**
0107      * Removes all gui clients added to the factory other than ourself.
0108      */
0109     void removeGUIClients();
0110     /**
0111      * Work around a crash. Adds the given KXMLGUIClient to a list of those
0112      * that ktechlab will not attempt to remove on calling removeGUIClients.
0113      */
0114     void addNoRemoveGUIClient(KXMLGUIClient *client);
0115     /**
0116      * For preventing flickering when we are updating the toolbars - grab
0117      * a pixmap of the current toolbars, and overlay it in position.
0118      */
0119     void overlayToolBarScreenshot();
0120     /**
0121      * Opens a file in the given ViewArea.
0122      */
0123     void openFile(ViewArea *viewArea);
0124 
0125     virtual void show();
0126 
0127 signals:
0128     /**
0129      * Emitted when the user changes the configuration settings in the config dialog
0130      */
0131     void configurationChanged();
0132     /**
0133      * Emitted when a recent file is added
0134      */
0135     void recentFileAdded(const QUrl &url);
0136     /**
0137      * Emitted when ViewContainers should update their captions.
0138      */
0139     void needUpdateCaptions();
0140 
0141 public slots:
0142     /**
0143      * The user right clicked on a tab item.
0144      */
0145     void slotTabContext(const QPoint &pos);
0146     /**
0147      * The user clicked on an item in the tab-menu (from right clicking).
0148      */
0149     void slotTabContextActivated(QAction *action);
0150     void slotChangeStatusbar(const QString &text);
0151     /**
0152      * Open the document at the given url. If viewArea is non-null, then the
0153      * new view will be put into viewArea.
0154      */
0155     void load(const QUrl &url, ViewArea *viewArea = nullptr);
0156     void slotUpdateConfiguration();
0157     /**
0158      * Adds a url to the list of recently opened files
0159      */
0160     void addRecentFile(const QUrl &url);
0161     /**
0162      * A document had its modified state changed; will update actions,
0163      * tab titles, etc as appropriate.
0164      */
0165     void slotDocModifiedChanged();
0166     /**
0167      * A document had its undo/redo state changed; will update actions,
0168      * tab titles, etc as appropriate.
0169      */
0170     void slotDocUndoRedoChanged();
0171 
0172     void slotFileNewAssembly();
0173     void slotFileNewMicrobe();
0174     void slotFileNewC();
0175     void slotFileNewCircuit();
0176     void slotFileNewFlowCode();
0177     void slotFileNewMechanics();
0178     void slotFileNew();
0179     void slotFileOpen();
0180     void slotFileSave();
0181     void slotFileSaveAs();
0182     void slotFilePrint();
0183     void slotFileQuit();
0184 
0185 protected:
0186     /**
0187      * Overridden virtuals for Qt drag 'n drop (XDND)
0188      */
0189     void dragEnterEvent(QDragEnterEvent *event) override;
0190     void dropEvent(QDropEvent *event) override;
0191     /**
0192      * This function is called when it is time for the app to save its
0193      * properties for session management purposes.
0194      */
0195     void savePropertiesInConfig(KConfig *);
0196     /**
0197      * This function is called when this app is restored.  The KConfig
0198      * object points to the session management config file that was saved
0199      * with @ref saveProperties
0200      */
0201     void readPropertiesInConfig(KConfig *);
0202     /**
0203      * Called before the window is closed, either by the user or indirectly by the session manager.
0204      * This function doesn't actually close the main window; it only queries the user and closes the active view.
0205      * To quit the appliaction completly, you should use KTechlab::slotFileQuit()
0206      */
0207     bool queryClose() override;
0208 
0209 protected slots:
0210     void slotViewContainerActivated(int index);
0211     void slotUpdateTabWidget();
0212     /**
0213      * Updates the tab and window captions from what is currently open and
0214      * focused.
0215      */
0216     void slotUpdateCaptions();
0217 
0218 private slots:
0219     /**
0220      * Called from a QTimer timeout (which should be after the toolbars have
0221      * finished constructing themselves).
0222      */
0223     void hideToolBarOverlay();
0224     /**
0225      * Called when the user clicks on an example (circuit, etc) from the
0226      * help menu/
0227      */
0228     void openExample(QAction *);
0229     void slotViewContainerDestroyed(QObject *obj);
0230 
0231     // Editing operations
0232     void slotEditUndo();
0233     void slotEditRedo();
0234     void slotEditCut();
0235     void slotEditCopy();
0236     void slotEditPaste();
0237 
0238     /**
0239      * Split the current view into two
0240      */
0241     void slotViewSplitLeftRight();
0242     /**
0243      * Split the current view into two
0244      */
0245     void slotViewSplitTopBottom();
0246     void slotViewContainerClose();
0247     void slotViewClose();
0248 
0249     void slotOptionsShowStatusbar();
0250     void slotOptionsConfigureKeys();
0251     void slotOptionsConfigureToolbars();
0252     void slotOptionsPreferences();
0253     void slotLoadRecent(const QUrl &url);
0254 
0255 private:
0256     void setupActions();
0257     void setupExampleActions();
0258     void setupToolDocks();
0259     void setupView();
0260     void setupTabWidget();
0261     void loadInternal(const QUrl &url, bool isRecent, ViewArea *viewArea = nullptr);
0262 
0263     KRecentFilesAction *m_recentFiles;
0264     KRecentFilesAction *m_recentProjects;
0265     KToggleAction *m_statusbarAction;
0266     QTabWidget *m_pViewContainerTabWidget;
0267     QString m_lastStatusBarMessage;
0268     QList<KXMLGUIClient *> m_noRemoveGUIClients;
0269     QLabel *m_pToolBarOverlayLabel;
0270     bool m_bIsShown; // Set true when show() is called
0271     ViewContainerList m_viewContainerList;
0272     QTimer *m_pUpdateCaptionsTimer;
0273     IntStringMap m_exampleFiles;
0274     QFont m_itemFont;
0275 
0276     static KTechlab *m_pSelf;
0277 
0278     QPointer<ViewContainer> m_pContextMenuContainer;
0279     QPointer<ViewContainer> m_pFocusedContainer;
0280     QPointer<ViewContainer> m_pContainerDropSource;
0281     QPointer<ViewContainer> m_pContainerDropReceived;
0282 };
0283 
0284 #endif // KTECHLAB_H