Commit d964b52f by NitefullWind

1. 修改消息框类,实现问题框。

parent 86b307be
......@@ -15,5 +15,6 @@
<file>img/tip_ok.png</file>
<file>img/tip_warning.png</file>
<file>img/num_del.png</file>
<file>img/tip_question.png</file>
</qresource>
</RCC>
#include "fmmsgwnd.h"
#include "ui_fmmsgwnd.h"
#include <QPushButton>
#include <QDebug>
FMMsgWnd::FMMsgWnd(QDialog *parent) :
......@@ -10,6 +11,8 @@ FMMsgWnd::FMMsgWnd(QDialog *parent) :
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_QuitOnClose, false);
this->setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &FMMsgWnd::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &FMMsgWnd::reject);
}
FMMsgWnd::~FMMsgWnd()
......@@ -17,8 +20,9 @@ FMMsgWnd::~FMMsgWnd()
delete ui;
}
void FMMsgWnd::show(InfoType type, const QString &info)
int FMMsgWnd::_exec(InfoType type, const QString &info)
{
ui->buttonBox->addButton(QString::fromLocal8Bit("确认"), QDialogButtonBox::AcceptRole);
QString iconUrl;
switch (type) {
case T_Normal:
......@@ -37,17 +41,34 @@ void FMMsgWnd::show(InfoType type, const QString &info)
ui->label_msg->setText(QString::fromLocal8Bit("会员认证成功"));
iconUrl = ":/img/tip_ok.png";
break;
case T_Question:
{
ui->buttonBox->addButton(QString::fromLocal8Bit("取消"), QDialogButtonBox::RejectRole);
iconUrl = ":/img/tip_question.png";
break;
}
default:
iconUrl = "";
break;
}
int btnWidth = ui->widget->width()/ui->buttonBox->buttons().size();
foreach (auto btn, ui->buttonBox->buttons()) {
QString styleSheet = QString("min-width: %1; min-height: 60;").arg(btnWidth);
if(ui->buttonBox->buttonRole(btn) == QDialogButtonBox::RejectRole) {
styleSheet.append("background-color: rgb(134, 134, 134);");
}
qDebug() << styleSheet;
btn->setStyleSheet(styleSheet);
}
if(iconUrl != ""){
ui->label_logo->setStyleSheet(QString("border-image: url(%1);").arg(iconUrl));
}
ui->label_msg->setText(info);
QDialog::exec();
return QDialog::exec();
}
void FMMsgWnd::FailureWnd(const QString &info, QDialog *parent)
......@@ -56,7 +77,7 @@ void FMMsgWnd::FailureWnd(const QString &info, QDialog *parent)
if(parent != nullptr) {
window.setGeometry(parent->geometry());
}
window.show(FMMsgWnd::T_Failure, info);
window._exec(FMMsgWnd::T_Failure, info);
}
void FMMsgWnd::WarningWnd(const QString &info, QDialog *parent)
{
......@@ -64,7 +85,7 @@ void FMMsgWnd::WarningWnd(const QString &info, QDialog *parent)
if(parent != nullptr) {
window.setGeometry(parent->geometry());
}
window.show(FMMsgWnd::T_Warning, info);
window._exec(FMMsgWnd::T_Warning, info);
}
void FMMsgWnd::SuccessWnd(const QString &info, QDialog *parent)
{
......@@ -72,7 +93,7 @@ void FMMsgWnd::SuccessWnd(const QString &info, QDialog *parent)
if(parent != nullptr) {
window.setGeometry(parent->geometry());
}
window.show(FMMsgWnd::T_Success, info);
window._exec(FMMsgWnd::T_Success, info);
}
void FMMsgWnd::LoginSuccess(const QString &account, const QString &name, const QString &birthday, QDialog *parent)
......@@ -82,10 +103,14 @@ void FMMsgWnd::LoginSuccess(const QString &account, const QString &name, const Q
window.setGeometry(parent->geometry());
}
QString info = QString::fromLocal8Bit("账号:%1\n姓名:%2\n生日:%3").arg(account).arg(name).arg(birthday);
window.show(FMMsgWnd::T_LoginSuccess, info);
window._exec(FMMsgWnd::T_LoginSuccess, info);
}
void FMMsgWnd::on_btn_confirm_clicked()
int FMMsgWnd::Question(const QString &info, QDialog *parent)
{
this->accept();
FMMsgWnd window(parent);
if(parent != nullptr) {
window.setGeometry(parent->geometry());
}
return window._exec(FMMsgWnd::T_Question, info);
}
......@@ -21,17 +21,16 @@ public:
T_Success,
T_Failure,
T_Warning,
T_LoginSuccess
T_LoginSuccess,
T_Question
};
void show(InfoType type = T_Normal, const QString &info = "");
int _exec(InfoType type = T_Normal, const QString &info = "");
static void FailureWnd(const QString &info, QDialog *parent=0);
static void WarningWnd(const QString &info, QDialog *parent=0);
static void SuccessWnd(const QString &info, QDialog *parent=0);
static void LoginSuccess(const QString &account, const QString &name, const QString &birthday, QDialog *parent=0);
private slots:
void on_btn_confirm_clicked();
static int Question(const QString &info, QDialog *parent=0);
private:
Ui::FMMsgWnd *ui;
......
......@@ -98,7 +98,7 @@
<property name="styleSheet">
<string notr="true">#widget
{
background-color: rgb(255, 255, 255);
background-color: rgb(245, 245, 245);
border-radius:8px;
opacity:0;
}</string>
......@@ -258,38 +258,28 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn_confirm">
<property name="minimumSize">
<size>
<width>121</width>
<height>62</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>62</height>
</size>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="styleSheet">
<string notr="true">#btn_confirm
<string notr="true">QPushButton
{
font: 75 16pt &quot;微软雅黑&quot;;
border-bottom-right-radius: 8px;
border-bottom-left-radius: 8px;
border-radius: 8px;
background-color: rgb(93, 144, 236);
color: rgb(255, 255, 255);
}</string>
</property>
<property name="text">
<string>确认</string>
<property name="standardButtons">
<set>QDialogButtonBox::NoButton</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
<zorder>verticalSpacer</zorder>
<zorder>verticalSpacer_2</zorder>
<zorder>btn_confirm</zorder>
<zorder>buttonBox</zorder>
</widget>
</item>
<item>
......
......@@ -31,6 +31,8 @@ private:
private slots:
void test_dotask_data();
void test_dotask();
void test_msgWnd();
};
TestPlugin::TestPlugin()
......@@ -151,6 +153,12 @@ void TestPlugin::test_Sign()
QCOMPARE(FMTask::Sign(jsonObj1), SignStr);
}
void TestPlugin::test_msgWnd()
{
FMMsgWnd::SuccessWnd("Success!");
FMMsgWnd::Question("确认吗?");
}
QTEST_MAIN(TestPlugin)
#include "tst_testplugin.moc"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment