Skip to content

Commit

Permalink
Merge pull request #5 from viktorgino/master
Browse files Browse the repository at this point in the history
Separate RadioInterface class and the QML layout
  • Loading branch information
AlbrechtL authored Feb 15, 2017
2 parents 028d4f4 + c5b37b8 commit d27cf36
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 230 deletions.
6 changes: 3 additions & 3 deletions gui/QML/InfoPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Item {

TextStandart {
id: showVersionText
text: "welle.io version"
text: cppGUI.licenses.version
Layout.alignment: Qt.AlignLeft
objectName: "showVersionText"
}
Expand All @@ -40,7 +40,7 @@ Item {

TextStandart {
id: showGraphLicense
text: "showGraphLicense"
text: cppGUI.licenses.graphLicense
Layout.alignment: Qt.AlignLeft
objectName: "showGraphLicense"
wrapMode: Text.Wrap
Expand All @@ -50,7 +50,7 @@ Item {

TextStandart {
id: showLicenseText
text: "showLicenseText"
text: cppGUI.licenses.license
Layout.alignment: Qt.AlignLeft
objectName: "showLicenseText"
wrapMode: Text.WrapAnywhere
Expand Down
17 changes: 11 additions & 6 deletions gui/QML/SettingsPage.qml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import QtQuick 2.2
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import Qt.labs.settings 1.0

// Import custom styles
import "style"

Item {
id: settingsPage

property alias showChannelState : enableExpertMode.checked
property alias enableFullScreenState : enableFullScreen.checked
property alias enableExpertModeState : enableExpertMode.checked

Settings {
property alias enableFullScreenState : settingsPage.enableFullScreenState
property alias enableExpertModeState : settingsPage.enableExpertModeState
}

Connections{
target: cppGUI
onChannelScanStopped:{
Expand Down Expand Up @@ -66,7 +71,7 @@ Item {
onClicked: {
startChannelScanButton.enabled = false
stopChannelScanButton.enabled = true
mainWindow.startChannelScanClicked()
cppGUI.startChannelScanClick()
}
}

Expand All @@ -79,7 +84,7 @@ Item {
onClicked: {
startChannelScanButton.enabled = true
stopChannelScanButton.enabled = false
mainWindow.stopChannelScanClicked()
cppGUI.stopChannelScanClick()
}
}
}
Expand Down Expand Up @@ -126,14 +131,14 @@ Item {
name: "Enable AGC"
objectName: "enableAGC"
checked: true
onChanged: mainWindow.inputEnableAGCChanged(valueChecked)
onChanged: cppGUI.inputEnableAGCChanged(valueChecked)
}

TouchSlider {
id: gain
enabled: !enableAGC.checked
name: "Manual gain"
onValueChanged: mainWindow.inputGainChanged(valueGain)
onValueChanged: cppGUI.inputGainChanged(valueGain)
}
}
}
Expand Down Expand Up @@ -175,7 +180,7 @@ Item {
TouchButton {
id: exitAppButton
text: "Exit welle.io"
onClicked: mainWindow.exitApplicationClicked()
onClicked: cppGUI.terminateProcess()
Layout.preferredWidth: parent.width
Layout.alignment: Qt.AlignBottom
}
Expand Down
23 changes: 10 additions & 13 deletions gui/QML/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,22 @@ import QtQuick 2.2
import QtQuick.Controls 2.0
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import Qt.labs.settings 1.0

// Import custom styles
import "style"

ApplicationWindow {
signal stationClicked(string statio, string channel)
signal startChannelScanClicked
signal stopChannelScanClicked
signal exitApplicationClicked
signal exitSettingsClicked
signal inputEnableAGCChanged(bool valueChecked)
signal inputGainChanged(double valueGain)

id: mainWindow
visible: true
width: Units.dp(700)
height: Units.dp(500)
visibility: settingsPageLoader.settingsPage.enableFullScreenState ? "FullScreen" : "Windowed"

Settings {
property alias width : mainWindow.width
property alias height : mainWindow.height
}
Loader {
id: settingsPageLoader
anchors.topMargin: Units.dp(10)
Expand Down Expand Up @@ -116,7 +113,7 @@ ApplicationWindow {
onClicked: {
if(stackView.depth > 1) {
stackView.pop();
exitSettingsClicked();
cppGUI.saveSettings();
}
else
{
Expand Down Expand Up @@ -197,12 +194,12 @@ ApplicationWindow {
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
model: stationModel
model: cppGUI.stationModel
anchors.fill: parent
delegate: StationDelegate {
stationNameText: stationName
channelNameText: channelName
onClicked: mainWindow.stationClicked(stationName, channelName)
stationNameText: modelData.stationName
channelNameText: modelData.channelName
onClicked: cppGUI.channelClick(modelData.stationName, modelData.channelName)
}
}
}
Expand Down
154 changes: 40 additions & 114 deletions gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ RadioInterface::RadioInterface(QSettings *Si,
int16_t latency = dabSettings -> value("latency", 1). toInt(); // latency is used to allow different settings for different situations wrt the output buffering
threshold = dabSettings -> value("threshold", 3). toInt(); // threshold is used in the phaseReference class as threshold for checking the validity of the correlation result
autoStart = dabSettings -> value("autoStart", 0). toInt() != 0;
int WindowHeight = dabSettings -> value("WindowHeight", 0). toInt();
int WindowWidth = dabSettings -> value("WindowWidth", 0). toInt();
bool isFullscreen = dabSettings -> value("StartInFullScreen", false). toBool();
bool isExpertMode = dabSettings-> value("EnableExpertMode", false). toBool();

// Read channels from the settings
dabSettings -> beginGroup("channels");
Expand All @@ -88,77 +84,11 @@ RadioInterface::RadioInterface(QSettings *Si,
dabSettings -> endGroup();
stationList. sort();

// Create new QML application, set some requried options and load the QML file
engine = new QQmlApplicationEngine;
QQmlContext *rootContext = engine -> rootContext();
rootContext -> setContextProperty("cppGUI", this);
rootContext -> setContextProperty("stationModel", QVariant::fromValue(stationList.getList()));
engine->load(QUrl("qrc:/QML/main.qml"));
QObject *rootObject = engine -> rootObjects().first();

// Set some properties
if(WindowHeight != 0) rootObject -> setProperty ("height", WindowHeight);
if(WindowWidth != 0)rootObject -> setProperty ("width", WindowWidth);
p_stationModel = QVariant::fromValue(stationList.getList());
emit stationModelChanged();

// Add image provider for the MOT slide show
MOTImage = new MOTImageProvider;
engine->addImageProvider(QLatin1String("motslideshow"), MOTImage);


// Restore the full screen property
QObject *enableFullScreenObject = rootObject -> findChild<QObject*> ("enableFullScreen");
if(enableFullScreenObject != NULL)
enableFullScreenObject -> setProperty("checked", isFullscreen);

// Restore expert mode
QObject *expertModeObject = rootObject -> findChild<QObject*> ("enableExpertMode");
if(expertModeObject != NULL)
expertModeObject -> setProperty("checked", isExpertMode);

// Set application version
QObject *showVersionTextObject = rootObject -> findChild<QObject*> ("showVersionText");
if(showVersionTextObject != NULL)
{
QString InfoText;
InfoText += "welle.io version: " + QString(CURRENT_VERSION) + "\n";
InfoText += "Build on: " + QString(__TIMESTAMP__);
showVersionTextObject -> setProperty("text", InfoText);
}

// Set graph license
QObject *showGraphLicenseObject = rootObject -> findChild<QObject*> ("showGraphLicense");
if(showGraphLicenseObject != NULL)
{
// Read license
QFile File(":/QML/images/NOTICE.txt");
File.open(QFile::ReadOnly);
QByteArray FileContent = File.readAll();

// Set license content
showGraphLicenseObject -> setProperty("text", FileContent);
}

// Set license
QObject *showLicenseTextObject = rootObject -> findChild<QObject*> ("showLicenseText");
if(showLicenseTextObject != NULL)
{
// Read license
QFile File(":/license");
File.open(QFile::ReadOnly);
QByteArray FileContent = File.readAll();

// Set license content
showLicenseTextObject -> setProperty("text", FileContent);
}

// Connect signals
connect(rootObject, SIGNAL(stationClicked(QString, QString)), this, SLOT(channelClick(QString, QString)));
connect(rootObject, SIGNAL(startChannelScanClicked(void)), this, SLOT(startChannelScanClick(void)));
connect(rootObject, SIGNAL(stopChannelScanClicked(void)), this, SLOT(stopChannelScanClick(void)));
connect(rootObject, SIGNAL(exitApplicationClicked(void)), this, SLOT(TerminateProcess(void)));
connect(rootObject, SIGNAL(exitSettingsClicked(void)), this, SLOT(saveSettings(void)));
connect(rootObject, SIGNAL(inputEnableAGCChanged(bool)), this, SLOT(inputEnableAGCChange(bool)));
connect(rootObject, SIGNAL(inputGainChanged(double)), this, SLOT(inputGainChange(double)));

// the name of the device is passed on from the main program
if(!setDevice(input_device))
Expand Down Expand Up @@ -214,6 +144,34 @@ RadioInterface::~RadioInterface()
{
fprintf(stderr, "deleting radioInterface\n");
}
/**
* \brief returns the licenses for all the relative libraries plus application version information
*/
const QVariantMap RadioInterface::licenses(){
QVariantMap ret;
// Set application version
QString InfoText;
InfoText += "welle.io version: " + QString(CURRENT_VERSION) + "\n";
InfoText += "Build on: " + QString(__TIMESTAMP__);
ret.insert("version", InfoText);

// Read graph license
QFile File(":/QML/images/NOTICE.txt");
File.open(QFile::ReadOnly);
QByteArray FileContent = File.readAll();

// Set graph license content
ret.insert("graphLicense", FileContent);

// Read license
QFile File2(":/license");
File2.open(QFile::ReadOnly);
QByteArray FileContent2 = File2.readAll();

// Set license content
ret.insert("license", FileContent2);
return ret;
}

/**
* \brief At the end, we might save some GUI values
Expand All @@ -240,37 +198,6 @@ void RadioInterface::dumpControlState(QSettings *s)
s -> setValue("channel/" + QString::number(i),
stationList. getStationAt(i - 1));
dabSettings -> endGroup();

// Read settings from GUI
// Take the root object
QObject *rootObject = engine -> rootObjects(). first();

// Save the windows properties
int WindowWidth = rootObject -> property("width"). toInt();
s -> setValue("WindowWidth", WindowWidth);
int WindowHeight = rootObject -> property("height"). toInt();
s -> setValue("WindowHeight", WindowHeight);
// Access the full screen mode switch
QObject *enableFullScreenObject =
rootObject -> findChild<QObject*>("enableFullScreen");
if(enableFullScreenObject != NULL)
{
bool isFullScreen =
enableFullScreenObject -> property("checked").toBool();
// Save the setting
s -> setValue("StartInFullScreen", isFullScreen);
}

// Access to the enable expert mode switch
QObject *expertModeObject =
rootObject -> findChild<QObject*> ("enableExpertMode");
if(expertModeObject != NULL)
{
bool isExpertMode =
expertModeObject->property("checked"). toBool();
// Save the setting
s -> setValue("EnableExpertMode", isExpertMode);
}
}
//
/// the values for the different Modes:
Expand Down Expand Up @@ -728,11 +655,11 @@ void RadioInterface::stopChannelScanClick(void)
scanMode = false;

emit currentStation("No Station");

// Sort stations
stationList. sort();
QQmlContext *rootContext = engine -> rootContext();
rootContext -> setContextProperty("stationModel",
QVariant::fromValue(stationList. getList()));
p_stationModel = QVariant::fromValue(stationList.getList());
emit stationModelChanged();
}

QString RadioInterface::nextChannel(QString currentChannel)
Expand Down Expand Up @@ -772,9 +699,9 @@ void RadioInterface::setSignalPresent(bool isSignal)
emit currentStation("No Station");
// Sort stations
stationList. sort();
QQmlContext *rootContext = engine -> rootContext();
rootContext -> setContextProperty("stationModel",
QVariant::fromValue(stationList. getList()));

p_stationModel = QVariant::fromValue(stationList.getList());
emit stationModelChanged();
return;
}
set_channelSelect(currentChannel);
Expand Down Expand Up @@ -802,9 +729,8 @@ void RadioInterface::end_of_waiting_for_stations(void)
emit currentStation("No Station");
// Sort stations
stationList. sort();
QQmlContext *rootContext = engine -> rootContext();
rootContext -> setContextProperty("stationModel",
QVariant::fromValue(stationList. getList()));
p_stationModel = QVariant::fromValue(stationList.getList());
emit stationModelChanged();
return;
}
set_channelSelect(currentChannel);
Expand Down Expand Up @@ -863,11 +789,11 @@ void RadioInterface::setStart(void)
}

/**
* \brief TerminateProcess
* \brief terminateProcess
* Pretty critical, since there are many threads involved
* A clean termination is what is needed, regardless of the GUI
*/
void RadioInterface::TerminateProcess(void)
void RadioInterface::terminateProcess(void)
{
running = false;
inputDevice -> stopReader(); // might be concurrent
Expand Down
Loading

0 comments on commit d27cf36

Please sign in to comment.