123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #include "warning.h"
- #include "ui_warning.h"
- #include <QPainter>
- #include <QLayout>
- #include <QDebug>
- #include "spdlog/spdlog.h"
- #include "oneshadow.h"
- Warning::Warning(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::Warning)
- {
- ui->setupUi(this);
-
- this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
- this->setAttribute(Qt::WA_TranslucentBackground);
-
- ui->label_Warn->setWordWrap(true);
-
-
- ui->label_Warn->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
-
- ui->label_warnIcon->setStyleSheet(R"(border-image: url(:/ESM-8C_ICON/Tip/Tips2x.png);)");
-
- this->layout()->setMargin(SHADOW_W);
- m_shadow = new OneShadow(QSize(width() - SHADOW_W*2, height() - SHADOW_W*2),SHADOW_W);
- connect(ui->pBtn_close,SIGNAL(clicked()),this,SLOT(close()));
- connect(ui->pBtn_cancel,SIGNAL(clicked()),this,SLOT(close()));
- connect(ui->pBtn_ok,SIGNAL(clicked()),this,SLOT(do_ok()));
- }
- Warning::~Warning()
- {
- delete ui;
- }
- void Warning::setText(const QString &text)
- {
-
- ui->label_Warn->setText(text);
-
- resetLabelSize();
- moveWarnICON();
- }
- void Warning::setTextWithOneButton(const QString &text)
- {
- ui->pBtn_cancel->hide();
-
- ui->label_Warn->setText(text);
-
- resetLabelSize();
- moveWarnICON();
- }
- void Warning::paintEvent(QPaintEvent *event)
- {
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
-
- painter.drawImage(QPoint(0,0),m_shadow->image());
- }
- void Warning::do_ok()
- {
- emit signal_ok();
- m_isOk = true;
- this->close();
- }
- void Warning::resetLabelSize()
- {
- int TextCount = ui->label_Warn->text().count();
- int width = TextCount * 18;
- if(width > 306)
- {
- width = 306;
- }
-
- ui->label_Warn->resize(width, ui->label_Warn->height());
-
- int widgetWidth = this->width();
- int x = (widgetWidth - width) / 2;
-
-
- ui->label_Warn->move(x, ui->label_Warn->y());
- }
- void Warning::moveWarnICON()
- {
- int x = ui->label_Warn->x() - ui->label_warnIcon->width() - 12;
- int y = ui->label_Warn->y() + ui->label_Warn->height() / 2 - ui->label_warnIcon->height() / 2;
- ui->label_warnIcon->move(x,y);
- }
|