1 Star 2 Fork 1

GXDE OS/garma

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gmessagebox.cpp 4.00 KB
一键复制 编辑 原始数据 按行查看 历史
gfdgd xi 提交于 2025-01-27 15:31 +08:00 . 进度窗口支持最小化
#include "gmessagebox.h"
#include "dapplication.h"
#include <QStyle>
#include <QPixmap>
#include <QLabel>
#include <QDebug>
DWIDGET_USE_NAMESPACE
GMessageBox::GMessageBox(QWidget *parent): DDialog(parent)
{
}
GMessageBox::GMessageBox(QWidget *parent,
const QString &title,
const QString &text): DDialog(parent)
{
this->setText(text);
this->setTitle(title);
}
GMessageBox::Icon GMessageBox::icon() const
{
return nowIcon;
}
void GMessageBox::setIcon(Icon icon)
{
enum QStyle::StandardPixmap dialogIcon;
nowIcon = icon;
switch(icon)
{
case Icon::NoIcon:
return;
case Icon::Critical:
dialogIcon = (enum QStyle::StandardPixmap)11;
break;
case Icon::Information:
dialogIcon = (enum QStyle::StandardPixmap)9;
break;
case Icon::Question:
dialogIcon = (enum QStyle::StandardPixmap)12;
break;
case Icon::Warning:
dialogIcon = (enum QStyle::StandardPixmap)10;
break;
}
// 获取设备像素比 (适配高分屏)
qreal scaleFactor = this->devicePixelRatioF();
int iconSize = static_cast<int>(64 * scaleFactor); // 基准大小为64px,根据比例调整
QPixmap pixmap = DApplication::style()->standardIcon(dialogIcon).pixmap(iconSize, iconSize);
pixmap.setDevicePixelRatio(scaleFactor); // 设置像素比以确保显示清晰
this->setIconPixmap(pixmap);
this->setWindowIcon(DApplication::style()->standardIcon(dialogIcon));
}
void GMessageBox::setStandardButtonsWithList(QList<StandardButtons> buttons)
{
QStringList buttonsList;
for(StandardButtons i: buttons) {
switch(i) {
case StandardButton::Ok:
buttonsList << tr("OK");
break;
case StandardButton::Save:
buttonsList << tr("Save");
break;
case StandardButton::SaveAll:
buttonsList << tr("Save All");
break;
case StandardButton::Open:
buttonsList << tr("Open");
break;
case StandardButton::Yes:
buttonsList << tr("Yes");
break;
case StandardButton::YesToAll:
buttonsList << tr("Yes To All");
break;
case StandardButton::No:
buttonsList << tr("No");
break;
case StandardButton::NoToAll:
buttonsList << tr("No To All");
break;
case StandardButton::Abort:
buttonsList << tr("Abort");
break;
case StandardButton::Retry:
buttonsList << tr("Retry");
break;
case StandardButton::Ignore:
buttonsList << tr("Ignore");
break;
case StandardButton::Close:
buttonsList << tr("Close");
break;
case StandardButton::Cancel:
buttonsList << tr("Cancel");
break;
case StandardButton::Discard:
buttonsList << tr("Discard");
break;
case StandardButton::Help:
buttonsList << tr("Help");
break;
case StandardButton::Apply:
buttonsList << tr("Apply");
break;
case StandardButton::Reset:
buttonsList << tr("Reset");
break;
case StandardButton::RestoreDefaults:
buttonsList << tr("Restore Defaults");
break;
}
}
for(int i = 0; i < buttonsList.count() - 1; ++i) {
this->addButton(buttonsList.at(i));
}
this->addButton(buttonsList.at(buttonsList.length() - 1), true, ButtonType::ButtonRecommend);
}
void GMessageBox::setText(const QString &text)
{
this->setWindowTitle(text);
QLabel *label = findChild<QLabel*>("MessageLabel");
if (label) {
qDebug() << "Find Label";
label->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
label->setAttribute(Qt::WA_TransparentForMouseEvents, false);
}
QString newText = text;
this->setMessage(newText.replace("\\n", "\n"));
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/GXDE-OS/garma.git
git@gitee.com:GXDE-OS/garma.git
GXDE-OS
garma
garma
master

搜索帮助