File indexing completed on 2024-05-12 04:43:04

0001 /***************************************************************************
0002  *   Copyright (C) 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_GEOMETRY_P_H
0019 #define KQUICKITEMVIEWS_GEOMETRY_P_H
0020 
0021 // Qt
0022 #include <QtCore/QRectF>
0023 #include <QtGlobal>
0024 
0025 #include <private/indexmetadata_p.h>
0026 #include <private/geoutils_p.h>
0027 
0028 namespace StateTracker {
0029 
0030 /**
0031  * Computing the absolute geometry of items isn't always trivial.
0032  *
0033  * There is always the case where you known part of the answer (point or size)
0034  * and/or where the item moves and the size is valid but not the position.
0035  *
0036  * If there is no scrollbar, having the absolute position right isn't
0037  * necessary as long as the relative one is correct.
0038  *
0039  * This structure tries to allow delaying the geometry computation as late
0040  * as possible.
0041  *
0042  * The geometry is built using 3 components:
0043  *
0044  * * The content size
0045  * * The outer decoration size
0046  * * The position
0047  *
0048  * What this entity doesn't known (and should not ever know)
0049  *
0050  * * Anything related about its neighbor.
0051  *
0052  */
0053 struct Geometry
0054 {
0055     enum class State {
0056         INIT    , /*!< The value has not been computed        */
0057         SIZE    , /*!< The size had been computed             */
0058         POSITION, /*!< The position has been computed         */
0059         PENDING , /*!< Has all information, but not assembled */
0060         VALID   , /*!< The geometry has been computed         */
0061     };
0062 
0063     State performAction(IndexMetadata::GeometryAction);
0064 
0065     QPointF position() const;
0066     void setPosition(const QPointF& pos);
0067 
0068     QSizeF size() const;
0069     void setSize(const QSizeF& size);
0070 
0071     QRectF decoratedGeometry() const;
0072 
0073     QRectF contentGeometry() const;
0074 
0075     qreal borderDecoration(Qt::Edge e) const;
0076     void setBorderDecoration(Qt::Edge e, qreal r);
0077 
0078     State state() const;
0079 
0080 private:
0081     QRectF rawGeometry() const;
0082 
0083     QPointF m_Position;
0084     QSizeF  m_Size;
0085 
0086     GeoRect<qreal> m_lBorderDecoration;
0087 
0088     typedef void(Geometry::*StateF)();
0089 
0090     static const State  m_fStateMap    [5][7];
0091     static const StateF m_fStateMachine[5][7];
0092 
0093     // Actions
0094     void nothing();
0095     void invalidate();
0096     void error();
0097     void dropCache();
0098     void dropSize();
0099     void dropPos();
0100     void buildCache();
0101 
0102     State m_State {State::INIT};
0103 };
0104 
0105 }
0106 
0107 #endif