File indexing completed on 2024-05-05 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_GEOUTILS_P_H
0019 #define KQUICKITEMVIEWS_GEOUTILS_P_H
0020 
0021 class GeoUtils
0022 {
0023 public:
0024     enum class Pos {Top, Left, Right, Bottom};
0025 
0026 //     static QPair<Qt::Edge,Qt::Edge> fromGravity() const;
0027 
0028     static constexpr Qt::Edge fromPos(Pos p) {
0029         return edgeMap[(int)p];
0030     }
0031 
0032     static constexpr Pos fromEdge(Qt::Edge e) {
0033         switch(e) {
0034             case Qt::TopEdge:
0035                 return Pos::Top;
0036             case Qt::LeftEdge:
0037                 return Pos::Left;
0038             case Qt::RightEdge:
0039                 return Pos::Right;
0040             case Qt::BottomEdge:
0041                 return Pos::Bottom;
0042         }
0043         return {};
0044     }
0045 
0046 private:
0047     static constexpr const Qt::Edge edgeMap[] = {
0048         Qt::TopEdge, Qt::LeftEdge, Qt::RightEdge, Qt::BottomEdge
0049     };
0050 //     Qt::TopEdge, Qt::LeftEdge, Qt::RightEdge, Qt::BottomEdge
0051 };
0052 
0053 template<typename T>
0054 class GeoRect
0055 {
0056 public:
0057     T get(Qt::Edge e) const {
0058         return get(GeoUtils::fromEdge(e));
0059     }
0060 
0061     T get(GeoUtils::Pos p) const {
0062         return m_lRect[(int)p];
0063     }
0064 
0065     void set(T v, Qt::Edge e) {
0066         set(v, GeoUtils::fromEdge(e));
0067     }
0068 
0069     void set(T v, GeoUtils::Pos p) {
0070         m_lRect[(int)p] = v;
0071     }
0072 
0073     //TODO implement operator[]
0074 private:
0075     T m_lRect[4] = {{}, {}, {}, {}};
0076 };
0077 
0078 // QPair<Qt::Edge,Qt::Edge> ViewportPrivate::fromGravity() const
0079 // {
0080 //     switch (m_pModelAdapter->view()->gravity()) {
0081 //         case Qt::Corner::TopLeftCorner:
0082 //             return {Qt::Edge::TopEdge, Qt::Edge::LeftEdge};
0083 //         case Qt::Corner::TopRightCorner:
0084 //             return {Qt::Edge::TopEdge, Qt::Edge::RightEdge};
0085 //         case Qt::Corner::BottomLeftCorner:
0086 //             return {Qt::Edge::BottomEdge, Qt::Edge::LeftEdge};
0087 //         case Qt::Corner::BottomRightCorner:
0088 //             return {Qt::Edge::BottomEdge, Qt::Edge::RightEdge};
0089 //     }
0090 //
0091 //     Q_ASSERT(false);
0092 //     return {};
0093 // }
0094 
0095 // static Pos edgeToPos(Qt::Edge e)
0096 // {
0097 //     switch(e) {
0098 //         case Qt::TopEdge:
0099 //             return Pos::Top;
0100 //         case Qt::LeftEdge:
0101 //             return Pos::Left;
0102 //         case Qt::RightEdge:
0103 //             return Pos::Right;
0104 //         case Qt::BottomEdge:
0105 //             return Pos::Bottom;
0106 //     }
0107 //
0108 //     Q_ASSERT(false);
0109 //
0110 //     return {};
0111 // }
0112 
0113 #endif