blob: ea0e5a212abd9c4bc38496c287c4e8bab78c9d14 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "modelnode.h"
#include <coreplugin/icontext.h>
#include <QFrame>
QT_BEGIN_NAMESPACE
class QPointF;
class QShortcut;
class QToolButton;
QT_END_NAMESPACE
class StudioQuickWidget;
namespace QmlDesigner {
class AssetImageProvider;
class MaterialBrowserView;
class MaterialBrowserModel;
class MaterialBrowserTexturesModel;
class PreviewImageProvider;
class MaterialBrowserWidget : public QFrame
{
Q_OBJECT
Q_PROPERTY(bool materialSectionFocused MEMBER m_materialSectionFocused NOTIFY materialSectionFocusedChanged)
// Needed for a workaround for a bug where after drag-n-dropping an item, the ScrollView scrolls to a random position
Q_PROPERTY(bool isDragging MEMBER m_isDragging NOTIFY isDraggingChanged)
public:
MaterialBrowserWidget(class AsynchronousImageCache &imageCache, MaterialBrowserView *view);
~MaterialBrowserWidget() = default;
QList<QToolButton *> createToolBarWidgets();
void contextHelp(const Core::IContext::HelpCallback &callback) const;
static QString qmlSourcesPath();
void clearSearchFilter();
QPointer<MaterialBrowserModel> materialBrowserModel() const;
QPointer<MaterialBrowserTexturesModel> materialBrowserTexturesModel() const;
void updateMaterialPreview(const ModelNode &node, const QPixmap &pixmap);
void deleteSelectedItem();
Q_INVOKABLE void handleSearchFilterChanged(const QString &filterText);
Q_INVOKABLE void startDragMaterial(int index, const QPointF &mousePos);
Q_INVOKABLE void startDragTexture(int index, const QPointF &mousePos);
Q_INVOKABLE void acceptBundleMaterialDrop();
Q_INVOKABLE bool hasAcceptableAssets(const QList<QUrl> &urls);
Q_INVOKABLE void acceptBundleTextureDrop();
Q_INVOKABLE void acceptBundleTextureDropOnMaterial(int matIndex, const QUrl &bundleTexPath);
Q_INVOKABLE void acceptAssetsDrop(const QList<QUrl> &urls);
Q_INVOKABLE void acceptAssetsDropOnMaterial(int matIndex, const QList<QUrl> &urls);
Q_INVOKABLE void acceptTextureDropOnMaterial(int matIndex, const QString &texId);
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
StudioQuickWidget *quickWidget() const;
void clearPreviewCache();
signals:
void materialSectionFocusedChanged();
void isDraggingChanged();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
void reloadQmlSource();
void updateSearch();
void setIsDragging(bool val);
QPointer<MaterialBrowserView> m_materialBrowserView;
QPointer<MaterialBrowserModel> m_materialBrowserModel;
QPointer<MaterialBrowserTexturesModel> m_materialBrowserTexturesModel;
QScopedPointer<StudioQuickWidget> m_quickWidget;
QShortcut *m_qmlSourceUpdateShortcut = nullptr;
PreviewImageProvider *m_previewImageProvider = nullptr;
AssetImageProvider *m_textureImageProvider = nullptr;
Core::IContext *m_context = nullptr;
QString m_filterText;
ModelNode m_materialToDrag;
ModelNode m_textureToDrag;
QPoint m_dragStartPoint;
bool m_materialSectionFocused = true;
bool m_isDragging = false;
};
} // namespace QmlDesigner
|