#include "MDialog.h"
#define MARGIN 5 //四个角的长度
#define SHADOW_WIDTH 10 //边框阴影宽度
MDialog::MDialog(QWidget *parent)
: QDialog(parent)
{
m_bIsExec = true;
bKeyMovePressed_ = false;
m_nRaidoBtnChoose = -1;
m_nButtonIndex = 0;
m_bNeedShowSecureTip = true;
m_bIsClickedForceQuitBtn = false;
m_dpi = 1;
m_pMainVLayout = new QVBoxLayout(this);
QHBoxLayout* pTitleHLayout = new QHBoxLayout(this);
m_pQuitContentLayout = new QHBoxLayout(this);
m_pMainTitleLabel = new QLabel(this);
m_pMainTitleLabel->setText(QString::fromLocal8Bit("退出账号"));
this->setMouseTracking(true);
Qt::WindowFlags flags = Qt::Dialog;
flags |= Qt::FramelessWindowHint;
flags |= Qt::Tool; //程序不在任务栏显示
flags |= Qt::WindowStaysOnTopHint; //置顶显示
setWindowFlags(flags);
setAttribute(Qt::WA_TranslucentBackground);
//this->setStyleSheet("QDialog{border-radius:15px;}");
QFont font(QString::fromLocal8Bit("微软雅黑"), 13, 6);//第一个属性是字体(微软雅黑),第二个是大小,第三个是加粗(权重是75)
m_pMainTitleLabel->setFont(font);
QPalette pa;
pa.setColor(QPalette::WindowText, Qt::black);
m_pMainTitleLabel->setPalette(pa);
m_pTitleCloseBtn = new QPushButton(this);
m_pTitleCloseBtn->installEventFilter(this);
m_pTitleCloseBtn->setMaximumWidth(12 * m_dpi);
m_pTitleCloseBtn->setMaximumHeight(12 * m_dpi);
m_pTitleCloseBtn->setIconSize(QSize(12 * m_dpi, 12 * m_dpi));
m_pTitleCloseBtn->setToolTip(QString::fromLocal8Bit("关闭"));
/*m_pTitleCloseBtn->setStyleSheet("QPushButton{ border-image:url('../dialog1/p2.png');}QPushButton:hover{ border-image:url('../dialog1/p2.png');\
background-color: qlineargradient(spread: pad, x1: 0, y1: 1, x2: 0, y2: 0, stop: 0 rgba(238, 0, 0, 128), stop: 1 rgba(238, 44, 44, 255));\
}QPushButton{border-radius:0px;color: #F0F0F0;background-color:rgba(0, 0, 0, 0);border-style:none;}");*/
m_pTitleCloseBtn->setStyleSheet("QPushButton{ border-image:url('../dialog1/p2.png');}");
QVBoxLayout* pTilteLayout = new QVBoxLayout(this);
pTitleHLayout->addWidget(m_pMainTitleLabel);
pTitleHLayout->addWidget(m_pTitleCloseBtn);
pTitleHLayout->setMargin(1);
pTilteLayout->addLayout(pTitleHLayout, 1);
QLabel *blueLine = new QLabel(this);
blueLine->setMaximumHeight(1);
blueLine->setStyleSheet("background-color:rgb(227, 227, 227);");
pTilteLayout->addWidget(blueLine);
pTilteLayout->setMargin(1);
m_pMainVLayout->addLayout(pTilteLayout);
m_pQuitLabel = new QLabel(this);
m_pQuitLabel->setWordWrap(true);
QString text;
text.append("<p style='line-height:20px'>").append(QString::fromLocal8Bit("此操作将强制关闭当前打开的文档,可能会"))
.append("\n\n").append("<p style='line-height:20px'>").append(QString::fromLocal8Bit("造成数据丢失, 是否继续 ?")).append("</p>");
m_pQuitLabel->setText(text);
QFont fontQuitLabel(QString::fromLocal8Bit("微软雅黑"), 11, 3);//第一个属性是字体(微软雅黑),第二个是大小,第三个是加粗(权重是75)
m_pQuitLabel->setFont(fontQuitLabel);
QPalette paQuitLabel;
paQuitLabel.setColor(QPalette::Text, QColor(66, 66, 66, 255));
m_pQuitLabel->setPalette(paQuitLabel);
//添加图片
m_pToolTipPicture = new QLabel(this);
m_pToolTipPicture->setMinimumSize(QSize(30 * m_dpi, 30 * m_dpi));
QPixmap pixmapTask("../dialog1/p1.png");
m_pToolTipPicture->setPixmap(pixmapTask);
m_pToolTipPicture->setAlignment(Qt::AlignCenter);
m_pQuitContentLayout->addWidget(m_pToolTipPicture, 1);
m_pQuitContentLayout->addWidget(m_pQuitLabel, 3);
m_pMainVLayout->addLayout(m_pQuitContentLayout, 5);
m_pForceCloseBtn = new QPushButton(this);
m_pForceCloseBtn->setText(QString::fromLocal8Bit("是"));
m_pForceCloseBtn->setMinimumSize(QSize(100 * m_dpi, 30 * m_dpi));
//m_pForceCloseBtn->setChecked(true);
m_pCancelBtn = new QPushButton(this);
m_pCancelBtn->setText(QString::fromLocal8Bit("否"));
m_pCancelBtn->setChecked(true);
m_pCancelBtn->setMinimumSize(QSize(100 * m_dpi, 30 * m_dpi));
m_pForceCloseAndCancelLayout = new QHBoxLayout(this);
setButtonStyleSheet(m_pForceCloseBtn);
setButtonStyleSheet(m_pCancelBtn);
m_pForceCloseAndCancelLayout->addStretch(6);
m_pForceCloseAndCancelLayout->addWidget(m_pForceCloseBtn);
m_pForceCloseAndCancelLayout->addWidget(m_pCancelBtn);
m_pForceCloseAndCancelLayout->addStretch(1);
m_pMainVLayout->addLayout(m_pForceCloseAndCancelLayout, 1);
m_pMainVLayout->addStretch(1);
this->setMinimumSize(QSize(430 * m_dpi, 180 * m_dpi));
this->setStyleSheet("background-color: white");
m_pMainVLayout->setMargin(SHADOW_WIDTH + 8);
this->setLayout(m_pMainVLayout);
connect(m_pTitleCloseBtn, SIGNAL(clicked(bool)), this, SLOT(onTitleCloseBtnClicked(bool)));
connect(m_pForceCloseBtn, SIGNAL(clicked(bool)), this, SLOT(onForceCloseBtnClicked(bool)));
connect(m_pCancelBtn, SIGNAL(clicked(bool)), this, SLOT(onTitleCloseBtnClicked(bool)));
}
MDialog::~MDialog()
{
qDebug() <<QString::fromLocal8Bit("析构函数,用户选择了:") << getResult();
}
int MDialog::getResult()
{
setDlgShowSymbol(false);
return m_nRaidoBtnChoose;
}
bool MDialog::getForceQuitResult()
{
setDlgShowSymbol(false);
return m_bIsClickedForceQuitBtn;
}
void MDialog::setSecureTipWidgetShow(bool bChoose)
{
m_bNeedShowSecureTip = bChoose;
}
//************************************
// Method: ShowSureQuit
// Description: 只显示安全提示页面
// Author: xxxx
// Date: 2020/10/26
// Returns: void
//************************************
void MDialog::ShowSureQuit()
{
m_pForceCloseBtn->clicked(true);
}
void MDialog::setQuitLabel(QString str)
{
m_pQuitLabel->setText(str);
}
void MDialog::setDialogTitle(QString str)
{
m_pMainTitleLabel->setText(str);
}
void MDialog::init()
{
m_nRaidoBtnChoose = -1;
setDlgShowSymbol(true);
}
void MDialog::mQuit()
{
m_nRaidoBtnChoose = -1;
this->close();
}
bool MDialog::mIsShow()
{
return m_bIsExec;
}
//************************************
// Method: createListItemWidget
// Description: 整个函数是为了组合成listWidget的一行
// Author: xxx
// Date:2020/10/26
// Returns: ListWidget的每行内容
// Parameter: QString strLabelTitle:窗口标题
// Parameter: QString strLabelContent:窗口内容
//************************************
QWidget* MDialog::createListItemWidget(QString strLabelTitle, QString strLabelContent)
{
QWidget* container = new QWidget(this);
QHBoxLayout* pContainerLayout = new QHBoxLayout(container);
QVBoxLayout* pLabelLayout = new QVBoxLayout(container);
QHBoxLayout* pButtonLayout = new QHBoxLayout(container);
QRadioButton* pRBChoose = new QRadioButton(container);
m_pButtonGroup->addButton(pRBChoose, m_nButtonIndex);
pRBChoose->setIconSize(QSize(30, 30));
QLabel* pLabelTitle = new QLabel(container);
pLabelTitle->setText(strLabelTitle);
QFont ft(QString::fromLocal8Bit("微软雅黑"), 11, 3);
QPalette pa;
pa.setColor(QPalette::WindowText, QColor(66, 66, 66, 255));
pLabelTitle->setPalette(pa);
pLabelTitle->setFont(ft);
pLabelLayout->addWidget(pLabelTitle);
pButtonLayout->addWidget(pRBChoose);
pContainerLayout->addLayout(pButtonLayout, 1);
pContainerLayout->addLayout(pLabelLayout, 5);
container->setLayout(pContainerLayout);
m_nButtonIndex++;
return container;
}
//************************************
// Method: setButtonStyleSheet
// Description:按钮的样式
// Author:xxx
// Date:2020/10/26
// Returns: void
// Parameter: QPushButton * & pBtn
//************************************
void MDialog::setButtonStyleSheet(QPushButton*& pBtn)
{
QString strStyle = "";
if (pBtn->text() == QString::fromLocal8Bit("否") || pBtn->text() == QString::fromLocal8Bit("确认退出"))
{
strStyle = "QPushButton{/*font-family:Microsoft Yahei;*//*字体大小为20点*/font-size:12pt;/*字体颜色为白色*/color:white;/*背景颜色*/background-color:rgb(65, 127, 249);/*边框圆角半径为5像素*/border-radius:5px;height:30;/* 边框风格 */border-style:outset;/* 边框宽度 */border-w