yhkylin-backup-tools/kybackup/messageboxutils.cpp

80 lines
2.5 KiB
C++
Executable File

#include "messageboxutils.h"
#include "gsettingswrapper.h"
#include "../common/mydefine.h"
#include "globalsignals.h"
#include "globalbackupinfo.h"
#include <QIcon>
MyMessageBox::MyMessageBox(QWidget *parent) :
QMessageBox(parent)
{
setThemeIcon(THEME_YHKYLIN_BACKUP_TOOLS);
}
MyMessageBox::~MyMessageBox()
{}
void MyMessageBox::setThemeIcon(const QString& themeIcon)
{
m_themeIcon = themeIcon;
on_themeIconChanged();
disconnect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &MyMessageBox::on_themeIconChanged);
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &MyMessageBox::on_themeIconChanged);
}
void MyMessageBox::on_themeIconChanged()
{
QIcon titleIcon = QIcon::fromTheme(m_themeIcon);
setWindowIcon(titleIcon);
}
void MessageBoxUtils::QMESSAGE_BOX_INFORMATION(QWidget* q_parent, const QString& typelabel, const QString& message, const QString& label)
{
MyMessageBox box(q_parent);
box.setIcon(QMessageBox::Information);
box.setWindowTitle(typelabel);
box.setText(message);
box.setStandardButtons(QMessageBox::Ok);
box.setButtonText(QMessageBox::Ok, label);
box.exec();
}
void MessageBoxUtils::QMESSAGE_BOX_WARNING(QWidget* q_parent, const QString& typelabel, const QString& message, const QString& label)
{
MyMessageBox box(q_parent);
box.setIcon(QMessageBox::Warning);
box.setWindowTitle(typelabel);
box.setText(message);
box.setStandardButtons(QMessageBox::Ok);
box.setButtonText(QMessageBox::Ok, label);
box.exec();
}
bool MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(QWidget *q_parent, const QString &typelabel, const QString &message, const QString &label_yes, const QString &label_no)
{
MyMessageBox box(q_parent);
box.setIcon(QMessageBox::Question);
box.setWindowTitle(typelabel);
box.setText(message);
box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
box.setButtonText(QMessageBox::Ok, label_yes);
box.setButtonText(QMessageBox::Cancel, label_no);
if (box.exec() != QMessageBox::Ok)
return false;
return true;
}
void MessageBoxUtils::QMESSAGE_BOX_CRITICAL(QWidget* q_parent, const QString& typelabel, const QString& message, const QString& label)
{
MyMessageBox box(q_parent);
box.setIcon(QMessageBox::Critical);
box.setWindowTitle(typelabel);
box.setText(message);
box.setStandardButtons(QMessageBox::Ok);
box.setButtonText(QMessageBox::Ok, label);
box.exec();
}