Преглед изворни кода

Initial work for FormOptionsWidget field

Signed-off-by: T.J. Kotha <[email protected]>
T.J. Kotha пре 2 година
родитељ
комит
01d2079712

+ 3 - 0
Code/Tools/ProjectManager/Source/CreateAGemScreen.cpp

@@ -269,6 +269,9 @@ namespace O3DE::ProjectManager
         m_requirements = new FormLineEditWidget(tr("Requirements"), "", tr("Notice of any requirements your Gem. i.e. This requires X other gem"), "");
         gemDetailsLayout->addWidget(m_requirements);
 
+        m_platformOptions = new FormOptionsWidget((QStringList() << tr("Windows") << tr("Linux") << tr("iOS") << tr("Android")), tr("All Platforms"));
+        gemDetailsLayout->addWidget(m_platformOptions);
+
         m_license = new FormLineEditWidget(
             tr("License*"), "", tr("License uses goes here: i.e. Apache-2.0 or MIT"), tr("License details are required."));
         gemDetailsLayout->addWidget(m_license);

+ 2 - 0
Code/Tools/ProjectManager/Source/CreateAGemScreen.h

@@ -13,6 +13,7 @@
 #include <FormFolderBrowseEditWidget.h>
 #include <FormLineEditWidget.h>
 #include <FormLineEditTagsWidget.h>
+#include <FormOptionsWidget.h>
 #include <FormComboBoxWidget.h>
 #include <GemCatalog/GemInfo.h>
 #include <PythonBindings.h>
@@ -75,6 +76,7 @@ namespace O3DE::ProjectManager
         FormLineEditWidget* m_gemDisplayName = nullptr;
         FormLineEditWidget* m_gemName = nullptr;
         FormLineEditWidget* m_gemSummary = nullptr;
+        FormOptionsWidget* m_platformOptions = nullptr;
         FormLineEditWidget* m_requirements = nullptr;
         FormLineEditWidget* m_license = nullptr;
         FormLineEditWidget* m_licenseURL = nullptr;

+ 162 - 0
Code/Tools/ProjectManager/Source/FormOptionsWidget.cpp

