File indexing completed on 2024-04-21 04:58:14

0001 /*  This file is part of the KDE project
0002     SPDX-FileCopyrightText: 1998, 1999 Michael Reiher <michael.reiher@gmx.de>
0003     SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KONQ_FRAMECONTAINER_H
0009 #define KONQ_FRAMECONTAINER_H
0010 
0011 #include "konqframe.h"
0012 #include <QSplitter>
0013 
0014 /**
0015  * Base class for containers
0016  * This implements the Composite pattern: a composite is a type of base element.
0017  */
0018 class KONQ_TESTS_EXPORT KonqFrameContainerBase : public KonqFrameBase
0019 {
0020 public:
0021     ~KonqFrameContainerBase() override {}
0022 
0023     /**
0024      * Insert a new frame into the container.
0025      */
0026     virtual void insertChildFrame(KonqFrameBase *frame, int index = -1) = 0;
0027     /**
0028      * Replace a child frame with another
0029      */
0030     virtual void replaceChildFrame(KonqFrameBase *oldFrame, KonqFrameBase *newFrame);
0031     /**
0032      * Split one of our child frames
0033      */
0034     KonqFrameContainer *splitChildFrame(KonqFrameBase *frame, Qt::Orientation orientation);
0035 
0036     /**
0037      * Call this before deleting one of our children.
0038      */
0039     virtual void childFrameRemoved(KonqFrameBase *frame) = 0;
0040 
0041     bool isContainer() const override
0042     {
0043         return true;
0044     }
0045 
0046     KonqFrameBase::FrameType frameType() const override
0047     {
0048         return KonqFrameBase::ContainerBase;
0049     }
0050 
0051     KonqFrameBase *activeChild() const
0052     {
0053         return m_pActiveChild;
0054     }
0055 
0056     virtual void setActiveChild(KonqFrameBase *activeChild)
0057     {
0058         m_pActiveChild = activeChild;
0059         m_pParentContainer->setActiveChild(this);
0060     }
0061 
0062     void activateChild() override
0063     {
0064         if (m_pActiveChild) {
0065             m_pActiveChild->activateChild();
0066         }
0067     }
0068 
0069     KonqView *activeChildView() const override
0070     {
0071         if (m_pActiveChild) {
0072             return m_pActiveChild->activeChildView();
0073         } else {
0074             return nullptr;
0075         }
0076     }
0077 
0078 protected:
0079     KonqFrameContainerBase() {}
0080 
0081     KonqFrameBase *m_pActiveChild;
0082 };
0083 
0084 /**
0085  * With KonqFrameContainers and @refKonqFrames we can create a flexible
0086  * storage structure for the views. The top most element is a
0087  * KonqFrameContainer. It's a direct child of the MainView. We can then
0088  * build up a binary tree of containers. KonqFrameContainers are the nodes.
0089  * That means that they always have two children. Which are either again
0090  * KonqFrameContainers or, as leaves, KonqFrames.
0091  */
0092 class KONQ_TESTS_EXPORT KonqFrameContainer : public QSplitter, public KonqFrameContainerBase   // TODO rename to KonqFrameContainerSplitter?
0093 {
0094     Q_OBJECT
0095 public:
0096     KonqFrameContainer(Qt::Orientation o,
0097                        QWidget *parent,
0098                        KonqFrameContainerBase *parentContainer);
0099     ~KonqFrameContainer() override;
0100 
0101     bool accept(KonqFrameVisitor *visitor) override;
0102 
0103     void saveConfig(KConfigGroup &config, const QString &prefix, const KonqFrameBase::Options &options, KonqFrameBase *docContainer, int id = 0, int depth = 0) override;
0104     void copyHistory(KonqFrameBase *other) override;
0105 
0106     KonqFrameBase *firstChild()
0107     {
0108         return m_pFirstChild;
0109     }
0110     KonqFrameBase *secondChild()
0111     {
0112         return m_pSecondChild;
0113     }
0114     KonqFrameBase *otherChild(KonqFrameBase *child);
0115 
0116     void swapChildren();
0117 
0118     void setTitle(const QString &title, QWidget *sender) override;
0119     void setTabIcon(const QUrl &url, QWidget *sender) override;
0120 
0121     QWidget *asQWidget() override
0122     {
0123         return this;
0124     }
0125     KonqFrameBase::FrameType frameType() const override
0126     {
0127         return KonqFrameBase::Container;
0128     }
0129 
0130     /**
0131      * Insert a new frame into the splitter.
0132      */
0133     void insertChildFrame(KonqFrameBase *frame, int index = -1) override;
0134     /**
0135      * Call this before deleting one of our children.
0136      */
0137     void childFrameRemoved(KonqFrameBase *frame) override;
0138 
0139     void replaceChildFrame(KonqFrameBase *oldFrame, KonqFrameBase *newFrame) override;
0140 
0141     void setAboutToBeDeleted()
0142     {
0143         m_bAboutToBeDeleted = true;
0144     }
0145 
0146 protected:
0147     void childEvent(QChildEvent *) override;
0148 
0149 Q_SIGNALS:
0150     void setRubberbandCalled();
0151 
0152 protected:
0153     KonqFrameBase *m_pFirstChild;
0154     KonqFrameBase *m_pSecondChild;
0155     bool m_bAboutToBeDeleted;
0156 };
0157 
0158 #endif /* KONQ_FRAMECONTAINER_H */
0159