File indexing completed on 2024-04-28 04:36:31
0001 /* 0002 SPDX-FileCopyrightText: 2007 Alexander Dymo <adymo@kdevelop.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVPLATFORM_IUICONTROLLER_H 0008 #define KDEVPLATFORM_IUICONTROLLER_H 0009 0010 #include "interfacesexport.h" 0011 0012 #include <QWidget> 0013 0014 class QAction; 0015 0016 namespace KParts { 0017 class MainWindow; 0018 } 0019 namespace Sublime{ 0020 class Controller; 0021 class View; 0022 class Area; 0023 class Message; 0024 } 0025 0026 namespace KDevelop { 0027 0028 class IDocument; 0029 class IAssistant; 0030 0031 class KDEVPLATFORMINTERFACES_EXPORT IToolViewFactory { 0032 public: 0033 virtual ~IToolViewFactory() {} 0034 /** 0035 * called to create a new widget for this tool view 0036 * @param parent the parent to use as parent for the widget 0037 * @returns the new widget for the tool view 0038 */ 0039 virtual QWidget* create(QWidget *parent = nullptr) = 0; 0040 /** 0041 * @returns the identifier of this tool view. The identifier 0042 * is used to remember which areas the tool view should appear 0043 * in, and must never change. 0044 */ 0045 virtual QString id() const = 0; 0046 /** 0047 * @returns the default position where this tool view should appear 0048 */ 0049 virtual Qt::DockWidgetArea defaultPosition() const = 0; 0050 /** 0051 * Fetch a list of actions to add to the toolbar of the tool view @p view 0052 * @param viewWidget the view to which the actions should be added 0053 * @returns a list of actions to be added to the toolbar 0054 */ 0055 virtual QList<QAction*> toolBarActions( QWidget* viewWidget ) const { return viewWidget->actions(); } 0056 /** 0057 * Fetch a list of actions to be shown in the context menu of the tool view @p view. 0058 * The default implementation will return all actions of @p viewWidget. 0059 * 0060 * @param viewWidget the view for which the context menu should be shown 0061 * @returns a list of actions to be shown in the context menu 0062 */ 0063 virtual QList<QAction*> contextMenuActions( QWidget* viewWidget ) const { return viewWidget->actions(); } 0064 0065 /** 0066 * called when a new view is created from this template 0067 * @param view the new sublime view that is being shown 0068 */ 0069 virtual void viewCreated(Sublime::View* view); 0070 0071 /** 0072 * @returns if multiple tool views can by created by this factory in the same area. 0073 */ 0074 virtual bool allowMultiple() const { return false; } 0075 }; 0076 0077 /** 0078 * 0079 * Allows to access various parts of the user-interface, like the tool views or the mainwindow 0080 */ 0081 class KDEVPLATFORMINTERFACES_EXPORT IUiController { 0082 public: 0083 virtual ~IUiController(); 0084 0085 enum SwitchMode { 0086 ThisWindow /**< indicates that the area switch should be in this window */, 0087 NewWindow /**< indicates that the area switch should be using a new window */ 0088 }; 0089 0090 enum FindFlags { 0091 None = 0, 0092 Create = 1, ///The tool-view is created if it doesn't exist in the current area yet 0093 Raise = 2, ///The tool-view is raised if it was found/created 0094 CreateAndRaise = Create | Raise ///The tool view is created and raised 0095 }; 0096 0097 virtual void switchToArea(const QString &areaName, SwitchMode switchMode) = 0; 0098 0099 virtual void addToolView(const QString &name, IToolViewFactory *factory, FindFlags state = Create) = 0; 0100 virtual void removeToolView(IToolViewFactory *factory) = 0; 0101 0102 /** Makes sure that this tool-view exists in the current area, raises it, and returns the contained widget 0103 * Returns zero on failure */ 0104 virtual QWidget* findToolView(const QString& name, IToolViewFactory *factory, FindFlags flags = CreateAndRaise) = 0; 0105 0106 /** 0107 * Makes sure that the tool view that contains the widget @p toolViewWidget is visible to the user. 0108 */ 0109 virtual void raiseToolView(QWidget* toolViewWidget) = 0; 0110 0111 /** @return active mainwindow or 0 if no such mainwindow is active.*/ 0112 virtual KParts::MainWindow *activeMainWindow() = 0; 0113 0114 /*! @p status must implement KDevelop::IStatus */ 0115 virtual void registerStatus(QObject* status) = 0; 0116 0117 /** 0118 * This is meant to be used by IDocument subclasses to initialize the 0119 * Sublime::Document. 0120 */ 0121 virtual Sublime::Controller* controller() = 0; 0122 0123 /** Shows an error message in the status bar. 0124 * 0125 * Unlike all other functions in this class, this function is thread-safe. 0126 * You can call it from the background. 0127 * 0128 * @p message The message 0129 * @p timeout The timeout in seconds how long to show the message */ 0130 virtual void showErrorMessage(const QString& message, int timeout = 5) = 0; 0131 // TODO: convert all these calls into postMessage 0132 0133 /** 0134 * Shows a message in the message area. 0135 * 0136 * If running in NoGui mode, the message will be discarded. 0137 * 0138 * Unlike all other functions in this class, this function is thread-safe. 0139 * You can call it from the background. 0140 * 0141 * @p message the message, ownership is transferred 0142 */ 0143 virtual void postMessage(Sublime::Message* message) = 0; 0144 0145 /** @return area for currently active sublime mainwindow or 0 if 0146 no sublime mainwindow is active.*/ 0147 virtual Sublime::Area *activeArea() = 0; 0148 0149 /** 0150 * Widget which is currently responsible for consuming special events in the UI 0151 * (such as shortcuts) 0152 * 0153 * @sa IToolViewActionListener 0154 * @return QWidget implementing the IToolViewActionListener interface 0155 */ 0156 virtual QWidget* activeToolViewActionListener() const = 0; 0157 0158 /** 0159 * @returns all areas in the shell 0160 * 0161 * @note there will be one per mainwindow, of each type, plus the default ones. 0162 */ 0163 virtual QList<Sublime::Area*> allAreas() const = 0; 0164 0165 protected: 0166 IUiController(); 0167 }; 0168 0169 } 0170 0171 #endif 0172