swift
configurationwizard.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "configurationwizard.h"
5 
6 #include <QPointer>
7 
8 #include "ui_configurationwizard.h"
9 
10 #include "gui/guiapplication.h"
11 #include "gui/guiutility.h"
12 #include "misc/directoryutils.h"
13 #include "misc/math/mathutils.h"
14 
15 using namespace swift::misc;
16 using namespace swift::misc::math;
17 
18 namespace swift::gui::components
19 {
20  CConfigurationWizard::CConfigurationWizard(QWidget *parent) : QWizard(parent), ui(new Ui::CConfigurationWizard)
21  {
22  ui->setupUi(this);
23  this->setWindowFlags(windowFlags() | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint |
24  Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
25 
26  ui->wp_CopyModels->setConfigComponent(ui->comp_CopyModels);
27  ui->wp_CopySettingsAndCaches->setConfigComponent(ui->comp_CopySettingsAndCachesComponent);
28  ui->wp_Simulator->setConfigComponent(ui->comp_Simulator);
29  ui->wp_SimulatorSpecific->setConfigComponent(ui->comp_InstallXSwiftBus, ui->comp_InstallFsxTerrainProbe);
30  ui->wp_DataLoad->setConfigComponent(ui->comp_DataLoad);
31  ui->wp_Hotkeys->setConfigComponent(ui->comp_Hotkeys);
32  ui->wp_Legal->setConfigComponent(ui->comp_LegalInformation);
33  ui->comp_Hotkeys->registerDummyPttEntry();
34  this->setButtonText(CustomButton1, "skip");
35 
36  // no other versions, skip copy pages
37  // disabled afetr discussion with RP as it is confusing
38  // if (!CApplicationInfoList::hasOtherSwiftDataDirectories()) { this->setStartId(ConfigSimulator); }
39 
40  ui->tb_SimulatorSpecific->setCurrentWidget(ui->comp_InstallXSwiftBus);
41 
42  const QList<int> ids = this->pageIds();
43  const auto mm = std::minmax_element(ids.begin(), ids.end());
44  m_maxId = *mm.second;
45  m_minId = *mm.first;
46 
47  connect(this, &QWizard::currentIdChanged, this, &CConfigurationWizard::wizardCurrentIdChanged);
48  connect(this, &QWizard::customButtonClicked, this, &CConfigurationWizard::clickedCustomButton);
49  connect(this, &QWizard::rejected, this, &CConfigurationWizard::ended);
50  connect(this, &QWizard::accepted, this, &CConfigurationWizard::ended);
51 
52  Q_ASSERT_X(sGui, Q_FUNC_INFO, "missing sGui");
53  const QPointer<CConfigurationWizard> myself(this);
54  connect(this, &QWizard::helpRequested, sGui, [=] {
55  if (!myself) { return; }
56  if (!sGui || sGui->isShuttingDown()) { return; }
57  sGui->showHelp(this);
58  });
59 
60  this->setScreenGeometry();
62  }
63 
65 
66  bool CConfigurationWizard::lastStepSkipped() const { return m_skipped; }
67 
68  bool CConfigurationWizard::lastWizardStepSkipped(const QWizard *standardWizard)
69  {
70  const CConfigurationWizard *wizard = qobject_cast<const CConfigurationWizard *>(standardWizard);
71  return wizard && wizard->lastStepSkipped();
72  }
73 
74  bool CConfigurationWizard::event(QEvent *event)
75  {
76  if (CGuiApplication::triggerShowHelp(this, event)) { return true; }
77  return QDialog::event(event);
78  }
79 
80  void CConfigurationWizard::wizardCurrentIdChanged(int id)
81  {
82  const int previousId = m_previousId;
83  const bool backward = id < previousId;
84  const bool skipped = m_skipped;
85  m_previousId = id; // update
86  m_skipped = false; // reset
87  Q_UNUSED(skipped);
88  Q_UNUSED(backward);
89 
90  this->setParentOpacity(0.5);
91  const QWizardPage *page = this->currentPage();
92  Q_UNUSED(page);
93 
94  this->setOption(HaveCustomButton1, id != m_maxId);
95  }
96 
97  void CConfigurationWizard::clickedCustomButton(int which)
98  {
99  if (which == static_cast<int>(CustomButton1))
100  {
101  m_skipped = true;
102  this->next();
103  }
104  else { m_skipped = false; }
105  }
106 
107  void CConfigurationWizard::ended() { this->setParentOpacity(1.0); }
108 
109  void CConfigurationWizard::setParentOpacity(qreal opacity)
110  {
111  QWidget *parent = this->parentWidget();
112  if (!parent) { return; }
113  if (CMathUtils::epsilonEqual(parent->windowOpacity(), opacity)) { return; }
114  parent->setWindowOpacity(opacity);
115  }
116 
117  void CConfigurationWizard::setScreenGeometry()
118  {
119  if (!sGui) { return; }
120  const QRect g = CGuiApplication::currentScreenGeometry();
121 
122  // 1280/720 on 4k hires
123  // 1920/1280 on non hires 1920 displays
124  const int gw = g.width();
125  const int gh = g.height();
126  const int calcW = qRound(gw * 0.8);
127  const int calcH = qRound(gh * 0.9); // normally critical as buttons are hidden
128 
129  // do not get too huge
130  const int w = qMin(900, calcW);
131  const int h = qMin(750, calcH);
132  this->resize(w, h);
133  }
134 } // namespace swift::gui::components
bool isShuttingDown() const
Is application shutting down?
static QRect currentScreenGeometry()
Current screen resolution.
static bool triggerShowHelp(const QWidget *widget, QEvent *event)
Static version used with dialogs.
void showHelp(const QString &context={}) const
Show help page (online help)
static void setWizardButtonWidths(QWizard *wizard)
Set button widths for a wizard.
Definition: guiutility.cpp:944
Configure the most important settings.
static bool lastWizardStepSkipped(const QWizard *standardWizard)
Static version of CConfigurationWizard::lastStepSkipped.
bool lastStepSkipped() const
Was the last step skipped?
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
High level reusable GUI components.
Definition: aboutdialog.cpp:13
Free functions in swift::misc.