1 | /* |
2 | SPDX-FileCopyrightText: 2008 Fredrik Höglund <fredrik@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef KABSTRACTVIEWADAPTER_H |
8 | #define KABSTRACTVIEWADAPTER_H |
9 | |
10 | #include "kiofilewidgets_export.h" |
11 | #include <QObject> |
12 | |
13 | class QAbstractItemModel; |
14 | class QModelIndex; |
15 | class QPalette; |
16 | class QRect; |
17 | class QSize; |
18 | |
19 | /* |
20 | * TODO KF6 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged) |
21 | * TODO KF6 virtual void setIconSize(const QSize &size); |
22 | * TODO KF6 iconSizeChanged(); |
23 | * |
24 | * TODO KF6: |
25 | * KAbstractViewAdapter exists to allow KFilePreviewGenerator to be |
26 | * reused with new kinds of views. Unfortunately it doesn't cover |
27 | * all use cases that would be useful right now, in particular there |
28 | * are no change notifications for the properties it has getters for. |
29 | * This requires view implementations to e.g. call updateIcons() on |
30 | * the generator when the icon size changes, which means updating two |
31 | * entities (the generator and the adapter) instead of only one. |
32 | * In KF6 we should make iconSize a Q_PROPERTY with a virtual setter |
33 | * and a change notification signal, and make KFilePreviewGenerator |
34 | * listen to that signal. |
35 | * A related problem is that while the adapter is supposed to inter- |
36 | * face a view to the generator, it is sometimes the generator that |
37 | * is responsible for instantiating the adapter: KDirOperator in this |
38 | * framework uses the KFilePreviewGenerator constructor that doesn't |
39 | * take an adapter instance, which makes the generator instantiate a |
40 | * KIO::DefaultViewAdapter internally, which it doesn't expose to the |
41 | * outside. That means even when a setIconSize() is added, |
42 | * KDirOperator won't be able to call it on the adapter. This mis- |
43 | * design needs to be addressed as well so all change notifications |
44 | * can run through the adapter, also for the DefaultViewAdapter |
45 | * implementation (though for this specific example, perhaps Qt will |
46 | * one day give us a NOTIFY for QAbstractItemView::iconSize that the |
47 | * DefaultViewAdapter can use, obviating the need for KDirOperator |
48 | * to do anything except call setIconSize on its QAbstractItemView). |
49 | */ |
50 | |
51 | /*! |
52 | * \class KAbstractViewAdapter |
53 | * \inmodule KIOFileWidgets |
54 | * |
55 | * \brief Interface used by KFilePreviewGenerator to generate previews |
56 | * for files. |
57 | * |
58 | * The interface allows KFilePreviewGenerator to be |
59 | * independent from the view implementation. |
60 | */ |
61 | class KIOFILEWIDGETS_EXPORT KAbstractViewAdapter : public QObject |
62 | { |
63 | public: |
64 | /*! |
65 | * \value ScrollBarValueChanged |
66 | * \value IconSizeChanged |
67 | */ |
68 | enum Signal { |
69 | ScrollBarValueChanged, |
70 | IconSizeChanged |
71 | }; |
72 | |
73 | /*! |
74 | * |
75 | */ |
76 | KAbstractViewAdapter(QObject *parent) |
77 | : QObject(parent) |
78 | { |
79 | } |
80 | |
81 | ~KAbstractViewAdapter() override |
82 | { |
83 | } |
84 | |
85 | /*! |
86 | * |
87 | */ |
88 | virtual QAbstractItemModel *model() const = 0; |
89 | |
90 | /*! |
91 | * |
92 | */ |
93 | virtual QSize iconSize() const = 0; |
94 | |
95 | /*! |
96 | * |
97 | */ |
98 | virtual QPalette palette() const = 0; |
99 | |
100 | /*! |
101 | * |
102 | */ |
103 | virtual QRect visibleArea() const = 0; |
104 | |
105 | /*! |
106 | * |
107 | */ |
108 | virtual QRect visualRect(const QModelIndex &index) const = 0; |
109 | |
110 | // TODO KF6 make this connect work with a PointerToMemberFunction/Functor |
111 | /*! |
112 | * |
113 | */ |
114 | virtual void connect(Signal signal, QObject *receiver, const char *slot) = 0; |
115 | }; |
116 | |
117 | #endif |
118 | |