File indexing completed on 2024-05-19 15:44:20
0001 /* 0002 SPDX-FileCopyrightText: 2006-2007 Alexander Dymo <adymo@kdevelop.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVPLATFORM_SUBLIMEMAINWINDOW_H 0008 #define KDEVPLATFORM_SUBLIMEMAINWINDOW_H 0009 0010 #include <QList> 0011 #include <QMenu> 0012 #include <QSet> 0013 0014 #include <KParts/MainWindow> 0015 0016 #include "sublimeexport.h" 0017 0018 namespace Sublime { 0019 0020 class Container; 0021 class Area; 0022 class View; 0023 class Controller; 0024 class MainWindowOperator; 0025 class ViewBarContainer; 0026 class Message; 0027 class MainWindowPrivate; 0028 0029 /** 0030 @short Sublime Main Window 0031 0032 The area-enabled mainwindow to show Sublime views and tool views. 0033 0034 To use, a controller and constructed areas are necessary: 0035 @code 0036 MainWindow w(controller); 0037 controller->showArea(area, &w); 0038 @endcode 0039 */ 0040 class KDEVPLATFORMSUBLIME_EXPORT MainWindow: public KParts::MainWindow { 0041 Q_OBJECT 0042 public: 0043 /**Creates a mainwindow and adds it to the controller.*/ 0044 explicit MainWindow(Controller *controller, Qt::WindowFlags flags = {}); 0045 ~MainWindow() override; 0046 0047 /**@return the list of dockwidgets that contain area's tool views.*/ 0048 QList<View*> toolDocks() const; 0049 /**@return area which mainwindow currently shows or 0 if no area has been set.*/ 0050 Area *area() const; 0051 /**@return controller for this mainwindow.*/ 0052 Controller *controller() const; 0053 0054 /**@return active view inside this mainwindow.*/ 0055 View *activeView() const; 0056 /**@return active tool view inside this mainwindow.*/ 0057 View *activeToolView() const; 0058 0059 /**Enable saving of per-area UI settings (like toolbar properties 0060 and position) whenever area is changed. This should be 0061 called after all areas are restored, and main window area is 0062 set, to prevent saving a half-broken state. */ 0063 void enableAreaSettingsSave(); 0064 0065 /** Allows setting an additional widget that will be inserted left to the document tab-bar. 0066 * The ownership goes to the target. */ 0067 void setTabBarLeftCornerWidget(QWidget* widget); 0068 0069 /**Sets the area of main window and fills it with views. 0070 *The contents is reconstructed, even if the area equals the currently set area. */ 0071 void setArea(Area *area); 0072 0073 /** 0074 * Reconstruct the view structure. This is required after significant untracked changes to the 0075 * area-index structure. 0076 * Views listed in topViews will be on top of their view stacks. 0077 * */ 0078 void reconstructViews(const QList<View*>& topViews = QList<View*>()); 0079 0080 /**Returns a list of all views which are on top of their corresponding view stacks*/ 0081 QList<View*> topViews() const; 0082 0083 QSet<Container*> containers() const; 0084 0085 /**Returns the view that is closest to the given global position, or zero.*/ 0086 View* viewForPosition(const QPoint& globalPos) const; 0087 0088 /**Returns true if this main-window contains this view*/ 0089 bool containsView(View* view) const; 0090 0091 /**Returns all areas that belong to this main-window*/ 0092 QList<Area*> areas() const; 0093 0094 /** Sets a @p w widget that will be shown when there are no opened documents. 0095 * This method takes the ownership of @p w. 0096 * Pass @c nullptr for @p w for a blank background (default). 0097 */ 0098 void setBackgroundCentralWidget(QWidget* w); 0099 0100 /**Returns a widget that can hold a centralized view bar*/ 0101 ViewBarContainer *viewBarContainer() const; 0102 0103 public Q_SLOTS: 0104 /**Shows the @p view and makes it active, focusing it by default).*/ 0105 void activateView(Sublime::View *view, bool focus = true); 0106 /** Shows the @p message in the message area */ 0107 void postMessage(Sublime::Message* message); 0108 /**Loads size/toolbar/menu/statusbar settings to the global configuration file. 0109 Reimplement in subclasses to load more and don't forget to call inherited method.*/ 0110 virtual void loadSettings(); 0111 0112 Q_SIGNALS: 0113 /**Emitted before the area is cleared from this mainwindow.*/ 0114 void areaCleared(Sublime::Area*); 0115 /**Emitted after the new area has been shown in this mainwindow.*/ 0116 void areaChanged(Sublime::Area*); 0117 /**Emitted when the active view is changed.*/ 0118 void activeViewChanged(Sublime::View*); 0119 /**Emitted when the active tool view is changed.*/ 0120 void activeToolViewChanged(Sublime::View*); 0121 /**Emitted when the user interface settings have changed.*/ 0122 void settingsLoaded(); 0123 0124 /**Emitted when a new view is added to the mainwindow.*/ 0125 void viewAdded(Sublime::View*); 0126 /**Emitted when a view is going to be removed from the mainwindow.*/ 0127 void aboutToRemoveView(Sublime::View*); 0128 0129 protected: 0130 QWidget *statusBarLocation() const; 0131 virtual void initializeStatusBar(); 0132 protected Q_SLOTS: 0133 virtual void tabDoubleClicked(Sublime::View* view); 0134 virtual void tabContextMenuRequested(Sublime::View*, QMenu*); 0135 virtual void tabToolTipRequested(Sublime::View* view, Sublime::Container* container, int tab); 0136 virtual void newTabRequested(); 0137 /**Called whenever the user requests a context menu on a dockwidget bar. 0138 You can then e.g. add actions to add dockwidgets. 0139 Default implementation does nothing.**/ 0140 virtual void dockBarContextMenuRequested(Qt::DockWidgetArea, const QPoint&); 0141 0142 public: // FIXME? 0143 /**Saves size/toolbar/menu/statusbar settings to the global configuration file. 0144 Reimplement in subclasses to save more and don't forget to call inherited method.*/ 0145 virtual void saveSettings(); 0146 0147 /**Reimplemented to save settings.*/ 0148 bool queryClose() override; 0149 /** Allow connecting to activateView without the need for a lambda for the default parameter */ 0150 void activateViewAndFocus(Sublime::View *view) { activateView(view, true); } 0151 0152 private: 0153 QString screenKey() const; 0154 0155 //Inherit MainWindowOperator to access four methods below 0156 /**Unsets the area clearing main window.*/ 0157 void clearArea(); 0158 /**Sets the active view.*/ 0159 void setActiveView(Sublime::View* view, bool focus = true); 0160 /**Sets the active tool view and focuses it.*/ 0161 void setActiveToolView(View *view); 0162 0163 void saveGeometry(KConfigGroup &config) const; 0164 void loadGeometry(const KConfigGroup &config); 0165 0166 private: 0167 const QScopedPointer<class MainWindowPrivate> d_ptr; 0168 Q_DECLARE_PRIVATE(MainWindow) 0169 0170 friend class MainWindowOperator; 0171 friend class MainWindowPrivate; 0172 }; 0173 0174 } 0175 0176 0177 #endif 0178