File indexing completed on 2024-04-28 08:50:39
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 1998, 1999 Michael Reiher <michael.reiher@gmx.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __konq_frame_h__ 0008 #define __konq_frame_h__ 0009 0010 #include "konqfactory.h" 0011 #include <KParts/ReadOnlyPart> // for the inline QPointer usage 0012 0013 #include <QPointer> 0014 #include <QWidget> 0015 #include <QCheckBox> 0016 #include <QPixmap> 0017 #include <QEvent> 0018 #include <QList> 0019 0020 #include <KConfig> 0021 0022 class KonqFrameStatusBar; 0023 class KonqFrameVisitor; 0024 class QVBoxLayout; 0025 class QUrl; 0026 0027 class KonqView; 0028 class KonqFrameBase; 0029 class KonqFrame; 0030 class KonqFrameContainerBase; 0031 class KonqFrameContainer; 0032 class KSeparator; 0033 0034 namespace KParts 0035 { 0036 class ReadOnlyPart; 0037 } 0038 0039 typedef QList<KonqView *> ChildViewList; 0040 0041 class KONQ_TESTS_EXPORT KonqFrameBase 0042 { 0043 public: 0044 enum Option { 0045 None = 0x0, 0046 SaveUrls = 0x01, 0047 SaveHistoryItems = 0x02 0048 }; 0049 Q_DECLARE_FLAGS(Options, Option) 0050 0051 enum FrameType { View, Tabs, ContainerBase, Container, MainWindow }; 0052 0053 virtual ~KonqFrameBase() {} 0054 0055 virtual bool isContainer() const = 0; 0056 0057 virtual bool accept(KonqFrameVisitor *visitor) = 0; 0058 0059 virtual void saveConfig(KConfigGroup &config, const QString &prefix, const KonqFrameBase::Options &options, KonqFrameBase *docContainer, int id = 0, int depth = 0) = 0; 0060 0061 virtual void copyHistory(KonqFrameBase *other) = 0; 0062 0063 KonqFrameContainerBase *parentContainer() const 0064 { 0065 return m_pParentContainer; 0066 } 0067 void setParentContainer(KonqFrameContainerBase *parent) 0068 { 0069 m_pParentContainer = parent; 0070 } 0071 0072 virtual void setTitle(const QString &title, QWidget *sender) = 0; 0073 virtual void setTabIcon(const QUrl &url, QWidget *sender) = 0; 0074 0075 virtual QWidget *asQWidget() = 0; 0076 0077 virtual FrameType frameType() const = 0; 0078 0079 virtual void activateChild() = 0; 0080 0081 virtual KonqView *activeChildView() const = 0; 0082 0083 static QString frameTypeToString(const FrameType frameType); 0084 static FrameType frameTypeFromString(const QString &str); 0085 0086 protected: 0087 KonqFrameBase(); 0088 0089 KonqFrameContainerBase *m_pParentContainer; 0090 }; 0091 0092 Q_DECLARE_OPERATORS_FOR_FLAGS(KonqFrameBase::Options) 0093 0094 /** 0095 * The KonqFrame is the actual container for the views. It takes care of the 0096 * widget handling i.e. it attaches/detaches the view widget and activates 0097 * them on click at the statusbar. 0098 * 0099 * We create a vertical layout in the frame, with the view and the KonqFrameStatusBar. 0100 */ 0101 0102 class KONQ_TESTS_EXPORT KonqFrame : public QWidget, public KonqFrameBase 0103 { 0104 Q_OBJECT 0105 0106 public: 0107 explicit KonqFrame(QWidget *parent, KonqFrameContainerBase *parentContainer = nullptr); 0108 ~KonqFrame() override; 0109 0110 bool isContainer() const override 0111 { 0112 return false; 0113 } 0114 0115 bool accept(KonqFrameVisitor *visitor) override; 0116 0117 /** 0118 * Attach a view to the KonqFrame. 0119 * @param viewFactory the view to attach (instead of the current one, if any) 0120 */ 0121 KParts::ReadOnlyPart *attach(const KonqViewFactory &viewFactory, bool allowPlaceholder = false); 0122 0123 /** 0124 * Inserts the widget and the statusbar into the layout 0125 */ 0126 void attachWidget(QWidget *widget); 0127 0128 /** 0129 * Inserts a widget at the top of the part's widget, in the layout 0130 * (used for the find functionality) 0131 */ 0132 void insertTopWidget(QWidget *widget); 0133 0134 /** 0135 * Returns the part that is currently connected to the Frame. 0136 */ 0137 KParts::ReadOnlyPart *part() 0138 { 0139 return m_pPart; 0140 } 0141 /** 0142 * Returns the view that is currently connected to the Frame. 0143 */ 0144 KonqView *childView() const; 0145 0146 bool isActivePart(); 0147 0148 void setView(KonqView *child); 0149 0150 void saveConfig(KConfigGroup &config, const QString &prefix, const KonqFrameBase::Options &options, KonqFrameBase *docContainer, int id = 0, int depth = 0) override; 0151 void copyHistory(KonqFrameBase *other) override; 0152 0153 void setTitle(const QString &title, QWidget *sender) override; 0154 void setTabIcon(const QUrl &url, QWidget *sender) override; 0155 0156 QWidget *asQWidget() override 0157 { 0158 return this; 0159 } 0160 KonqFrameBase::FrameType frameType() const override 0161 { 0162 return KonqFrameBase::View; 0163 } 0164 0165 QVBoxLayout *layout()const 0166 { 0167 return m_pLayout; 0168 } 0169 0170 KonqFrameStatusBar *statusbar() const 0171 { 0172 return m_pStatusBar; 0173 } 0174 0175 void activateChild() override; 0176 0177 KonqView *activeChildView() const override; 0178 0179 QString title() const 0180 { 0181 return m_title; 0182 } 0183 0184 public Q_SLOTS: 0185 0186 /** 0187 * Is called when the frame statusbar has been clicked 0188 */ 0189 void slotStatusBarClicked(); 0190 0191 void slotLinkedViewClicked(bool mode); 0192 0193 /** 0194 * Is called when 'Remove View' is called from the popup menu 0195 */ 0196 void slotRemoveView(); 0197 0198 private: 0199 QVBoxLayout *m_pLayout; 0200 QPointer<KonqView> m_pView; 0201 0202 QPointer<KParts::ReadOnlyPart> m_pPart; 0203 0204 KSeparator *m_separator; 0205 KonqFrameStatusBar *m_pStatusBar; 0206 0207 QString m_title; 0208 }; 0209 0210 #endif