/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #ifndef CRYINCLUDE_EDITOR_UTILS_PROPERTYRESOURCECTRL_H #define CRYINCLUDE_EDITOR_UTILS_PROPERTYRESOURCECTRL_H #pragma once #include #include #include #include "ReflectedVar.h" #include "Util/VariablePropertyType.h" #include #include #include class QLineEdit; class QHBoxLayout; class CBitmapToolTip; class QToolTipWidget; class BrowseButton : public QToolButton { Q_OBJECT public: AZ_CLASS_ALLOCATOR(BrowseButton, AZ::SystemAllocator, 0); BrowseButton(PropertyType type, QWidget* parent = nullptr); void SetPath(const QString& path) { m_path = path; } QString GetPath() const { return m_path; } PropertyType GetPropertyType() const {return m_propertyType; } signals: void PathChanged(const QString& path); protected: void SetPathAndEmit(const QString& path); virtual void OnClicked() = 0; PropertyType m_propertyType; QString m_path; }; class FileResourceSelectorWidget : public QWidget { Q_OBJECT public: AZ_CLASS_ALLOCATOR(FileResourceSelectorWidget, AZ::SystemAllocator, 0); FileResourceSelectorWidget(QWidget* pParent = nullptr); bool SetPath(const QString& path); QString GetPath() const; void SetPropertyType(PropertyType type); PropertyType GetPropertyType() const { return m_propertyType; } QWidget* GetFirstInTabOrder(); QWidget* GetLastInTabOrder(); void UpdateTabOrder(); bool eventFilter(QObject* obj, QEvent* event) override; signals: void PathChanged(const QString& path); protected: bool event(QEvent* event) override; private: void OnAssignClicked(); void OnMaterialClicked(); void UpdateWidgets(); void AddButton(BrowseButton* button); void OnPathChanged(const QString& path); private: QLineEdit* m_pathEdit; PropertyType m_propertyType; QString m_path; QHBoxLayout* m_mainLayout; QVector m_buttons; QScopedPointer m_previewToolTip; QToolTipWidget* m_tooltip; }; class FileResourceSelectorWidgetHandler : QObject , public AzToolsFramework::PropertyHandler < CReflectedVarResource, FileResourceSelectorWidget > { public: AZ_CLASS_ALLOCATOR(FileResourceSelectorWidgetHandler, AZ::SystemAllocator, 0); virtual AZ::u32 GetHandlerName(void) const override { return AZ_CRC("Resource", 0xbc91f416); } virtual bool IsDefaultHandler() const override { return true; } virtual QWidget* GetFirstInTabOrder(FileResourceSelectorWidget* widget) override { return widget->GetFirstInTabOrder(); } virtual QWidget* GetLastInTabOrder(FileResourceSelectorWidget* widget) override { return widget->GetLastInTabOrder(); } virtual void UpdateWidgetInternalTabbing(FileResourceSelectorWidget* widget) override { widget->UpdateTabOrder(); } virtual QWidget* CreateGUI(QWidget* pParent) override; virtual void ConsumeAttribute(FileResourceSelectorWidget* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override; virtual void WriteGUIValuesIntoProperty(size_t index, FileResourceSelectorWidget* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override; virtual bool ReadValuesIntoGUI(size_t index, FileResourceSelectorWidget* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override; }; #endif // CRYINCLUDE_EDITOR_UTILS_PROPERTYRESOURCECTRL_H