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_EDITOR_H
0022 #define TIKZUI_EDITOR_H
0023 
0024 #include "tikzui_export.h"
0025 
0026 #include <QObject>
0027 #include <QVector>
0028 
0029 namespace tikz {
0030 namespace ui {
0031 
0032 class Application;
0033 class Document;
0034 class View;
0035 class EditorPrivate;
0036 class ConfigPage;
0037 
0038 class TIKZKITUI_EXPORT Editor : public QObject
0039 {
0040     Q_OBJECT
0041 
0042 protected:
0043     /**
0044      * Constructor.
0045      *
0046      * Create the Editor object and pass it the internal
0047      * implementation to store a d-pointer.
0048      *
0049      * @param impl d-pointer to use
0050      */
0051     Editor(EditorPrivate *impl);
0052 
0053     /**
0054      * Virtual destructor.
0055      */
0056     virtual ~Editor();
0057 
0058 public:
0059     /**
0060      * Accessor to get the Editor instance.
0061      *
0062      * @note This object will stay alive until QCoreApplication terminates.
0063      *       You shall not delete it yourself.
0064      *       There is only ONE Editor instance of this per process.
0065      *
0066      * \return Editor controller, after initial construction, will
0067      *        live until QCoreApplication is terminating.
0068      */
0069     static Editor *instance();
0070 
0071 public:
0072     /**
0073      * Set the global application object.
0074      * This will allow the editor component to access
0075      * the hosting application.
0076      * @param application application object. If the argument is a nullptr,
0077      *                    this will reset the application back to a dummy interface.
0078      */
0079     virtual void setApplication(tikz::ui::Application *application) = 0;
0080 
0081     /**
0082      * Current hosting application, if any set.
0083      * @return current application object or a dummy interface that allows
0084      *         calling the functions without having to check for a nullptr.
0085      */
0086     virtual tikz::ui::Application *application() const = 0;
0087 
0088     /*
0089      * Methods to create and manage the documents.
0090      */
0091 public:
0092     /**
0093      * Create a new document object with \p parent.
0094      *
0095      * For each created document, the signal documentCreated() is emitted.
0096      *
0097      * \param parent parent object
0098      * \return new tikz::ui::Document object
0099      * \see documents(), documentCreated()
0100      */
0101     virtual Document *createDocument(QObject *parent) = 0;
0102 
0103     /**
0104      * Get a list of all documents of this editor.
0105      * \return list of all existing documents
0106      * \see createDocument()
0107      */
0108     virtual QVector<tikz::ui::Document *> documents() = 0;
0109 
0110     /**
0111      * Get a list of all Views of this editor.
0112      * \return list of all existing Views
0113      */
0114     virtual QVector<tikz::ui::View *> views() = 0;
0115 
0116 Q_SIGNALS:
0117     /**
0118      * The \p editor emits this signal whenever a \p document was successfully
0119      * created.
0120      * \param document the newly created document instance
0121      * \see createDocument()
0122      */
0123     void documentCreated(tikz::ui::Document * document);
0124 
0125     /*
0126      * Configuration management.
0127      */
0128 public:
0129     /**
0130      * Get the number of available config pages.
0131      * If a number < 1 is returned, it does not support config pages.
0132      * \return number of config pages
0133      * \see configPage()
0134      */
0135     virtual int configPages() const = 0;
0136 
0137     /**
0138      * Get the config page with the \p number, config pages from 0 to
0139      * configPages()-1 are available if configPages() > 0.
0140      * \param number index of config page
0141      * \param parent parent widget for config page
0142      * \return created config page or NULL, if the number is out of bounds
0143      * \see configPages()
0144      */
0145     virtual ConfigPage *configPage(int number, QWidget *parent) = 0;
0146 
0147 private:
0148     /**
0149      * private d-pointer, pointing to the internal implementation
0150      */
0151     EditorPrivate *const d;
0152 };
0153 
0154 }
0155 }
0156 
0157 #endif
0158 
0159 // kate: indent-width 4; replace-tabs on;