Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
mpmapwidget.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // mpmapwidget.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 <QDesktopServices>
10 
11 #include <QtCore/QString>
12 #include <QtCore/QVariant>
13 
14 
15 #include <QCloseEvent>
16 #include <QVBoxLayout>
17 #include <QToolBar>
18 #include <QLabel>
19 #include <QComboBox>
20 
21 #include "mpmap/mpmapwidget.h"
24 
25 
27  QWidget(parent)
28 {
29 
30  mainObject = mOb;
31 
32  setProperty("settings_namespace", QVariant("mpmap_window"));
34 
35  setWindowTitle(tr("Multi Player Map"));
36  setWindowIcon(QIcon(":/icon/mpmap"));
37 
38  QVBoxLayout *mainLayout = new QVBoxLayout(this);
39  mainLayout->setContentsMargins(0,0,0,0);
40  mainLayout->setSpacing(0);
41 
42 
43  //** Toolbar
44  QToolBar *toolbar = new QToolBar();
45  mainLayout->addWidget(toolbar, 1);
46 
47  //** Select server
48  QLabel *lblSelectServer = new QLabel(tr("Select Server:"));
49  toolbar->addWidget(lblSelectServer);
50 
51  comboServer = new QComboBox();
52  toolbar->addWidget(comboServer);
53 
54  //**get callsign
55 
56  //**add callsign to url
57  comboServer->addItem("MpMap-01", QVariant("http://mpmap01.flightgear.org/"));
58  comboServer->addItem("MpMap-02", QVariant("http://mpmap02.flightgear.org/"));
59  comboServer->setCurrentIndex(0);
60  connect(comboServer, SIGNAL(currentIndexChanged(int)), this, SLOT(on_combo_server()) );
61 
62  //=============================================================
63  //== Cache
64  //qDebug() << QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
65 
66  networkDiskCache = new QNetworkDiskCache(this);
67  networkDiskCache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
68 
69  networkCookieJar = new QNetworkCookieJar(this);
70 
71  //== Browser
72  webView = new QWebView(this);
73  mainLayout->addWidget(webView, 100);
74  webView->page()->networkAccessManager()->setCache(networkDiskCache);
75  webView->page()->networkAccessManager()->setCookieJar(networkCookieJar);
76  connect(webView, SIGNAL(loadStarted()), this, SLOT(start_progress()));
77  connect(webView, SIGNAL(loadProgress(int)), this, SLOT(update_progress(int)));
78  connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(end_progress(bool)));
79 
80  //*** Status Bar
81  statusBar = new QStatusBar(this);
82  mainLayout->addWidget(statusBar);
83  statusBar->showMessage("Idle");
84 
85  //** Progress Bar
86  progressBar = new QProgressBar();
87  progressBar->setVisible(false);
88  statusBar->addPermanentWidget(progressBar);
89 
90  //*** Initialise
92 }
93 
94 //=============================================================
95 //== Progress Slots
97  progressBar->setVisible(true);
98 }
99 
101  progressBar->setValue(v);
102 }
104  Q_UNUSED(Ok);
105  progressBar->setVisible(false);
106  statusBar->showMessage( webView->url().toString() );
107 }
108 
109 
111  QUrl server_url( comboServer->itemData(comboServer->currentIndex()).toString() );
112  server_url.addQueryItem("follow", mainObject->settings->value("callsign").toString() );
113  webView->load( server_url );
114  statusBar->showMessage(QString("Loading: ").append( server_url.toString()) );
115 }
116 
117 //** Overide the closeEvent
118 void MpMapWidget::closeEvent(QCloseEvent *event)
119  {
121  Q_UNUSED(event);
122  }
123 
QProgressBar * progressBar
Definition: mpmapwidget.h:40
void update_progress(int progress)
void on_combo_server()
void end_progress(bool Ok)
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
QStatusBar * statusBar
Definition: mpmapwidget.h:41
void saveWindow(QWidget *widget)
Saves a window's size and position.
Definition: xsettings.cpp:90
void start_progress()
Definition: mpmapwidget.cpp:96
void restoreWindow(QWidget *widget)
Restores a size window position.
Definition: xsettings.cpp:101
MainObject * mainObject
Definition: mpmapwidget.h:35
QNetworkCookieJar * networkCookieJar
Definition: mpmapwidget.h:47
QComboBox * comboServer
Definition: mpmapwidget.h:42
QWebView * webView
Definition: mpmapwidget.h:45
MpMapWidget(MainObject *mOb, QWidget *parent=0)
Definition: mpmapwidget.cpp:26
QNetworkDiskCache * networkDiskCache
Definition: mpmapwidget.h:46
XSettings * settings
Definition: mainobject.h:85
void closeEvent(QCloseEvent *event)