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);
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("install");
58  });
59 
60  this->setScreenGeometry();
62  }
63 
65 
66  bool CConfigurationWizard::lastStepSkipped() const { return m_skipped; }
67 
69  {
70  const CConfigurationWizard *wizard = qobject_cast<const CConfigurationWizard *>(standardWizard);
71  return wizard && wizard->lastStepSkipped();
72  }
73 
74  void CConfigurationWizard::wizardCurrentIdChanged(int id)
75  {
76  const int previousId = m_previousId;
77  const bool backward = id < previousId;
78  const bool skipped = m_skipped;
79  m_previousId = id; // update
80  m_skipped = false; // reset
81  Q_UNUSED(skipped);
82  Q_UNUSED(backward);
83 
84  this->setParentOpacity(0.5);
85  const QWizardPage *page = this->currentPage();
86  Q_UNUSED(page);
87 
88  this->setOption(HaveCustomButton1, id != m_maxId);
89  }
90 
91  void CConfigurationWizard::clickedCustomButton(int which)
92  {
93  if (which == static_cast<int>(CustomButton1))
94  {
95  m_skipped = true;
96  this->next();
97  }
98  else { m_skipped = false; }
99  }
100 
101  void CConfigurationWizard::ended() { this->setParentOpacity(1.0); }
102 
103  void CConfigurationWizard::setParentOpacity(qreal opacity)
104  {
105  QWidget *parent = this->parentWidget();
106  if (!parent) { return; }
107  if (CMathUtils::epsilonEqual(parent->windowOpacity(), opacity)) { return; }
108  parent->setWindowOpacity(opacity);
109  }
110 
111  void CConfigurationWizard::setScreenGeometry()
112  {
113  if (!sGui) { return; }
115 
116  // 1280/720 on 4k hires
117  // 1920/1280 on non hires 1920 displays
118  const int gw = g.width();
119  const int gh = g.height();
120  const int calcW = qRound(gw * 0.8);
121  const int calcH = qRound(gh * 0.9); // normally critical as buttons are hidden
122 
123  // do not get too huge
124  const int w = qMin(900, calcW);
125  const int h = qMin(750, calcH);
126  this->resize(w, h);
127  }
128 } // namespace swift::gui::components
bool isShuttingDown() const
Is application shutting down?
static QRect currentScreenGeometry()
Current screen resolution.
void showHelp(const QString &subpath={}) const
Show help page (online help)
static void setWizardButtonWidths(QWizard *wizard)
Set button widths for a wizard.
Definition: guiutility.cpp:921
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.
void accepted()
void rejected()
QList< T >::iterator begin()
QList< T >::iterator end()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
int height() const const
int width() const const
CustomizeWindowHint
QWidget * parentWidget() const const
void resize(const QSize &)
void setWindowFlags(Qt::WindowFlags type)
void currentIdChanged(int id)
QWizardPage * currentPage() const const
void customButtonClicked(int which)
void helpRequested()
void next()
QWizardPage * page(int id) const const
QList< int > pageIds() const const
void setButtonText(QWizard::WizardButton which, const QString &text)
void setOption(QWizard::WizardOption option, bool on)