File indexing completed on 2024-05-12 09:57:15
0001 /* 0002 SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef VIEWCONTAINER_H 0008 #define VIEWCONTAINER_H 0009 0010 // Qt 0011 #include <QObject> 0012 #include <QTabWidget> 0013 0014 // Konsole 0015 #include "ViewManager.h" 0016 #include "session/Session.h" 0017 0018 // Qt 0019 class QPoint; 0020 class QToolButton; 0021 class QMenu; 0022 0023 namespace Konsole 0024 { 0025 class ViewProperties; 0026 class ViewManager; 0027 class TabbedViewContainer; 0028 0029 /** 0030 * An interface for container widgets which can hold one or more views. 0031 * 0032 * The container widget typically displays a list of the views which 0033 * it has and provides a means of switching between them. 0034 * 0035 * Subclasses should reimplement the addViewWidget() and removeViewWidget() functions 0036 * to actually add or remove view widgets from the container widget, as well 0037 * as updating any navigation aids. 0038 */ 0039 class KONSOLEPRIVATE_EXPORT TabbedViewContainer : public QTabWidget 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 /** 0045 * Constructs a new view container with the specified parent. 0046 * 0047 * @param connectedViewManager Connect the new view to this manager 0048 * @param parent The parent object of the container 0049 */ 0050 TabbedViewContainer(ViewManager *connectedViewManager, QWidget *parent); 0051 0052 /** 0053 * Called when the ViewContainer is destroyed. When reimplementing this in 0054 * subclasses, use object->deleteLater() to delete any widgets or other objects 0055 * instead of 'delete object'. 0056 */ 0057 ~TabbedViewContainer() override; 0058 0059 /** Adds a new view to the container widget */ 0060 void addView(TerminalDisplay *view); 0061 void addSplitter(ViewSplitter *viewSplitter, int index = -1); 0062 0063 /** splits the currently focused Splitter */ 0064 void splitView(TerminalDisplay *view, Qt::Orientation orientation); 0065 0066 void setTabActivity(int index, bool activity); 0067 0068 /** Sets tab title to item title if the view is active */ 0069 void updateTitle(ViewProperties *item); 0070 /** Sets tab color to item color if the view is active */ 0071 void updateColor(ViewProperties *item); 0072 /** Sets tab icon to item icon if the view is active */ 0073 void updateIcon(ViewProperties *item); 0074 /** Sets tab activity status if the tab is not active */ 0075 void updateActivity(ViewProperties *item); 0076 /** Sets tab notification */ 0077 void updateNotification(ViewProperties *item, Konsole::Session::Notification notification, bool enabled); 0078 /** Sets tab special state (copy input or read-only) */ 0079 void updateSpecialState(ViewProperties *item); 0080 0081 /** Changes the active view to the next view */ 0082 void activateNextView(); 0083 0084 /** Changes the active view to the previous view */ 0085 void activatePreviousView(); 0086 0087 /** Changes the active view to the last view */ 0088 void activateLastView(); 0089 0090 void setCssFromFile(const QUrl &url); 0091 0092 ViewSplitter *activeViewSplitter(); 0093 /** 0094 * This enum describes the directions 0095 * in which views can be re-arranged within the container 0096 * using the moveActiveView() method. 0097 */ 0098 enum MoveDirection { 0099 /** Moves the view to the left. */ 0100 MoveViewLeft, 0101 /** Moves the view to the right. */ 0102 MoveViewRight, 0103 }; 0104 0105 /** 0106 * Moves the active view within the container and 0107 * updates the order in which the views are shown 0108 * in the container's navigation widget. 0109 * 0110 * The default implementation does nothing. 0111 */ 0112 void moveActiveView(MoveDirection direction); 0113 0114 /** Sets the menu to be shown when the new view button is clicked. 0115 * Only valid if the QuickNewView feature is enabled. 0116 * The default implementation does nothing. */ 0117 // TODO: Re-enable this later. 0118 // void setNewViewMenu(QMenu *menu); 0119 void renameTab(int index); 0120 ViewManager *connectedViewManager(); 0121 void currentTabChanged(int index); 0122 void closeCurrentTab(); 0123 void wheelScrolled(int delta); 0124 void currentSessionControllerChanged(SessionController *controller); 0125 void tabDoubleClicked(int index); 0126 void openTabContextMenu(const QPoint &point); 0127 void setNavigationVisibility(ViewManager::NavigationVisibility navigationVisibility); 0128 void moveTabToWindow(int index, QWidget *window); 0129 0130 void toggleMaximizeCurrentTerminal(); 0131 void toggleZoomMaximizeCurrentTerminal(); 0132 /* return the widget(int index) casted to TerminalDisplay* 0133 * 0134 * The only thing that this class holds are TerminalDisplays, so 0135 * this is the only thing that should be used to retrieve widgets. 0136 */ 0137 ViewSplitter *viewSplitterAt(int index); 0138 0139 ViewSplitter *findSplitter(int id); 0140 0141 /** 0142 * Returns the number of split views (i.e. TerminalDisplay widgets) 0143 * in this tab; if there are no split views, 1 is returned. 0144 */ 0145 int currentTabViewCount(); 0146 0147 void connectTerminalDisplay(TerminalDisplay *display); 0148 void disconnectTerminalDisplay(TerminalDisplay *display); 0149 void moveTabLeft(); 0150 void moveTabRight(); 0151 0152 /** 0153 * This enum describes where newly created tab should be placed. 0154 */ 0155 enum NewTabBehavior { 0156 /** Put newly created tab at the end. */ 0157 PutNewTabAtTheEnd = 0, 0158 /** Put newly created tab right after current tab. */ 0159 PutNewTabAfterCurrentTab = 1, 0160 }; 0161 0162 void setNavigationBehavior(int behavior); 0163 void terminalDisplayDropped(TerminalDisplay *terminalDisplay); 0164 0165 void moveToNewTab(TerminalDisplay *display); 0166 0167 QSize sizeHint() const override; 0168 0169 Q_SIGNALS: 0170 /** Emitted when the container has no more children */ 0171 void empty(TabbedViewContainer *container); 0172 0173 /** Emitted when the user requests to open a new view */ 0174 void newViewRequest(); 0175 0176 /** Requests creation of a new view, with the selected profile. */ 0177 void newViewWithProfileRequest(const QExplicitlySharedDataPointer<Profile> &profile); 0178 0179 /** a terminalDisplay was dropped in a child Splitter */ 0180 0181 /** 0182 * Emitted when the user requests to move a view from another container 0183 * into this container. If 'success' is set to true by a connected slot 0184 * then the original view will be removed. 0185 * 0186 * @param index Index at which to insert the new view in the container 0187 * or -1 to append it. This index should be passed to addView() when 0188 * the new view has been created. 0189 * @param sessionControllerId The identifier of the view. 0190 */ 0191 void moveViewRequest(int index, int sessionControllerId); 0192 0193 /** Emitted when the active view changes */ 0194 void activeViewChanged(TerminalDisplay *view); 0195 0196 /** Emitted when a view is added to the container. */ 0197 void viewAdded(TerminalDisplay *view); 0198 0199 /** Emitted when a view is removed from container. */ 0200 void viewRemoved(); 0201 0202 /** detach the specific tab */ 0203 void detachTab(int tabIdx); 0204 0205 /** set the color tab */ 0206 void setColor(int index, const QColor &color); 0207 0208 /** remove the color tab */ 0209 void removeColor(int idx); 0210 0211 protected: 0212 // close tabs and unregister 0213 void closeTerminalTab(int idx); 0214 0215 void keyReleaseEvent(QKeyEvent *event) override; 0216 private Q_SLOTS: 0217 void viewDestroyed(QObject *view); 0218 void konsoleConfigChanged(); 0219 void activateView(const QString &xdgActivationToken); 0220 0221 private: 0222 void forgetView(); 0223 0224 struct TabIconState { 0225 TabIconState() 0226 : readOnly(false) 0227 , broadcast(false) 0228 , notification(Session::NoNotification) 0229 { 0230 } 0231 0232 bool readOnly; 0233 bool broadcast; 0234 Session::Notification notification; 0235 0236 bool isAnyStateActive() const 0237 { 0238 return readOnly || broadcast || (notification != Session::NoNotification); 0239 } 0240 }; 0241 0242 bool _stylesheetSet = false; 0243 0244 QHash<const QWidget *, TabIconState> _tabIconState; 0245 ViewManager *_connectedViewManager; 0246 QMenu *_contextPopupMenu; 0247 QToolButton *_newTabButton; 0248 QToolButton *_closeTabButton; 0249 int _contextMenuTabIndex; 0250 NewTabBehavior _newTabBehavior; 0251 }; 0252 0253 } 0254 #endif // VIEWCONTAINER_H