File indexing completed on 2024-04-28 04:41:50

0001 /***************************************************************************
0002  *   Copyright (C) 2017-2018 by Emmanuel Lepage Vallee                     *
0003  *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@kde.org>             *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 3 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0017  **************************************************************************/
0018 #ifndef KQUICKITEMVIEWS_VIEWITEM_P_H
0019 #define KQUICKITEMVIEWS_VIEWITEM_P_H
0020 
0021 // KQuickItemViews
0022 #include "private/statetracker/viewitem_p.h"
0023 #include <adapters/abstractitemadapter.h>
0024 #include <private/indexmetadata_p.h>
0025 class ViewBase;
0026 class ViewItemContextAdapter;
0027 class ContextAdapter;
0028 class Viewport;
0029 
0030 // Qt
0031 class QQuickItem;
0032 #include <QtCore/QSharedPointer>
0033 
0034 namespace StateTracker {
0035 
0036 class Content;
0037 
0038 /**
0039  * Polymorphic tree item for the ViewBase.
0040  *
0041  * Classes implementing ViewBase need to provide an implementation of the pure
0042  * virtual functions. It is useful, for example, to manage both a raster and
0043  * QQuickItem based version of a view.
0044  *
0045  * The state is managed by the ViewBase and it's own protected virtual methods.
0046  */
0047 class ViewItem
0048 {
0049 public:
0050     explicit ViewItem(Viewport* r) :
0051         m_pViewport(r) {}
0052 
0053     virtual ~ViewItem() {
0054         m_pMetadata->setViewTracker(nullptr);
0055     }
0056 
0057     enum class State {
0058         POOLING , /*!< Being currently removed from view                      */
0059         POOLED  , /*!< Not currently in use, either new or waiting for re-use */
0060         BUFFER  , /*!< Not currently on screen, pre-loaded for performance    */
0061         ACTIVE  , /*!< Visible                                                */
0062         FAILED  , /*!< Loading the item was attempted, but failed             */
0063         DANGLING, /*!< Pending deletion, invalid pointers                     */
0064         ERROR   , /*!< Something went wrong                                   */
0065     };
0066 
0067     /// Call to notify that the geometry changed (for the selection delegate)
0068     void updateGeometry();
0069 
0070     void setCollapsed(bool v);
0071     bool isCollapsed() const;
0072 
0073     // Spacial navigation
0074     ViewItem* up   () const; //DEPRECATED
0075     ViewItem* down () const; //DEPRECATED
0076     ViewItem* left () const { return nullptr ;} //DEPRECATED
0077     ViewItem* right() const { return nullptr ;} //DEPRECATED
0078     ViewItem *next(Qt::Edge e) const;
0079 
0080     int row   () const;
0081     int column() const;
0082     int depth () const;
0083     //TODO firstChild, lastChild, parent
0084 
0085     // Getters
0086     QPersistentModelIndex index() const;
0087 
0088     /// Allow implementations to be notified when it becomes selected
0089     virtual void setSelected(bool) final;
0090 
0091     /// Geometry relative to the ViewBase::view()
0092     virtual QRectF currentGeometry() const final;
0093 
0094     virtual QQuickItem* item() const final;
0095 
0096     QQmlContext *context() const;
0097 
0098     Viewport      *m_pViewport {nullptr};
0099     IndexMetadata *m_pMetadata {nullptr};
0100 
0101     bool performAction(IndexMetadata::ViewAction a);
0102 
0103     State state() const;
0104 
0105     AbstractItemAdapter* d_ptr;
0106 private:
0107     State m_State {State::POOLED};
0108 };
0109 
0110 }
0111 
0112 #endif