diff --git a/Components/ErrorDisplayer/error.cpp b/Components/ErrorDisplayer/error.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c1fa6e3d5844c54873707a915bcd276c448c65d9 --- /dev/null +++ b/Components/ErrorDisplayer/error.cpp @@ -0,0 +1,35 @@ +#include "error.h" +#include <QDebug> + +Error::Error(QWidget* parent, QString _title, QString _description) : QWidget(parent) { + + layout.setSpacing(0); + layout.setMargin(0); + + this->setStyleSheet("QWidget {background-color: rgba(221, 74, 55, 0.5); color: black; margin: 0px; padding: 0px;} QLabel {padding: 10px; border-radius: 0px}"); + + title.setText(_title); + title.setStyleSheet("QLabel {font-weight: bold;}"); + layout.addWidget(&title, 0, 0); + + description.setText(_description); + description.setStyleSheet("QLabel {padding-top:0px}"); + layout.addWidget(&description, 1, 0); + + setLayout(&layout); + adjustSize(); +} + +void Error::mouseReleaseEvent(QMouseEvent *e) { + if (e->button() & Qt::LeftButton) { + this->deleteLater(); + } +} + +void Error::paintEvent(QPaintEvent* event) { + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); + QWidget::paintEvent(event); +} diff --git a/Components/ErrorDisplayer/error.h b/Components/ErrorDisplayer/error.h new file mode 100644 index 0000000000000000000000000000000000000000..ce30aa8b90c9649b1d77f416ba7cd061b2d90a50 --- /dev/null +++ b/Components/ErrorDisplayer/error.h @@ -0,0 +1,31 @@ +#ifndef ERROR_H +#define ERROR_H + +#include <QWidget> +#include <QtWidgets> +#include <QLabel> +#include <QString> +#include <QGridLayout> +#include <QTime> +#include "Core/modulemessage.h" +#include "Core/modulemessagesbroker.h" +#include "Core/skywardhubcore.h" + +class Error : public QWidget { + Q_OBJECT + + public: + Error(QWidget* parent, QString title, QString description); + + protected: + void mouseReleaseEvent(QMouseEvent*) override; + void paintEvent(QPaintEvent* event); + + private: + QLabel title; + QLabel description; + QGridLayout layout; + +}; + +#endif // ERROR_H diff --git a/Components/ErrorDisplayer/errordisplayer.cpp b/Components/ErrorDisplayer/errordisplayer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..740f78fd1027d4eb8f2a4afb601f208738af5081 --- /dev/null +++ b/Components/ErrorDisplayer/errordisplayer.cpp @@ -0,0 +1,31 @@ +#include "errordisplayer.h" +#include <QDebug> + +ErrorDisplayer::ErrorDisplayer(QWidget* _parent) : QWidget(_parent) { + + parent = _parent; + + createError("window title", "window description"); + createError("window title", "window description"); + +} + +void ErrorDisplayer::createError(QString title, QString description) { + Error* error = new Error(parent, title, description); + error->move(300, 300); + error->show(); +} + + + +ErrorDisplayer *ErrorDisplayerProxy::errorDisplayer = nullptr; + +void ErrorDisplayerProxy::createErrorDisplayer(QWidget* window, int window_int) { + if(ErrorDisplayerProxy::errorDisplayer == nullptr) { + ErrorDisplayerProxy::errorDisplayer = new ErrorDisplayer(window); + } +} + +ErrorDisplayer *ErrorDisplayerProxy::getErrorDisplayer(int window_int) { + return ErrorDisplayerProxy::errorDisplayer; +} diff --git a/Components/ErrorDisplayer/errordisplayer.h b/Components/ErrorDisplayer/errordisplayer.h new file mode 100644 index 0000000000000000000000000000000000000000..9dda0f19ea00ea6a3dd45406e693bc7103f3eefe --- /dev/null +++ b/Components/ErrorDisplayer/errordisplayer.h @@ -0,0 +1,39 @@ +#ifndef ERRORDISPLAYER_H +#define ERRORDISPLAYER_H + +#include <QWidget> +#include <QtWidgets> +#include <QLabel> +#include <QString> +#include <QGridLayout> +#include <QTime> +#include "Core/modulemessage.h" +#include "Core/modulemessagesbroker.h" +#include "Core/skywardhubcore.h" +#include "error.h" + +class ErrorDisplayer : public QWidget { + Q_OBJECT + + public: + ErrorDisplayer(QWidget* parent); + + public slots: + void createError(QString title, QString text); + + private: + QWidget* parent; + +}; + +class ErrorDisplayerProxy { + + public: + static void createErrorDisplayer(QWidget* window, int window_int); + static ErrorDisplayer* getErrorDisplayer(int window_int); + + private: + static ErrorDisplayer *errorDisplayer; +}; + +#endif // ERRORDISPLAYER_H diff --git a/Modules/MainWindow/window.cpp b/Modules/MainWindow/window.cpp index 8255edcd5111a88807262074a1f1661230b41857..323024bbbe997edbff9e94a09ec310b7381eae42 100644 --- a/Modules/MainWindow/window.cpp +++ b/Modules/MainWindow/window.cpp @@ -7,6 +7,9 @@ Window::Window(QWidget *parent) : QWidget(parent), ui(new Ui::Window) { ui->setupUi(this); + + ErrorDisplayerProxy::createErrorDisplayer(this, 0); + ErrorDisplayerProxy::getErrorDisplayer(0)->show(); } Window::~Window() { @@ -36,6 +39,7 @@ void Window::setCentralModule(Module *value) { connect(value->getModuleEventsHandler(), &QWidget::destroyed, this, &Window::onWidgetDestroyed); connect(value->getModuleEventsHandler(), &ModuleEventsHandler::replaceMeWith, this, &Window::onReplaceRequested); + value->toWidget()->lower(); } void Window::closeEvent(QCloseEvent *event) { @@ -54,6 +58,7 @@ void Window::onWidgetDestroyed() { } void Window::onReplaceRequested(Module *sender, Module *newModule) { - if(newModule != nullptr && sender != nullptr) + if(newModule != nullptr && sender != nullptr){ setCentralModule(newModule); + } } diff --git a/Modules/MainWindow/window.h b/Modules/MainWindow/window.h index b6f7ecd510bf164728409d7844d7cd034147f723..cd32e01a7f2cde9e1b848ce46007aa342aaebf15 100644 --- a/Modules/MainWindow/window.h +++ b/Modules/MainWindow/window.h @@ -3,6 +3,9 @@ #include <QWidget> #include <QMenu> +#include "Components/ErrorDisplayer/error.h" +#include "Components/ErrorDisplayer/errordisplayer.h" + class Module; namespace Ui { @@ -15,6 +18,7 @@ class Window : public QWidget { public: explicit Window(QWidget *parent = nullptr); ~Window(); + ErrorDisplayer* errorDisplayer; void updateModule(Module *m); diff --git a/SkywardHub.pro b/SkywardHub.pro index 6693dab3dad67d1ee384eb232698761b6df076d0..b6275d7484efdba0f2001ec20a40c6abd150db7b 100644 --- a/SkywardHub.pro +++ b/SkywardHub.pro @@ -15,6 +15,8 @@ SOURCES += \ Components/SaveConfigurationDialog/saveconfigurationdialog.cpp \ Components/SubscriptionsPanel/subscriptionspanel.cpp \ Components/ToggleButton/togglebutton.cpp \ + Components/ErrorDisplayer/error.cpp \ + Components/ErrorDisplayer/errordisplayer.cpp \ Core/module.cpp \ Core/moduleeventshandler.cpp \ Core/modulemessage.cpp \ @@ -69,6 +71,8 @@ HEADERS += \ Components/SaveConfigurationDialog/saveconfigurationdialog.h \ Components/SubscriptionsPanel/subscriptionspanel.h \ Components/ToggleButton/togglebutton.h \ + Components/ErrorDisplayer/error.h \ + Components/ErrorDisplayer/errordisplayer.h \ Core/module.h \ Core/moduleeventshandler.h \ Core/modulemessage.h \