Changeset View
Changeset View
Standalone View
Standalone View
kcms/style/previewitem.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright © 2003-2007 Fredrik Höglund <fredrik@kde.org> | ||||
3 | * Copyright 2019 Kai Uwe Broulik <kde@broulik.de> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU General Public | ||||
7 | * License version 2 as published by the Free Software Foundation. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; see the file COPYING. If not, write to | ||||
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | * Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #pragma once | ||||
21 | | ||||
22 | #include <QPointer> | ||||
23 | #include <QQuickPaintedItem> | ||||
24 | #include <QScopedPointer> | ||||
25 | | ||||
26 | #include "ui_stylepreview.h" | ||||
27 | | ||||
28 | class QWidget; | ||||
29 | class QStyle; | ||||
30 | | ||||
31 | class PreviewItem : public QQuickPaintedItem | ||||
32 | { | ||||
33 | Q_OBJECT | ||||
34 | | ||||
35 | Q_PROPERTY(QString styleName READ styleName WRITE setStyleName NOTIFY styleNameChanged) | ||||
36 | | ||||
37 | Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) | ||||
38 | | ||||
39 | public: | ||||
40 | explicit PreviewItem(QQuickItem *parent = nullptr); | ||||
41 | ~PreviewItem() override; | ||||
42 | | ||||
43 | QString styleName() const; | ||||
44 | void setStyleName(const QString &styleName); | ||||
45 | Q_SIGNAL void styleNameChanged(); | ||||
46 | | ||||
47 | bool isValid() const; | ||||
48 | Q_SIGNAL void validChanged(); | ||||
49 | | ||||
50 | Q_INVOKABLE void reload(); | ||||
51 | | ||||
52 | void componentComplete() override; | ||||
53 | | ||||
54 | protected: | ||||
55 | bool eventFilter(QObject *watched, QEvent *event) override; | ||||
56 | | ||||
57 | void paint(QPainter *painter) override; | ||||
58 | | ||||
59 | void hoverMoveEvent(QHoverEvent *event) override; | ||||
60 | void hoverLeaveEvent(QHoverEvent *event) override; | ||||
61 | | ||||
62 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; | ||||
63 | | ||||
64 | private: | ||||
65 | void sendHoverEvent(QHoverEvent *event); | ||||
66 | void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF); | ||||
67 | | ||||
68 | QString m_styleName; | ||||
69 | | ||||
70 | Ui::StylePreview m_ui; | ||||
71 | | ||||
72 | QScopedPointer<QWidget> m_widget; | ||||
73 | QPointer<QWidget> m_lastWidgetUnderMouse; | ||||
74 | | ||||
75 | QScopedPointer<QStyle> m_style; | ||||
76 | }; |