Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
menuwidget.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // menuwidget.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 "app_config.h"
10 #include <QtDebug>
11 
12 #include <QVBoxLayout>
13 #include <QHBoxLayout>
14 #include <QMenuBar>
15 #include <QMenu>
16 
17 #include "utilities/utilities.h"
18 #include "launcher/menuwidget.h"
20 #include "xobjects/mainobject.h"
21 
22 /*! \class MenuWidget
23  * \brief The MenuWidget is the top part of the LauncherWindow. Its contains the toplevel menu
24  * and has ended up separate to make tweaking for OSX easier.
25  *
26 */
28  QWidget(parent)
29 {
30 
31  mainObject = mob;
32 
33  settings = new XSettings();
34  debug_mode = settings->value("DEBUG_MODE","0").toBool();
35 
36  menuLayout = new QHBoxLayout();
37  menuLayout->setContentsMargins(0,0,0,0);
38 
39  // Macro needed to make the widget "placeholder" disappearing on OSX.
40  // Not nice at all, but working.
42  setLayout(menuLayout);
43  }
44 
45  // Menu "FGx" (OSX = "Windows") actions
46  quitAction = new QAction(tr("&Quit"), this);
47  quitAction->setShortcut(QString("Ctrl+q"));
48  quitAction->setStatusTip(tr("Exit the application"));
49  connect(quitAction, SIGNAL(triggered()), this, SLOT(on_menu_quit()));
50 
51  logWindowAction = new QAction(tr("Show &logs"), this);
52  logWindowAction->setShortcut(QString("Ctrl+Shift+l"));
53  logWindowAction->setStatusTip(tr("Shows all logs in a separate window"));
54  connect(logWindowAction, SIGNAL(triggered()), this, SLOT(on_show_log_window()));
55 
56  debugWindowAction = new QAction(tr("&Debug settings"), this);
57  debugWindowAction->setShortcut(QString("Ctrl+d"));
58  debugWindowAction->setStatusTip(tr("Shows the settings debug window"));
59  connect(debugWindowAction, SIGNAL(triggered()), this, SLOT(on_show_debug_window()));
60 
61  propsWindowAction = new QAction(tr("&Properties browser"), this);
62  propsWindowAction->setShortcut(QString("Ctrl+Shift+p"));
63  propsWindowAction->setStatusTip(tr("Shows properties browser"));
64  connect(propsWindowAction, SIGNAL(triggered()), this, SLOT(on_show_props_window()));
65 
66  // Menu "Mode" actions
67  debugmodeAction = new QAction(tr("&Debug mode"), this);
68  debugmodeAction->setShortcut(QString("Ctrl+Shift+d"));
69  debugmodeAction->setStatusTip(tr("Switching debug mode"));
70  debugmodeAction->setCheckable(true);
71  debugmodeAction->setChecked(debug_mode);
72  connect(debugmodeAction, SIGNAL(triggered()), this, SLOT(on_menu_debug_mode()));
73 
74  // Switching menu name, maybe should better go to two menus later
76  applicationMenu = new QMenu(tr("&Windows"));
77  }else {
78  applicationMenu = new QMenu(tr("&FGx"));
79  }
80 
81  modeMenu = new QMenu(tr("&Mode"));
82 
83  profileMenu = new QMenu(tr("&Profile"));
84 
85  //== Help Menu
86  helpMenu = new QMenu(tr("&Help"));
87  helpFGxGroup = new QMenu(tr("&FGx Online Help"));
88  helpFlightGearGroup = new QMenu(tr("&FlightGear Online Help"));
89 
90 
91 
92  // Menu Profile actions
93  loadProfileAction = new QAction(tr("&Load ..."), this);
94  loadProfileAction->setStatusTip(tr("Loads a profile"));
95  connect(loadProfileAction, SIGNAL(triggered()), this, SLOT(on_menu_load_profile()));
96 
97  saveProfileAction = new QAction(tr("&Save as ..."), this);
98  saveProfileAction->setStatusTip(tr("Saves current settings in a profile"));
99  connect(saveProfileAction, SIGNAL(triggered()), this, SLOT(on_menu_save_profile()));
100 
101  resetProfileAction = new QAction(tr("&Reset"), this);
102  resetProfileAction->setStatusTip(tr("Reset all settings to current loaded profile"));
103  connect(resetProfileAction, SIGNAL(triggered()), this, SLOT(on_menu_reset_profile()));
104 
105  defaultProfileAction = new QAction(tr("&Load default profile"), this);
106  defaultProfileAction->setStatusTip(tr("Reload FGx default profile (built-in)"));
107  connect(defaultProfileAction, SIGNAL(triggered()), this, SLOT(on_menu_default_profile()));
108 
109  //=======================================
110  // Menu FlightGear Help actions
111  urlActionWiki = new QAction(tr("Wiki - wiki.flightgear.org"), this);
112  connect(urlActionWiki, SIGNAL(triggered()), this, SLOT(on_menu_url_wiki()));
113 
114  urlActionForums = new QAction(tr("Forums - forums.flightgear.org"), this);
115  connect(urlActionForums, SIGNAL(triggered()), this, SLOT(on_menu_url_forums()));
116 
117  //=======================================
118  // Menu FGx Help actions
119 
120  urlActionFGxUserHelp = new QAction(tr("FGx - User Forum"), this);
121  connect(urlActionFGxUserHelp, SIGNAL(triggered()), this, SLOT(on_menu_fgx_user_forums()));
122 
123  // Add actions to menu "FGx"/"Windows" (OSX = "Windows")
124  applicationMenu->addAction(quitAction);
125  applicationMenu->addAction(logWindowAction);
128 
129  // Add actions to menu "Mode"
130  modeMenu->addAction(debugmodeAction);
131 
132  // Add actions to menu "Profile"
133  profileMenu->addAction(loadProfileAction);
134  profileMenu->addAction(saveProfileAction);
135  profileMenu->addAction(resetProfileAction);
136  profileMenu->addAction(defaultProfileAction);
137 
138  // Add actions to menu "Help"
141  helpFGxGroup->addAction("Website", this, SLOT(on_menu_fgx_www()) );
142  helpFGxGroup->addAction("Bugs & Requests", this, SLOT(on_menu_fgx_issues()) );
143  helpFGxGroup->addAction("Source Code", this, SLOT(on_menu_fgx_github()) );
145 
146  helpMenu->addMenu(helpFGxGroup);
147  helpMenu->addSeparator();
148  helpMenu->addMenu(helpFlightGearGroup);
149  helpMenu->addSeparator();
150  helpMenu->addAction("About FGx", this, SLOT(on_menu_fgx_version_info()));
151  helpMenu->addAction("About Qt", this, SLOT(on_menu_qt_version_info()));
152 
153  // Create menubar, parentless 0 is needed for OSX using the wrapper for
154  // getting native OSX menus, see qt4 MenuBar doc
155  mainMenu = new QMenuBar(0);
156 
157  // Adding the menus to the MenuBar
158  mainMenu->addMenu(applicationMenu);
159  mainMenu->addMenu(modeMenu);
160  mainMenu->addMenu(profileMenu);
161  mainMenu->addMenu(helpMenu);
162 
163  // No action for OSX, but gives the menu for x/win
164  menuLayout->addWidget(mainMenu, 0);
165 
166 }
167 
168 //================================================================================
169 // Quit application
170 //================================================================================
172  mainObject->on_quit();
173 }
174 
175 //================================================================================
176 // Show log window, focus
177 //================================================================================
179  mainObject->viewLogsWidget->show();
180  mainObject->viewLogsWidget->raise();
181  mainObject->viewLogsWidget->activateWindow();
182 
183 }
184 
185 //================================================================================
186 // Show debug window, focus
187 //================================================================================
189  mainObject->fgxDebugWidget->show();
190  mainObject->fgxDebugWidget->raise();
191  mainObject->fgxDebugWidget->activateWindow();
192 
193 }
194 
195 //================================================================================
196 // Show properties window, focus
197 //================================================================================
199  mainObject->propertiesBrowser->show();
200  mainObject->propertiesBrowser->raise();
201  mainObject->propertiesBrowser->activateWindow();
202 
203 }
204 
205 //================================================================================
206 // Set application to debug mode (show all exe buttons)
207 //================================================================================
209  debug_mode = debugmodeAction->isChecked();
211 
212 }
213 
214 //================================================================================
215 // Load Profile
216 //================================================================================
218 {
219  QString message("Profile load abandoned");
220  if (mainObject->X->load_profile()) {
221  // get lastused profile name
222  QString previous = mainObject->X->getLastUsed();
223  previous = util_getBaseName(previous);
224  message = "Profile loaded from "+previous;
225  }
227 }
228 
229 //================================================================================
230 // Save Profile
231 //================================================================================
233 {
234  QString message("Profile save abandoned");
235  if (mainObject->X->save_profile()) {
236  // get lastused profile name
237  QString previous = mainObject->X->getLastUsed();
238  previous = util_getBaseName(previous);
239  message = "Profile saved to "+previous;
240  }
242 }
243 
244 
245 //================================================================================
246 // Reset Profile
247 //================================================================================
249 {
250  QString message("Reset to loaded profile.");
251  QString previous = mainObject->X->getLastUsed();
252  mainObject->X->load_last_profile(previous);
254 }
255 
256 //================================================================================
257 // Default Profile
258 //================================================================================
260 {
261  QString message("Reset to FGx default profile.");
262  //QString previous = mainObject->X->getLastUsed();
265 }
266 
267 //================================================================================
268 // Help
269 //================================================================================
271 {
272  QUrl url("http://wiki.flightgear.org");
273  QDesktopServices::openUrl( url );
274 }
275 
277 {
278  QUrl url("http://forum.flightgear.org/");
279  QDesktopServices::openUrl( url );
280 }
281 
283 {
284  QUrl url("http://forum.flightgear.org/viewforum.php?f=65");
285  QDesktopServices::openUrl( url );
286 }
288  QDesktopServices::openUrl( QUrl(APP_WWW) );
289 }
291  QDesktopServices::openUrl( QUrl(APP_ISSUES) );
292 }
294  QDesktopServices::openUrl( QUrl(APP_PROJECT) );
295 }
296 
297 /**
298  * @todo Create the help text
299  */
301  QString s = "Version : ";
302  s.append(APP_VERSION);
303  QMessageBox::about(this, "About FGx", s);
304 }
305 
307  QMessageBox::aboutQt(this, "About Qt");
308 }
MainObject * mainObject
Definition: menuwidget.h:38
QMenu * applicationMenu
Definition: menuwidget.h:47
QAction * debugmodeAction
Definition: menuwidget.h:61
void on_menu_url_forums()
Definition: menuwidget.cpp:276
void on_show_log_window()
Definition: menuwidget.cpp:178
QMenu * profileMenu
Definition: menuwidget.h:49
MenuWidget(MainObject *mob, QWidget *parent=0)
Definition: menuwidget.cpp:27
void on_menu_save_profile()
Definition: menuwidget.cpp:232
The XSettings is an extended QSetttings, but also includes most to the FGx configuration.
Definition: xsettings.h:15
QAction * defaultProfileAction
Definition: menuwidget.h:66
QAction * saveProfileAction
Definition: menuwidget.h:64
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
void on_menu_reset_profile()
Definition: menuwidget.cpp:248
bool load_profile()
Opens Profile Dialog for loading a .ini File.
QAction * propsWindowAction
Definition: menuwidget.h:59
QAction * urlActionFGxUserHelp
Definition: menuwidget.h:70
QAction * debugWindowAction
Definition: menuwidget.h:58
static int runningOs()
What OS is running.
Definition: mainobject.cpp:367
ViewLogsWidget * viewLogsWidget
Definition: mainobject.h:93
void on_menu_fgx_github()
Definition: menuwidget.cpp:293
void on_menu_fgx_version_info()
Definition: menuwidget.cpp:300
QAction * resetProfileAction
Definition: menuwidget.h:65
void on_menu_qt_version_info()
Definition: menuwidget.cpp:306
void on_show_debug_window()
Definition: menuwidget.cpp:188
void on_menu_url_wiki()
Definition: menuwidget.cpp:270
HeaderWidget * headerWidget
QHBoxLayout * menuLayout
Definition: menuwidget.h:41
void on_menu_fgx_user_forums()
Definition: menuwidget.cpp:282
XSettings * settings
Definition: menuwidget.h:35
bool debug_mode
Definition: menuwidget.h:36
PropsTreeWidget * propertiesBrowser
Definition: mainobject.h:94
QMenu * helpFGxGroup
Definition: menuwidget.h:53
void on_quit()
Definition: mainobject.cpp:329
FgxDebugWidget * fgxDebugWidget
Definition: mainobject.h:95
QAction * loadProfileAction
Definition: menuwidget.h:63
void on_show_props_window()
Definition: menuwidget.cpp:198
void set_debug_mode(bool)
Definition: mainobject.cpp:353
void load_last_profile(QString profile)
Opens last used profile.
QMenuBar * mainMenu
Definition: menuwidget.h:44
QAction * logWindowAction
Definition: menuwidget.h:57
void read_default_ini()
Read Values from ini.
void on_menu_default_profile()
Definition: menuwidget.cpp:259
QString getLastUsed()
XSettingsModel * X
Definition: mainobject.h:86
void on_menu_load_profile()
Definition: menuwidget.cpp:217
QMenu * modeMenu
Definition: menuwidget.h:48
QMenu * helpFlightGearGroup
Definition: menuwidget.h:52
bool save_profile()
Opens Profile Dialog for loading a .ini File.
LauncherWindow * launcherWindow
Definition: mainobject.h:89
QMenu * helpMenu
Definition: menuwidget.h:51
void on_menu_fgx_www()
Definition: menuwidget.cpp:287
QAction * urlActionForums
Definition: menuwidget.h:69
void on_menu_debug_mode()
Definition: menuwidget.cpp:208
void on_menu_fgx_issues()
Definition: menuwidget.cpp:290
void showMessage(QString message, int timeout)
QAction * urlActionWiki
Definition: menuwidget.h:68
void on_menu_quit()
Definition: menuwidget.cpp:171
QAction * quitAction
Definition: menuwidget.h:56