1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

GCS- Handle loading of the configuration file. Stylesheets files

are now loaded from mainwindow instead of main.
This commit is contained in:
PT_Dreamer 2012-08-09 22:33:13 +01:00
parent dae15702ed
commit b0e6566114
4 changed files with 56 additions and 61 deletions

View File

@ -229,30 +229,6 @@ static void overrideSettings(QSettings &settings, int argc, char **argv){
settings.sync();
}
static inline void loadStyleSheet() {
/* Let's use QFile and point to a resource... */
#ifdef Q_OS_MAC
QFile data(QCoreApplication::applicationDirPath()+"/macos.qss");
#elif defined(Q_OS_LINUX)
QFile data(QCoreApplication::applicationDirPath()+"/linux.qss");
#else
QFile data(QCoreApplication::applicationDirPath()+"/windows.qss");
#endif
QString style;
/* ...to open the file */
if(data.open(QFile::ReadOnly)) {
/* QTextStream... */
QTextStream styleIn(&data);
/* ...read file to a string. */
style = styleIn.readAll();
data.close();
/* We'll use qApp macro to get the QApplication pointer
* and set the style sheet application wide. */
qApp->setStyleSheet(style);
qDebug()<<"Loaded stylesheet:"<<style;
}
}
int main(int argc, char **argv)
{
#ifdef Q_OS_MAC
@ -367,7 +343,6 @@ int main(int argc, char **argv)
return sendArguments(app, pluginManager.arguments()) ? 0 : -1;
pluginManager.loadPlugins();
loadStyleSheet();
if (coreplugin->hasError()) {
displayError(msgCoreLoadFailure(coreplugin->errorString()));
return 1;

View File

@ -63,7 +63,8 @@ SOURCES += mainwindow.cpp \
workspacesettings.cpp \
uavconfiginfo.cpp \
authorsdialog.cpp \
telemetrymonitorwidget.cpp
telemetrymonitorwidget.cpp \
dialogs/importsettings.cpp
HEADERS += mainwindow.h \
tabpositionindicator.h \
fancyactionbar.h \
@ -124,12 +125,14 @@ HEADERS += mainwindow.h \
uavconfiginfo.h \
authorsdialog.h \
iconfigurableplugin.h \
telemetrymonitorwidget.h
telemetrymonitorwidget.h \
dialogs/importsettings.h
FORMS += dialogs/settingsdialog.ui \
dialogs/shortcutsettings.ui \
generalsettings.ui \
uavgadgetoptionspage.ui \
workspacesettings.ui
workspacesettings.ui \
dialogs/importsettings.ui
RESOURCES += core.qrc \
fancyactionbar.qrc
unix:!macx {

View File

@ -84,18 +84,8 @@
#include <QtGui/QToolButton>
#include <QtGui/QMessageBox>
#include <QDesktopServices>
/*
#ifdef Q_OS_UNIX
#include <signal.h>
extern "C" void handleSigInt(int sig)
{
Q_UNUSED(sig)
Core::ICore::instance()->exit();
qDebug() << "SIGINT caught. Shutting down.";
}
#endif
*/
#include "dialogs/importsettings.h"
#include <QDir>
using namespace Core;
using namespace Core::Internal;
@ -125,7 +115,6 @@ MainWindow::MainWindow() :
m_modeManager(0),
m_connectionManager(0),
m_mimeDatabase(new MimeDatabase),
// m_rightPaneWidget(0),
m_versionDialog(0),
m_authorsDialog(0),
m_activeContext(0),
@ -197,12 +186,6 @@ MainWindow::MainWindow() :
connect(m_workspaceSettings, SIGNAL(tabBarSettingsApplied(QTabWidget::TabPosition,bool)),
this, SLOT(applyTabBarSettings(QTabWidget::TabPosition,bool)));
connect(m_modeManager, SIGNAL(newModeOrder(QVector<IMode*>)), m_workspaceSettings, SLOT(newModeOrder(QVector<IMode*>)));
// setUnifiedTitleAndToolBarOnMac(true);
#ifdef Q_OS_UNIX
//signal(SIGINT, handleSigInt);
#endif
statusBar()->setProperty("p_styled", true);
setAcceptDrops(true);
foreach (QString engine, qxtLog->allLoggerEngines())
@ -254,9 +237,6 @@ MainWindow::~MainWindow()
delete m_coreImpl;
m_coreImpl = 0;
// delete m_rightPaneWidget;
// m_rightPaneWidget = 0;
delete m_modeManager;
m_modeManager = 0;
delete m_mimeDatabase;
@ -288,19 +268,24 @@ void MainWindow::extensionsInitialized()
{
QSettings* qs = m_settings;
QSettings defaultSettings(":/core/OpenPilotGCS.xml", XmlConfig::XmlSettingsFormat);
// QSettings defaultSettings(":/core/OpenPilotGCS.ini", QSettings::IniFormat);
QSettings * settings;
if ( ! qs->allKeys().count() ){
QMessageBox msgBox;
msgBox.setText(tr("No configuration file could be found."));
msgBox.setInformativeText(tr("The default configuration will be loaded."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
qDebug() << "Load default config from resource /core/OpenPilotGCS.xml";
qs = &defaultSettings;
importSettings * dialog=new importSettings(this);
QDir directory(QCoreApplication::applicationDirPath());
directory.cdUp();
directory.cd("share");
directory.cd("openpilotgcs");
directory.cd("default_configurations");
dialog->loadFiles(directory.absolutePath());
dialog->exec();
settings=new QSettings(dialog->choosenConfig(), XmlConfig::XmlSettingsFormat);
qs=settings;
qDebug() << "Load default config from resource "<<dialog->choosenConfig();
delete dialog;
}
qs->beginGroup("General");
loadStyleSheet(qs->value("StyleSheet","none").toString());
qs->endGroup();
m_uavGadgetInstanceManager = new UAVGadgetInstanceManager(this);
m_uavGadgetInstanceManager->readSettings(qs);
@ -314,6 +299,37 @@ void MainWindow::extensionsInitialized()
emit m_coreImpl->coreOpened();
}
void MainWindow::loadStyleSheet(QString name) {
/* Let's use QFile and point to a resource... */
QDir directory(QCoreApplication::applicationDirPath());
directory.cdUp();
directory.cd("share");
directory.cd("openpilotgcs");
directory.cd("stylesheets");
#ifdef Q_OS_MAC
QFile data(directory.absolutePath()+"/"+name+"_macos.qss");
#elif defined(Q_OS_LINUX)
QFile data(directory.absolutePath()+"/"+name+"_linux.qss");
#else
QFile data(directory.absolutePath()+"/"+name+"_windows.qss");
#endif
QString style;
/* ...to open the file */
if(data.open(QFile::ReadOnly)) {
/* QTextStream... */
QTextStream styleIn(&data);
/* ...read file to a string. */
style = styleIn.readAll();
data.close();
/* We'll use qApp macro to get the QApplication pointer
* and set the style sheet application wide. */
qApp->setStyleSheet(style);
qDebug()<<"Loaded stylesheet:"<<style;
}
else
qDebug()<<"Failed to openstylesheet file"<<directory.absolutePath();
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if ( !m_generalSettings->saveSettingsOnExit() ){

View File

@ -170,6 +170,7 @@ private:
void registerDefaultContainers();
void registerDefaultActions();
void createWorkspaces(QSettings* qs, bool diffOnly = false);
void loadStyleSheet(QString name);
CoreImpl *m_coreImpl;
UniqueIDManager *m_uniqueIDManager;