DemoWizardDialog.cpp 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2021, Nick Vella <nick@nxk.io>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "DemoWizardDialog.h"
  27. #include <Demos/WidgetGallery/DemoWizardPage1GML.h>
  28. #include <Demos/WidgetGallery/DemoWizardPage2GML.h>
  29. #include <LibGUI/BoxLayout.h>
  30. #include <LibGUI/Button.h>
  31. #include <LibGUI/TextBox.h>
  32. #include <LibGUI/Wizards/WizardDialog.h>
  33. DemoWizardDialog::DemoWizardDialog(GUI::Window* parent_window)
  34. : GUI::WizardDialog(parent_window)
  35. {
  36. // Create the front cover
  37. m_front_page = GUI::CoverWizardPage::construct();
  38. m_front_page->set_header_text("Welcome to the SerenityOS demo wizard!");
  39. m_front_page->set_body_text("This wizard demonstrates the amazing wizardry\ncapabilities of LibGUI :^)");
  40. m_front_page->on_next_page = [&]() {
  41. return m_page_1;
  42. };
  43. // Create Page 1
  44. m_page_1 = GUI::WizardPage::construct(
  45. "Installation location",
  46. "Choose where Demo Application is installed on your computer.");
  47. m_page_1->body_widget().load_from_gml(demo_wizard_page_1_gml);
  48. m_page_1_location_text_box = m_page_1->body_widget().find_descendant_of_type_named<GUI::TextBox>("page_1_location_text_box");
  49. m_page_1->on_next_page = [&]() {
  50. return m_page_2;
  51. };
  52. // Create Page 2 with a progress bar :^)
  53. m_page_2 = GUI::WizardPage::construct(
  54. "Installation in progress...",
  55. "Please wait. Do not turn off your computer.");
  56. m_page_2->body_widget().load_from_gml(demo_wizard_page_2_gml);
  57. m_page_2_progressbar = m_page_2->body_widget().find_descendant_of_type_named<GUI::Progressbar>("page_2_progressbar");
  58. m_page_2_timer = Core::Timer::construct(this);
  59. m_page_2->on_page_enter = [&]() {
  60. m_page_2_progress_value = 0;
  61. m_page_2_timer->restart(100);
  62. };
  63. m_page_2->on_page_leave = [&]() {
  64. m_page_2_progress_value = 0;
  65. m_page_2_timer->stop();
  66. };
  67. m_page_2_timer->on_timeout = [&]() {
  68. if (m_page_2_progress_value < 100)
  69. m_page_2_progress_value++;
  70. m_page_2_progressbar->set_value(m_page_2_progress_value);
  71. // Go to final page on progress completion
  72. if (m_page_2_progress_value == 100) {
  73. m_page_2_progress_value = 0;
  74. replace_page(*m_back_page);
  75. }
  76. };
  77. // Don't set a on_next_page handler for page 2 as we automatically navigate to the final page on progress completion
  78. // Create the back cover
  79. m_back_page = GUI::CoverWizardPage::construct();
  80. m_back_page->set_header_text("Wizard complete.");
  81. m_back_page->set_body_text("That concludes the SerenityOS demo wizard :^)");
  82. m_back_page->set_is_final_page(true);
  83. push_page(*m_front_page);
  84. }