File indexing completed on 2025-01-26 05:06:21

0001 /*
0002     SPDX-FileCopyrightText: 2008 Fredrik Höglund <fredrik@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "itemviewadapter.h"
0008 
0009 #include <QModelIndex>
0010 #include <QPalette>
0011 #include <QSize>
0012 
0013 ItemViewAdapter::ItemViewAdapter(QObject *parent)
0014     : KAbstractViewAdapter(parent)
0015     , m_adapterView(nullptr)
0016     , m_adapterModel(nullptr)
0017     , m_adapterIconSize(-1)
0018 {
0019 }
0020 
0021 QAbstractItemModel *ItemViewAdapter::model() const
0022 {
0023     return m_adapterModel;
0024 }
0025 
0026 QSize ItemViewAdapter::iconSize() const
0027 {
0028     return QSize(m_adapterIconSize, m_adapterIconSize);
0029 }
0030 
0031 QPalette ItemViewAdapter::palette() const
0032 {
0033     return QPalette();
0034 }
0035 
0036 QRect ItemViewAdapter::visibleArea() const
0037 {
0038     return m_adapterVisibleArea;
0039 }
0040 
0041 QRect ItemViewAdapter::visualRect(const QModelIndex &index) const
0042 {
0043     // FIXME TODO: Implemented on DND branch.
0044 
0045     Q_UNUSED(index)
0046 
0047     return QRect();
0048 }
0049 
0050 void ItemViewAdapter::connect(Signal signal, QObject *receiver, const char *slot)
0051 {
0052     if (signal == ScrollBarValueChanged) {
0053         QObject::connect(this, SIGNAL(viewScrolled()), receiver, slot);
0054     } else if (signal == IconSizeChanged) {
0055         QObject::connect(this, SIGNAL(adapterIconSizeChanged()), receiver, slot);
0056     }
0057 }
0058 
0059 QAbstractItemModel *ItemViewAdapter::adapterModel() const
0060 {
0061     return m_adapterModel;
0062 }
0063 
0064 QObject *ItemViewAdapter::adapterView() const
0065 {
0066     return m_adapterView;
0067 }
0068 
0069 void ItemViewAdapter::setAdapterView(QObject *view)
0070 {
0071     if (m_adapterView != view) {
0072         m_adapterView = view;
0073 
0074         Q_EMIT adapterViewChanged();
0075     }
0076 }
0077 
0078 void ItemViewAdapter::setAdapterModel(QAbstractItemModel *model)
0079 {
0080     if (m_adapterModel != model) {
0081         m_adapterModel = model;
0082 
0083         Q_EMIT adapterModelChanged();
0084     }
0085 }
0086 
0087 int ItemViewAdapter::adapterIconSize() const
0088 {
0089     return m_adapterIconSize;
0090 }
0091 
0092 void ItemViewAdapter::setAdapterIconSize(int size)
0093 {
0094     if (m_adapterIconSize != size) {
0095         m_adapterIconSize = size;
0096 
0097         Q_EMIT adapterIconSizeChanged();
0098     }
0099 }
0100 
0101 QRect ItemViewAdapter::adapterVisibleArea() const
0102 {
0103     return m_adapterVisibleArea;
0104 }
0105 
0106 void ItemViewAdapter::setAdapterVisibleArea(QRect rect)
0107 {
0108     if (m_adapterVisibleArea != rect) {
0109         m_adapterVisibleArea = rect;
0110 
0111         Q_EMIT adapterVisibleAreaChanged();
0112     }
0113 }