File indexing completed on 2024-05-19 04:36:35

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2014-2016 Dominik Haumann <dhaumann@kde.org>
0004  * Copyright (C) 2014 Christoph Cullmann <cullmann@kde.org>
0005  *
0006  * This library is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU Library General Public License as published
0008  * by the Free Software Foundation, either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, see
0018  * <http://www.gnu.org/licenses/>.
0019  */
0020 
0021 #ifndef TIKZUI_MAINWINDOW_H
0022 #define TIKZUI_MAINWINDOW_H
0023 
0024 #include "tikzui_export.h"
0025 
0026 #include <QObject>
0027 #include <QVector>
0028 
0029 class QEvent;
0030 class QIcon;
0031 class QUrl;
0032 class QWidget;
0033 
0034 class KXMLGUIFactory;
0035 
0036 namespace tikz {
0037 namespace ui {
0038 
0039 class Document;
0040 class View;
0041 
0042 /**
0043  * This class allows the application that embeds the tikz::ui component to
0044  * allow it to access parts of its main window.
0045  *
0046  * For example the component can get a place to show view bar widgets (e.g. search&replace, goto line, ...).
0047  * This is useful to e.g. have one place inside the window to show such stuff even if the application allows
0048  * the user to have multiple split views available per window.
0049  *
0050  * The application must pass a pointer to the MainWindow object to the createView method on view creation
0051  * and ensure that this main window stays valid for the complete lifetime of the view.
0052  *
0053  * It must not reimplement this class but construct an instance and pass a pointer to a QObject that
0054  * has the required slots to receive the requests.
0055  */
0056 class TIKZKITUI_EXPORT MainWindow : public QObject
0057 {
0058     Q_OBJECT
0059 
0060 public:
0061     /**
0062      * Construct an MainWindow wrapper object.
0063      * The passed parent is both the parent of this QObject and the receiver of all interface
0064      * calls via invokeMethod.
0065      * @param parent object the calls are relayed to
0066      */
0067     MainWindow(QObject *parent);
0068 
0069     /**
0070      * Virtual Destructor
0071      */
0072     virtual ~MainWindow();
0073 
0074 //
0075 // View access and manipulation interface
0076 //
0077 public:
0078     /**
0079      * Get a list of all views for this main window.
0080      * @return all views, might be an empty list.
0081      */
0082     QVector<tikz::ui::View *> views() const;
0083 
0084     /**
0085      * Access the active view.
0086      * \return active view, nullptr, if not available.
0087      */
0088     tikz::ui::View *activeView();
0089 
0090     /**
0091      * Activate the view with the corresponding \p document.
0092      * If none exist for this document, create one
0093      * \param document the document
0094      * \return activated view of this document, or nullptr if not possible.
0095      */
0096     tikz::ui::View *activateView(tikz::ui::Document *document);
0097 
0098     /**
0099      * Open the document \p url.
0100      * \param url the document's url
0101      * \return a pointer to the created view for the new document, if a document
0102      *         with this url is already existing, its view will be activated.
0103      *         A nullptr is returned, if opening the url was not possible.
0104      */
0105     tikz::ui::View *openUrl(const QUrl &url);
0106 
0107     /**
0108      * Close selected view
0109      * \param view the view
0110      * \return true if view was closed
0111      */
0112     bool closeView(tikz::ui::View *view);
0113 
0114     //
0115     // Signals related to view handling
0116     //
0117 Q_SIGNALS:
0118     /**
0119      * This signal is emitted whenever the active view changes.
0120      * @param view new active view
0121      */
0122     void viewChanged(tikz::ui::View *view);
0123 
0124     /**
0125      * This signal is emitted whenever a new view is created
0126      * @param view view that was created
0127      */
0128     void viewCreated(tikz::ui::View *view);
0129 
0130 private:
0131     /**
0132      * Private d-pointer class is our best friend ;)
0133      */
0134     friend class MainWindowPrivate;
0135 
0136     /**
0137      * Private d-pointer
0138      */
0139     class MainWindowPrivate * const d;
0140 };
0141 
0142 }
0143 }
0144 
0145 #endif // TIKZUI_MAINWINDOW_H
0146 
0147 // kate: indent-width 4; replace-tabs on;