1 /* 2 SPDX-FileCopyrightText: 2003-2007 Fredrik Höglund <fredrik@kde.org> 3 4 SPDX-License-Identifier: GPL-2.0-only 5 */ 6 7 #pragma once 8 9 #include "sortproxymodel.h" 10 #include <QPointer> 11 #include <QQuickPaintedItem> 12 13 class CursorTheme; 14 class PreviewCursor; 15 16 class PreviewWidget : public QQuickPaintedItem 17 { 18 Q_OBJECT 19 Q_PROPERTY(SortProxyModel *themeModel READ themeModel WRITE setThemeModel NOTIFY themeModelChanged) 20 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) 21 Q_PROPERTY(int currentSize READ currentSize WRITE setCurrentSize NOTIFY currentSizeChanged) 22 23 public: 24 explicit PreviewWidget(QQuickItem *parent = nullptr); 25 ~PreviewWidget() override; 26 27 void setTheme(const CursorTheme *theme, const int size); 28 void setUseLables(bool); 29 void updateImplicitSize(); 30 31 void setThemeModel(SortProxyModel *themeModel); 32 SortProxyModel *themeModel(); 33 34 void setCurrentIndex(int idx); 35 int currentIndex() const; 36 37 void setCurrentSize(int size); 38 int currentSize() const; 39 40 Q_INVOKABLE void refresh(); 41 42 Q_SIGNALS: 43 void themeModelChanged(); 44 void currentIndexChanged(); 45 void currentSizeChanged(); 46 47 protected: 48 void paint(QPainter *) override; 49 void hoverMoveEvent(QHoverEvent *event) override; 50 void hoverLeaveEvent(QHoverEvent *e) override; 51 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; 52 53 private: 54 void layoutItems(); 55 56 QList<PreviewCursor *> list; 57 const PreviewCursor *current; 58 bool needLayout : 1; 59 QPointer<SortProxyModel> m_themeModel; 60 int m_currentIndex; 61 int m_currentSize; 62 }; 63