Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
timeweatherwidget.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // timeweatherwidget.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 <QString>
10 #include <QStringList>
11 #include <QVariant>
12 
13 #include <QHBoxLayout>
14 #include <QVBoxLayout>
15 #include <QGroupBox>
16 #include <QRadioButton>
17 
18 #include "timeweatherwidget.h"
19 #include "xwidgets/xgroupboxes.h"
20 #include "utilities/helpers.h"
21 
23  QWidget(parent)
24 {
25  mainObject = mOb;
26 
27  QHBoxLayout *mainLayout = new QHBoxLayout();
28  setLayout(mainLayout);
29 
30  //===============================================================
31  // Left Column with Time / Season
32  //===============================================================
33  QVBoxLayout *layTimeSeason = new QVBoxLayout();
34  mainLayout->addLayout(layTimeSeason, 1);
35 
36  //===============================================================
37  // Time group
38  QStringList time_vals; //= are the values
39  time_vals << "real" << "dawn" << "morning" << "noon" << "afternoon" << "dusk" << "evening" << "midnight";
40 
41  QStringList time_labels; //= are the labels
42  time_labels << tr("Real time") << tr("Dawn") << tr("Morning") << tr("Noon") << tr("Afternoon") << tr("Dusk") << tr("Evening") << tr("Midnight");
43 
44  XGroupVBox *grpBoxTime = new XGroupVBox(tr("Time"));
45  layTimeSeason->addWidget(grpBoxTime);
46  buttonGroupTime = new QButtonGroup(this);
47  buttonGroupTime->setExclusive(true);
48  connect(buttonGroupTime, SIGNAL(buttonClicked(int)),
49  this, SLOT(on_time_clicked())
50  );
51 
52  for(int i=0; i < time_vals.size(); i++){
53  QRadioButton *butt = new QRadioButton();
54  butt->setText(time_labels.at(i));
55  butt->setProperty("value", QVariant(time_vals.at(i)));
56  grpBoxTime->addWidget(butt);
57  buttonGroupTime->addButton(butt, i);
58  }
59  buttonGroupTime->button(0)->setChecked(true);
60 
61 
62 
63  //===============================================================
64  // Season group
65  QStringList season_vals; //= values
66  season_vals << "winter" << "summer";
67 
68  QStringList season_labels; // = labels
69  season_labels << tr("Winter") << tr("Summer");
70 
71  XGroupVBox *grpBoxSeason = new XGroupVBox(tr("Season"));
72  layTimeSeason->addWidget(grpBoxSeason);
73  buttonGroupSeason = new QButtonGroup(this);
74  buttonGroupSeason->setExclusive(true);
75  connect(buttonGroupSeason, SIGNAL(buttonClicked(int)),
76  this, SLOT(on_season_clicked(int))
77  );
78 
79  for(int i=0; i < season_vals.size(); i++){
80  QRadioButton *buttS = new QRadioButton();
81  buttS->setText(season_labels.at(i));
82  buttS->setProperty("value", QVariant(season_vals.at(i).toLower()));
83  grpBoxSeason->addWidget(buttS);
84  buttonGroupSeason->addButton(buttS, i);
85  }
86  buttonGroupSeason->button(0)->setChecked(true);
87 
88  //= Add some stretch to column bottom
89  layTimeSeason->addStretch(100);
90 
91  //= Add A Spacer in Middle Column
92  mainLayout->addStretch(1);
93 
94 
95  //===============================================================
96  // Right Column with Metar
97  //===============================================================
98  QVBoxLayout *laymetar = new QVBoxLayout();
99  mainLayout->addLayout(laymetar, 2);
100 
101  //===============================================================
102  // Metar group
103  QStringList metar_vals; //= values
104  metar_vals << "none" << "live" << "custom";
105  QStringList metar_labels; //= labels
106  metar_labels << tr("None (default weather)") << tr("Fetch METAR data live") << tr("Set static METAR below");
107 
108  XGroupVBox *grpBoxMetar = new XGroupVBox(tr("METAR"));
109  laymetar->setAlignment(Qt::AlignTop);
110  laymetar->addWidget(grpBoxMetar);
111  buttonGroupMetar = new QButtonGroup(this);
112  buttonGroupMetar->setExclusive(true);
113  connect(buttonGroupMetar, SIGNAL(buttonClicked(int)), this, SLOT(on_weather()));
114 
115  for(int i=0; i < metar_vals.size(); i++){
116  QRadioButton *buttM = new QRadioButton();
117  buttM->setText(metar_labels.at(i));
118  buttM->setProperty("value", QVariant(metar_vals.at(i)));
119  grpBoxMetar->addWidget(buttM);
120  buttonGroupMetar->addButton(buttM, i);
121  }
122  buttonGroupMetar->button(0)->setChecked(true);
123 
124  txtMetar = new QPlainTextEdit();
125  txtMetar->setMaximumHeight(80);
126  grpBoxMetar->addWidget(txtMetar);
127  laymetar->addStretch(20);
128 
129 
130  connect(this, SIGNAL(setx(QString,bool,QString)), mainObject->X, SLOT(set_option(QString,bool,QString)) );
131  connect(mainObject->X, SIGNAL(upx(QString,bool,QString)), this, SLOT(on_upx(QString,bool,QString)));
132 
133 }
134 
135 
136 
137 
138 //== Validate
140  if( buttonGroupMetar->checkedButton()->property("value").toString() == "custom"
141  && txtMetar->toPlainText().length() == 0){
142 
143  return QString("No metar text");
144  }
145 
146  return QString("");
147 }
148 
149 
150 //=========================================================================
151 //== Time clicked
153 {
154  emit setx("--timeofday=", true, buttonGroupTime->checkedButton()->property("value").toString());
155 }
156 
157 //== Season Clicked
159 {
160  emit setx("--season=", true, buttonGroupSeason->checkedButton()->property("value").toString());
161  Q_UNUSED(idx);
162 }
163 
164 //== Metar Clicked
166 {
167  QString w = buttonGroupMetar->checkedButton()->property("value").toString();
168  emit setx("weather", true, w);
169  emit setx("--disable-real-weather-fetch", w == "none", "");
170  emit setx("--enable-real-weather-fetch", w == "live", "");
171  emit setx("--metar=", w == "metar", txtMetar->toPlainText());
172 
173 
174 }
175 
176 
177 //=========================================================================
178 //= Update Settings
179 void TimeWeatherWidget::on_upx(QString option, bool enabled, QString value)
180 {
181  Q_UNUSED(enabled);
182  if(option == "--timeofday="){
183  Helpers::select_radio(buttonGroupTime, value);
184 
185  }else if(option == "--season="){
186  Helpers::select_radio(buttonGroupSeason, value);
187 
188  }else if(option == "weather"){
189  Helpers::select_radio(buttonGroupMetar, value);
190  txtMetar->setEnabled(value == "custom");
191  if(txtMetar->isEnabled()){
192  txtMetar->setFocus();
193  }
194 
195  }else if(option == "--metar="){
196  txtMetar->setPlainText(value);
197  }
198 
199 }
QButtonGroup * buttonGroupSeason
A QGroupBox with a QVBoxLyout layout.
Definition: xgroupboxes.h:19
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
QPlainTextEdit * txtMetar
TimeWeatherWidget(MainObject *mOb, QWidget *parent=0)
void setx(QString option, bool enabled, QString value)
void addWidget(QWidget *w)
Definition: xgroupboxes.cpp:21
XSettingsModel * X
Definition: mainobject.h:86
QButtonGroup * buttonGroupMetar
MainObject * mainObject
QButtonGroup * buttonGroupTime
void on_upx(QString option, bool enabled, QString value)