2021-12-01 15:12:38 +08:00
|
|
|
#include "messageboxutils.h"
|
2023-04-12 12:16:30 +08:00
|
|
|
#include <QIcon>
|
|
|
|
#include <QScopedPointer>
|
2021-12-01 15:12:38 +08:00
|
|
|
#include "gsettingswrapper.h"
|
2022-02-15 16:51:03 +08:00
|
|
|
#include "../common/mydefine.h"
|
2022-03-02 11:24:54 +08:00
|
|
|
#include "globalsignals.h"
|
|
|
|
#include "globalbackupinfo.h"
|
2023-09-05 09:07:25 +08:00
|
|
|
#include <QPushButton>
|
2024-03-31 20:45:04 +08:00
|
|
|
#include <ukuistylehelper/ukuistylehelper.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <windowmanager/windowmanager.h>
|
2022-03-02 11:24:54 +08:00
|
|
|
MyMessageBox::MyMessageBox(QWidget *parent) :
|
|
|
|
QMessageBox(parent)
|
|
|
|
{
|
|
|
|
setThemeIcon(THEME_YHKYLIN_BACKUP_TOOLS);
|
2024-03-31 20:45:04 +08:00
|
|
|
kdk::UkuiStyleHelper::self()->removeHeader(this);
|
2022-03-02 11:24:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MyMessageBox::~MyMessageBox()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void MyMessageBox::setThemeIcon(const QString& themeIcon)
|
|
|
|
{
|
|
|
|
m_themeIcon = themeIcon;
|
|
|
|
on_themeIconChanged();
|
2023-03-17 17:59:26 +08:00
|
|
|
disconnect(GlobelBackupInfo::instance().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &MyMessageBox::on_themeIconChanged);
|
|
|
|
connect(GlobelBackupInfo::instance().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &MyMessageBox::on_themeIconChanged);
|
2022-03-02 11:24:54 +08:00
|
|
|
}
|
|
|
|
|
2022-08-25 17:19:32 +08:00
|
|
|
void MyMessageBox::setMsgIcon(QMessageBox::Icon icon) {
|
|
|
|
m_icon = icon;
|
|
|
|
on_iconChanged();
|
2023-03-17 17:59:26 +08:00
|
|
|
disconnect(GlobelBackupInfo::instance().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &MyMessageBox::on_iconChanged);
|
|
|
|
connect(GlobelBackupInfo::instance().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &MyMessageBox::on_iconChanged);
|
2022-08-25 17:19:32 +08:00
|
|
|
}
|
|
|
|
|
2022-03-02 11:24:54 +08:00
|
|
|
void MyMessageBox::on_themeIconChanged()
|
|
|
|
{
|
2022-06-29 17:34:08 +08:00
|
|
|
QIcon titleIcon = QIcon::fromTheme(m_themeIcon, QIcon(":/images/yhkylin-backup-tools.png"));
|
2022-03-02 11:24:54 +08:00
|
|
|
setWindowIcon(titleIcon);
|
|
|
|
}
|
|
|
|
|
2022-08-25 17:19:32 +08:00
|
|
|
void MyMessageBox::on_iconChanged()
|
|
|
|
{
|
|
|
|
setIcon(m_icon);
|
|
|
|
}
|
|
|
|
|
2022-02-15 16:51:03 +08:00
|
|
|
void MessageBoxUtils::QMESSAGE_BOX_INFORMATION(QWidget* q_parent, const QString& typelabel, const QString& message, const QString& label)
|
|
|
|
{
|
2023-04-12 12:16:30 +08:00
|
|
|
QScopedPointer<MyMessageBox> box(new MyMessageBox(q_parent));
|
2022-08-25 17:19:32 +08:00
|
|
|
box->setMsgIcon(QMessageBox::Information);
|
2022-04-18 17:26:52 +08:00
|
|
|
box->setWindowTitle(typelabel);
|
|
|
|
box->setText(message);
|
2023-09-05 09:07:25 +08:00
|
|
|
QPushButton * okbtn = box->addButton(label, QMessageBox::AcceptRole);
|
|
|
|
box->setDefaultButton(okbtn);
|
2024-03-31 20:45:04 +08:00
|
|
|
box->show();
|
2022-04-18 17:26:52 +08:00
|
|
|
box->exec();
|
2022-02-15 16:51:03 +08:00
|
|
|
}
|
|
|
|
|
2021-12-01 15:12:38 +08:00
|
|
|
void MessageBoxUtils::QMESSAGE_BOX_WARNING(QWidget* q_parent, const QString& typelabel, const QString& message, const QString& label)
|
|
|
|
{
|
2023-04-12 12:16:30 +08:00
|
|
|
QScopedPointer<MyMessageBox> box(new MyMessageBox(q_parent));
|
2022-08-25 17:19:32 +08:00
|
|
|
box->setMsgIcon(QMessageBox::Warning);
|
2022-04-18 17:26:52 +08:00
|
|
|
box->setWindowTitle(typelabel);
|
|
|
|
box->setText(message);
|
2023-09-05 09:07:25 +08:00
|
|
|
QPushButton * okbtn = box->addButton(label, QMessageBox::AcceptRole);
|
|
|
|
box->setDefaultButton(okbtn);
|
2022-04-18 17:26:52 +08:00
|
|
|
box->exec();
|
2021-12-01 15:12:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(QWidget *q_parent, const QString &typelabel, const QString &message, const QString &label_yes, const QString &label_no)
|
|
|
|
{
|
2023-04-12 12:16:30 +08:00
|
|
|
QScopedPointer<MyMessageBox> box(new MyMessageBox(q_parent));
|
2022-08-25 17:19:32 +08:00
|
|
|
box->setMsgIcon(QMessageBox::Question);
|
2022-04-18 17:26:52 +08:00
|
|
|
box->setWindowTitle(typelabel);
|
|
|
|
box->setText(message);
|
2023-09-05 09:07:25 +08:00
|
|
|
QPushButton * okbtn = box->addButton(label_yes, QMessageBox::AcceptRole);
|
|
|
|
box->addButton(label_no, QMessageBox::RejectRole);
|
|
|
|
box->setDefaultButton(okbtn);
|
|
|
|
box->exec();
|
|
|
|
if (box->clickedButton() != okbtn) {
|
2021-12-01 15:12:38 +08:00
|
|
|
return false;
|
2022-04-18 17:26:52 +08:00
|
|
|
}
|
|
|
|
|
2021-12-01 15:12:38 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageBoxUtils::QMESSAGE_BOX_CRITICAL(QWidget* q_parent, const QString& typelabel, const QString& message, const QString& label)
|
|
|
|
{
|
2023-04-12 12:16:30 +08:00
|
|
|
QScopedPointer<MyMessageBox> box(new MyMessageBox(q_parent));
|
2022-08-25 17:19:32 +08:00
|
|
|
box->setMsgIcon(QMessageBox::Critical);
|
2022-04-18 17:26:52 +08:00
|
|
|
box->setWindowTitle(typelabel);
|
|
|
|
box->setText(message);
|
2023-09-05 09:07:25 +08:00
|
|
|
QPushButton * okbtn = box->addButton(label, QMessageBox::AcceptRole);
|
|
|
|
box->setDefaultButton(okbtn);
|
2022-04-18 17:26:52 +08:00
|
|
|
box->exec();
|
2021-12-01 15:12:38 +08:00
|
|
|
}
|