File indexing completed on 2024-05-12 04:35:02
0001 /* This file is part of the TikZKit project 0002 * 0003 * Copyright (C) 2014 Dominik Haumann <dhaumann@kde.org> 0004 * Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> 0005 * 0006 * This program is free software; you can redistribute it and/or modify 0007 * it under the terms of the GNU General Public License as published by 0008 * the Free Software Foundation, either version 2 or the License, or 0009 * (at your option) any later version. 0010 * 0011 * This program 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 GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program; If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef TIKZKIT_VIEW_MANAGER_H 0021 #define TIKZKIT_VIEW_MANAGER_H 0022 0023 #include <QWidget> 0024 0025 class QTabBar; 0026 class QStackedWidget; 0027 class MainWindow; 0028 0029 namespace tikz { 0030 namespace core { 0031 class Document; 0032 } 0033 namespace ui { 0034 class View; 0035 class Document; 0036 } 0037 } 0038 0039 class ViewManager : public QWidget 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 ViewManager(MainWindow * mainWin, QWidget * parent = nullptr); 0045 virtual ~ViewManager(); 0046 0047 public: 0048 void closeView(tikz::ui::View *view); 0049 MainWindow *mainWindow(); 0050 0051 Q_SIGNALS: 0052 void viewChanged(tikz::ui::View *); 0053 void viewCreated(tikz::ui::View *); 0054 0055 void closeDocumentRequested(tikz::ui::Document * doc); 0056 0057 public: 0058 /** 0059 * create and activate a new view for doc, if doc == 0, then 0060 * create a new document 0061 */ 0062 tikz::ui::View * createView(tikz::ui::Document *doc = nullptr); 0063 0064 0065 private: 0066 bool deleteView(tikz::ui::View *view); 0067 0068 public: 0069 /** 0070 * Get the currently active view. 0071 * Typically, the returned view is a valid pointer. However, sometimes the 0072 * returned view may be a @e nullptr, if there are no documents opened at all. 0073 */ 0074 tikz::ui::View *activeView(); 0075 0076 /** 0077 * Get the list of views in this ViewManager. 0078 */ 0079 QVector<tikz::ui::View*> views() const; 0080 0081 private Q_SLOTS: 0082 void slotViewChanged(); 0083 0084 void slotDocumentCreated(tikz::ui::Document *doc); 0085 void slotAboutToDeleteDocument(tikz::ui::Document *doc); 0086 void slotDocumentDeleted(tikz::ui::Document* doc); 0087 0088 public Q_SLOTS: 0089 /** 0090 * activate view for given document 0091 * @param doc document to activate view for 0092 */ 0093 tikz::ui::View *activateView(tikz::ui::Document *doc); 0094 0095 void activateView(tikz::ui::View *view); 0096 0097 protected: 0098 /** 0099 * Create a new tab for @p view. 0100 */ 0101 void addTab(tikz::ui::View * view); 0102 0103 /** 0104 * Remove the tab for @p view. 0105 */ 0106 void removeTab(tikz::ui::View * view); 0107 0108 protected Q_SLOTS: 0109 /** 0110 * Activate the view associated with tab @p index. 0111 */ 0112 void activateTab(int index); 0113 0114 /** 0115 * The close button on a tab with @p index was pressed. 0116 */ 0117 void closeRequest(int index); 0118 0119 /** 0120 * Call this slot to reflect the correct name in the tabbar. 0121 */ 0122 void updateDocumentName(tikz::core::Document * doc); 0123 0124 private: 0125 MainWindow * m_mainWindow; 0126 0127 QTabBar * m_tabBar; 0128 QStackedWidget * m_stack; 0129 0130 QVector<tikz::ui::View*> m_views; 0131 tikz::ui::View * m_activeView; 0132 }; 0133 0134 #endif // TIKZKIT_VIEW_MANAGER_H 0135 0136 // kate: indent-width 4; replace-tabs on;