Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
fgrootpage.cpp
Go to the documentation of this file.
1 
2 
3 #include <QtCore/QFile>
4 #include <QtGui/QGridLayout>
5 #include <QtGui/QFileDialog>
6 
8 #include "xobjects/xopt.h"
9 
11  QWizardPage(parent)
12 {
13  mainObject = mob;
14 
15  setTitle("Select FlightGear Data directory ");
16  setSubTitle("Select the default or a custom path to FG_ROOT");
17 
18 
19  QGridLayout *gridLayout = new QGridLayout();
20  setLayout(gridLayout);
21 
22  //= Default Path
23  int row = 0;
24  radioDefault = new QRadioButton();
25  radioDefault->setText("Use default path");
26  gridLayout->addWidget(radioDefault, row, 0, 1, 3);
27  connect(radioDefault, SIGNAL(toggled(bool)), this, SLOT(on_default_toggled(bool)));
28 
29  //= default help label
30  row++;
31  lblDefault = new QLabel("--");
32  gridLayout->addWidget(lblDefault, row, 1, 1, 2);
33 
34  //= Custom path
35  row++;
36  radioCustom = new QRadioButton();
37  radioCustom->setText("Select custom path");
38  radioCustom->setChecked(true);
39  gridLayout->addWidget(radioCustom, row, 0, 1, 3);
40 
41  //= select custom path
42  row++;
43  txtFgRoot = new QLineEdit("");
44  gridLayout->addWidget(txtFgRoot, row, 1, 1, 1);
45  connect(txtFgRoot, SIGNAL(textChanged(QString)), this, SLOT(check_paths()));
46 
47  //= Dropdown button for path
48  buttSelect = new QToolButton();
49  gridLayout->addWidget(buttSelect, row, 2);
50  buttSelect->setIcon(QIcon(":/icon/black"));
51  connect( buttSelect, SIGNAL(clicked()),
52  this, SLOT(on_select_path()) );
53 
54  //= custom help label
55  row++;
56  lblCustom = new QLabel("--");
57  gridLayout->addWidget(lblCustom, row, 1, 1, 2);
58 
59  gridLayout->setColumnStretch(0,1);
60  gridLayout->setColumnStretch(1,6);
61  gridLayout->setColumnStretch(2,0);
62 
63 
64  registerField("fgroot_use_default", radioDefault);
65  registerField("fgroot_use_custom", radioCustom);
66  registerField("fgroot_custom_path", txtFgRoot);
67 
68 }
69 
71 {
72  QString dirPath = QFileDialog::getExistingDirectory(this, tr("Select FG_ROOT directory"),
73  txtFgRoot->text(), QFileDialog::ShowDirsOnly);
74  if(dirPath.length() > 0){
75  txtFgRoot->setText(dirPath);
76  }
77  check_paths();
78 }
79 
80 //===================================================
81 //= initializePage
83 {
84  XOpt opt = mainObject->X->get_opt("fgroot_custom_path");
85  radioDefault->setChecked( opt.enabled == false );
86  radioCustom->setChecked( opt.enabled == true );
87  lblDefault->setText( mainObject->X->fgroot_default_path() );
88  txtFgRoot->setText( opt.value );
89 }
90 
91 
93 {
94  //= Check the default path
95  QString default_path = mainObject->X->fgroot_default_path();
96  bool default_exists = QFile::exists(default_path);
97  QString lbl_default(default_path);
98  lbl_default.append( default_exists ? " - Ok" : " - Not Found" );
99  QString style_default("");
100 
101  if(radioDefault->isChecked()){
102  style_default.append(default_exists ? "color:green;" : "color:#990000;");
103  }else{
104  style_default.append("color:#444444;");
105  }
106  lblDefault->setText(lbl_default);
107  lblDefault->setStyleSheet(style_default);
108 
109  //= Check Custom Path
110  if(radioCustom->isChecked()){
111  QString custom_path = txtFgRoot->text().trimmed();
112  if(custom_path.size() == 0){
113  lblCustom->setText("Select a path");
114  lblCustom->setStyleSheet("color: #000099;");
115  }else{
116  bool custom_exists = QFile::exists(custom_path);
117  lblCustom->setText(custom_exists ? "Ok" : "Not found");
118  lblCustom->setStyleSheet(custom_exists ? "color: green;" : "color:#990000;");
119  }
120  }else{
121  lblCustom->setText("");
122  }
123 }
124 
125 //====================================================
126 //= ValidatePage
128 {
129  check_paths();
130  if(radioDefault->isChecked()){
131  //TODO vaidate default path
132  return true;
133  }
134  if(QFile::exists(txtFgRoot->text())){
135  // TODO - check its executable
136  return true;
137  }else{
138  txtFgRoot->setFocus();
139  lblCustom->setText("File does not exist");
140  }
141  return false;
142 }
143 
144 
146  Q_UNUSED(state);
147  bool def = radioDefault->isChecked();
148 
149  txtFgRoot->setDisabled(def);
150  buttSelect->setDisabled( def);
151  if(def == false){
152  txtFgRoot->setFocus();
153  }
154  check_paths();
155 }
QToolButton * buttSelect
Definition: fgrootpage.h:22
QString value
Definition: xopt.h:19
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
void on_default_toggled(bool)
Definition: fgrootpage.cpp:145
QLabel * lblDefault
Definition: fgrootpage.h:24
void initializePage()
Definition: fgrootpage.cpp:82
QRadioButton * radioCustom
Definition: fgrootpage.h:21
Definition: xopt.h:14
QLabel * lblCustom
Definition: fgrootpage.h:25
FgRootPage(MainObject *mainObject, QWidget *parent=0)
Definition: fgrootpage.cpp:10
QRadioButton * radioDefault
Definition: fgrootpage.h:20
XSettingsModel * X
Definition: mainobject.h:86
bool validatePage()
Definition: fgrootpage.cpp:127
QLineEdit * txtFgRoot
Definition: fgrootpage.h:26
MainObject * mainObject
Definition: fgrootpage.h:17
void on_select_path()
Definition: fgrootpage.cpp:70
XOpt get_opt(QString option)
void check_paths()
Definition: fgrootpage.cpp:92
bool enabled
Definition: xopt.h:20