From a809a96d5d8e8f262f5ae1d938075259f024c664 Mon Sep 17 00:00:00 2001 From: Valentino Orlandi Date: Wed, 5 Oct 2022 21:19:39 +0200 Subject: [PATCH] Added custom Informational Dialog --- logdoctor/modules/dialogs/dialogmsg.cpp | 89 +++++++++ logdoctor/modules/dialogs/dialogmsg.h | 32 ++++ logdoctor/modules/dialogs/dialogmsg.ui | 242 ++++++++++++++++++++++++ 3 files changed, 363 insertions(+) create mode 100644 logdoctor/modules/dialogs/dialogmsg.cpp create mode 100644 logdoctor/modules/dialogs/dialogmsg.h create mode 100644 logdoctor/modules/dialogs/dialogmsg.ui diff --git a/logdoctor/modules/dialogs/dialogmsg.cpp b/logdoctor/modules/dialogs/dialogmsg.cpp new file mode 100644 index 00000000..3f93c74a --- /dev/null +++ b/logdoctor/modules/dialogs/dialogmsg.cpp @@ -0,0 +1,89 @@ + +#include "dialogmsg.h" +#include "ui_dialogmsg.h" + +#include "modules/exceptions.h" + +#include +#include +#include + + +DialogMsg::DialogMsg(const QString& title, const QString& text, const QString& additional, const int& type, QWidget* parent ) : + QDialog(parent), + ui(new Ui::DialogMsg) +{ + ui->setupUi(this); + + // icon + switch (type) { + case 0: + // info message + this->ui->label_Icon->setPixmap( QPixmap(":/icons/icons/dialog_info.png") ); + break; + case 1: + // warning message + this->ui->label_Icon->setPixmap( QPixmap(":/icons/icons/dialog_warn.png") ); + break; + case 2: + // error message, change the icon + this->ui->label_Icon->setPixmap( QPixmap(":/icons/icons/dialog_err.png") ); + break; + default: + // shouldn't be here + throw GenericException("Unexpected dialog type: "+ type); + } + + // insert the given text + this->ui->label_Title->setText( title ); + this->ui->label_Message->setText( text ); + + // additional info, hide by default + this->ui->frame_Additional->setVisible( false ); + if ( additional.size() == 0 ) { + this->ui->button_ShowAdditional->setEnabled( false ); + this->ui->button_ShowAdditional->setVisible( false ); + } else { + this->ui->text_Additional->setText( additional ); + } + + // adjust the initial size + this->adjustSize(); +} + +DialogMsg::~DialogMsg() +{ + delete ui; +} + + +void DialogMsg::on_button_ShowAdditional_clicked() +{ + this->additional_shown = ! this->additional_shown; + // set additional info visibility + this->ui->frame_Additional->setVisible( this->additional_shown ); + // set the icon + QIcon icon; + if ( this->additional_shown ) { + icon = QIcon(":/icons/icons/up.png"); + // resize + this->initial_height = this->height(); + if ( this->additional_height > 0 ) { + this->resize( this->width(), this->additional_height ); + } else { + this->resize( this->width(), this->height()+100 ); + } + } else { + icon = QIcon(":/icons/icons/down.png"); + this->additional_height = this->height(); + this->resize( this->width(), this->initial_height ); + } + this->ui->button_ShowAdditional->setIcon( icon ); +} + + +void DialogMsg::on_button_Ok_clicked() +{ + this->done( 1 ); +} + diff --git a/logdoctor/modules/dialogs/dialogmsg.h b/logdoctor/modules/dialogs/dialogmsg.h new file mode 100644 index 00000000..825c95a0 --- /dev/null +++ b/logdoctor/modules/dialogs/dialogmsg.h @@ -0,0 +1,32 @@ +#ifndef DIALOGMSG_H +#define DIALOGMSG_H + +#include + +namespace Ui { + class DialogMsg; +} + +class DialogMsg : public QDialog +{ + Q_OBJECT + +public: + explicit DialogMsg( const QString& title, const QString& text, const QString& additional, const int& type, QWidget *parent=nullptr ); + ~DialogMsg(); + +private slots: + void on_button_ShowAdditional_clicked(); + + void on_button_Ok_clicked(); + +private: + Ui::DialogMsg *ui; + + bool additional_shown = false; + + int initial_height = 0; + int additional_height = 0; +}; + +#endif // DIALOGMSG_H diff --git a/logdoctor/modules/dialogs/dialogmsg.ui b/logdoctor/modules/dialogs/dialogmsg.ui new file mode 100644 index 00000000..3c81eadc --- /dev/null +++ b/logdoctor/modules/dialogs/dialogmsg.ui @@ -0,0 +1,242 @@ + + + DialogMsg + + + + 0 + 0 + 512 + 256 + + + + + 512 + 192 + + + + + Metropolis + 13 + + + + + :/logo/logo/logdoctor.svg:/logo/logo/logdoctor.svg + + + true + + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + + + + 64 + 64 + + + + + 64 + 64 + + + + :/icons/icons/dialog_warn.png + + + Qt::AlignCenter + + + + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + + Metropolis + 13 + + + + + + + true + + + 8 + + + + + + + + 0 + 0 + + + + + 0 + 24 + + + + + Metropolis + 13 + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 4 + + + + + + + + + + + + + + 0 + 24 + + + + + Metropolis + 11 + + + + false + + + + + + + + + + + 0 + 48 + + + + + 16777215 + 48 + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + :/icons/icons/down.png:/icons/icons/down.png + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + + 333 + 27 + + + + + + + + + 96 + 32 + + + + + 96 + 32 + + + + Ok + + + + + + + + + + + + +