/dev/Code/Sandbox/Plugins/MaglevControlPanel/DetailWidget/ActionWidget.cpp

https://github.com/aws/lumberyard · C++ · 171 lines · 112 code · 38 blank · 21 comment · 0 complexity · 96c10a7bb71693f590c0e2cce78ecfb4 MD5 · raw file

  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include "ActionWidget.h"
  13. #include <QVariant>
  14. #include <QVBoxLayout>
  15. #include <QLabel>
  16. #include <QPushButton>
  17. #include <QDesktopServices>
  18. #include <QUrl>
  19. #include <QCursor>
  20. #include "ButtonBarWidget.h"
  21. #include "HeadingWidget.h"
  22. #include <DetailWidget/ActionWidget.moc>
  23. ActionWidget::ActionWidget(QWidget* parent)
  24. : QFrame(parent)
  25. {
  26. CreateUI();
  27. // default content
  28. SetLearnMoreMessageText(tr(
  29. "Cloud Canvas enables you to use AWS resources in your Lumberyard project. For "
  30. "more information on getting started with Cloud Canvas, check out our Getting "
  31. "Started Guide, documentation, or tutorials."
  32. ));
  33. AddCloudCanvasDocumentationLink();
  34. AddCloudCanvasTutorialsLink();
  35. }
  36. void ActionWidget::CreateUI()
  37. {
  38. setObjectName("Action");
  39. // root
  40. auto rootLayout = new QVBoxLayout {};
  41. rootLayout->setSpacing(0);
  42. rootLayout->setMargin(0);
  43. setLayout(rootLayout);
  44. // heading
  45. m_headingWidget = new HeadingWidget {this};
  46. m_headingWidget->HideRefresh();
  47. rootLayout->addWidget(m_headingWidget);
  48. // button bar
  49. m_buttonBarWidget = new ButtonBarWidget {};
  50. rootLayout->addWidget(m_buttonBarWidget);
  51. // button bar - action button
  52. m_actionButton = new QPushButton("(SetActioButtonText)");
  53. m_actionButton->setObjectName("ActionButton");
  54. m_actionButton->setProperty("class", "Primary");
  55. connect(m_actionButton, &QPushButton::clicked, this, &ActionWidget::ActionClicked);
  56. m_buttonBarWidget->AddButton(m_actionButton);
  57. // learn more
  58. auto learnMoreWidget = new QWidget {};
  59. learnMoreWidget->setObjectName("LearnMore");
  60. rootLayout->addWidget(learnMoreWidget);
  61. m_learnMoreLayout = new QVBoxLayout {};
  62. m_learnMoreLayout->setMargin(0);
  63. m_learnMoreLayout->setSpacing(0);
  64. learnMoreWidget->setLayout(m_learnMoreLayout);
  65. // learn more title
  66. auto learnMore = new QLabel("Learn more");
  67. learnMore->setObjectName("Title");
  68. learnMore->setWordWrap(true);
  69. m_learnMoreLayout->addWidget(learnMore);
  70. // learn more text
  71. m_learnMoreMessageLabel = new QLabel {
  72. "(SetLearnMoreMessageText)"
  73. };
  74. m_learnMoreMessageLabel->setObjectName("Message");
  75. m_learnMoreMessageLabel->setWordWrap(true);
  76. m_learnMoreLayout->addWidget(m_learnMoreMessageLabel);
  77. // stretch
  78. m_learnMoreLayout->addStretch();
  79. }
  80. void ActionWidget::SetTitleText(const QString& text)
  81. {
  82. m_headingWidget->SetTitleText(text);
  83. }
  84. void ActionWidget::SetMessageText(const QString& text)
  85. {
  86. m_headingWidget->SetMessageText(text);
  87. }
  88. void ActionWidget::SetActionText(const QString& text)
  89. {
  90. m_actionButton->setText(text);
  91. }
  92. void ActionWidget::SetActionToolTip(const QString& text)
  93. {
  94. m_actionButton->setToolTip(text);
  95. }
  96. void ActionWidget::AddButton(QPushButton* button)
  97. {
  98. // insert before stretch
  99. m_buttonBarWidget->AddButton(button);
  100. }
  101. void ActionWidget::SetLearnMoreMessageText(const QString& text)
  102. {
  103. m_learnMoreMessageLabel->setText(text);
  104. }
  105. void ActionWidget::AddLearnMoreLink(const QString& text, const QString& url)
  106. {
  107. auto link = new QPushButton(text);
  108. link->setObjectName("LinkButton");
  109. link->setCursor(QCursor {Qt::PointingHandCursor});
  110. link->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
  111. connect(link, &QPushButton::clicked, this, [this, url]() { OnLinkActivated(url); });
  112. m_learnMoreLayout->insertWidget(m_learnMoreLayout->count() - 1, link);
  113. }
  114. void ActionWidget::AddCloudCanvasDocumentationLink()
  115. {
  116. AddLearnMoreLink("Cloud Canvas documentation", "http://docs.aws.amazon.com/console/lumberyard/cloudcanvas/introduction");
  117. }
  118. void ActionWidget::AddCloudCanvasTutorialsLink()
  119. {
  120. AddLearnMoreLink("Cloud Canvas tutorial", "http://docs.aws.amazon.com/console/lumberyard/cloudcanvas/tutorial");
  121. }
  122. void ActionWidget::AddCloudFormationDocumentationLink()
  123. {
  124. AddLearnMoreLink("AWS CloudFormation documentation", "https://aws.amazon.com/cloudformation");
  125. }
  126. void ActionWidget::OnLinkActivated(const QString& link)
  127. {
  128. QDesktopServices::openUrl(link);
  129. }
  130. QPushButton* ActionWidget::GetActionButton()
  131. {
  132. return m_actionButton;
  133. }