File indexing completed on 2024-12-01 03:40:49
0001 /* 0002 SPDX-FileCopyrightText: 2008 Fredrik Höglund <fredrik@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KABSTRACTVIEWADAPTER_H 0008 #define KABSTRACTVIEWADAPTER_H 0009 0010 #include "kiofilewidgets_export.h" 0011 #include <QObject> 0012 0013 class QAbstractItemModel; 0014 class QModelIndex; 0015 class QPalette; 0016 class QRect; 0017 class QSize; 0018 0019 /* 0020 * TODO KF6 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged) 0021 * TODO KF6 virtual void setIconSize(const QSize &size); 0022 * TODO KF6 iconSizeChanged(); 0023 * 0024 * TODO KF6: 0025 * KAbstractViewAdapter exists to allow KFilePreviewGenerator to be 0026 * reused with new kinds of views. Unfortunately it doesn't cover 0027 * all use cases that would be useful right now, in particular there 0028 * are no change notifications for the properties it has getters for. 0029 * This requires view implementations to e.g. call updateIcons() on 0030 * the generator when the icon size changes, which means updating two 0031 * entities (the generator and the adapter) instead of only one. 0032 * In KF6 we should make iconSize a Q_PROPERTY with a virtual setter 0033 * and a change notification signal, and make KFilePreviewGenerator 0034 * listen to that signal. 0035 * A related problem is that while the adapter is supposed to inter- 0036 * face a view to the generator, it is sometimes the generator that 0037 * is responsible for instantiating the adapter: KDirOperator in this 0038 * framework uses the KFilePreviewGenerator constructor that doesn't 0039 * take an adapter instance, which makes the generator instantiate a 0040 * KIO::DefaultViewAdapter internally, which it doesn't expose to the 0041 * outside. That means even when a setIconSize() is added, 0042 * KDirOperator won't be able to call it on the adapter. This mis- 0043 * design needs to be addressed as well so all change notifications 0044 * can run through the adapter, also for the DefaultViewAdapter 0045 * implementation (though for this specific example, perhaps Qt will 0046 * one day give us a NOTIFY for QAbstractItemView::iconSize that the 0047 * DefaultViewAdapter can use, obviating the need for KDirOperator 0048 * to do anything except call setIconSize on its QAbstractItemView). 0049 */ 0050 0051 /** 0052 * @class KAbstractViewAdapter kabstractviewadapter.h <KAbstractViewAdapter> 0053 * 0054 * Interface used by KFilePreviewGenerator to generate previews 0055 * for files. The interface allows KFilePreviewGenerator to be 0056 * independent from the view implementation. 0057 */ 0058 class KIOFILEWIDGETS_EXPORT KAbstractViewAdapter : public QObject 0059 { 0060 public: 0061 enum Signal { ScrollBarValueChanged, IconSizeChanged }; 0062 0063 KAbstractViewAdapter(QObject *parent) 0064 : QObject(parent) 0065 { 0066 } 0067 ~KAbstractViewAdapter() override 0068 { 0069 } 0070 virtual QAbstractItemModel *model() const = 0; 0071 virtual QSize iconSize() const = 0; 0072 virtual QPalette palette() const = 0; 0073 virtual QRect visibleArea() const = 0; 0074 virtual QRect visualRect(const QModelIndex &index) const = 0; 0075 0076 // TODO KF6 make this connect work with a PointerToMemberFunction/Functor 0077 virtual void connect(Signal signal, QObject *receiver, const char *slot) = 0; 0078 }; 0079 0080 #endif