Bläddra i källkod

[LYN-2520] Added link and tag widgets (#663)

Benjamin Jillich 4 år sedan
förälder
incheckning
d49135659f

+ 52 - 0
Code/Tools/ProjectManager/Source/LinkWidget.cpp

@@ -0,0 +1,52 @@
+/*
+* 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 <LinkWidget.h>
+#include <QDesktopServices>
+#include <QEvent>
+#include <QMouseEvent>
+#include <QVBoxLayout>
+
+namespace O3DE::ProjectManager
+{
+    LinkLabel::LinkLabel(const QString& text, const QUrl& url, QWidget* parent)
+        : QLabel(text, parent)
+        , m_url(url)
+    {
+        SetDefaultStyle();
+    }
+
+    void LinkLabel::mousePressEvent([[maybe_unused]] QMouseEvent* event)
+    {
+        QDesktopServices::openUrl(m_url);
+    }
+
+    void LinkLabel::enterEvent([[maybe_unused]] QEvent* event)
+    {
+        setStyleSheet("font-size: 9pt; color: #94D2FF; text-decoration: underline;");
+    }
+
+    void LinkLabel::leaveEvent([[maybe_unused]] QEvent* event)
+    {
+        SetDefaultStyle();
+    }
+
+    void LinkLabel::SetUrl(const QUrl& url)
+    {
+        m_url = url;
+    }
+
+    void LinkLabel::SetDefaultStyle()
+    {
+        setStyleSheet("font-size: 9pt; color: #94D2FF;");
+    }
+} // namespace O3DE::ProjectManager

+ 42 - 0
Code/Tools/ProjectManager/Source/LinkWidget.h

@@ -0,0 +1,42 @@
+/*
+* 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.
+*
+*/
+
+#pragma once
+
+#if !defined(Q_MOC_RUN)
+#include <QLabel>
+#include <QUrl>
+#endif
+
+QT_FORWARD_DECLARE_CLASS(QEvent)
+QT_FORWARD_DECLARE_CLASS(QMouseEvent)
+QT_FORWARD_DECLARE_CLASS(QWidget)
+
+namespace O3DE::ProjectManager
+{
+    class LinkLabel
+        : public QLabel
+    {
+    public:
+        LinkLabel(const QString& text, const QUrl& url = {}, QWidget* parent = nullptr);
+
+        void SetUrl(const QUrl& url);
+    private:
+        void mousePressEvent(QMouseEvent* event) override;
+        void enterEvent(QEvent* event) override;
+        void leaveEvent(QEvent* event) override;
+        void SetDefaultStyle();
+
+    private:
+        QUrl m_url;
+    };
+} // namespace O3DE::ProjectManager

+ 98 - 0
Code/Tools/ProjectManager/Source/TagWidget.cpp

@@ -0,0 +1,98 @@
+/*
+* 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 <TagWidget.h>
+#include <QVBoxLayout>
+
+namespace O3DE::ProjectManager
+{
+    TagWidget::TagWidget(const QString& text, QWidget* parent)
+        : QLabel(text, parent)
+    {
+        setFixedHeight(35);
+        setMargin(5);
+        setStyleSheet("font-size: 12pt; background-color: #333333; border-radius: 4px;");
+    }
+
+    TagContainerWidget::TagContainerWidget(QWidget* parent)
+        : QWidget(parent)
+    {
+        m_layout = new QVBoxLayout();
+        m_layout->setAlignment(Qt::AlignTop);
+        m_layout->setMargin(0);
+        setLayout(m_layout);
+    }
+
+    void TagContainerWidget::Update(const QStringList& tags)
+    {
+        QWidget* parentWidget = qobject_cast<QWidget*>(parent());
+        int width = 250;
+        if (parentWidget)
+        {
+            width = parentWidget->width();
+        }
+
+        if (m_widget)
+        {
+            // Hide the old widget and request deletion.
+            m_widget->hide();
+            m_widget->deleteLater();
+        }
+
+        QVBoxLayout* vLayout = new QVBoxLayout();
+        m_widget = new QWidget(this);
+        m_widget->setLayout(vLayout);
+        m_layout->addWidget(m_widget);
+
+        vLayout->setAlignment(Qt::AlignTop);
+        vLayout->setMargin(0);
+
+        QHBoxLayout* hLayout = nullptr;
+        int usedSpaceInRow = 0;
+        const int numTags = tags.count();
+
+        for (int i = 0; i < numTags; ++i)
+        {
+            // Create the new tag widget.
+            TagWidget* tagWidget = new TagWidget(tags[i]);
+            const int tagWidgetWidth = tagWidget->minimumSizeHint().width();
+
+            // Calculate the width we're currently using in the current row. Does the new tag still fit in the current row?
+            const bool isRowFull = width - usedSpaceInRow - tagWidgetWidth < 0;
+            if (isRowFull || i == 0)
+            {
+                // Add a spacer widget after the last tag widget in a row to push the tag widgets to the left.
+                if (i > 0)
+                {
+                    QWidget* spacerWidget = new QWidget();
+                    spacerWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
+                    hLayout->addWidget(spacerWidget);
+                }
+
+                // Add a new row for the current tag widget.
+                hLayout = new QHBoxLayout();
+                hLayout->setAlignment(Qt::AlignLeft);
+                hLayout->setMargin(0);
+                vLayout->addLayout(hLayout);
+
+                // Reset the used space in the row.
+                usedSpaceInRow = 0;
+            }
+
+            // Calculate the width of the tag widgets including the spacing between them of the current row.
+            usedSpaceInRow += tagWidgetWidth + hLayout->spacing();
+
+            // Add the tag widget to the current row.
+            hLayout->addWidget(tagWidget);
+        }
+    }
+} // namespace O3DE::ProjectManager

+ 52 - 0
Code/Tools/ProjectManager/Source/TagWidget.h

@@ -0,0 +1,52 @@
+/*
+* 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.
+*
+*/
+
+#pragma once
+
+#if !defined(Q_MOC_RUN)
+#include <QLabel>
+#include <QStringList>
+#include <QWidget>
+#endif
+
+QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
+
+namespace O3DE::ProjectManager
+{
+    // Single tag
+    class TagWidget
+        : public QLabel
+    {
+        Q_OBJECT // AUTOMOC
+
+    public:
+        explicit TagWidget(const QString& text, QWidget* parent = nullptr);
+        ~TagWidget() = default;
+    };
+
+    // Widget containing multiple tags, automatically wrapping based on the size
+    class TagContainerWidget
+        : public QWidget
+    {
+        Q_OBJECT // AUTOMOC
+
+    public:
+        explicit TagContainerWidget(QWidget* parent = nullptr);
+        ~TagContainerWidget() = default;
+
+        void Update(const QStringList& tags);
+
+    private:
+        QVBoxLayout* m_layout = nullptr;
+        QWidget* m_widget = nullptr;
+    };
+} // namespace O3DE::ProjectManager

+ 4 - 0
Code/Tools/ProjectManager/project_manager_files.cmake

@@ -34,6 +34,10 @@ set(FILES
     Source/EngineSettings.h
     Source/EngineSettings.cpp
     Source/EngineSettings.ui
+    Source/LinkWidget.h
+    Source/LinkWidget.cpp
+    Source/TagWidget.h
+    Source/TagWidget.cpp
     Source/GemCatalog/GemCatalog.h
     Source/GemCatalog/GemCatalog.cpp
     Source/GemCatalog/GemInfo.h