further formatting changes for viewport ui
Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <AzToolsFramework/ViewportUi/Button.h>
|
#include <AzToolsFramework/ViewportUi/Button.h>
|
||||||
|
|
||||||
namespace AzToolsFramework::ViewportUi::Internal
|
namespace AzToolsFramework::ViewportUi::Internal
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
|
|
||||||
AZStd::string m_icon; //!< The icon for this button, string path to an image.
|
AZStd::string m_icon; //!< The icon for this button, string path to an image.
|
||||||
AZStd::string m_name; //!< The name displayed as a label next to the button's icon.
|
AZStd::string m_name; //!< The name displayed as a label next to the button's icon.
|
||||||
State m_state = State::Deselected;
|
State m_state = State::Deselected;
|
||||||
ButtonId m_buttonId;
|
ButtonId m_buttonId;
|
||||||
};
|
};
|
||||||
} // namespace AzToolsFramework::ViewportUi::Internal
|
} // namespace AzToolsFramework::ViewportUi::Internal
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
@@ -8,6 +6,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <AzToolsFramework/ViewportUi/ViewportUiRequestBus.h>
|
#include <AzToolsFramework/ViewportUi/ViewportUiRequestBus.h>
|
||||||
|
|
||||||
namespace AzToolsFramework::ViewportUi::Internal
|
namespace AzToolsFramework::ViewportUi::Internal
|
||||||
|
|||||||
@@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
namespace AzToolsFramework::ViewportUi::Internal
|
namespace AzToolsFramework::ViewportUi::Internal
|
||||||
{
|
{
|
||||||
TextField::TextField(
|
TextField::TextField(const AZStd::string& labelText, const AZStd::string& fieldText, TextFieldValidationType validationType)
|
||||||
const AZStd::string& labelText, const AZStd::string& fieldText,
|
|
||||||
TextFieldValidationType validationType)
|
|
||||||
: m_labelText(labelText)
|
: m_labelText(labelText)
|
||||||
, m_fieldText(fieldText)
|
, m_fieldText(fieldText)
|
||||||
, m_validationType(validationType)
|
, m_validationType(validationType)
|
||||||
|
|||||||
@@ -19,16 +19,17 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextField(
|
TextField(
|
||||||
const AZStd::string& labelText = "", const AZStd::string& fieldText = "",
|
const AZStd::string& labelText = "",
|
||||||
|
const AZStd::string& fieldText = "",
|
||||||
TextFieldValidationType validationType = TextFieldValidationType::String);
|
TextFieldValidationType validationType = TextFieldValidationType::String);
|
||||||
~TextField() = default;
|
~TextField() = default;
|
||||||
|
|
||||||
void ConnectEventHandler(AZ::Event<AZStd::string>::Handler& handler);
|
void ConnectEventHandler(AZ::Event<AZStd::string>::Handler& handler);
|
||||||
|
|
||||||
//! Default text for the text field. Will be cast to same type as m_validationType.
|
//! Default text for the text field. Will be cast to same type as m_validationType.
|
||||||
AZStd::string m_fieldText;
|
AZStd::string m_fieldText;
|
||||||
AZStd::string m_labelText;
|
AZStd::string m_labelText;
|
||||||
TextFieldValidationType m_validationType; //<! The type of validator for this text edit.
|
TextFieldValidationType m_validationType; //!< The type of validator for this text edit.
|
||||||
TextFieldId m_textFieldId;
|
TextFieldId m_textFieldId;
|
||||||
ViewportUiElementId m_viewportId;
|
ViewportUiElementId m_viewportId;
|
||||||
AZ::Event<AZStd::string> m_textEditedEvent;
|
AZ::Event<AZStd::string> m_textEditedEvent;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <AzToolsFramework/ViewportUi/ButtonGroup.h>
|
#include <AzToolsFramework/ViewportUi/ButtonGroup.h>
|
||||||
#include <AzToolsFramework/ViewportUi/ViewportUiCluster.h>
|
#include <AzToolsFramework/ViewportUi/ViewportUiCluster.h>
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||||
#include <AzFramework/Viewport/ViewportScreen.h>
|
#include <AzFramework/Viewport/ViewportScreen.h>
|
||||||
#include <AzToolsFramework/Viewport/ViewportMessages.h>
|
#include <AzToolsFramework/Viewport/ViewportMessages.h>
|
||||||
|
|||||||
+10
-7
@@ -6,15 +6,19 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <AzCore/Console/IConsole.h>
|
#include <AzCore/Console/IConsole.h>
|
||||||
#include <AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.h>
|
#include <AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.h>
|
||||||
#include <QtWidgets/QWidget>
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
namespace AzToolsFramework::ViewportUi::Internal
|
namespace AzToolsFramework::ViewportUi::Internal
|
||||||
{
|
{
|
||||||
AZ_CVAR(
|
AZ_CVAR(
|
||||||
int, ViewportUiDisplayLayoutSpacing, 5, nullptr, AZ::ConsoleFunctorFlags::Null,
|
int,
|
||||||
|
ViewportUiDisplayLayoutSpacing,
|
||||||
|
5,
|
||||||
|
nullptr,
|
||||||
|
AZ::ConsoleFunctorFlags::Null,
|
||||||
"The spacing between elements attached to the Viewport UI Display Layout");
|
"The spacing between elements attached to the Viewport UI Display Layout");
|
||||||
|
|
||||||
ViewportUiDisplayLayout::ViewportUiDisplayLayout(QWidget* parent)
|
ViewportUiDisplayLayout::ViewportUiDisplayLayout(QWidget* parent)
|
||||||
@@ -27,7 +31,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
setSpacing(ViewportUiDisplayLayoutSpacing);
|
setSpacing(ViewportUiDisplayLayoutSpacing);
|
||||||
|
|
||||||
// create a 3x2 map of sub layouts which will stack widgets according to their mapped alignment
|
// create a 3x2 map of sub layouts which will stack widgets according to their mapped alignment
|
||||||
m_internalLayouts = AZStd::unordered_map<Qt::Alignment, QBoxLayout*> {
|
m_internalLayouts = AZStd::unordered_map<Qt::Alignment, QBoxLayout*>{
|
||||||
CreateSubLayout(new QVBoxLayout(), 0, 0, Qt::AlignTop | Qt::AlignLeft),
|
CreateSubLayout(new QVBoxLayout(), 0, 0, Qt::AlignTop | Qt::AlignLeft),
|
||||||
CreateSubLayout(new QVBoxLayout(), 1, 0, Qt::AlignBottom | Qt::AlignLeft),
|
CreateSubLayout(new QVBoxLayout(), 1, 0, Qt::AlignBottom | Qt::AlignLeft),
|
||||||
CreateSubLayout(new QVBoxLayout(), 0, 1, Qt::AlignTop),
|
CreateSubLayout(new QVBoxLayout(), 0, 1, Qt::AlignTop),
|
||||||
@@ -45,8 +49,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find the corresponding sub layout for the alignment and add the widget
|
// find the corresponding sub layout for the alignment and add the widget
|
||||||
if (auto layoutForAlignment = m_internalLayouts.find(alignment);
|
if (auto layoutForAlignment = m_internalLayouts.find(alignment); layoutForAlignment != m_internalLayouts.end())
|
||||||
layoutForAlignment != m_internalLayouts.end())
|
|
||||||
{
|
{
|
||||||
// place the widget before or after the invisible spacer
|
// place the widget before or after the invisible spacer
|
||||||
// depending on the layout alignment
|
// depending on the layout alignment
|
||||||
@@ -97,7 +100,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
// without this, alignment and resizing within the sublayouts becomes difficult
|
// without this, alignment and resizing within the sublayouts becomes difficult
|
||||||
layout->addStretch(1);
|
layout->addStretch(1);
|
||||||
|
|
||||||
addLayout(layout, row, column, /*rowSpan=*/ 1, /*colSpan=*/ 1, alignment);
|
addLayout(layout, row, column, /*rowSpan=*/1, /*colSpan=*/1, alignment);
|
||||||
|
|
||||||
return { alignment, layout };
|
return { alignment, layout };
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -9,8 +9,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AzCore/std/containers/unordered_map.h>
|
#include <AzCore/std/containers/unordered_map.h>
|
||||||
#include <QGridLayout>
|
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
|
#include <QGridLayout>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
namespace AzToolsFramework::ViewportUi::Internal
|
namespace AzToolsFramework::ViewportUi::Internal
|
||||||
@@ -33,8 +34,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
private:
|
private:
|
||||||
//! Create a sub-layout to add to the grid of layouts.
|
//! Create a sub-layout to add to the grid of layouts.
|
||||||
//! @return A pair of the new layout along with its alignment on the grid.
|
//! @return A pair of the new layout along with its alignment on the grid.
|
||||||
AZStd::pair<Qt::Alignment, QBoxLayout*> CreateSubLayout(
|
AZStd::pair<Qt::Alignment, QBoxLayout*> CreateSubLayout(QBoxLayout* layout, int row, int column, Qt::Alignment alignment);
|
||||||
QBoxLayout* layout, int row, int column, Qt::Alignment alignment);
|
|
||||||
|
|
||||||
//! A mapping of each sub-layout to its corresponding alignment on the grid.
|
//! A mapping of each sub-layout to its corresponding alignment on the grid.
|
||||||
AZStd::unordered_map<Qt::Alignment, QBoxLayout*> m_internalLayouts;
|
AZStd::unordered_map<Qt::Alignment, QBoxLayout*> m_internalLayouts;
|
||||||
|
|||||||
@@ -6,12 +6,11 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||||
#include <AzToolsFramework/ViewportUi/Button.h>
|
#include <AzToolsFramework/ViewportUi/Button.h>
|
||||||
#include <AzToolsFramework/ViewportUi/ButtonGroup.h>
|
#include <AzToolsFramework/ViewportUi/ButtonGroup.h>
|
||||||
#include <AzToolsFramework/ViewportUi/ViewportUiManager.h>
|
|
||||||
#include <AzToolsFramework/ViewportUi/ViewportUiDisplay.h>
|
#include <AzToolsFramework/ViewportUi/ViewportUiDisplay.h>
|
||||||
|
#include <AzToolsFramework/ViewportUi/ViewportUiManager.h>
|
||||||
|
|
||||||
namespace AzToolsFramework::ViewportUi
|
namespace AzToolsFramework::ViewportUi
|
||||||
{
|
{
|
||||||
@@ -114,7 +113,8 @@ namespace AzToolsFramework::ViewportUi
|
|||||||
return ButtonId(0);
|
return ButtonId(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ButtonId ViewportUiManager::CreateSwitcherButton(const SwitcherId switcherId, const AZStd::string& icon, const AZStd::string& name)
|
const ButtonId ViewportUiManager::CreateSwitcherButton(
|
||||||
|
const SwitcherId switcherId, const AZStd::string& icon, const AZStd::string& name)
|
||||||
{
|
{
|
||||||
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
|
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
|
||||||
{
|
{
|
||||||
@@ -146,8 +146,7 @@ namespace AzToolsFramework::ViewportUi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetViewportUiElementVisible(
|
static void SetViewportUiElementVisible(Internal::ViewportUiDisplay* ui, ViewportUiElementId id, bool visible)
|
||||||
Internal::ViewportUiDisplay* ui, ViewportUiElementId id, bool visible)
|
|
||||||
{
|
{
|
||||||
if (visible)
|
if (visible)
|
||||||
{
|
{
|
||||||
@@ -186,11 +185,9 @@ namespace AzToolsFramework::ViewportUi
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TextFieldId ViewportUiManager::CreateTextField(
|
const TextFieldId ViewportUiManager::CreateTextField(
|
||||||
const AZStd::string& labelText, const AZStd::string& textFieldDefaultText,
|
const AZStd::string& labelText, const AZStd::string& textFieldDefaultText, TextFieldValidationType validationType)
|
||||||
TextFieldValidationType validationType)
|
|
||||||
{
|
{
|
||||||
auto textField = AZStd::make_shared<Internal::TextField>(
|
auto textField = AZStd::make_shared<Internal::TextField>(labelText, textFieldDefaultText, validationType);
|
||||||
labelText, textFieldDefaultText, validationType);
|
|
||||||
m_viewportUi->AddTextField(textField);
|
m_viewportUi->AddTextField(textField);
|
||||||
|
|
||||||
return RegisterNewTextField(textField);
|
return RegisterNewTextField(textField);
|
||||||
@@ -206,8 +203,7 @@ namespace AzToolsFramework::ViewportUi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportUiManager::RegisterTextFieldCallback(
|
void ViewportUiManager::RegisterTextFieldCallback(TextFieldId textFieldId, AZ::Event<AZStd::string>::Handler& handler)
|
||||||
TextFieldId textFieldId, AZ::Event<AZStd::string>::Handler& handler)
|
|
||||||
{
|
{
|
||||||
if (auto textFieldIt = m_textFields.find(textFieldId); textFieldIt != m_textFields.end())
|
if (auto textFieldIt = m_textFields.find(textFieldId); textFieldIt != m_textFields.end())
|
||||||
{
|
{
|
||||||
@@ -234,7 +230,6 @@ namespace AzToolsFramework::ViewportUi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ViewportUiManager::CreateComponentModeBorder(const AZStd::string& borderTitle)
|
void ViewportUiManager::CreateComponentModeBorder(const AZStd::string& borderTitle)
|
||||||
{
|
{
|
||||||
m_viewportUi->CreateComponentModeBorder(borderTitle);
|
m_viewportUi->CreateComponentModeBorder(borderTitle);
|
||||||
@@ -248,8 +243,7 @@ namespace AzToolsFramework::ViewportUi
|
|||||||
void ViewportUiManager::PressButton(ClusterId clusterId, ButtonId buttonId)
|
void ViewportUiManager::PressButton(ClusterId clusterId, ButtonId buttonId)
|
||||||
{
|
{
|
||||||
// Find cluster using ID and cluster map
|
// Find cluster using ID and cluster map
|
||||||
if (auto clusterIt = m_clusterButtonGroups.find(clusterId);
|
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
|
||||||
clusterIt != m_clusterButtonGroups.end())
|
|
||||||
{
|
{
|
||||||
clusterIt->second->PressButton(buttonId);
|
clusterIt->second->PressButton(buttonId);
|
||||||
}
|
}
|
||||||
@@ -305,7 +299,7 @@ namespace AzToolsFramework::ViewportUi
|
|||||||
SwitcherId ViewportUiManager::RegisterNewSwitcher(AZStd::shared_ptr<Internal::ButtonGroup>& buttonGroup)
|
SwitcherId ViewportUiManager::RegisterNewSwitcher(AZStd::shared_ptr<Internal::ButtonGroup>& buttonGroup)
|
||||||
{
|
{
|
||||||
SwitcherId newId = SwitcherId(m_switcherButtonGroups.size() + 1);
|
SwitcherId newId = SwitcherId(m_switcherButtonGroups.size() + 1);
|
||||||
m_switcherButtonGroups.insert({newId, buttonGroup});
|
m_switcherButtonGroups.insert({ newId, buttonGroup });
|
||||||
|
|
||||||
return newId;
|
return newId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace AzToolsFramework::ViewportUi
|
|||||||
{
|
{
|
||||||
class ButtonGroup;
|
class ButtonGroup;
|
||||||
class ViewportUiDisplay;
|
class ViewportUiDisplay;
|
||||||
}
|
} // namespace Internal
|
||||||
|
|
||||||
class ViewportUiManager : public ViewportUiRequestBus::Handler
|
class ViewportUiManager : public ViewportUiRequestBus::Handler
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -65,8 +65,12 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
// resize to fit new action with minimum extra space
|
// resize to fit new action with minimum extra space
|
||||||
resize(minimumSizeHint());
|
resize(minimumSizeHint());
|
||||||
|
|
||||||
const AZStd::function<void()>& callback = [this, button]() { m_buttonGroup->PressButton(button->m_buttonId); };
|
const AZStd::function<void()>& callback = [this, button]()
|
||||||
const AZStd::function<void(QAction*)>& updateCallback = [button](QAction* action) {
|
{
|
||||||
|
m_buttonGroup->PressButton(button->m_buttonId);
|
||||||
|
};
|
||||||
|
const AZStd::function<void(QAction*)>& updateCallback = [button](QAction* action)
|
||||||
|
{
|
||||||
action->setChecked(button->m_state == Button::State::Selected);
|
action->setChecked(button->m_state == Button::State::Selected);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -78,9 +82,13 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
|
|
||||||
// register the action
|
// register the action
|
||||||
m_widgetCallbacks.AddWidget(
|
m_widgetCallbacks.AddWidget(
|
||||||
action, [updateCallback](QPointer<QObject> object) { updateCallback(static_cast<QAction*>(object.data())); });
|
action,
|
||||||
|
[updateCallback](QPointer<QObject> object)
|
||||||
|
{
|
||||||
|
updateCallback(static_cast<QAction*>(object.data()));
|
||||||
|
});
|
||||||
|
|
||||||
m_buttonActionMap.insert({button->m_buttonId, action});
|
m_buttonActionMap.insert({ button->m_buttonId, action });
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportUiSwitcher::RemoveButton(ButtonId buttonId)
|
void ViewportUiSwitcher::RemoveButton(ButtonId buttonId)
|
||||||
@@ -121,9 +129,12 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
// Check if it is the first active mode to be set
|
// Check if it is the first active mode to be set
|
||||||
bool initialActiveMode = (m_activeButtonId == ButtonId(0));
|
bool initialActiveMode = (m_activeButtonId == ButtonId(0));
|
||||||
|
|
||||||
// Change the toolbutton's name and icon to that button
|
// Change the tool button's name and icon to that button
|
||||||
const AZStd::vector<Button*> buttons = m_buttonGroup->GetButtons();
|
const AZStd::vector<Button*> buttons = m_buttonGroup->GetButtons();
|
||||||
auto found = [buttonId](Button* button) { return (button->m_buttonId == buttonId); };
|
auto found = [buttonId](Button* button)
|
||||||
|
{
|
||||||
|
return (button->m_buttonId == buttonId);
|
||||||
|
};
|
||||||
|
|
||||||
if (auto buttonIt = AZStd::find_if(buttons.begin(), buttons.end(), found); buttonIt != buttons.end())
|
if (auto buttonIt = AZStd::find_if(buttons.begin(), buttons.end(), found); buttonIt != buttons.end())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,11 +8,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AzToolsFramework/ViewportUi/Button.h>
|
|
||||||
#include <AzCore/std/containers/unordered_map.h>
|
#include <AzCore/std/containers/unordered_map.h>
|
||||||
#include <AzCore/std/smart_ptr/shared_ptr.h>
|
#include <AzCore/std/smart_ptr/shared_ptr.h>
|
||||||
|
#include <AzToolsFramework/ViewportUi/Button.h>
|
||||||
#include <AzToolsFramework/ViewportUi/ViewportUiWidgetCallbacks.h>
|
#include <AzToolsFramework/ViewportUi/ViewportUiWidgetCallbacks.h>
|
||||||
#include <functional>
|
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
|||||||
+13
-7
@@ -6,7 +6,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "ViewportUiTextField.h"
|
#include "ViewportUiTextField.h"
|
||||||
|
|
||||||
#include <AzCore/Console/IConsole.h>
|
#include <AzCore/Console/IConsole.h>
|
||||||
@@ -16,7 +15,11 @@
|
|||||||
namespace AzToolsFramework::ViewportUi::Internal
|
namespace AzToolsFramework::ViewportUi::Internal
|
||||||
{
|
{
|
||||||
AZ_CVAR(
|
AZ_CVAR(
|
||||||
int, ViewportUiTextFieldLength, 35, nullptr, AZ::ConsoleFunctorFlags::Null,
|
int,
|
||||||
|
ViewportUiTextFieldLength,
|
||||||
|
35,
|
||||||
|
nullptr,
|
||||||
|
AZ::ConsoleFunctorFlags::Null,
|
||||||
"The pixel length of the text field part of a ViewportUiTextField");
|
"The pixel length of the text field part of a ViewportUiTextField");
|
||||||
|
|
||||||
ViewportUiTextField::ViewportUiTextField(AZStd::shared_ptr<TextField> textField)
|
ViewportUiTextField::ViewportUiTextField(AZStd::shared_ptr<TextField> textField)
|
||||||
@@ -56,11 +59,14 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
|
|
||||||
m_lineEdit.setValidator(m_validator);
|
m_lineEdit.setValidator(m_validator);
|
||||||
|
|
||||||
connect(&m_lineEdit, &QLineEdit::textEdited, &m_lineEdit, [textField](QString text) {
|
connect(
|
||||||
// convert the text using toLocal8Bit().data() as recommended by Qt, then emit signal
|
&m_lineEdit, &QLineEdit::textEdited, &m_lineEdit,
|
||||||
textField->m_fieldText = text.toLocal8Bit().data();
|
[textField](QString text)
|
||||||
textField->m_textEditedEvent.Signal(textField->m_fieldText);
|
{
|
||||||
});
|
// convert the text using toLocal8Bit().data() as recommended by Qt, then emit signal
|
||||||
|
textField->m_fieldText = text.toLocal8Bit().data();
|
||||||
|
textField->m_textEditedEvent.Signal(textField->m_fieldText);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportUiTextField::Update()
|
void ViewportUiTextField::Update()
|
||||||
|
|||||||
@@ -7,7 +7,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AzCore/std/smart_ptr/shared_ptr.h>
|
||||||
#include <AzToolsFramework/ViewportUi/TextField.h>
|
#include <AzToolsFramework/ViewportUi/TextField.h>
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@@ -17,13 +20,10 @@ AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option")
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
AZ_POP_DISABLE_WARNING
|
AZ_POP_DISABLE_WARNING
|
||||||
|
|
||||||
#include <AzCore/std/smart_ptr/shared_ptr.h>
|
|
||||||
|
|
||||||
namespace AzToolsFramework::ViewportUi::Internal
|
namespace AzToolsFramework::ViewportUi::Internal
|
||||||
{
|
{
|
||||||
//! Helper class for a widget that holds and manages multiple LabelTextFields.
|
//! Helper class for a widget that holds and manages multiple LabelTextFields.
|
||||||
class ViewportUiTextField
|
class ViewportUiTextField : public QWidget
|
||||||
: public QWidget
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -34,9 +34,9 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel m_label; //<! The text label.
|
QLabel m_label; //!< The text label.
|
||||||
QLineEdit m_lineEdit; //<! The editable text field.
|
QLineEdit m_lineEdit; //!< The editable text field.
|
||||||
QValidator* m_validator; //<! The validator for the line edit text.
|
QValidator* m_validator; //!< The validator for the line edit text.
|
||||||
AZStd::shared_ptr<TextField> m_textField; //<! Reference to the text field data struct.
|
AZStd::shared_ptr<TextField> m_textField; //!< Reference to the text field data struct.
|
||||||
};
|
};
|
||||||
} // namespace AzToolsFramework::ViewportUi::Internal
|
} // namespace AzToolsFramework::ViewportUi::Internal
|
||||||
|
|||||||
+3
-6
@@ -6,13 +6,11 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "ViewportUiWidgetCallbacks.h"
|
#include "ViewportUiWidgetCallbacks.h"
|
||||||
|
|
||||||
namespace AzToolsFramework::ViewportUi::Internal
|
namespace AzToolsFramework::ViewportUi::Internal
|
||||||
{
|
{
|
||||||
void ViewportUiWidgetCallbacks::AddWidget(
|
void ViewportUiWidgetCallbacks::AddWidget(QPointer<QObject> widget, const AZStd::function<void(QPointer<QObject>)>& updateCallback)
|
||||||
QPointer<QObject> widget, const AZStd::function<void(QPointer<QObject>)>& updateCallback)
|
|
||||||
{
|
{
|
||||||
if (widget.isNull())
|
if (widget.isNull())
|
||||||
{
|
{
|
||||||
@@ -40,7 +38,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
{
|
{
|
||||||
// if widget exists on the manager, register the callback
|
// if widget exists on the manager, register the callback
|
||||||
auto callBackWidget = AZStd::find(m_widgets.begin(), m_widgets.end(), widget);
|
auto callBackWidget = AZStd::find(m_widgets.begin(), m_widgets.end(), widget);
|
||||||
AZ_Assert(callBackWidget != m_widgets.end(), "Unable to register a callback for an unregistered widget.")
|
AZ_Assert(callBackWidget != m_widgets.end(), "Unable to register a callback for an unregistered widget.");
|
||||||
|
|
||||||
if (callBackWidget != m_widgets.end())
|
if (callBackWidget != m_widgets.end())
|
||||||
{
|
{
|
||||||
@@ -58,8 +56,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
RemoveWidget(widget);
|
RemoveWidget(widget);
|
||||||
}
|
}
|
||||||
// check if the widget has not been deleted externally
|
// check if the widget has not been deleted externally
|
||||||
else if (auto callback = m_updateCallbacks.find(widget);
|
else if (auto callback = m_updateCallbacks.find(widget); callback != m_updateCallbacks.end())
|
||||||
callback != m_updateCallbacks.end())
|
|
||||||
{
|
{
|
||||||
callback->second(widget);
|
callback->second(widget);
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-5
@@ -9,12 +9,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AzCore/Memory/Memory.h>
|
#include <AzCore/Memory/Memory.h>
|
||||||
#include <AzCore/std/function/function_template.h>
|
|
||||||
#include <AzCore/std/containers/unordered_map.h>
|
#include <AzCore/std/containers/unordered_map.h>
|
||||||
#include <QPointer>
|
#include <AzCore/std/function/function_template.h>
|
||||||
#include <QObject>
|
|
||||||
#include <QMetaMethod>
|
|
||||||
|
|
||||||
|
#include <QMetaMethod>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
namespace AzToolsFramework::ViewportUi::Internal
|
namespace AzToolsFramework::ViewportUi::Internal
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,8 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
//! Must call ViewportUiWidgetCallbacks::Update to execute the callback.
|
//! Must call ViewportUiWidgetCallbacks::Update to execute the callback.
|
||||||
void RegisterUpdateCallback(QPointer<QObject> widget, const AZStd::function<void(QPointer<QObject>)>& callback);
|
void RegisterUpdateCallback(QPointer<QObject> widget, const AZStd::function<void(QPointer<QObject>)>& callback);
|
||||||
void Update();
|
void Update();
|
||||||
const AZStd::vector<QPointer<QObject>>& GetWidgets() const { return m_widgets; }
|
|
||||||
|
const AZStd::vector<QPointer<QObject>>& GetWidgets() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! A map of all update callbacks and their respective widgets.
|
//! A map of all update callbacks and their respective widgets.
|
||||||
@@ -38,4 +39,9 @@ namespace AzToolsFramework::ViewportUi::Internal
|
|||||||
AZStd::unordered_map<QObject*, AZStd::function<void(QPointer<QObject>)>> m_updateCallbacks;
|
AZStd::unordered_map<QObject*, AZStd::function<void(QPointer<QObject>)>> m_updateCallbacks;
|
||||||
AZStd::vector<QPointer<QObject>> m_widgets;
|
AZStd::vector<QPointer<QObject>> m_widgets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline const AZStd::vector<QPointer<QObject>>& ViewportUiWidgetCallbacks::GetWidgets() const
|
||||||
|
{
|
||||||
|
return m_widgets;
|
||||||
|
}
|
||||||
} // namespace AzToolsFramework::ViewportUi::Internal
|
} // namespace AzToolsFramework::ViewportUi::Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user