From ea344c281c5c4a853fb71357d1062a601c43f96f Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Sun, 10 Sep 2023 16:00:27 +0200 Subject: [PATCH] larger buttons --- src/Button.cpp | 10 ++++++++++ src/Button.h | 7 +++++++ src/MainWindow.cpp | 34 ++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 src/Button.cpp create mode 100644 src/Button.h diff --git a/src/Button.cpp b/src/Button.cpp new file mode 100644 index 0000000..fceb3ce --- /dev/null +++ b/src/Button.cpp @@ -0,0 +1,10 @@ +#include "Button.h" + +Button::Button(QString text) : QPushButton(text) { + setMinimumHeight(30); + setIconSize(QSize(25, 25)); +} + +Button::Button(QString text, QString icon) : Button(text) { + setIcon(QIcon(icon)); +} diff --git a/src/Button.h b/src/Button.h new file mode 100644 index 0000000..b9f6f0c --- /dev/null +++ b/src/Button.h @@ -0,0 +1,7 @@ +#include + +class Button : public QPushButton { +public: + explicit Button(QString text); + explicit Button(QString text, QString icon); +}; \ No newline at end of file diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index d50f359..18dbd3b 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -10,10 +10,10 @@ #include #include #include -#include #include #include #include "Pendulum.h" +#include "Button.h" MainWindow::MainWindow() { simulation = new Simulation; @@ -130,13 +130,13 @@ QWidget * MainWindow::buildAddUI() { auto segmentButtonGrid = new QHBoxLayout; lyt->addLayout(segmentButtonGrid); - auto resetMassesBtn = new QPushButton("Reset"); - auto normalizeLengthsBtn = new QPushButton("Normalize"); - auto resetLengthsBtn = new QPushButton("Reset"); + auto resetMassesBtn = new Button("Reset", ":/icons/refresh.svg"); + auto normalizeLengthsBtn = new Button("Normalize", ":/icons/compress.svg"); + auto resetLengthsBtn = new Button("Reset", ":/icons/refresh.svg"); - resetMassesBtn->setIcon(QIcon(":/icons/refresh.svg")); - normalizeLengthsBtn->setIcon(QIcon(":/icons/compress.svg")); - resetLengthsBtn->setIcon(QIcon(":/icons/refresh.svg")); + resetMassesBtn->setToolTip("Reset masses to 1kg"); + normalizeLengthsBtn->setToolTip("Normalize lengths to fit screen"); + resetLengthsBtn->setToolTip("Reset lengths to 1m"); connect(resetMassesBtn, &QPushButton::clicked, this, &MainWindow::resetMasses); connect(normalizeLengthsBtn, &QPushButton::clicked, this, &MainWindow::normalizeLengths); @@ -170,7 +170,7 @@ QWidget * MainWindow::buildAddUI() { auto colorLyt = new QHBoxLayout; lyt->addLayout(colorLyt); - auto colorBtn = new QPushButton("Select color"); + auto colorBtn = new Button("Select color"); auto colorLabel = new QLabel; colorLabel->setStyleSheet("background-color: white"); @@ -281,10 +281,11 @@ QWidget * MainWindow::buildAddUI() { auto btnLyt = new QHBoxLayout; lyt->addLayout(btnLyt); - auto addBtn = new QPushButton("Add"); - auto removeBtn = new QPushButton("Remove all"); - addBtn->setIcon(QIcon(":/icons/add.svg")); - removeBtn->setIcon(QIcon(":/icons/delete.svg")); + auto addBtn = new Button("Add", ":/icons/add.svg"); + auto removeBtn = new Button("Remove all", ":/icons/delete.svg"); + + addBtn->setToolTip("Add configured pendulum"); + removeBtn->setToolTip("Remove all pendula"); connect(addBtn, &QPushButton::clicked, this, &MainWindow::add); connect(removeBtn, &QPushButton::clicked, this, &MainWindow::remove); @@ -334,10 +335,11 @@ QWidget * MainWindow::buildSimulationUI() { auto btnLyt = new QHBoxLayout; lyt->addLayout(btnLyt); - auto reset = new QPushButton("Reset"); - auto togglePlay = new QPushButton("Resume"); - reset->setIcon(QIcon(":/icons/refresh.svg")); - togglePlay->setIcon(QIcon(":/icons/play.svg")); + auto reset = new Button("Reset", ":/icons/refresh.svg"); + auto togglePlay = new Button("Resume", ":/icons/play.svg"); + + reset->setToolTip("Reset Simulation controls"); + togglePlay->setToolTip("Pause/Resume Simulation"); connect(reset, &QPushButton::clicked, this, &MainWindow::resetSimulationControl); connect(togglePlay, &QPushButton::clicked, this, &MainWindow::toggleSimulation);