/* * 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. * */ #include "precompiled.h" AZ_PUSH_DISABLE_WARNING(4251 4800 4244, "-Wunknown-warning-option") #include #include AZ_POP_DISABLE_WARNING #include #include #include #include #include #include namespace GraphCanvas { ////////////////////////////// // GeneralNodeFrameComponent ////////////////////////////// void GeneralNodeFrameComponent::Reflect(AZ::ReflectContext* context) { AZ::SerializeContext* serializeContext = azrtti_cast(context); if (serializeContext) { serializeContext->Class() ->Version(1) ; } } GeneralNodeFrameComponent::GeneralNodeFrameComponent() : m_frameWidget(nullptr) , m_shouldDeleteFrame(true) { } GeneralNodeFrameComponent::~GeneralNodeFrameComponent() { if (m_shouldDeleteFrame) { delete m_frameWidget; } } void GeneralNodeFrameComponent::Init() { m_frameWidget = aznew GeneralNodeFrameGraphicsWidget(GetEntityId()); } void GeneralNodeFrameComponent::Activate() { NodeNotificationBus::Handler::BusConnect(GetEntityId()); m_frameWidget->Activate(); } void GeneralNodeFrameComponent::Deactivate() { m_frameWidget->Deactivate(); NodeNotificationBus::Handler::BusDisconnect(); } void GeneralNodeFrameComponent::OnNodeActivated() { QGraphicsLayout* layout = nullptr; NodeLayoutRequestBus::EventResult(layout, GetEntityId(), &NodeLayoutRequests::GetLayout); m_frameWidget->setLayout(layout); } void GeneralNodeFrameComponent::OnNodeWrapped(const AZ::EntityId& wrappingNode) { // When wrapped, our NodeFrame widget is part of another objects layout, and will // be deleted when that object gets deleted. m_shouldDeleteFrame = false; } void GeneralNodeFrameComponent::OnNodeUnwrapped(const AZ::EntityId& wrappingNode) { m_shouldDeleteFrame = true; } /////////////////////////////////// // GeneralNodeFrameGraphicsWidget /////////////////////////////////// GeneralNodeFrameGraphicsWidget::GeneralNodeFrameGraphicsWidget(const AZ::EntityId& entityKey) : NodeFrameGraphicsWidget(entityKey) { } QPainterPath GeneralNodeFrameGraphicsWidget::GetOutline() const { QPainterPath path; QPen border = m_style.GetBorder(); qreal cornerRadius = GetCornerRadius(); qreal halfBorder = border.widthF() / 2.; QRectF adjusted = sceneBoundingRect().marginsRemoved(QMarginsF(halfBorder, halfBorder, halfBorder, halfBorder)); if (cornerRadius >= 1.0) { path.addRoundedRect(adjusted, cornerRadius, cornerRadius); } else { path.addRect(adjusted); } return path; } void GeneralNodeFrameGraphicsWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { GRAPH_CANVAS_DETAILED_PROFILE_FUNCTION(); QPen border = m_style.GetBorder(); QBrush background = m_style.GetBrush(Styling::Attribute::BackgroundColor); if (border.style() != Qt::NoPen || background.color().alpha() > 0) { qreal cornerRadius = GetCornerRadius(); border.setJoinStyle(Qt::PenJoinStyle::MiterJoin); // sharp corners painter->setPen(border); painter->setBrush(background); qreal halfBorder = border.widthF() / 2.; QRectF adjusted = boundingRect().marginsRemoved(QMarginsF(halfBorder, halfBorder, halfBorder, halfBorder)); if (cornerRadius >= 1.0) { painter->drawRoundedRect(adjusted, cornerRadius, cornerRadius); } else { painter->drawRect(adjusted); } } QGraphicsWidget::paint(painter, option, widget); } }