File indexing completed on 2024-04-28 04:37:34
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_SUBLIMEVIEW_H 0008 #define KDEVPLATFORM_SUBLIMEVIEW_H 0009 0010 #include <QObject> 0011 #include <QMetaType> 0012 0013 #include "sublimeexport.h" 0014 0015 class KConfigGroup; 0016 0017 class QAction; 0018 0019 namespace Sublime { 0020 0021 class Document; 0022 class ViewPrivate; 0023 0024 /** 0025 @short View - the wrapper to the widget that knows about its document 0026 0027 Views are the convenient way to manage a widget. It is specifically designed to be 0028 light and fast. Use @ref Document::createView() to get the new view for the document 0029 and call @ref View::widget() to create and get the actual widget. 0030 0031 It is not possible to create a view by hand. You need either subclass it or use a Document. 0032 0033 If you create a subclass of View you need to override Sublime::View::createWidget to 0034 provide a custom widget for your view. 0035 0036 */ 0037 class KDEVPLATFORMSUBLIME_EXPORT View: public QObject { 0038 Q_OBJECT 0039 public: 0040 enum WidgetOwnership { 0041 TakeOwnership, 0042 DoNotTakeOwnerShip 0043 }; 0044 ~View() override; 0045 0046 /**@return the toolbar actions for this view, this needs to be called _after_ the first call to widget() */ 0047 QList<QAction*> toolBarActions() const; 0048 0049 /**@return the toolbar actions for this view, this needs to be called _after_ the first call to widget() */ 0050 QList<QAction*> contextMenuActions() const; 0051 0052 /**@return the document for this view.*/ 0053 Document *document() const; 0054 /**@return widget for this view (creates it if it's not yet created).*/ 0055 QWidget *widget(QWidget *parent = nullptr); 0056 /**@return true if this view has an initialized widget.*/ 0057 bool hasWidget() const; 0058 0059 /// Retrieve information to be placed in the status bar. 0060 virtual QString viewStatus() const; 0061 0062 /** 0063 * Read session settings from the given \p config. 0064 * 0065 * The default implementation is a no-op 0066 * 0067 * @see KTextEditor::View::readSessionConfig() 0068 */ 0069 virtual void readSessionConfig(KConfigGroup &config); 0070 /** 0071 * Write session settings to the \p config. 0072 * 0073 * The default implementation is a no-op 0074 * 0075 * @see KTextEditor::View::writeSessionConfig() 0076 */ 0077 virtual void writeSessionConfig(KConfigGroup &config); 0078 0079 void notifyPositionChanged(int newPositionInArea); 0080 0081 Q_SIGNALS: 0082 void raise(Sublime::View*); 0083 /// Notify that the status for this document has changed 0084 void statusChanged(Sublime::View*); 0085 void positionChanged(Sublime::View*, int); 0086 0087 public Q_SLOTS: 0088 void requestRaise(); 0089 0090 protected: 0091 explicit View(Document *doc, WidgetOwnership ws = DoNotTakeOwnerShip ); 0092 /** 0093 * override this function to create a custom widget in your View subclass 0094 * @param parent the parent widget 0095 * @returns a new widget which is used for this view 0096 */ 0097 virtual QWidget *createWidget(QWidget *parent); 0098 0099 private: 0100 //copy is not allowed, create a new view from the document instead 0101 View(const View &v); 0102 const QScopedPointer<class ViewPrivate> d_ptr; 0103 Q_DECLARE_PRIVATE(View) 0104 0105 friend class Document; 0106 }; 0107 0108 } 0109 0110 #endif 0111