1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "popMsgBox.h"
- #include "ui_popMsgBox.h"
- #include "CAppInfo.h"
- #include <QDesktopWidget>
- popMsgBox::popMsgBox(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::popMsgBox)
- {
- ui->setupUi(this);
- setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
- setAttribute(Qt::WA_TranslucentBackground); //小部件应该具有半透明的背景
- setStyleSheet(g_appInfoPtr->m_sQssStr);
- }
- popMsgBox::~popMsgBox()
- {
- delete ui;
- }
- void popMsgBox::setMsg(QString sMsg, QString sTitle)
- {
- ui->label_pmb_content->setText(sMsg);
- ui->label_pmb_title->setText(sTitle);
- }
- void popMsgBox::initUI(POP_MSG_BTN btn)
- {
- int nCW = g_appInfoPtr->m_fRate*340;
- QDesktopWidget *dekwiget = QApplication::desktop();
- setGeometry((dekwiget->width() - nCW)/2, (dekwiget->height() - g_appInfoPtr->m_fRate*203)/2, nCW, g_appInfoPtr->m_fRate*203);
- ui->widget_pmb_bg->setGeometry(0, 0 , nCW, g_appInfoPtr->m_fRate*203);
- ui->label_pmb_icon->setGeometry(g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*30,
- g_appInfoPtr->m_fRate*40, g_appInfoPtr->m_fRate*40);
- ui->label_pmb_title->adjustSize();
- ui->label_pmb_title->setGeometry(ui->label_pmb_icon->x() + ui->label_pmb_icon->width() + g_appInfoPtr->m_fRate*16, g_appInfoPtr->m_fRate*30,
- ui->label_pmb_title->width(), ui->label_pmb_title->height());
- ui->label_pmb_content->setGeometry(ui->label_pmb_icon->x() + ui->label_pmb_icon->width() + g_appInfoPtr->m_fRate*16,
- ui->label_pmb_title->y() + ui->label_pmb_title->height() + g_appInfoPtr->m_fRate*8,
- 224, 80);
- if (btn == POP_MSG_BTN::pmb_yes)
- {
- ui->btn_no->setVisible(false);
- }
- ui->btn_yes->setGeometry(ui->widget_pmb_bg->width() - g_appInfoPtr->m_fRate*(20 + 80),
- ui->widget_pmb_bg->height() - g_appInfoPtr->m_fRate*(20 + 30),
- g_appInfoPtr->m_fRate*80, g_appInfoPtr->m_fRate*30);
- ui->btn_no->setGeometry(ui->btn_yes->x() - g_appInfoPtr->m_fRate*15 - ui->btn_yes->width(),
- ui->btn_yes->y(), ui->btn_yes->width(), ui->btn_yes->height());
- }
- int popMsg(QString sMsg, QString sTitle, QWidget *parent, POP_MSG_BTN btn, int nStayTime)
- {
- popMsgBox msgDlg(parent);
- msgDlg.setMsg(sMsg, sTitle);
- msgDlg.initUI(btn);
- if (nStayTime != 0)
- {
- msgDlg.setStayTime(nStayTime);
- }
- return msgDlg.exec();
- }
- void popMsgBox::setStayTime(int nStayTime)
- {
- m_timePtr = std::make_shared<QTimer>();
- m_timePtr->setInterval(nStayTime * 1000);
- connect(m_timePtr.get(), &QTimer::timeout, this, [&](){
- accept();
- });
- m_timePtr->start();
- }
- void popMsgBox::on_btn_yes_clicked()
- {
- if (m_timePtr != nullptr)
- {
- m_timePtr->stop();
- }
- accept();
- }
- void popMsgBox::on_btn_no_clicked()
- {
- if (m_timePtr != nullptr)
- {
- m_timePtr->stop();
- }
- reject();
- }
|