From 03425bcb5b8b419d5a69ec6efd8b8c95c4aeff19 Mon Sep 17 00:00:00 2001 From: Simon De Backer Date: Tue, 21 Jul 2020 20:29:05 +0200 Subject: [PATCH 1/4] Add gui resize depending on screen size Init of request https://qelectrotech.org/bugtracker/view.php?id=195 This is a start will have to be adjusted further. --- sources/configdialog.cpp | 9 +++++- sources/machine_info.cpp | 68 ++++++++++++++++++++++++++++++++++++++++ sources/machine_info.h | 28 +++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 sources/machine_info.cpp create mode 100644 sources/machine_info.h diff --git a/sources/configdialog.cpp b/sources/configdialog.cpp index 12f6f0ea9..e5963dd7e 100644 --- a/sources/configdialog.cpp +++ b/sources/configdialog.cpp @@ -19,15 +19,22 @@ #include "configpages.h" #include "qetapp.h" +#include "machine_info.h" + /** Constructeur @param parent QWidget parent */ ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) { + Machine_info *mymachineinfo= new Machine_info(this); // liste des pages pages_list = new QListWidget(); pages_list -> setViewMode(QListView::IconMode); - pages_list -> setIconSize(QSize(128, 128)); + if(mymachineinfo->get_max_screen_height()<1000){ + pages_list -> setIconSize(QSize(64, 64)); + } else { + pages_list -> setIconSize(QSize(128, 128)); + } pages_list -> setMovement(QListView::Static); pages_list -> setMinimumWidth(168); pages_list -> setMaximumWidth(168); diff --git a/sources/machine_info.cpp b/sources/machine_info.cpp new file mode 100644 index 000000000..0bb9ba2a1 --- /dev/null +++ b/sources/machine_info.cpp @@ -0,0 +1,68 @@ +#include "machine_info.h" +#include +#include + +/** + @brief Machine_info::Machine_info + @param parent +*/ +Machine_info::Machine_info(QObject *parent) : QObject(parent) +{ + init_get_Screen_info(); +} + +/** + @brief Machine_info::init_get_Screen_info + Finds the largest screen and saves the values +*/ +void Machine_info::init_get_Screen_info() +{ + const auto screens = qApp->screens(); + for (int ii = 0; ii < screens.count(); ++ii) + { + if( + Max_screen_width + < + screens[ii]->geometry().width() + * + screens[ii]->devicePixelRatio() + ) + { + Max_screen_width = + screens[ii]->geometry().width() + * + screens[ii]->devicePixelRatio(); + } + if( + Max_screen_height + < + screens[ii]->geometry().height() + * + screens[ii]->devicePixelRatio() + ) + { + Max_screen_height = + screens[ii]->geometry().height() + * + screens[ii]->devicePixelRatio(); + } + } +} + +/** + @brief Machine_info::get_max_screen_width + @return max screen width + */ +int32_t Machine_info::get_max_screen_width() +{ + return Max_screen_width; +} + +/** + @brief Machine_info::get_max_screen_height + @return max screen height +*/ +int32_t Machine_info::get_max_screen_height() +{ + return Max_screen_height; +} diff --git a/sources/machine_info.h b/sources/machine_info.h new file mode 100644 index 000000000..4bcfaff13 --- /dev/null +++ b/sources/machine_info.h @@ -0,0 +1,28 @@ +#ifndef MACHINE_INFO_H +#define MACHINE_INFO_H + +#include + +/** + @brief The Machine_info class + This class hold information from your PC. +*/ +class Machine_info : public QObject +{ + Q_OBJECT +public: + explicit Machine_info(QObject *parent = nullptr); + int32_t get_max_screen_width(); + int32_t get_max_screen_height(); + +signals: + +private: + void init_get_Screen_info(); + int32_t Max_screen_width; + int32_t Max_screen_height; + + +}; + +#endif // MACHINE_INFO_H From 6b95c6bf6f34d4553a526de365c83129e1737876 Mon Sep 17 00:00:00 2001 From: Simon De Backer Date: Wed, 22 Jul 2020 21:03:54 +0200 Subject: [PATCH 2/4] Add QScrollArea to configdialog and resize to max_screen --- sources/configdialog.cpp | 55 +++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/sources/configdialog.cpp b/sources/configdialog.cpp index e5963dd7e..7cd3e56be 100644 --- a/sources/configdialog.cpp +++ b/sources/configdialog.cpp @@ -15,6 +15,7 @@ You should have received a copy of the GNU General Public License along with QElectroTech. If not, see . */ +#include #include "configdialog.h" #include "configpages.h" #include "qetapp.h" @@ -27,6 +28,11 @@ */ ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) { Machine_info *mymachineinfo= new Machine_info(this); + //ScrollArea for low screens + QScrollArea *scroll = new QScrollArea(this); + scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + // liste des pages pages_list = new QListWidget(); pages_list -> setViewMode(QListView::IconMode); @@ -36,32 +42,47 @@ ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) { pages_list -> setIconSize(QSize(128, 128)); } pages_list -> setMovement(QListView::Static); - pages_list -> setMinimumWidth(168); - pages_list -> setMaximumWidth(168); - pages_list -> setSpacing(16); - pages_list -> setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - + pages_list -> setMinimumWidth(168); + pages_list -> setMaximumWidth(168); + pages_list -> setSpacing(16); + pages_list -> setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + // pages pages_widget = new QStackedWidget(); - // boutons - buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); - + buttons = new QDialogButtonBox( + QDialogButtonBox::Ok + |QDialogButtonBox::Cancel); + + + QWidget *viewport = new QWidget(this); + scroll->setWidget(viewport); + scroll->setWidgetResizable(true); + // layouts - QHBoxLayout *hlayout1 = new QHBoxLayout(); + QHBoxLayout *hlayout1 = new QHBoxLayout(viewport); + // add needed widgets to layout "hlayout1" hlayout1 -> addWidget(pages_list); hlayout1 -> addWidget(pages_widget); - - QVBoxLayout *vlayout1 = new QVBoxLayout(); - vlayout1 -> addLayout(hlayout1); - vlayout1 -> addWidget(buttons); - setLayout(vlayout1); - + + //add hlayout1 to widget + viewport->setLayout(hlayout1); + + // Add a layout for QDialog + QVBoxLayout *dialog_layout = new QVBoxLayout(this); + dialog_layout->addWidget(scroll); // add scroll to the QDialog's layout + dialog_layout -> addWidget(buttons); + setLayout(dialog_layout); + // connexion signaux / slots connect(buttons, SIGNAL(accepted()), this, SLOT(applyConf())); connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); - connect(pages_list, SIGNAL(currentRowChanged(int)), pages_widget, SLOT(setCurrentIndex(int))); - + connect(pages_list, SIGNAL(currentRowChanged(int)), + pages_widget, SLOT(setCurrentIndex(int))); + + resize(mymachineinfo->get_max_screen_width(), + mymachineinfo->get_max_screen_height()); + #ifdef Q_OS_MACOS if (parent) { setWindowFlags(Qt::Sheet); From 698db4e5c022171a8a6a66d87c9f286c61143924 Mon Sep 17 00:00:00 2001 From: Simon De Backer Date: Wed, 22 Jul 2020 21:16:38 +0200 Subject: [PATCH 3/4] Add Copyright to machine_info class --- sources/machine_info.cpp | 17 +++++++++++++++++ sources/machine_info.h | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/sources/machine_info.cpp b/sources/machine_info.cpp index 0bb9ba2a1..14de9d386 100644 --- a/sources/machine_info.cpp +++ b/sources/machine_info.cpp @@ -1,3 +1,20 @@ +/* + Copyright 2006-2020 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech 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 2 of the License, or + (at your option) any later version. + + QElectroTech 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 QElectroTech. If not, see . +*/ #include "machine_info.h" #include #include diff --git a/sources/machine_info.h b/sources/machine_info.h index 4bcfaff13..30d9c18fb 100644 --- a/sources/machine_info.h +++ b/sources/machine_info.h @@ -1,3 +1,20 @@ +/* + Copyright 2006-2020 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech 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 2 of the License, or + (at your option) any later version. + + QElectroTech 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 QElectroTech. If not, see . +*/ #ifndef MACHINE_INFO_H #define MACHINE_INFO_H From 7420eeb60d301870d321929a0f5fb6ecba84f1ce Mon Sep 17 00:00:00 2001 From: Simon De Backer Date: Thu, 23 Jul 2020 16:49:31 +0200 Subject: [PATCH 4/4] Mod name to clarify value is int --- sources/configdialog.cpp | 6 +++--- sources/machine_info.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sources/configdialog.cpp b/sources/configdialog.cpp index 7cd3e56be..d890548ba 100644 --- a/sources/configdialog.cpp +++ b/sources/configdialog.cpp @@ -36,7 +36,7 @@ ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) { // liste des pages pages_list = new QListWidget(); pages_list -> setViewMode(QListView::IconMode); - if(mymachineinfo->get_max_screen_height()<1000){ + if(mymachineinfo->i_max_screen_height()<1000){ pages_list -> setIconSize(QSize(64, 64)); } else { pages_list -> setIconSize(QSize(128, 128)); @@ -80,8 +80,8 @@ ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) { connect(pages_list, SIGNAL(currentRowChanged(int)), pages_widget, SLOT(setCurrentIndex(int))); - resize(mymachineinfo->get_max_screen_width(), - mymachineinfo->get_max_screen_height()); + resize(mymachineinfo->i_max_screen_width(), + mymachineinfo->i_max_screen_height()); #ifdef Q_OS_MACOS if (parent) { diff --git a/sources/machine_info.h b/sources/machine_info.h index 30d9c18fb..86c89183a 100644 --- a/sources/machine_info.h +++ b/sources/machine_info.h @@ -29,8 +29,8 @@ class Machine_info : public QObject Q_OBJECT public: explicit Machine_info(QObject *parent = nullptr); - int32_t get_max_screen_width(); - int32_t get_max_screen_height(); + int32_t i_max_screen_width(); + int32_t i_max_screen_height(); signals: