Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
terrasyncpage.cpp
Go to the documentation of this file.
1 
2 
3 
4 #include <QGridLayout>
5 #include <QFileDialog>
6 
8 #include "xobjects/xopt.h"
9 
11  QWizardPage(parent)
12 {
13 
14  mainObject = mob;
15 
16  setTitle("Setup TerraSync");
17  setSubTitle("Select the directory for TerraSync");
18 
19  QGridLayout *gridLayout = new QGridLayout();
20  setLayout(gridLayout);
21 
22  //= Terrasync enabled
23  int row = 0;
24  checkBoxUseTerrasync = new QCheckBox();
25  checkBoxUseTerrasync->setText("Download Scenery via TerraSync");
26  gridLayout->addWidget(checkBoxUseTerrasync, row, 0, 1, 3);
27  connect(checkBoxUseTerrasync, SIGNAL(clicked()), this, SLOT(on_checkbox_clicked()));
28 
29 
30  //= Path
31  row++;
32  txtTerraSyncPath = new QLineEdit("");
33  gridLayout->addWidget(txtTerraSyncPath, row, 1, 1, 1);
34  txtTerraSyncPath->setDisabled(true);
35  connect(txtTerraSyncPath, SIGNAL(textChanged(QString)), this, SLOT(check_paths()));
36 
37  //= Select path button
38  buttSelectPath = new QToolButton();
39  gridLayout->addWidget(buttSelectPath, row, 2);
40  buttSelectPath->setIcon(QIcon(":/icon/black"));
41  buttSelectPath->setDisabled(true);
42  connect(buttSelectPath, SIGNAL(clicked()), this, SLOT(on_select_path()));
43 
44  //= help label
45  row++;
46  lblHelp = new QLabel("");
47  gridLayout->addWidget(lblHelp, row, 1, 1, 2);
48 
49 
50  registerField("terrasync_enabled", checkBoxUseTerrasync);
51  registerField("terrasync_path", txtTerraSyncPath);
52 
53 }
54 
56 {
57  QString dirPath = QFileDialog::getExistingDirectory(this, tr("Select TerraSync directory"),
58  txtTerraSyncPath->text(), QFileDialog::ShowDirsOnly);
59  if(dirPath.length() > 0){
60  txtTerraSyncPath->setText(dirPath);
61  }
62  check_paths();
63 }
64 
65 
66 
68  bool ena = checkBoxUseTerrasync->isChecked();
69  txtTerraSyncPath->setEnabled(ena);
70  buttSelectPath->setEnabled(ena);
71  if(ena){
72  txtTerraSyncPath->setFocus();
73  }
74  check_paths();
75 }
76 
77 //===============================================================
78 //= check_paths() - does not return value but colours help labels
80 {
81 
82  if(checkBoxUseTerrasync->isChecked()){
83  if(QFile::exists(txtTerraSyncPath->text())){
84  lblHelp->setText("Ok");
85  lblHelp->setStyleSheet("color: green;");
86 
87  }else{
88  lblHelp->setText("Not found");
89  lblHelp->setStyleSheet("color:#990000;");
90  }
91  }else{
92  lblHelp->setText("");
93  lblHelp->setStyleSheet("color: #000000;");
94  }
95 
96 }
97 
98 //===================================================
99 //= InitializePage
101 {
102  XOpt opt = mainObject->X->get_opt("terrasync_path");
103  checkBoxUseTerrasync->setChecked( opt.enabled );
104  txtTerraSyncPath->setText( opt.value );
106 }
107 
108 //====================================================
109 //= ValidatePage
111 {
112  check_paths();
113 
114  if(checkBoxUseTerrasync->isChecked()){
115  if(QFile::exists(txtTerraSyncPath->text())){
116  // TODO - check its writable
117  return true;
118  }else{
119  txtTerraSyncPath->setFocus();
120  return false;
121  }
122  }
123  return true;
124 }
void on_select_path()
QLineEdit * txtTerraSyncPath
Definition: terrasyncpage.h:22
QString value
Definition: xopt.h:19
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
MainObject * mainObject
Definition: terrasyncpage.h:19
Definition: xopt.h:14
XSettingsModel * X
Definition: mainobject.h:86
void on_checkbox_clicked()
TerraSyncPage(MainObject *mob, QWidget *parent=0)
QLabel * lblHelp
Definition: terrasyncpage.h:23
XOpt get_opt(QString option)
QToolButton * buttSelectPath
Definition: terrasyncpage.h:21
bool enabled
Definition: xopt.h:20
QCheckBox * checkBoxUseTerrasync
Definition: terrasyncpage.h:20