Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
expertoptionswidget.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // expertoptionswidget.cpp
3 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
4 // (c) 2010-2012
5 // Yves Sablonier, Pete Morgan
6 // Geoff McLane
7 // GNU GPLv2, see main.cpp and shipped licence.txt for further information
8 
9 #include <QProcess>
10 
11 #include <QHBoxLayout>
12 #include <QVBoxLayout>
13 #include <QPushButton>
14 
15 #include "xwidgets/xgroupboxes.h"
17 #include "utilities/helpers.h"
18 #include "utilities/utilities.h"
19 
21  QWidget(parent)
22 {
23  mainObject = mOb;
24 
25 
26  //===============================================================================
27  //= Create Layouts
28  //===============================================================================
29  QHBoxLayout *mainLayout = new QHBoxLayout();
30  setLayout(mainLayout);
31 
32  QVBoxLayout *leftLayout = new QVBoxLayout();
33  mainLayout->addLayout(leftLayout);
34 
35  QVBoxLayout *rightLayout = new QVBoxLayout();
36  mainLayout->addLayout(rightLayout);
37 
38 
39  //===============================================================================
40  //= Left is additional args
41  //===============================================================================
42 
43  //======================
44  //== Additional Args
45  groupBoxArgs = new XGroupVBox(tr("Additional Command Arguments"));
46  groupBoxArgs->setCheckable(true);
47  leftLayout->addWidget(groupBoxArgs);
48  connect(groupBoxArgs, SIGNAL(toggled(bool)), this, SLOT(on_extra()));
49 
50  txtExtraArgs = new QPlainTextEdit();
52  connect(txtExtraArgs, SIGNAL(textChanged()), this, SLOT(on_extra()));
53 
54 
55  //======================
56  //== Environment Variables
57  groupBoxEnv = new XGroupVBox(tr("Additional Environment Variables"));
58  groupBoxEnv->setCheckable(true);
59  leftLayout->addWidget(groupBoxEnv);
60  connect(groupBoxEnv, SIGNAL(toggled(bool)), this, SLOT(on_env()));
61 
62  txtExtraEnv = new QPlainTextEdit();
64  connect(txtExtraEnv, SIGNAL(textChanged()), this, SLOT(on_env()));
65 
66 
67  //======================
68  //== Runtime Directory
69  // *TBD* Would also be nice to have a button [...] to aid in setting this directory.
70  XGroupHBox *groupBoxRun = new XGroupHBox(tr("Set a specific runtime directory"));
71  leftLayout->addWidget(groupBoxRun);
72 
73  txtRuntime = new QLineEdit("");
74  groupBoxRun->addWidget(txtRuntime);
75  connect(txtRuntime, SIGNAL(textChanged(QString)), this, SLOT(on_runtime()));
76 
77 
78  //======================
79  //== Write Log
80  groupBoxWriteLog = new XGroupVBox(tr("FlightGear Loglevel"));
81  leftLayout->addWidget(groupBoxWriteLog);
82 
83  comboLogLevels = new QComboBox();
85  connect(comboLogLevels, SIGNAL(currentIndexChanged(int)), this, SLOT(on_log_level()));
86 
87  //TODO - these need to go in "DD"
88  QStringList values;
89  values << "none" << "warn" << "info" << "debug" << "bulk" << "alert";
90  QStringList labels;
91  labels << tr("None") << tr("Warn") << tr("Info") << tr("Debug") << tr("Bulk") << tr("Alert");
92 
93  for(int i = 0; i < values.length(); i++){
94  comboLogLevels->addItem(labels.at(i), values.at(i));
95  }
96 
97 
98 
99  //===============================================================================
100  //= Right is Output preview and help
101  //===============================================================================
102 
103  XGroupVBox *groupBox = new XGroupVBox(tr("Command Output"));
104  rightLayout->addWidget(groupBox);
105 
107  groupBox->addWidget(commandPreviewWidget);
108 
109 
110  connect(this, SIGNAL(setx(QString,bool,QString)), mainObject->X, SLOT(set_option(QString,bool,QString)) );
111  connect(mainObject->X, SIGNAL(upx(QString,bool,QString)), this, SLOT(on_upx(QString,bool,QString)));
112 
113 }
114 
115 
116 
117 
118 //==========================================================
119 //= Events
120 //==========================================================
121 
122 //= Extras Options changed
124 {
125  emit setx("extra_args", groupBoxArgs->isChecked(), txtExtraArgs->toPlainText().trimmed());
126 }
127 
128 //= Extra Env changed
130 {
131  emit setx("extra_env", groupBoxEnv->isChecked(), txtExtraEnv->toPlainText().trimmed());
132 }
133 
134 //= Log level changed
136 {
137  QString log = comboLogLevels->itemData(comboLogLevels->currentIndex()).toString();
138  emit setx("--log-level=", log != "none", log);
139 }
140 
141 //= Runtime changed
143 {
144  emit setx("runtime", true, txtRuntime->text().trimmed());
145 }
146 
147 
148 
149 //==========================================================
150 //= Update
151 //==========================================================
152 // NOTE: QPlainTextEfit need only be "set" when
153 // text is different to void recursive loop
154 
155 void ExpertOptionsWidget::on_upx(QString option, bool enabled, QString value)
156 {
157  Q_UNUSED(enabled);
158 
159 
160 
161  if(option == "extra_args"){
162  if(value != txtExtraArgs->toPlainText()){
163  txtExtraArgs->setPlainText(value);
164  }
165  groupBoxArgs->setChecked(enabled);
166 
167  }else if(option == "extra_env"){
168  if(value != txtExtraEnv->toPlainText()){
169  txtExtraEnv->setPlainText(value);
170  }
171  groupBoxEnv->setChecked(enabled);
172 
173  }else if(option == "runtime"){
174  txtRuntime->setText(value);
175 
176  }else if(option == "--log-level="){
177  Helpers::select_combo(comboLogLevels, value);
178  }
179 }
180 
181 
A QGroupBox with a QVBoxLyout layout.
Definition: xgroupboxes.h:19
void on_upx(QString option, bool enabled, QString value)
XGroupVBox * groupBoxWriteLog
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
ExpertOptionsWidget(MainObject *mOb, QWidget *parent=0)
A QGroupBox with a QHBoxLyout layout.
Definition: xgroupboxes.h:39
XCommandPrevieWidget * commandPreviewWidget
void addWidget(QWidget *w)
Definition: xgroupboxes.cpp:21
QPlainTextEdit * txtExtraArgs
XSettingsModel * X
Definition: mainobject.h:86
QPlainTextEdit * txtExtraEnv
void addWidget(QWidget *w)
Definition: xgroupboxes.cpp:45
void setx(QString option, bool enabled, QString value)