refs #273, own settings component (GUI)

This commit is contained in:
Klaus Basan
2014-06-27 01:48:38 +02:00
parent 9afe8b0f8b
commit 33315dc0e1
5 changed files with 219 additions and 11 deletions

View File

@@ -527,7 +527,7 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="BlackGui::CSettingsFsxComponent" name="comp_SettingsSimulatorFsx">
<widget class="BlackGui::CSettingsSimulatorComponent" name="comp_SettingsSimulator">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
@@ -743,9 +743,9 @@
<header>blackgui/serverview.h</header>
</customwidget>
<customwidget>
<class>BlackGui::CSettingsFsxComponent</class>
<class>BlackGui::CSettingsSimulatorComponent</class>
<extends>QFrame</extends>
<header>blackgui/settingsfsxcomponent.h</header>
<header>blackgui/settingssimulatorcomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<height>150</height>
</rect>
</property>
<property name="windowTitle">
@@ -40,35 +40,35 @@
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="lbl_SettingsFsxAddress">
<property name="text">
<string>FSX address</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QLineEdit" name="le_SettingsFsxAddress">
<property name="text">
<string>127.0.0.1</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="lbl_SettingsFsxPort">
<property name="text">
<string>FSX port</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="le_SettingsFsxPort">
<property name="text">
<string>500</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="hl_SettingsSimconnectCfgButtons">
<item>
<widget class="QPushButton" name="pb_SettingsFsxOpenSimconnectCfg">
@@ -100,14 +100,14 @@
</item>
</layout>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="lbl_SettingsFsxExistsSimconncetCfg">
<property name="text">
<string>&quot;simconnect.cfg&quot; exists?</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QWidget" name="wi_SettingsFsxExistsSimconncetCfg" native="true">
<layout class="QHBoxLayout" name="hl_SettingsFsxExistsSimconncetCfg">
<property name="spacing">
@@ -142,6 +142,13 @@
</layout>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="lbl_HeaderFsxSimConnect">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:10pt; font-weight:600;&quot;&gt;FSX simconnect config files&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>

View File

@@ -0,0 +1,74 @@
#include "settingssimulatorcomponent.h"
#include "ui_settingssimulatorcomponent.h"
#include "blackcore/context_settings.h"
#include "blacksim/simulatorinfolist.h"
#include "blacksim/setsimulator.h"
#include "blackmisc/settingutilities.h"
#include <QComboBox>
using namespace BlackMisc;
using namespace BlackMisc::Settings;
using namespace BlackSim;
using namespace BlackSim::Settings;
using namespace BlackCore;
namespace BlackGui
{
CSettingsSimulatorComponent::CSettingsSimulatorComponent(QWidget *parent) :
QFrame(parent), CRuntimeBasedComponent(nullptr, false),
ui(new Ui::CSettingsSimulatorComponent)
{
ui->setupUi(this);
bool connected = this->connect(this->ui->cb_SimulatorDriver, SIGNAL(currentIndexChanged(int)), this, SLOT(driverHasChanged(int)));
Q_ASSERT(connected);
Q_UNUSED(connected);
}
CSettingsSimulatorComponent::~CSettingsSimulatorComponent()
{
delete ui;
}
void CSettingsSimulatorComponent::runtimeHasBeenSet()
{
Q_ASSERT(this->getIContextSimulator());
if (this->getIContextSimulator())
{
QStringList drivers = this->getIContextSimulator()->getAvailableSimulatorPlugins().toStringList(true);
this->ui->cb_SimulatorDriver->addItems(drivers);
bool fsxDriver =
this->getIContextSimulator()->getAvailableSimulatorPlugins().supportsSimulator(CSimulatorInfo::FSX());
this->ui->comp_SettingsSimulatorFsx->setVisible(fsxDriver);
}
}
void CSettingsSimulatorComponent::driverHasChanged(int index)
{
Q_ASSERT(this->getIContextSimulator());
Q_ASSERT(this->getIContextSettings());
if (!this->getIContextSimulator() || !this->getIContextSettings()) return;
CSimulatorInfoList simDrivers = this->getIContextSimulator()->getAvailableSimulatorPlugins();
if (simDrivers.isEmpty())
{
this->sendStatusMessage(CStatusMessage::getErrorMessage("No drivers available", CStatusMessage::TypeSimulator));
return;
}
if (simDrivers.size() <= index)
{
this->sendStatusMessage(CStatusMessage::getErrorMessage("Wrong driver index", CStatusMessage::TypeSimulator));
return;
}
// update
CSimulatorInfo currentDriver = simDrivers[index];
const QString path = CSettingUtilities::appendPaths(IContextSettings::PathSimulatorSettings(), CSettingsSimulator::ValueSelectedDriver());
this->sendStatusMessages(
this->getIContextSettings()->value(path, CSettingUtilities::CmdUpdate(), currentDriver.toCVariant())
);
}
} // namespace

View File

@@ -0,0 +1,38 @@
#ifndef BLACKGUI_SETTINGSSIMULATORCOMPONENT_H
#define BLACKGUI_SETTINGSSIMULATORCOMPONENT_H
#include "runtimebasedcomponent.h"
#include <QFrame>
namespace Ui { class CSettingsSimulatorComponent; }
namespace BlackGui
{
/*!
* All simulator settings component (GUI)
*/
class CSettingsSimulatorComponent : public QFrame, public CRuntimeBasedComponent
{
Q_OBJECT
public:
//! Constructor
explicit CSettingsSimulatorComponent(QWidget *parent = nullptr);
//! Destructor
~CSettingsSimulatorComponent();
protected:
//! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet()
virtual void runtimeHasBeenSet() override;
private slots:
//! Driver changed
void driverHasChanged(int index);
private:
Ui::CSettingsSimulatorComponent *ui; //!< UI
};
} // namespace
#endif // guard

View File

@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSettingsSimulatorComponent</class>
<widget class="QFrame" name="CSettingsSimulatorComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>424</width>
<height>318</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="vl_SettingsSimulatorComponent">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="ql_SettingsSimulatorsAll">
<item row="0" column="0">
<layout class="QFormLayout" name="fl_SettingsSimulatorsAll">
<item row="1" column="0">
<widget class="QLabel" name="lbl_SimulatorDriver">
<property name="text">
<string>Driver</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cb_SimulatorDriver"/>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="lbl_SettingsSimulatorAllHeader">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:10pt; font-weight:600;&quot;&gt;All simulators&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gl_SettingsSimulatorsSpecific">
<item row="0" column="0">
<widget class="BlackGui::CSettingsFsxComponent" name="comp_SettingsSimulatorFsx">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::CSettingsFsxComponent</class>
<extends>QFrame</extends>
<header>blackgui/settingsfsxcomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>