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

0001 /***************************************************************************
0002  *   Copyright (C) 2019 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 "sizehintview.h"
0019 
0020 #include <KQuickItemViews/adapters/AbstractItemAdapter>
0021 #include <KQuickItemViews/adapters/ModelAdapter>
0022 #include <KQuickItemViews/Viewport>
0023 #include <KQuickItemViews/strategies/role.h>
0024 
0025 class SizeHintViewPrivate
0026 {
0027 public:
0028     ModelAdapter *m_pModelAdapter;
0029     Viewport     *m_pViewport;
0030 };
0031 
0032 SizeHintView::SizeHintView(QQuickItem* parent) : SingleModelViewBase(new ItemFactory<AbstractItemAdapter>(), parent),
0033     d_ptr(new SizeHintViewPrivate())
0034 {
0035     //TODO use ViewBase directly once there is some Q interfaces for its parts.
0036     d_ptr->m_pModelAdapter = modelAdapters().first();
0037     d_ptr->m_pViewport     = d_ptr->m_pModelAdapter->viewports().first();
0038     auto a = new GeometryStrategies::Role(d_ptr->m_pViewport);
0039     setDelegateSizeForced(true);
0040     a->setPositionRole(Qt::SizeHintRole);
0041     d_ptr->m_pViewport->setGeometryAdapter(a);
0042 }
0043 
0044 SizeHintView::~SizeHintView()
0045 {
0046     delete d_ptr;
0047 }