Warning, file /sdk/ktechlab/src/katemdi.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org> 0003 Copyright (C) 2002, 2003 Joseph Wenninger <jowenn@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef __KATE_MDI_H__ 0022 #define __KATE_MDI_H__ 0023 0024 #include <KParts/MainWindow> 0025 0026 #include <KMultiTabBar> 0027 0028 // #include <q3dict.h> 0029 // #include <q3intdict.h> 0030 // #include <q3vbox.h> 0031 #include <QMap> 0032 #include <QSplitter> 0033 0034 class QAction; 0035 0036 namespace KateMDI 0037 { 0038 class MainWindow; 0039 class ToolView; 0040 0041 /** This class is needed because QSplitter cant return an index for a widget. */ 0042 class Splitter : public QSplitter 0043 { 0044 Q_OBJECT 0045 0046 public: 0047 Splitter(Qt::Orientation o, QWidget *parent = nullptr); 0048 ~Splitter() override; 0049 0050 /** Since there is supposed to be only 2 childs of a katesplitter, 0051 * any child other than the last is the first. 0052 * This method uses QSplitter::idAfter(widget) which 0053 * returns 0 if there is no widget after this one. 0054 * This results in an error if widget is not a child 0055 * in this splitter */ 0056 // bool isLastChild(QWidget* w) const; 0057 0058 // int idAfter ( QWidget * w ) const; 0059 }; 0060 0061 class GUIClient : public QObject, public KXMLGUIClient 0062 { 0063 Q_OBJECT 0064 0065 public: 0066 GUIClient(MainWindow *mw); 0067 ~GUIClient() override; 0068 0069 void registerToolView(ToolView *tv); 0070 0071 private slots: 0072 void clientAdded(KXMLGUIClient *client); 0073 void updateActions(); 0074 0075 private: 0076 MainWindow *m_mw; 0077 }; 0078 0079 class ToolView : public QWidget 0080 { 0081 Q_OBJECT 0082 0083 friend class Sidebar; 0084 friend class MainWindow; 0085 friend class GUIClient; 0086 friend class ToggleToolViewAction; 0087 0088 protected: 0089 /** 0090 * ToolView 0091 * Objects of this clas represent a toolview in the mainwindow 0092 * you should only add one widget as child to this toolview, it will 0093 * be automatically set to be the focus proxy of the toolview 0094 * @param mainwin main window for this toolview 0095 * @param sidebar sidebar of this toolview 0096 * @param parent parent widget, e.g. the splitter of one of the sidebars 0097 */ 0098 ToolView(MainWindow *mainwin, class Sidebar *sidebar, QWidget *parent); 0099 0100 public: 0101 /** 0102 * destuct me, this is allowed for all, will care itself that the toolview is removed 0103 * from the mainwindow and sidebar 0104 */ 0105 ~ToolView() override; 0106 0107 signals: 0108 /** 0109 * toolview hidden or shown 0110 * @param visible is this toolview made visible? 0111 */ 0112 void visibleChanged(bool visible); 0113 0114 /** 0115 * some internal methodes needed by the main window and the sidebars 0116 */ 0117 protected: 0118 MainWindow *mainWindow() 0119 { 0120 return m_mainWin; 0121 } 0122 0123 Sidebar *sidebar() 0124 { 0125 return m_sidebar; 0126 } 0127 0128 void setVisibleToolView(bool vis); 0129 0130 public: 0131 bool visible() const; 0132 0133 protected: 0134 void childEvent(QChildEvent *ev) override; 0135 0136 private: 0137 MainWindow *m_mainWin; 0138 Sidebar *m_sidebar; 0139 0140 /** 0141 * unique id 0142 */ 0143 QString id; 0144 0145 /** 0146 * is visible in sidebar 0147 */ 0148 bool m_visible; 0149 0150 /** 0151 * is this view persistent? 0152 */ 0153 bool persistent; 0154 0155 QIcon icon; 0156 QString text; 0157 }; 0158 0159 class Sidebar : public KMultiTabBar 0160 { 0161 Q_OBJECT 0162 0163 public: 0164 Sidebar(KMultiTabBar::KMultiTabBarPosition pos, MainWindow *mainwin, QWidget *parent); 0165 ~Sidebar() override; 0166 0167 void setSplitter(Splitter *sp); 0168 0169 // HACK use these functions intead of their respective functions in 0170 // KMultiTabBar so that we know what they were set to. 0171 void setSidebarPosition(KMultiTabBarPosition pos); 0172 KMultiTabBar::KMultiTabBarPosition sidebarPosition() const 0173 { 0174 return m_pos; 0175 } 0176 void setSidebarStyle(KMultiTabBarStyle style); 0177 KMultiTabBar::KMultiTabBarStyle sidebarTabStyle() const 0178 { 0179 return m_sidebarTabStyle; 0180 } 0181 0182 public: 0183 ToolView *addWidget(const QIcon &icon, const QString &text, ToolView *widget); 0184 bool removeWidget(ToolView *widget); 0185 0186 bool showWidget(ToolView *widget); 0187 bool hideWidget(ToolView *widget); 0188 0189 void setLastSize(int s) 0190 { 0191 m_lastSize = s; 0192 } 0193 int lastSize() const 0194 { 0195 return m_lastSize; 0196 } 0197 void updateLastSize(); 0198 0199 bool splitterVisible() const 0200 { 0201 return m_ownSplit->isVisible(); 0202 } 0203 0204 void restoreSession(); 0205 void updateMinimumSize(); 0206 0207 /** 0208 * restore the current session config from given object, use current group 0209 * @param config config object to use 0210 */ 0211 void restoreSession(KConfigGroup *config); 0212 0213 /** 0214 * save the current session config to given object, use current group 0215 * @param config config object to use 0216 */ 0217 void saveSession(KConfigGroup *config); 0218 0219 private slots: 0220 void tabClicked(int); 0221 0222 protected: 0223 bool eventFilter(QObject *obj, QEvent *ev) override; 0224 0225 private slots: 0226 void buttonPopupActivate(QAction *action); 0227 0228 private: 0229 MainWindow *m_mainWin; 0230 0231 KMultiTabBar::KMultiTabBarStyle m_sidebarTabStyle; 0232 KMultiTabBar::KMultiTabBarPosition m_pos; 0233 Splitter *m_splitter; 0234 KMultiTabBar *m_tabBar; 0235 Splitter *m_ownSplit; 0236 0237 // Q3IntDict<ToolView> m_idToWidget; 0238 QMap<int, ToolView *> m_idToWidget; 0239 QMap<ToolView *, int> m_widgetToId; 0240 0241 /** 0242 * list of all toolviews around in this sidebar 0243 */ 0244 QList<ToolView *> m_toolviews; 0245 0246 int m_lastSize; 0247 0248 int m_popupButton; 0249 }; 0250 0251 class MainWindow : public KParts::MainWindow 0252 { 0253 Q_OBJECT 0254 0255 friend class ToolView; 0256 0257 // 0258 // Constructor area 0259 // 0260 public: 0261 /** 0262 * Constructor 0263 */ 0264 MainWindow(QWidget *parentWidget = nullptr); 0265 0266 /** 0267 * Destructor 0268 */ 0269 ~MainWindow() override; 0270 0271 // 0272 // public interfaces 0273 // 0274 public: 0275 /** 0276 * central widget ;) 0277 * use this as parent for your content 0278 * this widget will get focus if a toolview is hidden 0279 * @return central widget 0280 */ 0281 QWidget *centralWidget() const; 0282 0283 /** 0284 * add a given widget to the given sidebar if possible, name is very important 0285 * @param identifier unique identifier for this toolview 0286 * @param pos position for the toolview, if we are in session restore, this is only a preference 0287 * @param icon icon to use for the toolview 0288 * @param text text to use in addition to icon 0289 * @return created toolview on success or 0 0290 */ 0291 ToolView *createToolView(const QString &identifier, KMultiTabBar::KMultiTabBarPosition pos, const QIcon &icon, const QString &text); 0292 0293 /** 0294 * give you handle to toolview for the given name, 0 if no toolview around 0295 * @param identifier toolview name 0296 * @return toolview if existing, else 0 0297 */ 0298 ToolView *toolView(const QString &identifier) const; 0299 0300 /** 0301 * set the toolview's tabbar style. 0302 * @param style the tabbar style. 0303 */ 0304 void setToolViewStyle(KMultiTabBar::KMultiTabBarStyle style); 0305 0306 /** 0307 * get the toolview's tabbar style. Call this before @p startRestore(), 0308 * otherwise you overwrite the usersettings. 0309 * @return toolview's tabbar style 0310 */ 0311 KMultiTabBar::KMultiTabBarStyle toolViewStyle() const; 0312 0313 protected: 0314 /** 0315 * called by toolview destructor 0316 * @param widget toolview which is destroyed 0317 */ 0318 void toolViewDeleted(ToolView *widget); 0319 0320 /** 0321 * modifiers for existing toolviews 0322 */ 0323 public: 0324 /** 0325 * move a toolview around 0326 * @param widget toolview to move 0327 * @param pos position to move too, during session restore, only preference 0328 * @return success 0329 */ 0330 bool moveToolView(ToolView *widget, KMultiTabBar::KMultiTabBarPosition pos); 0331 0332 /** 0333 * show given toolview, discarded while session restore 0334 * @param widget toolview to show 0335 * @return success 0336 */ 0337 bool showToolView(ToolView *widget); 0338 0339 /** 0340 * hide given toolview, discarded while session restore 0341 * @param widget toolview to hide 0342 * @return success 0343 */ 0344 bool hideToolView(ToolView *widget); 0345 0346 /** 0347 * session saving and restore stuff 0348 */ 0349 public: 0350 /** 0351 * start the restore 0352 * @param config config object to use 0353 * @param group config group to use 0354 */ 0355 void startRestore(KConfig *config, const QString &group); 0356 0357 /** 0358 * finish the restore 0359 */ 0360 void finishRestore(); 0361 0362 /** 0363 * save the current session config to given object and group 0364 * @param config config object to use 0365 */ 0366 void saveSession(KConfigGroup *config); 0367 0368 void updateSidebarMinimumSizes(); 0369 0370 /** 0371 * internal data ;) 0372 */ 0373 private: 0374 /** 0375 * map identifiers to widgets 0376 */ 0377 // Q3Dict<ToolView> m_idToWidget; 0378 QMap<QString, ToolView *> m_idToWidget; 0379 0380 /** 0381 * list of all toolviews around 0382 */ 0383 QList<ToolView *> m_toolviews; 0384 0385 /** 0386 * widget, which is the central part of the 0387 * main window ;) 0388 */ 0389 QWidget *m_centralWidget; 0390 0391 /** 0392 * horizontal splitter 0393 */ 0394 Splitter *m_hSplitter; 0395 0396 /** 0397 * vertical splitter 0398 */ 0399 Splitter *m_vSplitter; 0400 0401 /** 0402 * sidebars for the four sides 0403 */ 0404 Sidebar *m_sidebars[4]; 0405 0406 /** 0407 * config object for session restore, only valid between 0408 * start and finish restore calls 0409 */ 0410 KConfig *m_restoreConfig; 0411 0412 /** 0413 * restore group 0414 */ 0415 QString m_restoreGroup; 0416 0417 /** 0418 * out guiclient 0419 */ 0420 GUIClient *m_guiClient; 0421 }; 0422 0423 } 0424 0425 #endif