Browse Source

Add some basic graphical user interface.

master
Andrius Štikonas 4 years ago
parent
commit
fb36cfaca2
6 changed files with 217 additions and 1 deletions
  1. +7
    -1
      CMakeLists.txt
  2. +62
    -0
      dialog.cpp
  3. +46
    -0
      dialog.h
  4. +62
    -0
      dialog.ui
  5. +35
    -0
      main-gui.cpp
  6. +5
    -0
      s20-gui.pro

+ 7
- 1
CMakeLists.txt View File

@@ -4,6 +4,12 @@ project(s20)
add_definitions(-std=gnu++11)
set(CMAKE_AUTOMOC TRUE)

find_package(Qt5 REQUIRED Core Network)
find_package(Qt5 REQUIRED Core Gui Widgets Network)

add_executable(s20 main.cpp socket.cpp consolereader.cpp server.cpp)
target_link_libraries(s20 Qt5::Core Qt5::Network)

include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
qt5_wrap_ui(UIS_HDRS dialog.ui)
add_executable(s20-gui main-gui.cpp dialog.cpp socket.cpp server.cpp ${UIS_HDRS})
target_link_libraries(s20-gui Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network)

+ 62
- 0
dialog.cpp View File

@@ -0,0 +1,62 @@
/*************************************************************************
* Copyright (C) 2015 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/

#include <QComboBox>

#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(std::vector<Socket*> *sockets_vector, QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
sockets = sockets_vector;
ui->setupUi(this);

}

Dialog::~Dialog()
{
delete ui;
}

void Dialog::updateUi()
{
for ( unsigned int i = 0; i < (*sockets).size(); ++i)
{
ui->toggleButton->setText((*sockets)[i]->powered ? QStringLiteral("Turn off") : QStringLiteral("Turn on"));
ui->comboBox->setItemText(i, (*sockets)[i]->socketName);
}
}

void Dialog::discovered()
{
ui->comboBox->clear();
for ( std::vector<Socket*>::const_iterator i = sockets->begin() ; i != sockets->end(); ++i )
{
connect(*i, &Socket::stateChanged, this, &Dialog::updateUi);
connect(ui->toggleButton, &QPushButton::clicked, this, &Dialog::togglePower);
ui->comboBox->addItem("Socket");
}
updateUi();
}

void Dialog::togglePower()
{
(*sockets)[ui->comboBox->currentIndex()]->toggle();
}

+ 46
- 0
dialog.h View File

@@ -0,0 +1,46 @@
/*************************************************************************
* Copyright (C) 2015 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/

#include "socket.h"

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
Q_OBJECT

public:
explicit Dialog(std::vector<Socket*> *sockets_vector, QWidget *parent = 0);
~Dialog();

void discovered();
void updateUi();

private:
Ui::Dialog *ui;
std::vector<Socket*> *sockets;
void togglePower();
};

#endif // DIALOG_H

+ 62
- 0
dialog.ui View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>269</height>
</rect>
</property>
<property name="windowTitle">
<string>S20 socket manager</string>
</property>
<widget class="QPushButton" name="toggleButton">
<property name="geometry">
<rect>
<x>300</x>
<y>200</y>
<width>84</width>
<height>33</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>30</x>
<y>10</y>
<width>351</width>
<height>33</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Sockets:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<property name="minimumSize">
<size>
<width>250</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

+ 35
- 0
main-gui.cpp View File

@@ -0,0 +1,35 @@
/*************************************************************************
* Copyright (C) 2015 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/

#include <QApplication>
#include <vector>

#include "dialog.h"
#include "server.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

std::vector<Socket*> *sockets = new std::vector<Socket*>;
Server *server = new Server(sockets);
Dialog *w = new Dialog(sockets);
QObject::connect(server, &Server::discovered, w, &Dialog::discovered);
w->show();

return app.exec();
}

+ 5
- 0
s20-gui.pro View File

@@ -0,0 +1,5 @@
SOURCES = dialog.cpp main-gui.cpp server.cpp socket.cpp
HEADERS = dialog.h server.h socket.h
FORMS = dialog.ui
QT += network widgets gui
CONFIG += c++11

Loading…
Cancel
Save