@@ -0,0 +1,162 @@
+/*
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+
+
+#include <AzQtComponents/Components/Widgets/CheckBox.h>
+
+#include <FormOptionsWidget.h>
+
+#include <QCheckBox>
+#include <QFrame>
+#include <QHash>
+#include <QHBoxLayout>
+#include <QWidget>
+#include <QVBoxLayout>
+
+namespace O3DE::ProjectManager
+{
+
+    FormOptionsWidget::FormOptionsWidget(const QStringList& options, const QString& allOptionsText, QWidget* parent) : QWidget(parent)
+    {
+        setObjectName("formOptionsWidget");
+
+        QVBoxLayout* mainLayout = new QVBoxLayout();
+        mainLayout->setAlignment(Qt::AlignTop);
+        {
+            m_optionFrame = QFrame(this);
+            QHBoxLayout* optionFrameLayout = new QHBoxLayout();
+            {
+                //Add the options
+                for(const QString& option : options)
+                {
+                    QCheckBox* optionCheckBox = new QCheckBox(option);
+                    optionFrameLayout->addWidget(optionCheckBox);
+                    connect(optionCheckBox, &QCheckBox::clicked, this, [=](bool checked){
+                        if(checked)
+                        {
+                            enable(option);
+                        }
+                        else
+                        {
+                            disable(option);
+                        }
+                    });
+                    m_options.insert(option, optionCheckBox);
+                }
+
+                //Add the platform option toggle
+                m_allOptionsToggle = new QCheckBox(allOptionsText);
+                connect(m_allOptionsToggle, &QCheckBox::clicked, this, [=](bool checked){
+                    if(checked)
+                    {
+                        enableAll();
+                    }
+                    else
+                    {
+                        clear();
+                    }
+                });
+                AzQtComponents::CheckBox::applyToggleSwitchStyle(m_allOptionsToggle);
+
+                optionFrameLayout->addWidget(m_allOptionsToggle);
+            }
+
+            m_optionFrame->setLayout(optionFrameLayout);
+            mainLayout->addWidget(m_optionFrame);
+        }
+        setLayout(mainLayout);
+    }
+
+    void FormOptionsWidget::enable(const QString& option)
+    {
+        if(m_options.contains(option))
+        {
+            auto checkbox = m_options.value(option);
+            if(!checkbox->isChecked())
+            {
+                m_currentlyActive++;
+                if(m_currentlyActive == m_options.keys().count())
+                {
+                    m_allOptionsToggle->setChecked(true);
+                }
+            }
+            checkbox->setChecked(true);
+        }
+    }
+
+    void FormOptionsWidget::enable(const QStringList& options)
+    {
+        for(const QString& option : options)
+        {
+            enable(option);   
+        }
+    }
+
+    void FormOptionsWidget::disable(const QString& option)
+    {
+        if(m_options.contains(option))
+        {
+            auto checkbox = m_options.value(option);
+            if(checkbox->isChecked())
+            {
+                m_currentlyActive--;
+                m_allOptionsToggle->setChecked(false);
+            }
+            checkbox->setChecked(false);
+        }
+    }
+
+    void FormOptionsWidget::disable(const QStringList& options)
+    {
+        for (const QString& option : options)
+        {
+            disable(option);
+        }
+    }
+
+    void FormOptionsWidget::enableAll()
+    {
+        for(const auto& checkbox : m_options.values())
+        {
+            checkbox->setChecked(true);
+        }
+        m_allOptionsToggle->setChecked(true);
+        m_currentlyActive = m_options.keys().count();
+    }
+    
+    void FormOptionsWidget::clear()
+    {
+        for(const auto& checkbox : m_options.values())
+        {
+            checkbox->setChecked(false);
+        }
+        m_allOptionsToggle->setChecked(false);
+        m_currentlyActive = 0;
+    }
+
+    QStringList FormOptionsWidget::getOptions() const
+    {
+        if(m_allOptionsToggle->isChecked())
+        {
+            return QStringList(m_options.keys());
+        }
+
+        QStringList options;
+        for(const QString& option : m_options.keys())
+        {
+            auto checkbox = m_options.value(option);
+            if(checkbox->isChecked())
+            {
+                options << option;
+            }
+        }
+
+        return options;
+    }
+
+} // namespace O3DE::ProjectManager

+ 57 - 0
Code/Tools/ProjectManager/Source/FormOptionsWidget.h

@@ -0,0 +1,57 @@
+/*
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+
+#pragma once
+
+#if !defined(Q_MOC_RUN)
+#include <QWidget>
+#endif
+
+QT_FORWARD_DECLARE_CLASS(QCheckBox)
+QT_FORWARD_DECLARE_CLASS(QFrame)
+
+namespace AzQtComponents
+{
+    class CheckBox;
+}
+
+namespace O3DE::ProjectManager
+{
+    class FormOptionsWidget
+        : public QWidget
+    {
+        Q_OBJECT
+
+    public:
+        FormOptionsWidget(const QStringList& options, const QString& allOptionsText, QWidget* parent = nullptr);
+
+        void clear();
+
+        void enable(const QString& option);
+
+        void enable(const QStringList& options);
+
+        void disable(const QString& option);
+
+        void disable(const QStringList& options);
+
+        void enableAll();
+
+        QStringList getOptions() const;
+
+    private:
+        QFrame* m_optionFrame = nullptr;
+        QHash<QString, QCheckBox*> m_options;
+        QCheckBox* m_allOptionsToggle = nullptr;
+
+        //! Represents active options in m_options. Should never exceed the count of keys in m_options
+        int m_currentlyActive = 0;
+    }
+
+} // namespace O3DE::ProjectManager
+

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

@@ -23,6 +23,8 @@ set(FILES
     Source/FormLineEditWidget.cpp
     Source/FormLineEditTagsWidget.h
     Source/FormLineEditTagsWidget.cpp
+    Source/FormOptionsWidget.h
+    Source/FormOptionsWidget.cpp
     Source/FormBrowseEditWidget.h
     Source/FormBrowseEditWidget.cpp
     Source/FormComboBoxWidget.h