From ae5de9f8a6e109551e362d6d0b813400b33341fc Mon Sep 17 00:00:00 2001 From: Thomas Renne <thomas.renne@u-psud.fr> Date: Mon, 26 Jul 2021 13:24:37 +0200 Subject: [PATCH 1/2] Create switch button widget --- src/libpappsomsppresources.qrc | 4 + src/pappsomspp/widget/CMakeLists.txt | 1 + .../switchbuttonwidget/switchbuttonwidget.cpp | 74 ++++++++++++++++ .../switchbuttonwidget/switchbuttonwidget.h | 56 ++++++++++++ src/resources/icons/switch_off.svg | 86 +++++++++++++++++++ src/resources/icons/switch_on.svg | 86 +++++++++++++++++++ 6 files changed, 307 insertions(+) create mode 100644 src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.cpp create mode 100644 src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.h create mode 100644 src/resources/icons/switch_off.svg create mode 100644 src/resources/icons/switch_on.svg diff --git a/src/libpappsomsppresources.qrc b/src/libpappsomsppresources.qrc index e4ee7b471..f9c3838e5 100644 --- a/src/libpappsomsppresources.qrc +++ b/src/libpappsomsppresources.qrc @@ -3,4 +3,8 @@ <qresource> <file>resources/PSI-MOD.obo</file> </qresource> +<qresource prefix="/icons"> + <file>resources/icons/switch_off.svg</file> + <file>resources/icons/switch_on.svg</file> +</qresource> </RCC> diff --git a/src/pappsomspp/widget/CMakeLists.txt b/src/pappsomspp/widget/CMakeLists.txt index 41509da37..839edac92 100644 --- a/src/pappsomspp/widget/CMakeLists.txt +++ b/src/pappsomspp/widget/CMakeLists.txt @@ -47,6 +47,7 @@ SET(PAPPSOWIDGET_CPP_FILES plotwidget/ticxicchrommassspeccolormapplotwidget.cpp plotwidget/ticxicchromdriftspeccolormapplotwidget.cpp plotwidget/driftspecmassspeccolormapplotwidget.cpp + switchbuttonwidget/switchbuttonwidget.cpp ) diff --git a/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.cpp b/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.cpp new file mode 100644 index 000000000..0c64d1811 --- /dev/null +++ b/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.cpp @@ -0,0 +1,74 @@ +/** + * \file pappsomspp/widget/switchbuttonwidget.cpp + * \date 26/07/2021 + * \author Thomas Renne + * \brief widget to transform a push button to a switch button + */ + + +/******************************************************************************* + * Copyright (c) 2021 Thomas Renne <thomas.renne@e.email>. + * + * This file is part of the PAPPSOms++ library. + * + * PAPPSOms++ 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. + * + * PAPPSOms++ 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 PAPPSOms++. If not, see <http://www.gnu.org/licenses/>. + * + * Contributors: + * Thomas Renne <thomas.renne@e.email> - initial API and + *implementation + ******************************************************************************/ + +#include "switchbuttonwidget.h" + +pappso::SwitchWidget::SwitchWidget(QWidget *parent) + : QPushButton(parent) +{ + setSwitchValue(false); + setIconSize(QSize(40, 16)); + setFlat(true); + setMaximumSize(40,16); + + connect(this, &SwitchWidget::clicked, this, &SwitchWidget::updateSwitchValue); +} + +pappso::SwitchWidget::~SwitchWidget() +{ +} + +void +pappso::SwitchWidget::setSwitchValue(bool switch_value) +{ + m_switchButtonValue = switch_value; + if(m_switchButtonValue) + { + setIcon(QIcon(":/icons/resources/icons/switch_on.svg")); + } + else + { + setIcon(QIcon(":/icons/resources/icons/switch_off.svg")); + } +} + + +bool +pappso::SwitchWidget::getSwitchValue() +{ + return m_switchButtonValue; +} + +void +pappso::SwitchWidget::updateSwitchValue() +{ + setSwitchValue(!m_switchButtonValue); +} diff --git a/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.h b/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.h new file mode 100644 index 000000000..e21493892 --- /dev/null +++ b/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.h @@ -0,0 +1,56 @@ +/** + * \file pappsomspp/widget/switchbuttonwidget.h + * \date 26/07/2021 + * \author Thomas Renne + * \brief widget to transform a push button to a switch button + */ + + +/******************************************************************************* + * Copyright (c) 2021 Thomas Renne <thomas.renne@e.email>. + * + * This file is part of the PAPPSOms++ library. + * + * PAPPSOms++ 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. + * + * PAPPSOms++ 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 PAPPSOms++. If not, see <http://www.gnu.org/licenses/>. + * + * Contributors: + * Thomas Renne <thomas.renne@e.email> - initial API and + *implementation + ******************************************************************************/ + +#pragma once + +#include <QPushButton> +#include "../../exportinmportconfig.h" + +namespace pappso +{ + +class PMSPP_LIB_DECL SwitchWidget : public QPushButton +{ + Q_OBJECT + public: + SwitchWidget(QWidget *parent = 0); + ~SwitchWidget(); + + bool getSwitchValue(); + void setSwitchValue(bool switch_value); + + public slots: + void updateSwitchValue(); + + private: + bool m_switchButtonValue = false; +}; +} // namespace pappso diff --git a/src/resources/icons/switch_off.svg b/src/resources/icons/switch_off.svg new file mode 100644 index 000000000..b2ff2b062 --- /dev/null +++ b/src/resources/icons/switch_off.svg @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="96.726051mm" + height="37.47493mm" + viewBox="0 0 96.726048 37.474929" + version="1.1" + id="svg8" + inkscape:version="0.92.4 (5da689c313, 2019-01-14)" + sodipodi:docname="switch_off.svg"> + <defs + id="defs2" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="1.979899" + inkscape:cx="135.83869" + inkscape:cy="74.171173" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="false" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + inkscape:window-width="1866" + inkscape:window-height="1025" + inkscape:window-x="54" + inkscape:window-y="27" + inkscape:window-maximized="1" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Calque 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(-64.437469,-49.718491)"> + <rect + style="opacity:1;fill:#cf5b5b;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.10289172;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal" + id="rect815" + width="96.726051" + height="37.47493" + x="64.437469" + y="49.718491" + ry="18.737465" /> + <circle + style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.57715964;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal" + id="path825" + cx="81.602684" + cy="68.455956" + r="14.250884" /> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332" + x="106.26515" + y="76.160912" + id="text820"><tspan + sodipodi:role="line" + id="tspan818" + x="106.26515" + y="76.160912" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:21.16666603px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332">OFF</tspan></text> + </g> +</svg> diff --git a/src/resources/icons/switch_on.svg b/src/resources/icons/switch_on.svg new file mode 100644 index 000000000..a7ba5c718 --- /dev/null +++ b/src/resources/icons/switch_on.svg @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="96.726051mm" + height="37.47493mm" + viewBox="0 0 96.726048 37.474929" + version="1.1" + id="svg8" + inkscape:version="0.92.4 (5da689c313, 2019-01-14)" + sodipodi:docname="switch_on.svg"> + <defs + id="defs2" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="1.979899" + inkscape:cx="145.94022" + inkscape:cy="86.293003" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="false" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + inkscape:window-width="1866" + inkscape:window-height="1025" + inkscape:window-x="54" + inkscape:window-y="27" + inkscape:window-maximized="1" /> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Calque 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(-64.437469,-49.718491)"> + <rect + style="opacity:1;fill:#5ba9e5;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.10289172;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal" + id="rect815" + width="96.726051" + height="37.47493" + x="64.437469" + y="49.718491" + ry="18.737465" /> + <circle + style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.57715964;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal" + id="path825" + cx="142.67377" + cy="68.455956" + r="14.250884" /> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332" + x="81.943626" + y="76.160912" + id="text820"><tspan + sodipodi:role="line" + id="tspan818" + x="81.943626" + y="76.160912" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:21.16666603px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332">ON</tspan></text> + </g> +</svg> -- GitLab From ce9d3f054c193ee9252d1691308a27e369dc3346 Mon Sep 17 00:00:00 2001 From: Thomas Renne <thomas.renne@u-psud.fr> Date: Tue, 27 Jul 2021 15:02:54 +0200 Subject: [PATCH 2/2] finish switch widget --- src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.cpp | 2 +- src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.cpp b/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.cpp index 0c64d1811..b586d34e6 100644 --- a/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.cpp +++ b/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.cpp @@ -1,5 +1,5 @@ /** - * \file pappsomspp/widget/switchbuttonwidget.cpp + * \file pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.cpp * \date 26/07/2021 * \author Thomas Renne * \brief widget to transform a push button to a switch button diff --git a/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.h b/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.h index e21493892..521dfc19d 100644 --- a/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.h +++ b/src/pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.h @@ -1,5 +1,5 @@ /** - * \file pappsomspp/widget/switchbuttonwidget.h + * \file pappsomspp/widget/switchbuttonwidget/switchbuttonwidget.h * \date 26/07/2021 * \author Thomas Renne * \brief widget to transform a push button to a switch button -- GitLab