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

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 #include "geometryadapter.h"
0019 
0020 #include <viewport.h>
0021 
0022 class GeometryAdapterPrivate
0023 {
0024 public:
0025     bool m_hasPositionHints {false};
0026     bool m_hasUniformHeight {false};
0027     bool m_hasUniformWidth  {false};
0028 
0029     int m_Flags {GeometryAdapter::Capabilities::NONE};
0030 
0031     Viewport *m_pViewport;
0032 };
0033 
0034 GeometryAdapter::GeometryAdapter(Viewport *parent) : QObject(parent),
0035     d_ptr(new GeometryAdapterPrivate())
0036 {
0037     d_ptr->m_pViewport = parent;
0038 }
0039 
0040 GeometryAdapter::~GeometryAdapter()
0041 {
0042     delete d_ptr;
0043 }
0044 
0045 Viewport *GeometryAdapter::viewport() const
0046 {
0047     return d_ptr->m_pViewport;
0048 }
0049 
0050 QPointF GeometryAdapter::positionHint(const QModelIndex &index, AbstractItemAdapter *adapter) const
0051 {
0052     Q_UNUSED(adapter)
0053     Q_UNUSED(index)
0054     return {};
0055 }
0056 
0057 QSizeF GeometryAdapter::sizeHint(const QModelIndex &index, AbstractItemAdapter *adapter) const
0058 {
0059     Q_UNUSED(adapter)
0060     Q_UNUSED(index)
0061 
0062     return {};
0063 }
0064 
0065 void GeometryAdapter::setCapabilities(int f)
0066 {
0067     if (f == d_ptr->m_Flags)
0068         return;
0069 
0070     d_ptr->m_Flags = f;
0071 
0072     emit flagsChanged();
0073 }
0074 
0075 void GeometryAdapter::addCapabilities(int f)
0076 {
0077     if ((d_ptr->m_Flags | f) == d_ptr->m_Flags)
0078         return;
0079 
0080     d_ptr->m_Flags |= f;
0081 
0082     emit flagsChanged();
0083 }
0084 
0085 void GeometryAdapter::removeCapabilities(int f)
0086 {
0087     int newFlags = d_ptr->m_Flags & (~f);
0088 
0089     if (d_ptr->m_Flags == newFlags)
0090         return;
0091 
0092     d_ptr->m_Flags = newFlags;
0093 
0094     emit flagsChanged();
0095 }
0096 
0097 int GeometryAdapter::capabilities() const
0098 {
0099     return d_ptr->m_Flags;
0100 }
0101 
0102 bool GeometryAdapter::isSizeForced() const
0103 {
0104     return  d_ptr->m_Flags & Capabilities::FORCE_DELEGATE_SIZE;
0105 }
0106 
0107 void GeometryAdapter::setSizeForced(bool f)
0108 {
0109     // This capability has a property because it really depends on the how
0110     // the QML delegate is implemented. The developer should be able to
0111     // select the preferred value form QML.
0112     if (f)
0113         addCapabilities   (Capabilities::FORCE_DELEGATE_SIZE);
0114     else
0115         removeCapabilities(Capabilities::FORCE_DELEGATE_SIZE);
0116 }