File indexing completed on 2024-03-24 05:54:24
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef VIEWPROPERTIES_H 0008 #define VIEWPROPERTIES_H 0009 0010 // Qt 0011 #include <QColor> 0012 #include <QHash> 0013 #include <QIcon> 0014 #include <QObject> 0015 #include <QUrl> 0016 0017 // Konsole 0018 #include "konsoleprivate_export.h" 0019 #include "session/Session.h" 0020 0021 namespace Konsole 0022 { 0023 /** 0024 * Encapsulates user-visible information about the terminal session currently being displayed in a view, 0025 * such as the associated title and icon. 0026 * 0027 * This can be used by navigation widgets in a ViewContainer sub-class to provide a tab, label or other 0028 * item for switching between views. 0029 */ 0030 class KONSOLEPRIVATE_EXPORT ViewProperties : public QObject 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 explicit ViewProperties(QObject *parent); 0036 ~ViewProperties() override; 0037 0038 /** Returns the icon associated with a view */ 0039 QIcon icon() const; 0040 /** Returns the title associated with a view */ 0041 QString title() const; 0042 /** Returns the color associated with a view */ 0043 QColor color() const; 0044 0045 /** 0046 * Returns the URL current associated with a view. 0047 * The default implementation returns an empty URL. 0048 */ 0049 virtual QUrl url() const; 0050 0051 /** 0052 * Returns the current directory associated with a view. 0053 * This may be the same as url() 0054 * The default implementation returns an empty string. 0055 */ 0056 virtual QString currentDir() const; 0057 0058 /** 0059 * A unique identifier associated with this 0060 * ViewProperties instance. 0061 */ 0062 int identifier() const; 0063 0064 /** 0065 * Sub-classes may re-implement this method to display a message to the user 0066 * to allow them to confirm whether to close a view. 0067 * The default implementation always returns true 0068 */ 0069 virtual bool confirmClose() const 0070 { 0071 return true; 0072 } 0073 0074 /** Finds a ViewProperties instance given its numeric identifier. */ 0075 static ViewProperties *propertiesById(int id); 0076 0077 Q_SIGNALS: 0078 /** Emitted when the icon for a view changes */ 0079 void iconChanged(ViewProperties *properties); 0080 /** Emitted when the title for a view changes */ 0081 void titleChanged(ViewProperties *properties); 0082 /** Emitted when the color for a view changes */ 0083 void colorChanged(ViewProperties *properties); 0084 /** Emitted when activity has occurred in this view. */ 0085 void activity(ViewProperties *item); 0086 /** Emitted when notification for a view changes */ 0087 void notificationChanged(ViewProperties *item, Session::Notification notification, bool enabled); 0088 /** Emitted when read only state changes */ 0089 void readOnlyChanged(ViewProperties *item); 0090 /** Emitted when "copy input" state changes */ 0091 void copyInputChanged(ViewProperties *item); 0092 0093 public Q_SLOTS: 0094 /** 0095 * Requests the renaming of this view. 0096 * The default implementation does nothing. 0097 */ 0098 virtual void rename(); 0099 0100 protected Q_SLOTS: 0101 /** Emits the activity() signal. */ 0102 void fireActivity(); 0103 0104 protected: 0105 /** 0106 * Subclasses may call this method to change the title. This causes 0107 * a titleChanged() signal to be emitted 0108 */ 0109 void setTitle(const QString &title); 0110 /** 0111 * Subclasses may call this method to change the icon. This causes 0112 * an iconChanged() signal to be emitted 0113 */ 0114 void setIcon(const QIcon &icon); 0115 /** 0116 * Subclasses may call this method to change the color. This causes 0117 * a colorChanged() signal to be emitted 0118 */ 0119 void setColor(const QColor &color); 0120 /** Subclasses may call this method to change the identifier. */ 0121 void setIdentifier(int id); 0122 0123 private: 0124 Q_DISABLE_COPY(ViewProperties) 0125 0126 QIcon _icon; 0127 QString _title; 0128 QColor _color; 0129 int _identifier; 0130 0131 static QHash<int, ViewProperties *> _viewProperties; 0132 }; 0133 } 0134 0135 #endif // VIEWPROPERTIES_H