1 #ifndef _KVI_FRAME_H_ 2 #define _KVI_FRAME_H_ 3 //============================================================================= 4 // 5 // File : KviMainWindow.h 6 // Creation date : Sun Jun 18 2000 17:59:02 CEST by Szymon Stefanek 7 // 8 // This file is part of the KVIrc IRC client distribution 9 // Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) 10 // 11 // This program is FREE software. You can redistribute it and/or 12 // modify it under the terms of the GNU General Public License 13 // as published by the Free Software Foundation; either version 2 14 // of the License, or (at your option) any later version. 15 // 16 // This program is distributed in the HOPE that it will be USEFUL, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 // See the GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with this program. If not, write to the Free Software Foundation, 23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24 // 25 //============================================================================= 26 27 // 28 // KviMainWindow: 29 // The main window for the KVIrc application 30 // 31 32 #include "kvi_settings.h" 33 34 #include "KviTalMainWindow.h" 35 36 #include <algorithm> 37 #include <list> 38 #include <unordered_set> 39 #include <vector> 40 41 class KviConfigurationFile; 42 class KviConsoleWindow; 43 class KviIrcConnection; 44 class KviIrcContext; 45 class KviMenuBar; 46 class KviMexToolBar; 47 class KviStatusBar; 48 class KviTrayIcon; 49 class KviWindow; 50 class KviWindowListBase; 51 class KviWindowStack; 52 class QMenu; 53 class QSplitter; 54 class QShortcut; 55 class QString; 56 57 class KVIRC_API KviMainWindow : public KviTalMainWindow 58 { 59 friend class KviApplication; 60 friend class KviConsoleWindow; 61 friend class KviIrcConnection; 62 friend class KviIrcContext; 63 friend class KviIrcServerParser; 64 friend class KviLagMeter; 65 friend class KviMexToolBar; 66 friend class KviToolBar; 67 friend class KviUserListView; 68 friend class KviUserListViewArea; 69 friend class KviWindow; 70 friend class KviWindowStack; 71 Q_OBJECT 72 public: 73 KviMainWindow(QWidget * pParent); 74 ~KviMainWindow(); 75 76 protected: 77 // subwindows 78 QSplitter * m_pSplitter; // the frame is split vertically and thus can host widgets 79 KviMenuBar * m_pMenuBar; // the main menu bar 80 KviWindowStack * m_pWindowStack; // the mdi manager widget (child of the splitter) 81 std::unordered_set<KviMexToolBar *> m_pModuleExtensionToolBarList; // the module extension toolbars 82 KviWindowListBase * m_pWindowList = nullptr; // the WindowList 83 KviStatusBar * m_pStatusBar = nullptr; 84 // the mdi workspace child windows 85 std::list<KviWindow *> m_WinList; // the main list of windows 86 KviIrcContext * m_pActiveContext = nullptr; // the context of the m_pActiveWindow 87 // other 88 KviTrayIcon * m_pTrayIcon = nullptr; // the frame's dock extension: this should be prolly moved ? 89 std::vector<QShortcut *> m_pAccellerators; // global application accellerators 90 public: 91 // the mdi manager: handles mdi children windowStack()92 KviWindowStack * windowStack() const { return m_pWindowStack; } 93 // the splitter is the central widget for this frame splitter()94 QSplitter * splitter() const { return m_pSplitter; } 95 // KviWindowListBase is the base class for KviTreeWindowList and the KviClassicWindowList windowListWidget()96 KviWindowListBase * windowListWidget() const { return m_pWindowList; } 97 // well.. the menu bar :D mainMenuBar()98 KviMenuBar * mainMenuBar() const { return m_pMenuBar; } mainStatusBar()99 KviStatusBar * mainStatusBar() const { return m_pStatusBar; } 100 // this function may return nullptr if the active window has no irc context activeContext()101 KviIrcContext * activeContext() const { return m_pActiveContext; } 102 // shortcut to a = activeContext(); return a ? a->connection() : 0 103 KviIrcConnection * activeConnection(); 104 // The list of the windows belonging to this frame 105 // Note that the windows may be also undocked, but they are still owned by the frame windowList()106 std::list<KviWindow *> & windowList() { return m_WinList; } 107 // Sets the specified window to be the active one 108 // Raises it and focuses it 109 void setActiveWindow(KviWindow * wnd); 110 // Adds a new KviWindow to this frame 111 // This should be done just after the KviWindow constructor has returned 112 // If bShow is false then the window is not explicitly shown 113 // otherwise it is set as active window. 114 void addWindow(KviWindow * wnd, bool bShow = true); // public for modules 115 void closeWindow(KviWindow * wnd); 116 // Checks if a specified window is still existing in this frame child 117 // window list. This is useful for asynchronous functions 118 // that keep a window pointer and need to ensure that it is still 119 // valid after an uncontrolled delay. (Think of a /timer implementation) windowExists(KviWindow * wnd)120 bool windowExists(KviWindow * wnd) const { return (std::find(m_WinList.begin(), m_WinList.end(), wnd) != m_WinList.end()); } 121 // The number of consoles in this frame 122 int consoleCount(); 123 // Creates a new console window. DON'T use the KviConsoleWindow constructor directly. 124 // (The script creation events are triggered from here) 125 KviConsoleWindow * createNewConsole(bool bFirstInFrame = false, bool bShowIt = true); 126 // Returns the first available console. 127 // There is almost always an available console. 128 // Exceptions are the startup and the shutdown (see activeWindow()) 129 KviConsoleWindow * firstConsole(); 130 // Returns the first console that has no connection in progress 131 // This function CAN return nullptr if all the consoles are connected 132 KviConsoleWindow * firstNotConnectedConsole(); 133 // this is explicitly dedicated to the TrayIcon module setTrayIcon(KviTrayIcon * e)134 void setTrayIcon(KviTrayIcon * e) { m_pTrayIcon = e; } 135 // returns the dockExtension applet. Useful for calling refresh() when 136 // some particular event happens trayIcon()137 KviTrayIcon * trayIcon() const { return m_pTrayIcon; } 138 // helper for saving the window properties 139 void saveWindowProperties(KviWindow * wnd, const QString & szSection); 140 // finds the module extension toolbar with the specified identifier 141 // see KviModuleExtension.h and KviMexToolBar.h 142 KviMexToolBar * moduleExtensionToolBar(int extensionId); 143 // Helper to fill the toolbars popup 144 // it is used by KviToolBar and KviMenuBar 145 void fillToolBarsPopup(QMenu * p); 146 void fillIconSizePopup(QMenu * p); 147 // Set the size of the icons used by the whole app 148 // Allowed sizes are 16, 22, 32 and 48 149 void setIconSize(unsigned int uSize); 150 void setButtonStyle(unsigned int uStyle); 151 // allows scripts and actions to override builtin accellerators, avoiding ambiguous events 152 void freeAccelleratorKeySequence(const QString & key); 153 // called by children windows when they have updated their titles. 154 void updateWindowTitle(KviWindow * wnd); 155 public slots: 156 void newConsole(); 157 void executeInternalCommand(int index); 158 void toggleStatusBar(); 159 void toggleMenuBar(); 160 void toggleWindowList(); 161 void customizeToolBars(); 162 163 protected: 164 void restoreModuleExtensionToolBars(); 165 void saveModuleExtensionToolBars(); 166 void registerModuleExtensionToolBar(KviMexToolBar * t); 167 void unregisterModuleExtensionToolBar(KviMexToolBar * t); 168 169 void createWindowList(); 170 void recreateWindowList(); 171 172 void dockWindow(KviWindow * wnd); 173 void undockWindow(KviWindow * wnd); 174 175 // called by KviWindow 176 void childWindowCloseRequest(KviWindow * wnd); 177 void windowActivated(KviWindow * wnd, bool bForce = false); 178 179 void childContextStateChange(KviIrcContext * c); 180 void childConnectionNickNameChange(KviIrcConnection * c); 181 void childConnectionAwayStateChange(KviIrcConnection * c); 182 void childConnectionUserModeChange(KviIrcConnection * c); 183 void childConnectionLagChange(KviIrcConnection * c); 184 void childConnectionServerInfoChange(KviIrcConnection * c); 185 void childWindowSelectionStateChange(KviWindow * pWnd, bool bGotSelectionNow); 186 187 void closeEvent(QCloseEvent * e) override; 188 void hideEvent(QHideEvent * e) override; 189 void resizeEvent(QResizeEvent * e) override; 190 void moveEvent(QMoveEvent * e) override; 191 bool focusNextPrevChild(bool next) override; 192 void changeEvent(QEvent * event) override; 193 void contextMenuEvent(QContextMenuEvent * event) override; 194 195 void updatePseudoTransparency(); 196 void installAccelerators(); 197 protected slots: 198 void switchToNextWindow(); 199 void switchToPrevWindow(); 200 void switchToNextHighlightedWindow(); 201 void switchToPrevHighlightedWindow(); 202 void switchToNextWindowInContext(); 203 void switchToPrevWindowInContext(); 204 void closeActiveWindow(); 205 206 void accelActivated(); 207 void toolbarsPopupSelected(QAction * pAction); 208 void iconSizePopupSelected(QAction * pAction); 209 void buttonStylePopupSelected(QAction * pAction); 210 signals: 211 void activeWindowChanged(); // almost never 0.. but may be 212 void activeContextChanged(); // may be 0! 213 void activeContextStateChanged(); // emitted only when the active context is non 0 and it changes state 214 void activeConnectionNickNameChanged(); 215 void activeConnectionUserModeChanged(); 216 void activeConnectionAwayStateChanged(); 217 void activeConnectionServerInfoChanged(); 218 void activeConnectionLagChanged(); 219 void activeWindowSelectionStateChanged(bool bGotSelectionNow); 220 221 protected: 222 void applyOptions(); 223 224 private: 225 void saveToolBarPositions(); 226 void restoreToolBarPositions(); 227 }; 228 229 #ifndef _KVI_FRAME_CPP_ 230 extern KVIRC_API KviMainWindow * g_pMainWindow; 231 #endif 232 233 #endif //_KVI_FRAME_H_ 234