You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
whellvalue/src/tpMain/qpulpewidget.cpp

134 lines
3.1 KiB
C++

#include "qpulpewidget.h"
#include "QApplication.h"
#include "qdesktopwidget.h"
#include "QLabel"
#include "QBoxLayout"
#pragma execution_character_set("utf-8")
/*弹窗提示UI类*/
QPulpewidget::QPulpewidget(QWidget *parent)
: QWidget(parent), lay(NULL), label(NULL)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
setWindowModality(Qt::NonModal);
m_nDesktopHeight = (QApplication::desktop()->height() / 2 + 10);
m_dTransparent = 1.0;
label = new QLabel;
QFont font;
font.setBold(true);
font.setPixelSize(12);
label->setFont(font);
lay = new QHBoxLayout;
lay->addWidget(label);
this->setLayout(lay);
m_showTimer = new QTimer(this);
m_StayTimer = new QTimer(this);
m_pcloseTimer = new QTimer(this);
connect(m_showTimer, SIGNAL(timeout()), this, SLOT(onMove()));
connect(m_pcloseTimer, SIGNAL(timeout()), this, SLOT(onClose()));
connect(m_StayTimer, SIGNAL(timeout()), this, SLOT(onStay()));
//connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
}
QPulpewidget::~QPulpewidget()
{
if (m_StayTimer)
{
delete m_StayTimer;
m_StayTimer = NULL;
}
if (m_showTimer){
delete m_showTimer;
m_showTimer = NULL;
}
if (m_pcloseTimer){
delete m_pcloseTimer;
m_pcloseTimer = NULL;
}
if (lay){
delete lay;
lay = NULL;
}
if (label){
delete label;
label = NULL;
}
}
Q_SLOT void QPulpewidget::onMove()
{
m_nDesktopHeight--;
move(m_point.x(), m_nDesktopHeight);
if (m_nDesktopHeight <= m_point.y())
{
m_showTimer->stop();
m_StayTimer->start(100);
}
}
Q_SLOT void QPulpewidget::onClose()
{
m_dTransparent -= 0.1;
if (m_dTransparent <= 0.0)
{
m_pcloseTimer->stop();
close();
emit(finished());
emit(finishshow(this));
}
else
{
setWindowOpacity(m_dTransparent);
}
}
Q_SLOT void QPulpewidget::onStay()
{
m_StayTimer->stop();
m_pcloseTimer->start(100);
}
void QPulpewidget::showmessage(QString str)
{
// QRect rect = QApplication::desktop()->availableGeometry();
// int rectwid = rect.width();
// int recthid = rect.height();
// int wid = width();
// int hid = height();
//m_point.setX((rect.width() - width())/2);
//m_point.setY((rect.height() - height())/2+100);
//move(m_point.x(), m_point.y()/2);
m_showTimer->start(2);
label->setStyleSheet("background-color:rgb(0,210,200,10);font:20px;color:blue");
label->setText(str);
show();
}
void QPulpewidget::setParent(QWidget * pare/*=NULL*/)
{
if (pare)
{
m_nDesktopHeight = pare->height()/2;
QRect m_rect = pare->geometry();
//m_point.setX(m_rect.x() + ((pare->width() / 2.0 - pare->width() / 5.0/*-width()*/)));
// m_point.setX(m_rect.x() + ((pare->width() / 2.0 - pare->width() / 10.0/*-width()*/)));
// m_point.setY(m_rect.y()+((pare->height()-height())/2)+ 50);
m_point.setX(m_rect.x() + (m_rect.width() - width()) / 2.0);
m_point.setY(m_rect.y() + (m_rect.height() - height()) / 2.0);
move(m_point.x(), m_point.y() / 2);
m_dTransparent = 1.0;
}
else
{
m_nDesktopHeight = (QApplication::desktop()->height() / 2 + 10);
int m_XPos = QApplication::desktop()->width() / 2;
m_point.setX(m_XPos);
m_point.setY(m_nDesktopHeight);
move(m_point.x(), m_point.y() -10);
m_dTransparent = 1.0;
}
}