2020-10-26 15:44:45 +00:00
|
|
|
|
#include "Qss.h"
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
#include <QtMath>
|
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
|
#include <QParallelAnimationGroup>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QSizePolicy>
|
|
|
|
|
#include <QDesktopWidget>
|
2020-12-06 16:00:45 +00:00
|
|
|
|
#include "windows.h"
|
|
|
|
|
#include "winuser.h"
|
2020-12-06 17:05:32 +00:00
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
|
#include <QScreen>
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
2020-10-26 15:44:45 +00:00
|
|
|
|
|
|
|
|
|
#define QSSDIALOG_SHADOW_WIDTH 12 //QFrame#dialog,QFrame#messagebox padding
|
|
|
|
|
#define QSSDIALOG_BODER_WIDTH 0
|
|
|
|
|
|
2020-11-24 02:19:29 +00:00
|
|
|
|
QssTtitleBar::QssTtitleBar(QWidget *parent ,
|
|
|
|
|
QTitleBar_Type type/* = QTitleBar_Type_Window*/)
|
|
|
|
|
: QWidget(parent),
|
|
|
|
|
m_maxOrRestore(false),
|
|
|
|
|
m_pressed(false),
|
|
|
|
|
m_type(type),
|
|
|
|
|
m_Main(nullptr)
|
2020-10-26 15:44:45 +00:00
|
|
|
|
{
|
2020-12-14 15:48:37 +00:00
|
|
|
|
setObjectName("qssTitleBar");
|
|
|
|
|
m_closeBtn = new QPushButton(this);
|
|
|
|
|
m_closeBtn->setObjectName("titlebarclosebtn");
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_closeBtn->setToolTip(QString::fromLocal8Bit(""));
|
|
|
|
|
m_closeBtn->setVisible(m_type & QTitleBar_Button_Close);
|
|
|
|
|
|
|
|
|
|
m_minBtn = new QPushButton(this);
|
2020-12-14 15:48:37 +00:00
|
|
|
|
m_minBtn->setObjectName("titlebarminbtn");
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_minBtn->setToolTip(QString::fromLocal8Bit("最大化"));
|
|
|
|
|
m_minBtn->setVisible(m_type & QTitleBar_Button_Min);
|
|
|
|
|
|
|
|
|
|
m_restoreBtn = new QPushButton(this);//
|
2020-12-14 15:48:37 +00:00
|
|
|
|
m_restoreBtn->setObjectName("titlebarrestorebtn");
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_restoreBtn->setToolTip(QString::fromLocal8Bit(""));
|
|
|
|
|
m_restoreBtn->setVisible(m_type & QTitleBar_Button_Restore);
|
|
|
|
|
|
|
|
|
|
m_maxBtn = new QPushButton(this);//normal
|
|
|
|
|
m_maxBtn->setObjectName("titlebarmaxbtn");//css
|
|
|
|
|
m_maxBtn->setToolTip(QString::fromLocal8Bit(""));
|
|
|
|
|
m_maxBtn->setVisible(m_type & QTitleBar_Button_Max);
|
|
|
|
|
|
2020-12-14 15:48:37 +00:00
|
|
|
|
m_iconBtn = new QPushButton(this);
|
|
|
|
|
m_iconBtn->setObjectName("titlebaricon");
|
2020-10-26 15:44:45 +00:00
|
|
|
|
|
2020-12-14 15:48:37 +00:00
|
|
|
|
m_titlebarTitle = new QLabel(this);
|
2020-12-14 16:11:15 +00:00
|
|
|
|
m_titlebarTitle->setObjectName("title");
|
2020-10-26 15:44:45 +00:00
|
|
|
|
QHBoxLayout* hBox = new QHBoxLayout(this);
|
2020-11-24 02:19:29 +00:00
|
|
|
|
|
2020-10-26 15:44:45 +00:00
|
|
|
|
hBox->setMargin(0);
|
|
|
|
|
hBox->addWidget(m_iconBtn);
|
2020-12-04 13:12:58 +00:00
|
|
|
|
hBox->addStretch(20);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
hBox->addWidget(m_titlebarTitle);
|
2020-12-04 13:12:58 +00:00
|
|
|
|
hBox->addStretch(19);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
hBox->addWidget(m_minBtn);
|
|
|
|
|
hBox->addWidget(m_restoreBtn);
|
2020-12-04 13:12:58 +00:00
|
|
|
|
m_restoreBtn->setVisible(m_maxOrRestore);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
hBox->addWidget(m_maxBtn);
|
|
|
|
|
hBox->addWidget(m_closeBtn);
|
|
|
|
|
|
|
|
|
|
hBox->setSpacing(0);
|
2020-12-04 13:12:58 +00:00
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
|
2020-12-04 13:12:58 +00:00
|
|
|
|
connect(m_closeBtn, SIGNAL(clicked()), parent, SLOT(close()));
|
2020-10-26 15:44:45 +00:00
|
|
|
|
connect(m_minBtn, SIGNAL(clicked()), parent, SLOT(showMinimized()));
|
2020-12-04 13:12:58 +00:00
|
|
|
|
connect(m_maxBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
|
2020-10-26 15:44:45 +00:00
|
|
|
|
connect(m_restoreBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
|
|
|
|
|
|
|
|
|
|
m_iconBtn->installEventFilter(this);//m_iconLab
|
2020-12-14 15:48:37 +00:00
|
|
|
|
installEventFilter(this);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
|
|
|
|
|
m_rcValid = QApplication::desktop()->availableGeometry();
|
2020-11-24 02:19:29 +00:00
|
|
|
|
this->setFixedHeight(37);
|
2020-12-14 16:11:15 +00:00
|
|
|
|
setWindowFlags(windowFlags()|Qt::MSWindowsFixedSizeDialogHint);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
this->setGeometry(parent->geometry().x(),parent->geometry().y(),0,0);
|
2020-11-24 02:19:29 +00:00
|
|
|
|
m_rcNormal = parentWidget()->geometry();
|
2020-12-14 15:48:37 +00:00
|
|
|
|
|
|
|
|
|
QFile file(":/qss/css/QssTitleBar.css");
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly)){
|
|
|
|
|
qDebug()<<"error bar";
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
QTextStream in(&file);
|
|
|
|
|
QString css = in.readAll();
|
|
|
|
|
this->setStyleSheet(css);
|
|
|
|
|
|
2020-10-26 15:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QssTtitleBar::~QssTtitleBar()
|
|
|
|
|
{
|
2021-04-01 16:46:23 +00:00
|
|
|
|
delete(this->m_maxBtn);
|
|
|
|
|
delete(this->m_restoreBtn);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssTtitleBar::setTitle( QString title )
|
|
|
|
|
{
|
|
|
|
|
m_titlebarTitle->setText(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssTtitleBar::setIcon( QIcon icon)
|
|
|
|
|
{
|
|
|
|
|
m_iconBtn->setIcon(icon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssTtitleBar::setMaxOrRestore( bool val)
|
|
|
|
|
{
|
|
|
|
|
m_maxOrRestore = val;//true
|
|
|
|
|
if ((m_type & QTitleBar_Button_Restore) && (m_type & QTitleBar_Button_Max))
|
|
|
|
|
{
|
|
|
|
|
m_restoreBtn->setVisible(m_maxOrRestore);
|
|
|
|
|
m_maxBtn->setVisible(!m_maxOrRestore);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssTtitleBar::SetMainWindow(QMainWindow *p)
|
|
|
|
|
{
|
|
|
|
|
if(nullptr ==p){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this->m_Main = p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** m_maxNormaltrue */
|
|
|
|
|
void QssTtitleBar::onMaxOrRestore()
|
|
|
|
|
{
|
|
|
|
|
if (m_type != QTitleBar_Type_MainWindow)
|
|
|
|
|
return ;
|
2020-11-24 02:19:29 +00:00
|
|
|
|
emit(OnMaxOrRestore(m_maxOrRestore));
|
2020-10-26 15:44:45 +00:00
|
|
|
|
|
|
|
|
|
setMaxOrRestore(!m_maxOrRestore);
|
|
|
|
|
}
|
|
|
|
|
void QssTtitleBar::paintEvent(QPaintEvent *)
|
|
|
|
|
{
|
|
|
|
|
QStyleOption opt;
|
|
|
|
|
opt.init(this);
|
|
|
|
|
QPainter p(this);
|
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssTtitleBar::mouseMoveEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
if (m_maxOrRestore)
|
|
|
|
|
return;
|
|
|
|
|
if (!m_pressed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QPoint globalPt = ev->globalPos();
|
|
|
|
|
QPoint movePt = globalPt - m_pressedPos;//FrameglobalPos
|
|
|
|
|
parentWidget()->move(movePt);//globalPos
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssTtitleBar::mousePressEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
m_pressed = true;
|
|
|
|
|
m_pressedPos = mapToParent(ev->pos());
|
|
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssTtitleBar::mouseReleaseEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
m_pressed = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QssTtitleBar::eventFilter( QObject * obj, QEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
if (obj == this)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::MouseButtonDblClick)
|
|
|
|
|
{
|
|
|
|
|
onMaxOrRestore();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QWidget::eventFilter(obj, ev);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 02:19:29 +00:00
|
|
|
|
void QssMainWindow::OnMaxOrRestore(bool max)
|
|
|
|
|
{
|
|
|
|
|
if (max)
|
|
|
|
|
{
|
|
|
|
|
setMinimumSize(0, 0);
|
|
|
|
|
setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
|
|
|
|
this->m_frame->setMinimumSize(0, 0);
|
|
|
|
|
this->m_frame->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
|
|
|
|
|
|
|
|
|
if (!m_rcNormal.isValid())
|
|
|
|
|
{
|
|
|
|
|
QSize sizeHint = parentWidget()->sizeHint();
|
|
|
|
|
if (sizeHint.width() > m_rcValid.width())
|
|
|
|
|
sizeHint.setWidth(m_rcValid.width() -100);
|
|
|
|
|
if (sizeHint.height() > m_rcValid.height())
|
|
|
|
|
sizeHint.setHeight(m_rcValid.height() - 100);
|
|
|
|
|
|
|
|
|
|
m_rcNormal.setLeft((m_rcValid.width() - sizeHint.width())/2);
|
|
|
|
|
m_rcNormal.setTop((m_rcValid.height() - sizeHint.height())/2);
|
|
|
|
|
m_rcNormal.setWidth(sizeHint.width());
|
|
|
|
|
m_rcNormal.setHeight(sizeHint.height());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->parentWidget()->setGeometry(m_rcNormal);
|
|
|
|
|
this->setGeometry(m_rcNormalCentral);
|
|
|
|
|
setMinimumSize(0, 0);
|
|
|
|
|
setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
|
|
|
|
this->m_frame->setMinimumSize(0, 0);
|
|
|
|
|
this->m_frame->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_rcNormal = this->parentWidget()->geometry();
|
|
|
|
|
m_rcNormalCentral = this->geometry();
|
|
|
|
|
|
|
|
|
|
setMinimumSize(0, 0);
|
|
|
|
|
setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
|
|
|
|
this->m_frame->setMinimumSize(0, 0);
|
|
|
|
|
this->m_frame->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
|
|
|
|
QSize sizeHint = parentWidget()->sizeHint();
|
|
|
|
|
|
|
|
|
|
QDesktopWidget desktop;
|
|
|
|
|
QRect rc = desktop.availableGeometry(-1);
|
|
|
|
|
|
|
|
|
|
parentWidget()->setGeometry(rc);
|
|
|
|
|
rc.setRight(rc.right() - 50);
|
|
|
|
|
|
|
|
|
|
this->setGeometry(rc);
|
|
|
|
|
this->setFixedHeight(rc.height());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* = 0*/,float scale)
|
|
|
|
|
: QMainWindow(parent, flags),
|
2020-12-04 13:12:58 +00:00
|
|
|
|
ICallDPIChanged(),
|
2020-11-24 02:19:29 +00:00
|
|
|
|
m_mousePressedInBoundy(false),
|
|
|
|
|
m_bLeftPress(false)
|
2020-10-26 15:44:45 +00:00
|
|
|
|
{
|
|
|
|
|
m_rcValid = QApplication::desktop()->availableGeometry();
|
|
|
|
|
m_frame = new QFrame(parent, flags);
|
|
|
|
|
m_frame->setObjectName("window");
|
|
|
|
|
|
2020-11-24 02:19:29 +00:00
|
|
|
|
m_frame->setWindowFlags(Qt::Window |
|
|
|
|
|
Qt::FramelessWindowHint|
|
|
|
|
|
Qt::WindowSystemMenuHint |
|
|
|
|
|
Qt::WindowMinimizeButtonHint);
|
2020-12-08 16:23:00 +00:00
|
|
|
|
m_frame->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_frame->setMouseTracking(true);
|
|
|
|
|
m_frame->installEventFilter(this);
|
|
|
|
|
m_titleBar = new QssTtitleBar(m_frame);
|
|
|
|
|
m_titleBar->installEventFilter(this);
|
|
|
|
|
m_titleBar->SetMainWindow(this);
|
|
|
|
|
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
|
|
|
|
vbox->addWidget(m_titleBar);
|
2020-12-08 16:23:00 +00:00
|
|
|
|
vbox->setMargin(1);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
vbox->setSpacing(0);
|
|
|
|
|
vbox->addWidget(this);
|
|
|
|
|
installEventFilter(this);
|
2020-11-24 02:19:29 +00:00
|
|
|
|
|
|
|
|
|
mFrameRect = m_frame->geometry();
|
2020-12-07 16:11:45 +00:00
|
|
|
|
m_rcNormal = m_frame->geometry();
|
2020-11-24 02:19:29 +00:00
|
|
|
|
m_rcNormalCentral = this->geometry();
|
|
|
|
|
connect(this->titleBar(),SIGNAL( OnMaxOrRestore(bool )),this,SLOT(OnMaxOrRestore(bool)));
|
2020-12-14 15:48:37 +00:00
|
|
|
|
QFile file(":/qss/css/QssMainWindow.css");
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly)){
|
|
|
|
|
qDebug()<<"error bar";
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
QTextStream in(&file);
|
|
|
|
|
QString css = in.readAll();
|
|
|
|
|
//this->setStyleSheet(css);
|
|
|
|
|
return;
|
2020-10-26 15:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QssMainWindow::~QssMainWindow()
|
|
|
|
|
{
|
|
|
|
|
m_frame->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::show()
|
|
|
|
|
{
|
|
|
|
|
m_frame->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::showMinimized()
|
|
|
|
|
{
|
|
|
|
|
m_frame->showMinimized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
TOPLEFT = 11,
|
|
|
|
|
TOP = 12,
|
|
|
|
|
TOPRIGHT = 13,
|
|
|
|
|
LEFT = 21,
|
|
|
|
|
CENTER = 22,
|
|
|
|
|
RIGHT = 23,
|
|
|
|
|
BUTTOMLEFT = 31,
|
|
|
|
|
BUTTOM = 32,
|
|
|
|
|
BUTTOMRIGHT = 33
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::setCursorShape(int CalPos)
|
|
|
|
|
{
|
|
|
|
|
Qt::CursorShape cursor;
|
|
|
|
|
switch(CalPos)
|
|
|
|
|
{
|
|
|
|
|
case TOPLEFT:
|
|
|
|
|
case BUTTOMRIGHT:
|
|
|
|
|
cursor = Qt::SizeFDiagCursor;
|
|
|
|
|
break;
|
|
|
|
|
case TOPRIGHT:
|
|
|
|
|
case BUTTOMLEFT:
|
|
|
|
|
cursor = Qt::SizeBDiagCursor;
|
|
|
|
|
break;
|
|
|
|
|
case TOP:
|
|
|
|
|
case BUTTOM:
|
|
|
|
|
cursor = Qt::SizeVerCursor;
|
|
|
|
|
break;
|
|
|
|
|
case LEFT:
|
|
|
|
|
case RIGHT:
|
|
|
|
|
cursor = Qt::SizeHorCursor;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
cursor = Qt::ArrowCursor;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
setCursor(cursor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::showMaximized()
|
|
|
|
|
{
|
|
|
|
|
m_titleBar->setMaxOrRestore(true);
|
|
|
|
|
m_frame->setGeometry(m_rcValid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::showFullScreen()
|
|
|
|
|
{
|
|
|
|
|
m_titleBar->setMaxOrRestore(true);
|
|
|
|
|
m_frame->showFullScreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::showNormal()
|
|
|
|
|
{
|
|
|
|
|
m_titleBar->setMaxOrRestore(false);
|
|
|
|
|
m_frame->resize(rect().width(), rect().height() + m_titleBar->rect().height());
|
|
|
|
|
m_frame->showNormal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::setWindowTitle( QString title )
|
|
|
|
|
{
|
2020-12-14 16:11:15 +00:00
|
|
|
|
//m_frame->setWindowTitle(title);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_titleBar->setTitle(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::setWindowIcon( QIcon icon )
|
|
|
|
|
{
|
|
|
|
|
m_frame->setWindowIcon(icon);
|
|
|
|
|
m_titleBar->setIcon(icon);
|
|
|
|
|
}
|
|
|
|
|
#define FRAMESHAPE 10
|
|
|
|
|
|
|
|
|
|
int QssMainWindow::CalCursorPos(QPoint pt, int colPos)
|
|
|
|
|
{
|
|
|
|
|
return ((pt.y() < FRAMESHAPE ? 10 : ((pt.y() > this->height() - FRAMESHAPE) ? 30 : 20)) + colPos);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 13:12:58 +00:00
|
|
|
|
void QssMainWindow::SetTitleHeight(uint32_t height)
|
|
|
|
|
{
|
|
|
|
|
this->m_titleBar->setFixedHeight(height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-10-26 15:44:45 +00:00
|
|
|
|
int QssMainWindow::CalCursorCol(QPoint pt)
|
|
|
|
|
{
|
|
|
|
|
return (pt.x() < FRAMESHAPE ? 1 : ((pt.x() > this->width() - FRAMESHAPE) ? 3 : 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::onMouseMoveEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
if (m_titleBar->maxOrRestore())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(Qt::WindowMaximized != windowState())
|
|
|
|
|
{
|
|
|
|
|
setCursorShape(CalCursorPos(ev->pos(),CalCursorCol(ev->pos())));
|
|
|
|
|
}
|
|
|
|
|
QPoint ptCurrentPos = QCursor::pos();
|
|
|
|
|
QPoint ptMoveSize = ptCurrentPos - m_ptViewMousePos;
|
|
|
|
|
QRect rtTempGeometry = this->geometry();
|
|
|
|
|
QRect rtCentralGeo = this->centralWidget()->geometry();
|
|
|
|
|
QRect rtMainWindow = this->geometry();
|
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
|
if (m_mousePressedInBoundy)
|
|
|
|
|
{
|
|
|
|
|
int x = ev->globalPos().x();
|
|
|
|
|
int y = ev->globalPos().y();
|
|
|
|
|
|
|
|
|
|
int dx = x - m_pos.x();
|
|
|
|
|
int dy = y - m_pos.y();
|
|
|
|
|
|
2020-12-08 16:27:00 +00:00
|
|
|
|
if ((m_left || m_right) && qAbs(dx) < 10)
|
2020-10-26 15:44:45 +00:00
|
|
|
|
return;
|
2020-12-08 16:27:00 +00:00
|
|
|
|
if ((m_top || m_bottom) && qAbs(dy) < 15)
|
2020-10-26 15:44:45 +00:00
|
|
|
|
return;
|
2020-11-24 02:19:29 +00:00
|
|
|
|
if (m_left && dx > 0 && mFrameRect.width() <= m_frame->minimumWidth())
|
2020-10-26 15:44:45 +00:00
|
|
|
|
return ;
|
2020-11-24 02:19:29 +00:00
|
|
|
|
if (m_top && dy > 0 && mFrameRect.height() <= m_frame->minimumHeight())
|
2020-10-26 15:44:45 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-11-24 02:19:29 +00:00
|
|
|
|
QRect rc = mFrameRect;
|
2020-10-26 15:44:45 +00:00
|
|
|
|
if (m_left){
|
|
|
|
|
rc.setLeft(rc.left() + dx);
|
|
|
|
|
rtMainWindow.setLeft(rtMainWindow.left() + dx);
|
|
|
|
|
}
|
|
|
|
|
if (m_right){
|
|
|
|
|
rc.setRight(rc.right() + dx);
|
|
|
|
|
rtCentralGeo.setRight(rtCentralGeo.right() + dx);
|
|
|
|
|
rtMainWindow.setRight(rtMainWindow.right() + dx);
|
|
|
|
|
}
|
|
|
|
|
if (m_top){
|
|
|
|
|
rc.setTop(rc.top() + dy);
|
|
|
|
|
rtCentralGeo.setTop(rtCentralGeo.top() + dy);
|
|
|
|
|
rtMainWindow.setTop(rtMainWindow.top() + dy);
|
|
|
|
|
}
|
|
|
|
|
if (m_bottom){
|
|
|
|
|
rc.setBottom(rc.bottom() + dy);
|
|
|
|
|
rtCentralGeo.setBottom(rtCentralGeo.bottom() + dy);
|
|
|
|
|
rtMainWindow.setBottom(rtMainWindow.bottom() + dy);
|
|
|
|
|
}
|
|
|
|
|
m_frame->setGeometry(rc);
|
|
|
|
|
m_frame->show();
|
2020-11-24 02:19:29 +00:00
|
|
|
|
mFrameRect = rc;
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_CentralRect = rtCentralGeo;
|
|
|
|
|
m_pos = ev->globalPos();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int x = ev->x();
|
|
|
|
|
int y = ev->y();
|
|
|
|
|
|
|
|
|
|
QRect rc = m_frame->rect();
|
2020-12-08 16:27:00 +00:00
|
|
|
|
m_left = qAbs(x - rc.left()) <= 10;
|
|
|
|
|
m_right = qAbs(x - rc.right()) <= 10;
|
|
|
|
|
m_top = qAbs(y - rc.top()) <= 10;
|
|
|
|
|
m_bottom = qAbs(y - rc.bottom()) <= 10;
|
2020-10-26 15:44:45 +00:00
|
|
|
|
|
|
|
|
|
if ((m_left && m_top) || (m_right && m_bottom))
|
|
|
|
|
m_frame->setCursor(Qt::SizeFDiagCursor);
|
|
|
|
|
else if ((m_right && m_top) || (m_left && m_bottom))
|
|
|
|
|
m_frame->setCursor(Qt::SizeBDiagCursor);
|
|
|
|
|
else if ((m_left && !m_top && !m_bottom) || (m_right && !m_top && !m_bottom))
|
|
|
|
|
m_frame->setCursor(Qt::SizeHorCursor);
|
|
|
|
|
else if ((m_top && !m_right && !m_left) || (m_bottom && !m_right && !m_left))
|
|
|
|
|
m_frame->setCursor(Qt::SizeVerCursor);
|
|
|
|
|
else
|
|
|
|
|
m_frame->setCursor(Qt::ArrowCursor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::onMousePressEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
m_pos = ev->globalPos();
|
|
|
|
|
this->show();
|
2020-11-24 02:19:29 +00:00
|
|
|
|
mFrameRect = m_frame->geometry();
|
2020-10-26 15:44:45 +00:00
|
|
|
|
if(nullptr != centralWidget()){
|
|
|
|
|
m_CentralRect = centralWidget()->geometry();
|
|
|
|
|
}
|
|
|
|
|
m_mousePressedInBoundy = (ev->button() == Qt::LeftButton) && (m_left || m_right || m_top || m_bottom);
|
|
|
|
|
|
|
|
|
|
m_iCalCursorPos = CalCursorPos(ev->pos(),CalCursorCol(ev->pos()));
|
|
|
|
|
if (ev->button() == Qt::LeftButton)
|
|
|
|
|
{
|
|
|
|
|
if(m_iCalCursorPos != CENTER)
|
|
|
|
|
{
|
|
|
|
|
m_bLeftPress = true;
|
|
|
|
|
m_ptViewMousePos = ev->globalPos();
|
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-24 02:19:29 +00:00
|
|
|
|
m_rtPreGeometry = mFrameRect;
|
2020-12-04 13:12:58 +00:00
|
|
|
|
|
2020-10-26 15:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMainWindow::onMouseReleaseEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
m_bLeftPress = false;
|
|
|
|
|
m_mousePressedInBoundy = false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 02:19:29 +00:00
|
|
|
|
void QssMainWindow::showEvent(QShowEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-08 16:23:00 +00:00
|
|
|
|
bool QssMainWindow::eventFilter( QObject * obj, QEvent * ev ){
|
2020-10-26 15:44:45 +00:00
|
|
|
|
if (obj == m_frame)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::MouseMove)
|
|
|
|
|
{
|
|
|
|
|
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
|
|
|
|
|
if (ev)
|
|
|
|
|
{
|
|
|
|
|
onMouseMoveEvent(mouseEv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::MouseButtonPress)
|
|
|
|
|
{
|
|
|
|
|
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
|
|
|
|
|
if (ev)
|
|
|
|
|
{
|
|
|
|
|
onMousePressEvent(mouseEv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::MouseButtonRelease)
|
|
|
|
|
{
|
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
|
|
|
|
|
|
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
|
|
|
|
|
if (ev)
|
|
|
|
|
{
|
|
|
|
|
onMouseReleaseEvent(mouseEv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::Show)
|
|
|
|
|
{
|
|
|
|
|
/* */
|
|
|
|
|
QRect rc = m_frame->rect();
|
|
|
|
|
QRect parentRc = m_rcValid;
|
|
|
|
|
|
|
|
|
|
/** m_frame */
|
|
|
|
|
int x = parentRc.left() + (parentRc.width() - rc.width())*0.5; x = x <= 0 ? 1 : x;
|
|
|
|
|
int y = parentRc.top() + (parentRc.height() - rc.height())*0.5; y = y <= 0 ? 1 : y;
|
|
|
|
|
m_frame->move(x, y);
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::Close)
|
|
|
|
|
{
|
|
|
|
|
close();
|
|
|
|
|
m_titleBar->close();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (obj == m_titleBar)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::Enter)
|
|
|
|
|
{
|
|
|
|
|
m_left = false;m_right = false; m_top = false; m_bottom = false;
|
|
|
|
|
if (m_frame->cursor().shape() != Qt::ArrowCursor)
|
|
|
|
|
m_frame->setCursor(Qt::ArrowCursor);
|
|
|
|
|
}
|
2020-11-24 02:19:29 +00:00
|
|
|
|
if(ev->type() == QEvent::Resize){
|
|
|
|
|
}
|
2020-10-26 15:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
else if (obj == this)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::Enter)
|
|
|
|
|
{
|
|
|
|
|
m_left = false;m_right = false; m_top = false; m_bottom = false;
|
|
|
|
|
if (m_frame->cursor().shape() != Qt::ArrowCursor)
|
|
|
|
|
m_frame->setCursor(Qt::ArrowCursor);
|
|
|
|
|
}
|
|
|
|
|
if(QEvent::Resize == ev->type()){
|
2020-12-08 16:27:00 +00:00
|
|
|
|
|
2020-10-26 15:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::MouseButtonRelease)
|
|
|
|
|
{
|
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
|
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
|
|
|
|
|
if (ev)
|
|
|
|
|
{
|
|
|
|
|
onMouseReleaseEvent(mouseEv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-24 02:19:29 +00:00
|
|
|
|
if(QEvent::Resize == ev->type()){
|
|
|
|
|
|
|
|
|
|
}
|
2020-10-26 15:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
if(QEvent::Resize == ev->type()){
|
|
|
|
|
QDesktopWidget desktop;
|
|
|
|
|
QRect sizeHint = desktop.availableGeometry(-1);
|
|
|
|
|
}
|
|
|
|
|
return QMainWindow::eventFilter(obj, ev);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-06 16:00:45 +00:00
|
|
|
|
|
|
|
|
|
bool QssMainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
MSG* pMsg = reinterpret_cast<MSG*>(message);
|
|
|
|
|
switch (pMsg->message)
|
|
|
|
|
{
|
|
|
|
|
case WM_DPICHANGED:
|
|
|
|
|
{
|
|
|
|
|
qDebug()<<"DPI CHANGED";
|
|
|
|
|
/*DWORD dpi = LOWORD(pMsg->wParam);
|
|
|
|
|
//WId id = WINDOW_WINID;
|
|
|
|
|
//if (DPIHelper()->DPIChanged(dpi, id))
|
|
|
|
|
{
|
|
|
|
|
ScaleChanged(DPIHelper()->GetDPIScale(id));
|
|
|
|
|
RefrushSheet(this, id);
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QMainWindow::nativeEvent(eventType, message, result);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 13:12:58 +00:00
|
|
|
|
void QssMainWindow::ScaleChanged(float scale)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WId QssMainWindow::GetWID() const
|
|
|
|
|
{
|
2021-04-01 16:46:23 +00:00
|
|
|
|
return 0;
|
2020-12-04 13:12:58 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 16:46:23 +00:00
|
|
|
|
|
|
|
|
|
|
2020-12-04 13:12:58 +00:00
|
|
|
|
void QssMainWindow::SetScale(float scale)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 15:44:45 +00:00
|
|
|
|
QssDialog::QssDialog(QWidget *parent)
|
|
|
|
|
: QDialog(0),
|
2021-04-01 16:46:23 +00:00
|
|
|
|
m_parent(parent),
|
|
|
|
|
m_mousePressedInBorder(false)
|
2020-10-26 15:44:45 +00:00
|
|
|
|
{
|
|
|
|
|
m_rcValid = QApplication::desktop()->availableGeometry();
|
|
|
|
|
|
|
|
|
|
m_frame = new QFrame(parent);
|
|
|
|
|
m_frame->setObjectName("dialog");//css
|
|
|
|
|
m_frame->setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
|
m_frame->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint| Qt::WindowSystemMenuHint/* | Qt::WindowMinimizeButtonHint*/);//Qt::WindowMinimizeButtonHintdialog<6F><67>
|
|
|
|
|
m_frame->setMouseTracking(true);
|
|
|
|
|
m_frame->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
m_titleBar = new QssTtitleBar(m_frame, QssTtitleBar::QTitleBar_Type_Dialog);
|
|
|
|
|
m_titleBar->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
|
|
|
|
vbox->setMargin(0);
|
|
|
|
|
vbox->setSpacing(0);
|
|
|
|
|
vbox->addWidget(m_titleBar);
|
|
|
|
|
vbox->addWidget(this);
|
|
|
|
|
|
|
|
|
|
installEventFilter(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QssDialog::~QssDialog()
|
|
|
|
|
{
|
|
|
|
|
m_frame->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDialog::show()
|
|
|
|
|
{
|
|
|
|
|
/** resize m_framem_framesizehint */
|
|
|
|
|
int offset = (QSSDIALOG_SHADOW_WIDTH + QSSDIALOG_BODER_WIDTH)*2;
|
|
|
|
|
m_frame->resize(rect().width() + offset, rect().height() + m_titleBar->rect().height() + offset);
|
|
|
|
|
|
|
|
|
|
QDialog::show();
|
|
|
|
|
m_frame->show();
|
|
|
|
|
}
|
|
|
|
|
void QssDockWidget::paintEvent(QPaintEvent *){
|
|
|
|
|
QStyleOption opt;
|
|
|
|
|
opt.init(this);
|
|
|
|
|
QPainter p(this);
|
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDockWidget::show()
|
|
|
|
|
{
|
|
|
|
|
int offset = (QSSDIALOG_SHADOW_WIDTH + QSSDIALOG_BODER_WIDTH)*2;//rect()<29><><EFBFBD><EFBFBD>padding<6E><67>paddingframe
|
|
|
|
|
m_frame->resize(rect().width() + offset, rect().height() + m_titleBar->rect().height() + offset);
|
|
|
|
|
|
|
|
|
|
QDockWidget::show();
|
|
|
|
|
m_frame->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDialog::raise()
|
|
|
|
|
{
|
|
|
|
|
m_frame->raise();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDialog::activateWindow()
|
|
|
|
|
{
|
|
|
|
|
m_frame->activateWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int QssDialog::exec()
|
|
|
|
|
{
|
|
|
|
|
/** resize m_framem_framesizehint */
|
|
|
|
|
int offset = (QSSDIALOG_SHADOW_WIDTH + QSSDIALOG_BODER_WIDTH)*2;//rect()<29><><EFBFBD><EFBFBD>padding<6E><67>paddingframe
|
|
|
|
|
m_frame->resize(rect().width() + offset, rect().height() + m_titleBar->rect().height() + offset);
|
|
|
|
|
|
|
|
|
|
m_frame->setWindowModality(Qt::ApplicationModal);//Qt::ApplicationModal
|
|
|
|
|
|
|
|
|
|
m_frame->show();
|
|
|
|
|
m_frame->raise();
|
|
|
|
|
m_frame->activateWindow();
|
|
|
|
|
|
|
|
|
|
int ret = QDialog::exec();
|
|
|
|
|
m_frame->close();
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDialog::setWindowTitle( QString title )
|
|
|
|
|
{
|
|
|
|
|
m_frame->setWindowTitle(title);
|
|
|
|
|
m_titleBar->setTitle(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDialog::setWindowIcon( QIcon icon )
|
|
|
|
|
{
|
|
|
|
|
m_frame->setWindowIcon(icon);
|
|
|
|
|
m_titleBar->setIcon(icon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDialog::onMouseMoveEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
2020-12-04 13:12:58 +00:00
|
|
|
|
if (m_mousePressedInBorder) {
|
2020-10-26 15:44:45 +00:00
|
|
|
|
int x = ev->globalPos().x();
|
|
|
|
|
int y = ev->globalPos().y();
|
|
|
|
|
|
|
|
|
|
int dx = x - m_pos.x();
|
|
|
|
|
int dy = y - m_pos.y();
|
|
|
|
|
|
|
|
|
|
if ((m_left || m_right) && qAbs(dx) < 5)
|
|
|
|
|
return;
|
|
|
|
|
if ((m_top || m_bottom) && qAbs(dy) < 5)
|
|
|
|
|
return;
|
2020-11-24 02:19:29 +00:00
|
|
|
|
if (m_left && dx > 0 && mFrameRect.width() <= m_frame->minimumWidth())
|
2020-10-26 15:44:45 +00:00
|
|
|
|
return ;
|
2020-11-24 02:19:29 +00:00
|
|
|
|
if (m_top && dy > 0 && mFrameRect.height() <= m_frame->minimumHeight())
|
2020-10-26 15:44:45 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-11-24 02:19:29 +00:00
|
|
|
|
QRect rc = mFrameRect;
|
2020-10-26 15:44:45 +00:00
|
|
|
|
if (m_left)
|
|
|
|
|
rc.setLeft(rc.left() + dx);
|
|
|
|
|
if (m_right)
|
|
|
|
|
rc.setRight(rc.right() + dx);
|
|
|
|
|
if (m_top)
|
|
|
|
|
rc.setTop(rc.top() + dy);
|
|
|
|
|
if (m_bottom)
|
|
|
|
|
rc.setBottom(rc.bottom() + dy);
|
|
|
|
|
|
|
|
|
|
m_frame->setGeometry(rc);
|
2020-11-24 02:19:29 +00:00
|
|
|
|
mFrameRect = rc;
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_pos = ev->globalPos();
|
|
|
|
|
}
|
2020-12-04 13:12:58 +00:00
|
|
|
|
else {
|
2020-10-26 15:44:45 +00:00
|
|
|
|
int x = ev->x() + QSSDIALOG_SHADOW_WIDTH - 2;
|
|
|
|
|
int y = ev->y() + QSSDIALOG_SHADOW_WIDTH - 2;
|
|
|
|
|
|
|
|
|
|
QRect rc = m_frame->rect();
|
|
|
|
|
m_left = qAbs(x - rc.left()) <= 5;
|
|
|
|
|
m_right = qAbs(x - rc.right()) <= 5;
|
|
|
|
|
m_top = qAbs(y - rc.top()) <= 5;
|
|
|
|
|
m_bottom = qAbs(y - rc.bottom()) <= 5;
|
|
|
|
|
|
|
|
|
|
if ((m_left && m_top) || (m_right && m_bottom))
|
|
|
|
|
m_frame->setCursor(Qt::SizeFDiagCursor);
|
|
|
|
|
else if ((m_right && m_top) || (m_left && m_bottom))
|
|
|
|
|
m_frame->setCursor(Qt::SizeBDiagCursor);
|
|
|
|
|
else if ((m_left && !m_top && !m_bottom) || (m_right && !m_top && !m_bottom))
|
|
|
|
|
m_frame->setCursor(Qt::SizeHorCursor);
|
|
|
|
|
else if ((m_top && !m_right && !m_left) || (m_bottom && !m_right && !m_left))
|
|
|
|
|
m_frame->setCursor(Qt::SizeVerCursor);
|
|
|
|
|
else
|
|
|
|
|
m_frame->setCursor(Qt::ArrowCursor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDockWidget::onMouseMoveEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
if (m_mousePressedInBorder)
|
|
|
|
|
{
|
|
|
|
|
int x = ev->globalPos().x();
|
|
|
|
|
int y = ev->globalPos().y();
|
|
|
|
|
|
|
|
|
|
int dx = x - m_pos.x();
|
|
|
|
|
int dy = y - m_pos.y();
|
|
|
|
|
|
|
|
|
|
if ((m_left || m_right) && qAbs(dx) < 5)
|
|
|
|
|
return;
|
|
|
|
|
if ((m_top || m_bottom) && qAbs(dy) < 5)
|
|
|
|
|
return;
|
2020-11-24 02:19:29 +00:00
|
|
|
|
if (m_left && dx > 0 && mFrameRect.width() <= m_frame->minimumWidth())
|
2020-10-26 15:44:45 +00:00
|
|
|
|
return ;
|
2020-11-24 02:19:29 +00:00
|
|
|
|
if (m_top && dy > 0 && mFrameRect.height() <= m_frame->minimumHeight())
|
2020-10-26 15:44:45 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-11-24 02:19:29 +00:00
|
|
|
|
QRect rc = mFrameRect;
|
2020-10-26 15:44:45 +00:00
|
|
|
|
if (m_left)
|
|
|
|
|
rc.setLeft(rc.left() + dx);
|
|
|
|
|
if (m_right)
|
|
|
|
|
rc.setRight(rc.right() + dx);
|
|
|
|
|
if (m_top)
|
|
|
|
|
rc.setTop(rc.top() + dy);
|
|
|
|
|
if (m_bottom)
|
|
|
|
|
rc.setBottom(rc.bottom() + dy);
|
|
|
|
|
|
|
|
|
|
m_frame->setGeometry(rc);
|
2020-11-24 02:19:29 +00:00
|
|
|
|
mFrameRect = rc;
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_pos = ev->globalPos();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int x = ev->x() + QSSDIALOG_SHADOW_WIDTH - 2;
|
|
|
|
|
int y = ev->y() + QSSDIALOG_SHADOW_WIDTH - 2;
|
|
|
|
|
|
|
|
|
|
QRect rc = m_frame->rect();
|
|
|
|
|
m_left = qAbs(x - rc.left()) <= 5;
|
|
|
|
|
m_right = qAbs(x - rc.right()) <= 5;
|
|
|
|
|
m_top = qAbs(y - rc.top()) <= 5;
|
|
|
|
|
m_bottom = qAbs(y - rc.bottom()) <= 5;
|
|
|
|
|
|
|
|
|
|
if ((m_left && m_top) || (m_right && m_bottom))
|
|
|
|
|
m_frame->setCursor(Qt::SizeFDiagCursor);
|
|
|
|
|
else if ((m_right && m_top) || (m_left && m_bottom))
|
|
|
|
|
m_frame->setCursor(Qt::SizeBDiagCursor);
|
|
|
|
|
else if ((m_left && !m_top && !m_bottom) || (m_right && !m_top && !m_bottom))
|
|
|
|
|
m_frame->setCursor(Qt::SizeHorCursor);
|
|
|
|
|
else if ((m_top && !m_right && !m_left) || (m_bottom && !m_right && !m_left))
|
|
|
|
|
m_frame->setCursor(Qt::SizeVerCursor);
|
|
|
|
|
else
|
|
|
|
|
m_frame->setCursor(Qt::ArrowCursor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDialog::onMousePressEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
m_pos = ev->globalPos();
|
2020-11-24 02:19:29 +00:00
|
|
|
|
mFrameRect = m_frame->geometry();
|
2020-10-26 15:44:45 +00:00
|
|
|
|
if(m_left || m_right || m_top || m_bottom)
|
|
|
|
|
{
|
|
|
|
|
m_mousePressedInBorder = ev->button() == Qt::LeftButton;
|
|
|
|
|
//qDebug() << "mousePressed pressed in border";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QssDockWidget::onMousePressEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
m_pos = ev->globalPos();
|
2020-11-24 02:19:29 +00:00
|
|
|
|
mFrameRect = m_frame->geometry();
|
2020-10-26 15:44:45 +00:00
|
|
|
|
if(m_left || m_right || m_top || m_bottom)
|
|
|
|
|
{
|
|
|
|
|
m_mousePressedInBorder = ev->button() == Qt::LeftButton;
|
|
|
|
|
//qDebug() << "mousePressed pressed in border";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 02:19:29 +00:00
|
|
|
|
void QssDialog::onMouseReleaseEvent( QMouseEvent * )
|
2020-10-26 15:44:45 +00:00
|
|
|
|
{
|
|
|
|
|
m_mousePressedInBorder = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDockWidget::onMouseReleaseEvent( QMouseEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
m_mousePressedInBorder = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QssDialog::eventFilter( QObject * obj, QEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
if (obj == m_frame)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::MouseMove)
|
|
|
|
|
{
|
|
|
|
|
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
|
|
|
|
|
if (ev)
|
|
|
|
|
{
|
|
|
|
|
onMouseMoveEvent(mouseEv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::MouseButtonPress)
|
|
|
|
|
{
|
|
|
|
|
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
|
|
|
|
|
if (ev)
|
|
|
|
|
{
|
|
|
|
|
onMousePressEvent(mouseEv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::MouseButtonRelease)
|
|
|
|
|
{
|
|
|
|
|
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
|
|
|
|
|
if (ev)
|
|
|
|
|
{
|
|
|
|
|
onMouseReleaseEvent(mouseEv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}/** */
|
|
|
|
|
else if (ev->type() == QEvent::Paint)
|
|
|
|
|
{
|
|
|
|
|
const int shadowWidth = QSSDIALOG_SHADOW_WIDTH;
|
|
|
|
|
const int boderWidht = QSSDIALOG_BODER_WIDTH;
|
|
|
|
|
|
|
|
|
|
QPainter paiter(m_frame);
|
|
|
|
|
|
|
|
|
|
QColor colorBorder(0xaa,0xaa,0xaa);
|
|
|
|
|
paiter.setPen(colorBorder);
|
|
|
|
|
|
|
|
|
|
int boderOffset = shadowWidth + boderWidht - 1;
|
|
|
|
|
paiter.drawLine(boderOffset,boderOffset,m_frame->width() - boderOffset - 1, boderOffset);//top
|
|
|
|
|
paiter.drawLine(boderOffset,m_frame->height() - boderOffset - 1,m_frame->width() - boderOffset - 1, m_frame->height() - boderOffset - 1);//bottom
|
|
|
|
|
|
|
|
|
|
paiter.drawLine(boderOffset,boderOffset,boderOffset,m_frame->height() - boderOffset - 1);//left
|
|
|
|
|
paiter.drawLine(m_frame->width() - boderOffset - 1,boderOffset,m_frame->width() - boderOffset - 1,m_frame->height() - boderOffset - 1);//right
|
|
|
|
|
|
|
|
|
|
QColor colorShadow(0xaa,0xaa,0xaa);
|
|
|
|
|
for (int i = 0; i < shadowWidth; i++)
|
|
|
|
|
{
|
|
|
|
|
colorShadow.setAlpha(100*cos(1.5707963*i/(shadowWidth - 1)));
|
|
|
|
|
paiter.setPen(colorShadow);
|
|
|
|
|
paiter.drawRect(boderOffset + i, boderOffset + i,
|
|
|
|
|
m_frame->width() - 2*shadowWidth ,
|
|
|
|
|
m_frame->height() - 2*shadowWidth );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::Show)
|
|
|
|
|
{
|
|
|
|
|
QRect rc = m_frame->rect(), parentRc;
|
|
|
|
|
if (m_parent)
|
|
|
|
|
{
|
|
|
|
|
/** */
|
|
|
|
|
QPoint pt = m_parent->mapToGlobal(QPoint(0,0));
|
|
|
|
|
parentRc =m_parent->rect();
|
|
|
|
|
parentRc.translate(pt);
|
|
|
|
|
}
|
|
|
|
|
else/** */
|
|
|
|
|
parentRc = m_rcValid;
|
|
|
|
|
|
|
|
|
|
/** m_frame */
|
|
|
|
|
int x = parentRc.left() + (parentRc.width() - rc.width())*0.5;x = x <= 0?1:x;
|
|
|
|
|
int y = parentRc.top() + (parentRc.height() - rc.height())*0.5;y = y <= 0?1:y;
|
|
|
|
|
m_frame->move(x,y);
|
|
|
|
|
|
|
|
|
|
/** */
|
|
|
|
|
QPropertyAnimation* aniSize = new QPropertyAnimation(m_frame,"geometry");
|
|
|
|
|
aniSize->setDuration(200);
|
|
|
|
|
aniSize->setKeyValueAt(0, QRect(x,y,0,0));
|
|
|
|
|
aniSize->setKeyValueAt(0.5, QRect(x ,y,rc.width() + 20,rc.height() + 30));
|
|
|
|
|
aniSize->setKeyValueAt(1 , QRect(x,y,rc.width(),rc.height()));
|
|
|
|
|
//aniSize->setEasingCurve(QEasingCurve::InOutBack);//
|
|
|
|
|
|
|
|
|
|
QPropertyAnimation* aniOpacity = new QPropertyAnimation(m_frame,"windowOpacity");
|
|
|
|
|
aniOpacity->setDuration(200);
|
|
|
|
|
aniOpacity->setStartValue(0);
|
|
|
|
|
aniOpacity->setEndValue(1);
|
|
|
|
|
|
|
|
|
|
QParallelAnimationGroup* aniGroup = new QParallelAnimationGroup(m_frame);
|
|
|
|
|
aniGroup->addAnimation(aniSize);
|
|
|
|
|
aniGroup->addAnimation(aniOpacity);
|
|
|
|
|
|
|
|
|
|
aniGroup->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::Close)
|
|
|
|
|
{
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (obj == m_titleBar)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::Enter)
|
|
|
|
|
{
|
|
|
|
|
m_left = false;m_right = false; m_top = false; m_bottom = false;
|
|
|
|
|
if (m_frame->cursor().shape() != Qt::ArrowCursor)
|
|
|
|
|
m_frame->setCursor(Qt::ArrowCursor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (obj == this)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::Enter)
|
|
|
|
|
{
|
|
|
|
|
m_left = false;m_right = false; m_top = false; m_bottom = false;
|
|
|
|
|
if (m_frame->cursor().shape() != Qt::ArrowCursor)
|
|
|
|
|
m_frame->setCursor(Qt::ArrowCursor);
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::Hide)
|
|
|
|
|
{
|
|
|
|
|
m_frame->hide();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QDialog::eventFilter(obj, ev);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 02:19:29 +00:00
|
|
|
|
QssMessageBox::QssMessageBox( Icon icon, const QString &title, const QString &text,
|
|
|
|
|
StandardButtons buttons /*= NoButton*/,
|
|
|
|
|
QWidget *parent /*= 0*/,
|
|
|
|
|
Qt::WindowFlags flags /*= Qt::Widget | Qt::FramelessWindowHint*/ )
|
2020-10-26 15:44:45 +00:00
|
|
|
|
:QMessageBox(icon, title, text, buttons, 0, flags),m_parent(parent)
|
|
|
|
|
{
|
|
|
|
|
m_rcValid = QApplication::desktop()->availableGeometry();
|
|
|
|
|
|
|
|
|
|
m_frame = new QFrame;
|
|
|
|
|
m_frame->setObjectName("messagebox");//css
|
2020-11-24 02:19:29 +00:00
|
|
|
|
//m_frame->setAttribute(Qt::WA_TranslucentBackground);/** padding */
|
|
|
|
|
m_frame->setWindowFlags(Qt::FramelessWindowHint);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_frame->setMouseTracking(true);
|
|
|
|
|
m_frame->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
m_frame->setWindowTitle(title);
|
|
|
|
|
m_frame->setWindowIcon(style()->standardIcon((QStyle::StandardPixmap)(icon + 8)));
|
|
|
|
|
m_frame->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
|
|
|
|
m_titleBar = new QssTtitleBar(m_frame, QssTtitleBar::QTitleBar_Type_MessageBox);
|
|
|
|
|
m_titleBar->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
m_titleBar->setTitle(title);
|
|
|
|
|
m_titleBar->setIcon(style()->standardIcon((QStyle::StandardPixmap)(icon + 8)));
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
|
|
|
|
vbox->setMargin(0);
|
|
|
|
|
vbox->setSpacing(0);
|
|
|
|
|
vbox->addWidget(m_titleBar);
|
|
|
|
|
vbox->addWidget(this);
|
|
|
|
|
|
|
|
|
|
installEventFilter(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QssMessageBox::QssMessageBox( QWidget *parent /*= 0*/ )
|
|
|
|
|
:QMessageBox(parent),m_parent(parent)
|
|
|
|
|
{
|
|
|
|
|
m_rcValid = QApplication::desktop()->availableGeometry();
|
|
|
|
|
|
|
|
|
|
m_frame = new QFrame;
|
|
|
|
|
m_frame->setObjectName("messagebox");//css
|
|
|
|
|
m_frame->setAttribute(Qt::WA_TranslucentBackground);/** padding */
|
2020-11-24 02:19:29 +00:00
|
|
|
|
m_frame->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_frame->setMouseTracking(true);
|
|
|
|
|
m_frame->installEventFilter(this);
|
|
|
|
|
m_frame->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
m_titleBar = new QssTtitleBar(m_frame, QssTtitleBar::QTitleBar_Type_MessageBox);
|
|
|
|
|
m_titleBar->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
|
|
|
|
vbox->setMargin(0);
|
|
|
|
|
vbox->setSpacing(0);
|
|
|
|
|
vbox->addWidget(m_titleBar);
|
|
|
|
|
vbox->addWidget(this);
|
2020-11-24 02:19:29 +00:00
|
|
|
|
this->setStyleSheet("{background:rgb(0,0,0);}");
|
2020-10-26 15:44:45 +00:00
|
|
|
|
installEventFilter(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QssMessageBox::~QssMessageBox()
|
|
|
|
|
{
|
|
|
|
|
m_frame->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QssMessageBox::eventFilter( QObject * obj, QEvent * ev )
|
|
|
|
|
{
|
|
|
|
|
if (obj == m_frame)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::Paint)
|
|
|
|
|
{
|
2020-11-24 02:19:29 +00:00
|
|
|
|
|
2020-10-26 15:44:45 +00:00
|
|
|
|
const int shadowWidth = QSSDIALOG_SHADOW_WIDTH;
|
|
|
|
|
const int boderWidht = QSSDIALOG_BODER_WIDTH;
|
|
|
|
|
|
|
|
|
|
QPainter paiter(m_frame);
|
|
|
|
|
|
|
|
|
|
QColor colorBorder(0xaa,0xaa,0xaa);
|
|
|
|
|
paiter.setPen(colorBorder);
|
|
|
|
|
|
|
|
|
|
int boderOffset = shadowWidth + boderWidht - 1;
|
|
|
|
|
paiter.drawLine(boderOffset,boderOffset,m_frame->width() - boderOffset - 1, boderOffset);//top
|
|
|
|
|
paiter.drawLine(boderOffset,m_frame->height() - boderOffset - 1,m_frame->width() - boderOffset - 1, m_frame->height() - boderOffset - 1);//bottom
|
|
|
|
|
|
|
|
|
|
paiter.drawLine(boderOffset,boderOffset,boderOffset,m_frame->height() - boderOffset - 1);//left
|
|
|
|
|
paiter.drawLine(m_frame->width() - boderOffset - 1,boderOffset,m_frame->width() - boderOffset - 1,m_frame->height() - boderOffset - 1);//right
|
|
|
|
|
|
|
|
|
|
QColor colorShadow(0xaa,0xaa,0xaa);
|
|
|
|
|
for (int i = 0; i < shadowWidth; i++)
|
|
|
|
|
{
|
|
|
|
|
colorShadow.setAlpha(100*cos(1.5707963*i/(shadowWidth - 1)));
|
|
|
|
|
paiter.setPen(colorShadow);
|
|
|
|
|
paiter.drawRect(boderOffset + i, boderOffset + i,
|
|
|
|
|
m_frame->width() - 2*shadowWidth ,
|
|
|
|
|
m_frame->height() - 2*shadowWidth );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::Show)
|
|
|
|
|
{
|
|
|
|
|
QRect rc = m_frame->rect(), parentRc;
|
|
|
|
|
if (m_parent)/**<2A><> */
|
|
|
|
|
{
|
|
|
|
|
QPoint pt = m_parent->mapToGlobal(QPoint(0,0));
|
|
|
|
|
parentRc =m_parent->rect();
|
|
|
|
|
parentRc.translate(pt);
|
|
|
|
|
}
|
|
|
|
|
else/** */
|
|
|
|
|
parentRc = m_rcValid;
|
|
|
|
|
/** m_frame */
|
|
|
|
|
int x = parentRc.left() + (parentRc.width() - rc.width())*0.5;x = x <= 0?1:x;
|
|
|
|
|
int y = parentRc.top() + (parentRc.height() - rc.height())*0.5;y = y <= 0?1:y;
|
|
|
|
|
m_frame->move(x,y);
|
|
|
|
|
|
|
|
|
|
/** */
|
|
|
|
|
QPropertyAnimation* aniSize = new QPropertyAnimation(m_frame,"geometry");
|
|
|
|
|
aniSize->setDuration(200);
|
|
|
|
|
aniSize->setKeyValueAt(0, QRect(x,y,0,0));
|
|
|
|
|
aniSize->setKeyValueAt(0.5, QRect(x ,y,rc.width() + 10,rc.height() + 15));
|
|
|
|
|
aniSize->setKeyValueAt(1 , QRect(x,y,rc.width(),rc.height()));
|
|
|
|
|
//aniSize->setEasingCurve(QEasingCurve::InOutBack);//
|
|
|
|
|
|
|
|
|
|
QPropertyAnimation* aniOpacity = new QPropertyAnimation(m_frame,"windowOpacity");
|
|
|
|
|
aniOpacity->setDuration(200);
|
|
|
|
|
aniOpacity->setStartValue(0);
|
|
|
|
|
aniOpacity->setEndValue(1);
|
|
|
|
|
|
|
|
|
|
QParallelAnimationGroup* aniGroup = new QParallelAnimationGroup(m_frame);
|
|
|
|
|
aniGroup->addAnimation(aniSize);
|
|
|
|
|
aniGroup->addAnimation(aniOpacity);
|
|
|
|
|
|
|
|
|
|
aniGroup->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::Close)
|
|
|
|
|
{
|
|
|
|
|
close();
|
|
|
|
|
m_titleBar->close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(obj == this)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::Resize)
|
|
|
|
|
{
|
2020-11-24 02:19:29 +00:00
|
|
|
|
frame()->setFixedWidth(size().width());
|
2020-10-26 15:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QDialog::eventFilter(obj, ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::tips( const QString & text, QWidget* parent /*= 0*/, const QString & title /*= QString::fromLocal8Bit("")*/, StandardButtons btn /*= QMessageBox::Ok*/ )
|
|
|
|
|
{
|
|
|
|
|
QssMessageBox box(QMessageBox::Information, title, "\n" + text/* + "\n"*/, btn, parent);
|
|
|
|
|
box.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
|
|
|
|
|
box.frame()->show();
|
|
|
|
|
box.frame()->raise();
|
|
|
|
|
box.frame()->activateWindow();
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton ret = (QMessageBox::StandardButton)box.exec();
|
|
|
|
|
box.frame()->close();
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::warn( const QString & text, QWidget* parent /*= 0*/, const QString & title /*= QString::fromLocal8Bit("")*/, StandardButtons btn /*= QMessageBox::Ok*/ )
|
|
|
|
|
{
|
|
|
|
|
QssMessageBox box(QMessageBox::Warning, title, "\n" + text/* + "\n"*/ , btn, parent);
|
|
|
|
|
box.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
|
|
|
|
|
box.frame()->show();
|
|
|
|
|
box.frame()->raise();
|
|
|
|
|
box.frame()->activateWindow();
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton ret = (QMessageBox::StandardButton)box.exec();
|
|
|
|
|
box.frame()->close();
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::error( const QString & text, QWidget* parent /*= 0*/, const QString & title /*= QString::fromLocal8Bit("")*/, StandardButtons btn /*= QMessageBox::Ok*/ )
|
|
|
|
|
{
|
|
|
|
|
QssMessageBox box(QMessageBox::Critical, title, "\n" + text/* + "\n"*/, btn, parent);
|
|
|
|
|
box.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
|
|
|
|
|
box.frame()->show();
|
|
|
|
|
box.frame()->raise();
|
|
|
|
|
box.frame()->activateWindow();
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton ret = (QMessageBox::StandardButton)box.exec();
|
|
|
|
|
box.frame()->close();
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::ask( const QString & text, QWidget* parent /*= 0*/, const QString & title /*= QString::fromLocal8Bit("")*/, StandardButtons btn /*= QMessageBox::Yes | QMessageBox::No*/ )
|
|
|
|
|
{
|
|
|
|
|
QssMessageBox box(QMessageBox::Question, title, "\n" + text/* + "\n"*/, btn, parent);
|
|
|
|
|
box.setDefaultButton(QMessageBox::Yes);
|
|
|
|
|
|
|
|
|
|
box.frame()->show();
|
|
|
|
|
box.frame()->raise();
|
|
|
|
|
box.frame()->activateWindow();
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton ret = (QMessageBox::StandardButton)box.exec();
|
|
|
|
|
box.frame()->close();
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::regard( const QString & text, QWidget* parent /*= 0*/, const QString & title /*= QString::fromLocal8Bit("")*/ )
|
|
|
|
|
{
|
|
|
|
|
QssMessageBox box(parent);
|
|
|
|
|
|
|
|
|
|
QIcon icon = QApplication::windowIcon();
|
|
|
|
|
QSize size = icon.actualSize(QSize(64, 64));
|
|
|
|
|
box.setIconPixmap(icon.pixmap(size));
|
|
|
|
|
box.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
|
|
|
|
|
box.frame()->setWindowIcon(icon);
|
|
|
|
|
box.titleBar()->setIcon(icon);
|
|
|
|
|
|
|
|
|
|
box.frame()->setWindowTitle(title);
|
|
|
|
|
box.titleBar()->setTitle(title);
|
|
|
|
|
|
|
|
|
|
box.setInformativeText(text);
|
|
|
|
|
|
|
|
|
|
box.frame()->show();
|
|
|
|
|
box.frame()->raise();
|
|
|
|
|
box.frame()->activateWindow();
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton ret = (QMessageBox::StandardButton)box.exec();
|
|
|
|
|
box.frame()->close();
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::regard( const QString & text, QIcon icon, QWidget* parent /*= 0*/, const QString & title /*= QString::fromLocal8Bit("")*/ )
|
|
|
|
|
{
|
|
|
|
|
QssMessageBox box(parent);
|
|
|
|
|
QSize size = icon.actualSize(QSize(64, 64));
|
|
|
|
|
box.setIconPixmap(icon.pixmap(size));
|
|
|
|
|
box.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
|
|
|
|
|
box.frame()->setWindowIcon(icon);
|
|
|
|
|
box.titleBar()->setIcon(icon);
|
|
|
|
|
|
|
|
|
|
box.frame()->setWindowTitle(title);
|
|
|
|
|
box.titleBar()->setTitle(title);
|
|
|
|
|
|
|
|
|
|
box.setInformativeText(text);
|
|
|
|
|
|
|
|
|
|
box.frame()->show();
|
|
|
|
|
box.frame()->raise();
|
|
|
|
|
box.frame()->activateWindow();
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton ret = (QMessageBox::StandardButton)box.exec();
|
|
|
|
|
box.frame()->close();
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::regardQt(QWidget* parent /*= 0*/, const QString & title /*= QString::fromLocal8Bit("Qt")*/ )
|
|
|
|
|
{
|
|
|
|
|
QString translatedTextAboutQtCaption;
|
|
|
|
|
translatedTextAboutQtCaption = QMessageBox::tr(
|
|
|
|
|
"<h3>About Qt</h3>"
|
|
|
|
|
"<p>This program uses Qt version %1.</p>"
|
|
|
|
|
).arg(QLatin1String(QT_VERSION_STR));
|
|
|
|
|
QString translatedTextAboutQtText;
|
|
|
|
|
translatedTextAboutQtText = QMessageBox::tr(
|
|
|
|
|
"<p>Qt is a C++ toolkit for cross-platform application "
|
|
|
|
|
"development.</p>"
|
|
|
|
|
"<p>Qt provides single-source portability across MS Windows, "
|
|
|
|
|
"Mac OS X, Linux, and all major commercial Unix variants. "
|
|
|
|
|
"Qt is also available for embedded devices as Qt for Embedded Linux "
|
|
|
|
|
"and Qt for Windows CE.</p>"
|
|
|
|
|
"<p>Qt is available under three different licensing options designed "
|
|
|
|
|
"to accommodate the needs of our various users.</p>"
|
|
|
|
|
"<p>Qt licensed under our commercial license agreement is appropriate "
|
|
|
|
|
"for development of proprietary/commercial software where you do not "
|
|
|
|
|
"want to share any source code with third parties or otherwise cannot "
|
|
|
|
|
"comply with the terms of the GNU LGPL version 2.1 or GNU GPL version "
|
|
|
|
|
"3.0.</p>"
|
|
|
|
|
"<p>Qt licensed under the GNU LGPL version 2.1 is appropriate for the "
|
|
|
|
|
"development of Qt applications (proprietary or open source) provided "
|
|
|
|
|
"you can comply with the terms and conditions of the GNU LGPL version "
|
|
|
|
|
"2.1.</p>"
|
|
|
|
|
"<p>Qt licensed under the GNU General Public License version 3.0 is "
|
|
|
|
|
"appropriate for the development of Qt applications where you wish to "
|
|
|
|
|
"use such applications in combination with software subject to the "
|
|
|
|
|
"terms of the GNU GPL version 3.0 or where you are otherwise willing "
|
|
|
|
|
"to comply with the terms of the GNU GPL version 3.0.</p>"
|
|
|
|
|
"<p>Please see <a href=\"http://qt.nokia.com/products/licensing\">qt.nokia.com/products/licensing</a> "
|
|
|
|
|
"for an overview of Qt licensing.</p>"
|
|
|
|
|
"<p>Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).</p>"
|
|
|
|
|
"<p>Qt is a Nokia product. See <a href=\"http://qt.nokia.com/\">qt.nokia.com</a> "
|
|
|
|
|
"for more information.</p>"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
QPixmap pm(QMessageBox::tr(":/trolltech/qmessagebox/images/qtlogo-64.png"));
|
|
|
|
|
|
|
|
|
|
QssMessageBox box(parent);
|
|
|
|
|
box.setWindowTitle(title.isEmpty() ? QString::fromLocal8Bit("Qt") : title);
|
|
|
|
|
box.setText(translatedTextAboutQtCaption);
|
|
|
|
|
box.setInformativeText(translatedTextAboutQtText);
|
|
|
|
|
if (!pm.isNull())
|
|
|
|
|
box.setIconPixmap(pm);
|
|
|
|
|
box.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
|
|
|
|
|
box.frame()->setWindowIcon(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"));
|
|
|
|
|
box.frame()->setWindowTitle(title.isEmpty() ? QString::fromLocal8Bit("Qt") : title);
|
|
|
|
|
box.titleBar()->setIcon(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"));
|
|
|
|
|
box.titleBar()->setTitle(title.isEmpty() ? QString::fromLocal8Bit("Qt") : title);
|
|
|
|
|
|
|
|
|
|
box.frame()->show();
|
|
|
|
|
box.frame()->raise();
|
|
|
|
|
box.frame()->activateWindow();
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton ret = (QMessageBox::StandardButton)box.exec();
|
|
|
|
|
box.frame()->close();
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::information( QWidget *parent, const QString &title, const QString &text, StandardButtons buttons /*= Ok*/, StandardButton defaultButton /*= NoButton*/ )
|
|
|
|
|
{
|
|
|
|
|
return QssMessageBox::tips(text, parent, title, buttons);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::question( QWidget *parent, const QString &title, const QString &text, StandardButtons buttons /*= QMessageBox::Ok*/, StandardButton defaultButton /*= QMessageBox::NoButton*/ )
|
|
|
|
|
{
|
|
|
|
|
return QssMessageBox::ask(text, parent, title, buttons);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::warning( QWidget *parent, const QString &title, const QString &text, StandardButtons buttons /*= QMessageBox::Ok*/, StandardButton defaultButton /*= QMessageBox::NoButton*/ )
|
|
|
|
|
{
|
|
|
|
|
return QssMessageBox::warn(text, parent, title, buttons);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton QssMessageBox::critical( QWidget *parent, const QString &title, const QString &text, StandardButtons buttons /*= QMessageBox::Ok*/, StandardButton defaultButton /*= QMessageBox::NoButton*/ )
|
|
|
|
|
{
|
|
|
|
|
return QssMessageBox::error(text, parent, title, buttons);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMessageBox::about( QWidget *parent, const QString &title, const QString &text )
|
|
|
|
|
{
|
|
|
|
|
QssMessageBox::regard(text, parent, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMessageBox::about( QWidget *parent, const QString &title, const QString &text, QIcon icon )
|
|
|
|
|
{
|
|
|
|
|
QssMessageBox::regard(text, icon, parent, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssMessageBox::aboutQt( QWidget *parent, const QString &title /*= QString()*/ )
|
|
|
|
|
{
|
|
|
|
|
QssMessageBox::regardQt(parent, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QssDockWidget::QssDockWidget(QWidget *parent)
|
|
|
|
|
: QDockWidget(parent),
|
2020-12-08 16:27:00 +00:00
|
|
|
|
m_parent(parent),
|
|
|
|
|
m_mousePressedInBorder(false)
|
2020-10-26 15:44:45 +00:00
|
|
|
|
{
|
|
|
|
|
m_rcValid = QApplication::desktop()->availableGeometry();
|
|
|
|
|
|
|
|
|
|
m_frame = new QFrame(parent);
|
|
|
|
|
m_frame->setObjectName("dialog");//css
|
|
|
|
|
m_frame->setAttribute(Qt::WA_TranslucentBackground);/** padding css boder<65><72>*/
|
2020-12-14 15:48:37 +00:00
|
|
|
|
m_frame->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
|
2020-10-26 15:44:45 +00:00
|
|
|
|
m_frame->setMouseTracking(true);
|
|
|
|
|
m_frame->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
m_titleBar = new QssTtitleBar(m_frame, QssTtitleBar::QTitleBar_Type_Dialog);
|
|
|
|
|
m_titleBar->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
|
|
|
|
vbox->setMargin(0);
|
|
|
|
|
vbox->setSpacing(0);
|
|
|
|
|
vbox->addWidget(m_titleBar);
|
|
|
|
|
vbox->addWidget(this);
|
|
|
|
|
|
|
|
|
|
installEventFilter(this);
|
|
|
|
|
this->setStyleSheet(QString("{background: rgb(232, 241, 252);""color: black;border: 1px solid rgb(111, 156, 207);}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QssDockWidget::~QssDockWidget()
|
|
|
|
|
{
|
|
|
|
|
m_frame->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssDockWidget::setWindowTitle(QString title)
|
|
|
|
|
{
|
|
|
|
|
m_frame->setWindowTitle(title);
|
|
|
|
|
m_titleBar->setTitle(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QssDockWidget::eventFilter(QObject *obj, QEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
if (obj == m_frame)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::MouseMove)
|
|
|
|
|
{
|
|
|
|
|
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
|
|
|
|
|
if (ev)
|
|
|
|
|
{
|
|
|
|
|
onMouseMoveEvent(mouseEv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::MouseButtonPress)
|
|
|
|
|
{
|
|
|
|
|
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
|
|
|
|
|
if (ev)
|
|
|
|
|
{
|
|
|
|
|
onMousePressEvent(mouseEv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::MouseButtonRelease)
|
|
|
|
|
{
|
|
|
|
|
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
|
|
|
|
|
if (ev)
|
|
|
|
|
{
|
|
|
|
|
onMouseReleaseEvent(mouseEv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}/** */
|
|
|
|
|
else if (ev->type() == QEvent::Paint)
|
|
|
|
|
{
|
|
|
|
|
const int shadowWidth = QSSDIALOG_SHADOW_WIDTH;
|
|
|
|
|
const int boderWidht = QSSDIALOG_BODER_WIDTH;
|
|
|
|
|
|
|
|
|
|
QPainter paiter(m_frame);
|
|
|
|
|
|
|
|
|
|
QColor colorBorder(0xaa,0xaa,0xaa);
|
|
|
|
|
paiter.setPen(colorBorder);
|
|
|
|
|
|
|
|
|
|
int boderOffset = shadowWidth + boderWidht - 1;
|
|
|
|
|
paiter.drawLine(boderOffset,boderOffset,m_frame->width() - boderOffset - 1, boderOffset);//top
|
|
|
|
|
paiter.drawLine(boderOffset,m_frame->height() - boderOffset - 1,m_frame->width() - boderOffset - 1, m_frame->height() - boderOffset - 1);//bottom
|
|
|
|
|
|
|
|
|
|
paiter.drawLine(boderOffset,boderOffset,boderOffset,m_frame->height() - boderOffset - 1);//left
|
|
|
|
|
paiter.drawLine(m_frame->width() - boderOffset - 1,boderOffset,m_frame->width() - boderOffset - 1,m_frame->height() - boderOffset - 1);//right
|
|
|
|
|
|
|
|
|
|
QColor colorShadow(0xaa,0xaa,0xaa);
|
|
|
|
|
for (int i = 0; i < shadowWidth; i++)
|
|
|
|
|
{
|
|
|
|
|
colorShadow.setAlpha(100*cos(1.5707963*i/(shadowWidth - 1)));
|
|
|
|
|
paiter.setPen(colorShadow);
|
|
|
|
|
paiter.drawRect(boderOffset + i, boderOffset + i,
|
|
|
|
|
m_frame->width() - 2*shadowWidth ,
|
|
|
|
|
m_frame->height() - 2*shadowWidth );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::Show)
|
|
|
|
|
{
|
|
|
|
|
QRect rc = m_frame->rect(), parentRc;
|
2020-12-08 16:27:00 +00:00
|
|
|
|
if (m_parent)
|
2020-10-26 15:44:45 +00:00
|
|
|
|
{
|
2020-12-08 16:27:00 +00:00
|
|
|
|
|
2020-10-26 15:44:45 +00:00
|
|
|
|
QPoint pt = m_parent->mapToGlobal(QPoint(0,0));
|
|
|
|
|
parentRc =m_parent->rect();
|
|
|
|
|
parentRc.translate(pt);
|
|
|
|
|
}
|
2020-12-08 16:27:00 +00:00
|
|
|
|
else
|
2020-10-26 15:44:45 +00:00
|
|
|
|
parentRc = m_rcValid;
|
|
|
|
|
|
|
|
|
|
int x = parentRc.left() + (parentRc.width() - rc.width())*0.5;x = x <= 0?1:x;
|
|
|
|
|
int y = parentRc.top() + (parentRc.height() - rc.height())*0.5;y = y <= 0?1:y;
|
|
|
|
|
m_frame->move(x,y);
|
|
|
|
|
|
|
|
|
|
QPropertyAnimation* aniSize = new QPropertyAnimation(m_frame,"geometry");
|
|
|
|
|
aniSize->setDuration(200);
|
|
|
|
|
aniSize->setKeyValueAt(0, QRect(x,y,0,0));
|
|
|
|
|
aniSize->setKeyValueAt(0.5, QRect(x ,y,rc.width() + 20,rc.height() + 30));
|
|
|
|
|
aniSize->setKeyValueAt(1 , QRect(x,y,rc.width(),rc.height()));
|
|
|
|
|
//aniSize->setEasingCurve(QEasingCurve::InOutBack);//
|
|
|
|
|
|
|
|
|
|
QPropertyAnimation* aniOpacity = new QPropertyAnimation(m_frame,"windowOpacity");
|
|
|
|
|
aniOpacity->setDuration(200);
|
|
|
|
|
aniOpacity->setStartValue(0);
|
|
|
|
|
aniOpacity->setEndValue(1);
|
|
|
|
|
|
|
|
|
|
QParallelAnimationGroup* aniGroup = new QParallelAnimationGroup(m_frame);
|
|
|
|
|
aniGroup->addAnimation(aniSize);
|
|
|
|
|
aniGroup->addAnimation(aniOpacity);
|
|
|
|
|
|
|
|
|
|
aniGroup->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::Close)
|
|
|
|
|
{
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (obj == m_titleBar)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::Enter)
|
|
|
|
|
{
|
|
|
|
|
m_left = false;m_right = false; m_top = false; m_bottom = false;
|
|
|
|
|
if (m_frame->cursor().shape() != Qt::ArrowCursor)
|
|
|
|
|
m_frame->setCursor(Qt::ArrowCursor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (obj == this)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::Enter)
|
|
|
|
|
{
|
|
|
|
|
m_left = false;m_right = false; m_top = false; m_bottom = false;
|
|
|
|
|
if (m_frame->cursor().shape() != Qt::ArrowCursor)
|
|
|
|
|
m_frame->setCursor(Qt::ArrowCursor);
|
|
|
|
|
}
|
|
|
|
|
else if (ev->type() == QEvent::Hide)
|
|
|
|
|
{
|
|
|
|
|
m_frame->hide();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QDockWidget::eventFilter(obj, ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QssPushButton::QssPushButton(QWidget *parent, QString objName):
|
|
|
|
|
QPushButton(parent)
|
|
|
|
|
{
|
|
|
|
|
this->setObjectName(objName);
|
|
|
|
|
|
|
|
|
|
}
|
2020-12-06 17:05:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QssToastWidget::QssToastWidget(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
|
|
setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::Tool);// 无边框 无任务栏
|
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QssToastWidget::~QssToastWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
void QssToastWidget::setText(const QString& text)
|
|
|
|
|
{
|
|
|
|
|
ui.label->setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssToastWidget::showAnimation(int timeout /*= 2000*/)
|
|
|
|
|
{
|
|
|
|
|
// 开始动画
|
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
|
|
|
|
|
animation->setDuration(1000);
|
|
|
|
|
animation->setStartValue(0);
|
|
|
|
|
animation->setEndValue(1);
|
|
|
|
|
animation->start();
|
|
|
|
|
show();
|
|
|
|
|
|
|
|
|
|
QTimer::singleShot(timeout, [&]
|
|
|
|
|
{
|
|
|
|
|
// 结束动画
|
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
|
|
|
|
|
animation->setDuration(1000);
|
|
|
|
|
animation->setStartValue(1);
|
|
|
|
|
animation->setEndValue(0);
|
|
|
|
|
animation->start();
|
|
|
|
|
connect(animation, &QPropertyAnimation::finished, [&]
|
|
|
|
|
{
|
|
|
|
|
close();
|
|
|
|
|
deleteLater();// 关闭后析构
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssToastWidget::showTip(const QString& text, QWidget* parent /*= nullptr*/)
|
|
|
|
|
{
|
|
|
|
|
QssToastWidget* toast = new QssToastWidget(parent);
|
2020-12-08 16:27:00 +00:00
|
|
|
|
toast->setWindowFlags(toast->windowFlags() | Qt::WindowStaysOnTopHint);
|
2020-12-06 17:05:32 +00:00
|
|
|
|
toast->setText(text);
|
|
|
|
|
toast->setStyleSheet("font:bold;font-size:24px;color:rgb(255,255,255);");
|
2020-12-08 16:27:00 +00:00
|
|
|
|
toast->adjustSize();
|
2020-12-06 17:05:32 +00:00
|
|
|
|
QScreen* pScreen = QGuiApplication::primaryScreen();
|
|
|
|
|
toast->move((pScreen->size().width() - toast->width()) / 2,
|
|
|
|
|
pScreen->size().height() * 5 / 10);
|
|
|
|
|
toast->showAnimation(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QssToastWidget::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QPainter paint(this);
|
|
|
|
|
paint.begin(this);
|
|
|
|
|
auto kBackgroundColor = QColor(255, 255, 255);
|
|
|
|
|
kBackgroundColor.setAlpha(0.0 * 255);// 透明度为0
|
|
|
|
|
paint.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
|
paint.setPen(Qt::NoPen);
|
|
|
|
|
paint.setBrush(QBrush(kBackgroundColor, Qt::SolidPattern));//设置画刷形式
|
|
|
|
|
paint.drawRect(0, 0, width(), height());
|
|
|
|
|
paint.end();
|
|
|
|
|
}
|