Skip to content

Commit

Permalink
fix: 修改了重命名窗口的文件名后缀颜色
Browse files Browse the repository at this point in the history
修改了重命名窗口的文件名后缀颜色,添加了其主题变更的颜色变化

Log: 修复了深色模式下重命名弹窗文字看不清的问题
Bug: https://pms.uniontech.com/bug-view-231485.html
  • Loading branch information
lJxDabab authored and rb-union committed Jan 12, 2024
1 parent 3f0608c commit 5dc3e9c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 79 deletions.
67 changes: 32 additions & 35 deletions libimageviewer/viewpanel/contents/imgviewdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ namespace {
const QString IMAGE_DEFAULTTYPE = "All pics";
}

//const int NotSupportedOrDamagedWidth = 40; //损坏图片宽度
//const int NotSupportedOrDamagedHeigh = 40;
// const int NotSupportedOrDamagedWidth = 40; //损坏图片宽度
// const int NotSupportedOrDamagedHeigh = 40;
const QString LOCMAP_SELECTED_DARK = ":/dark/images/58 drak.svg";
const QString LOCMAP_NOT_SELECTED_DARK = ":/dark/images/imagewithbg-dark.svg";
const QString LOCMAP_SELECTED_LIGHT = ":/light/images/58.svg";
const QString LOCMAP_NOT_SELECTED_LIGHT = ":/light/images/imagewithbg.svg";

//const QString DAMAGE_IMAGE_DARK_PICTURE = ":/dark/images/picture damaged_dark.svg";
//const QString DAMAGE_IMAGE_LIGHT_PICTURE = ":/light/images/picture damaged_light.svg";
// const QString DAMAGE_IMAGE_DARK_PICTURE = ":/dark/images/picture damaged_dark.svg";
// const QString DAMAGE_IMAGE_LIGHT_PICTURE = ":/light/images/picture damaged_light.svg";
const QString DAMAGE_IMAGE_DARK_PICTURE = ":/dark/images/picture_damaged-58_drak.svg";
const QString DAMAGE_IMAGE_LIGHT_PICTURE = ":/light/images/picture_damaged_58.svg";

const int NORMAL_ITEM_PAINT_OFFSET = 10;//绘制时普通项向下偏移大小
const int SELECT_ITEM_PAINT_OFFSET = 2;//绘制时选中项向下偏移大小
const int NORMAL_ITEM_PAINT_OFFSET = 10; //绘制时普通项向下偏移大小
const int SELECT_ITEM_PAINT_OFFSET = 2; //绘制时选中项向下偏移大小

LibImgViewDelegate::LibImgViewDelegate(QObject *parent)
: QStyledItemDelegate(parent)
Expand All @@ -49,13 +49,10 @@ LibImgViewDelegate::LibImgViewDelegate(QObject *parent)
} else {
m_damageImage = QImage(DAMAGE_IMAGE_DARK_PICTURE);
}
QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged,
this, [ = ] {
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
{
QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [=] {
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
m_damageImage = QImage(DAMAGE_IMAGE_LIGHT_PICTURE);
} else
{
} else {
m_damageImage = QImage(DAMAGE_IMAGE_DARK_PICTURE);
}
});
Expand All @@ -64,14 +61,14 @@ LibImgViewDelegate::LibImgViewDelegate(QObject *parent)
void LibImgViewDelegate::setItemSize(QSize size)
{
Q_UNUSED(size);
// m_size = size;
// m_size = size;
}
#include "service/imagedataservice.h"
void LibImgViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
// QRect backgroundRect2 = option.rect;
// painter->fillRect(backgroundRect2, QBrush(DGuiApplicationHelper::instance()->applicationPalette().highlight().color()));
// return ;
// QRect backgroundRect2 = option.rect;
// painter->fillRect(backgroundRect2, QBrush(DGuiApplicationHelper::instance()->applicationPalette().highlight().color()));
// return ;
painter->save();
QString pixmapstring;
QImage _pixmap;
Expand All @@ -81,19 +78,17 @@ void LibImgViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
return;
}
_pixmap = data.image;
// _pixmap = ImageDataService::instance()->getThumnailImageByPath(data.path);
// _pixmap = ImageDataService::instance()->getThumnailImageByPath(data.path);
if (_pixmap.isNull()) {
// _pixmap = data.damagedPixmap;
// _pixmap = data.damagedPixmap;
_pixmap = m_damageImage;
}
// bool selected = data.isSelected;
// if (/*(option.state & QStyle::State_MouseOver) &&*/
// (option.state & QStyle::State_Selected) != 0) {
// selected = true;
// }
painter->setRenderHints(QPainter::HighQualityAntialiasing |
QPainter::SmoothPixmapTransform |
QPainter::Antialiasing);
// bool selected = data.isSelected;
// if (/*(option.state & QStyle::State_MouseOver) &&*/
// (option.state & QStyle::State_Selected) != 0) {
// selected = true;
// }
painter->setRenderHints(QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform | QPainter::Antialiasing);
QRect backgroundRect = option.rect;
if (backgroundRect.width() != LibImgViewListView::ITEM_CURRENT_WH) {
backgroundRect.setTopLeft(QPoint(backgroundRect.topLeft() + QPoint(0, NORMAL_ITEM_PAINT_OFFSET)));
Expand All @@ -103,7 +98,7 @@ void LibImgViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
backgroundRect.setBottomRight(QPoint(backgroundRect.bottomRight() + QPoint(0, SELECT_ITEM_PAINT_OFFSET)));
}
QRect pixmapRect;
QBrush backbrush;
QBrush backbrush;
//当前显示项
if (backgroundRect.width() == LibImgViewListView::ITEM_CURRENT_WH) {
QPainterPath backgroundBp;
Expand Down Expand Up @@ -155,7 +150,7 @@ void LibImgViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
pixmapstring = LOCMAP_NOT_SELECTED_LIGHT;

Check warning on line 150 in libimageviewer/viewpanel/contents/imgviewdelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'pixmapstring' is assigned a value that is never used.
}

// QPixmap pixmap = utils::base::renderSVG(pixmapstring, QSize(32, 40));
// QPixmap pixmap = utils::base::renderSVG(pixmapstring, QSize(32, 40));
QPainterPath bg;
bg.addRoundedRect(pixmapRect, 4, 4);
painter->setClipPath(bg);
Expand All @@ -164,16 +159,15 @@ void LibImgViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
QPainterPath bp1;
bp1.addRoundedRect(pixmapRect, 4, 4);
painter->setClipPath(bp1);
_pixmap=_pixmap.scaled(pixmapRect.size(),Qt::KeepAspectRatioByExpanding,Qt::SmoothTransformation);
qreal adjustx=_pixmap.width()-pixmapRect.width();
qreal adjusty=_pixmap.height()-pixmapRect.height();
painter->drawImage(pixmapRect,_pixmap,_pixmap.rect().adjusted(adjustx/2,-adjusty/2,-adjustx/2,adjusty/2));
_pixmap = _pixmap.scaled(pixmapRect.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
qreal adjustx = _pixmap.width() - pixmapRect.width();
qreal adjusty = _pixmap.height() - pixmapRect.height();
painter->drawImage(pixmapRect, _pixmap, _pixmap.rect().adjusted(adjustx / 2, -adjusty / 2, -adjustx / 2, adjusty / 2));

painter->restore();
}

QSize LibImgViewDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
QSize LibImgViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const

Check warning on line 170 in libimageviewer/viewpanel/contents/imgviewdelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'sizeHint' is never used.
{
Q_UNUSED(option)
return index.data(Qt::SizeHintRole).value<QSize>();
Expand All @@ -186,7 +180,10 @@ imageViewerSpace::ItemInfo LibImgViewDelegate::itemData(const QModelIndex &index
return data;
}

bool LibImgViewDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
bool LibImgViewDelegate::editorEvent(QEvent *event,

Check warning on line 183 in libimageviewer/viewpanel/contents/imgviewdelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'editorEvent' is never used.
QAbstractItemModel *model,
const QStyleOptionViewItem &option,
const QModelIndex &index)
{
Q_UNUSED(option);
Q_UNUSED(event);
Expand Down
94 changes: 50 additions & 44 deletions libimageviewer/widgets/renamedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "unionimage/imageutils.h"

#include "accessibility/ac-desktop-define.h"

#include <DGuiApplicationHelper>
#include <DMessageBox>
#include <DLabel>
#include <DFontSizeManager>
Expand All @@ -26,8 +26,8 @@ RenameDialog::RenameDialog(const QString &filename, QWidget *parent)
{
this->setIcon(QIcon::fromTheme("deepin-image-viewer"));
DWidget *widet = new DWidget(this);
this->setContentsMargins(0,0,0,0);
layout()->setSpacing(0); // 标题栏和内容部件间隙设为0,在视觉上缩短标题栏间隙
this->setContentsMargins(0, 0, 0, 0);
layout()->setSpacing(0); // 标题栏和内容部件间隙设为0,在视觉上缩短标题栏间隙
addContent(widet);
m_vlayout = new QVBoxLayout(widet);
m_labvlayout = new QVBoxLayout();
Expand All @@ -38,33 +38,33 @@ RenameDialog::RenameDialog(const QString &filename, QWidget *parent)
m_lineedt = new DLineEdit(widet);
QFrame *line = new QFrame(widet);
line->setLineWidth(2);
line->setFixedHeight(25);// 垂直分割线短于按钮高度
line->setFixedHeight(25); // 垂直分割线短于按钮高度
QLbtoDLabel *labtitle = new QLbtoDLabel();
okbtn = new DSuggestButton(tr("Confirm"), widet);
cancelbtn = new DPushButton(tr("Cancel"), widet);
okbtn->setFixedHeight(35);
cancelbtn->setFixedHeight(35);
m_labformat = new DLabel(widet);
m_vlayout->setContentsMargins(2, 0, 2, 1);
// okbtn->setText();
// cancelbtn->setText();
// okbtn->setText();
// cancelbtn->setText();
m_hlayout->addWidget(cancelbtn);
line->setFrameShape(QFrame::VLine);
line->setFrameShadow(QFrame::Plain); // 垂直分割线颜色应为浅灰
line->setFrameShadow(QFrame::Plain); // 垂直分割线颜色应为浅灰
m_hlayout->addWidget(line);
m_hlayout->addWidget(okbtn);
m_hlayout->setSpacing(7);// 保证按钮间距20px
m_hlayout->setSpacing(7); // 保证按钮间距20px
labtitle->setText(tr("Input a new name"));
labtitle->setFixedHeight(40); //增加标签区域显示高度,在视觉上缩短标题栏间隙
labtitle->setFixedHeight(40); //增加标签区域显示高度,在视觉上缩短标题栏间隙
labtitle->setAlignment(Qt::AlignCenter);
m_labvlayout->addWidget(labtitle);
// m_vlayout->addWidget(labtitle);
// m_vlayout->addStretch();
// m_vlayout->addWidget(labtitle);
// m_vlayout->addStretch();

m_edtlayout->addWidget(m_lineedt);
m_lineedt->setFixedHeight(35);

// connect(m_lineedt, &DLineEdit::focusChanged, this, &RenameDialog::slotsFocusChanged);
// connect(m_lineedt, &DLineEdit::focusChanged, this, &RenameDialog::slotsFocusChanged);

m_labformat->setEnabled(false);
m_edtlayout->addWidget(m_labformat);
Expand All @@ -73,39 +73,36 @@ RenameDialog::RenameDialog(const QString &filename, QWidget *parent)
m_vlayout->addLayout(m_labvlayout);
m_vlayout->addStretch();


m_vlayout->addLayout(m_hlayout);
// m_vlayout->setStretch(0, 5);
// m_vlayout->setStretch(1, 1);
// m_vlayout->setStretch(2, 1);
// m_vlayout->setStretch(3, 1);
// m_vlayout->setStretch(0, 5);
// m_vlayout->setStretch(1, 1);
// m_vlayout->setStretch(2, 1);
// m_vlayout->setStretch(3, 1);
widet->setLayout(m_vlayout);
// onThemeChanged(dApp->viewerTheme->getCurrentTheme());
// onThemeChanged(dApp->viewerTheme->getCurrentTheme());
onThemeChanged(DGuiApplicationHelper::instance()->themeType());
InitDlg();
m_lineedt->lineEdit()->setFocus();
int Dirlen = /*m_DirPath.size() +*/ 1 + m_labformat->text().size();
//正则表达式排除文管不支持的字符
QRegExp rx("^[^\\.\\\\/\':\\*\\?\"<>|%&][^\\\\/\':\\*\\?\"<>|%&]*"); //屏蔽特殊字符
// QRegExp rx("[^\\\\//:*?\"<>|]*");
QRegExp rx("^[^\\.\\\\/\':\\*\\?\"<>|%&][^\\\\/\':\\*\\?\"<>|%&]*"); //屏蔽特殊字符
// QRegExp rx("[^\\\\//:*?\"<>|]*");
QRegExpValidator *pReg = new QRegExpValidator(rx, this);
m_lineedt->lineEdit()->setValidator(pReg);
connect(okbtn, &DSuggestButton::clicked, this, [ = ] {
connect(okbtn, &DSuggestButton::clicked, this, [=] {
m_filename = m_lineedt->text() + m_labformat->text();
m_filenamepath = m_DirPath + "/" + m_filename;
accept();
});
connect(cancelbtn, &DPushButton::clicked, this, [ = ] {
reject();
});

connect(m_lineedt, &DLineEdit::textChanged, this, [ = ](const QString & arg) {
connect(cancelbtn, &DPushButton::clicked, this, [=] { reject(); });
connect(m_lineedt, &DLineEdit::textChanged, this, [=](const QString &arg) {
setCurrentTip();
int len = arg.toLocal8Bit().length();
//修复字符串长度超长会将
if (len > 256 - Dirlen) return;

if (len > 256 - Dirlen)
return;
});
connect(m_lineedt, &DLineEdit::textEdited, this, [ = ](const QString & arg) {
connect(m_lineedt, &DLineEdit::textEdited, this, [=](const QString &arg) {
if (arg.isEmpty()) {
return;
}
Expand All @@ -124,7 +121,8 @@ RenameDialog::RenameDialog(const QString &filename, QWidget *parent)
for (; i < arg.size(); i++) {
if (arg.at(i) >= 0x4e00 && arg.at(i) <= 0x9fa5) {
num += 3;
if (num >= 256 - Dirlen - 1) break;
if (num >= 256 - Dirlen - 1)
break;
} else if (num < 256 - Dirlen) {
num += 1;
} else {
Expand All @@ -150,18 +148,16 @@ RenameDialog::RenameDialog(const QString &filename, QWidget *parent)
setFixedSize(380, 190);
}


//void RenameDialog::onThemeChanged(ViewerThemeManager::AppTheme theme)
// void RenameDialog::onThemeChanged(ViewerThemeManager::AppTheme theme)
//{
// QPalette pe;
// if (theme == ViewerThemeManager::Dark) {
// pe.setColor(QPalette::WindowText, Qt::darkGray);
// } else {
// pe.setColor(QPalette::WindowText, Qt::lightGray);
// }
// m_labformat->setPalette(pe);
//}

// QPalette pe;
// if (theme == ViewerThemeManager::Dark) {
// pe.setColor(QPalette::WindowText, Qt::darkGray);
// } else {
// pe.setColor(QPalette::WindowText, Qt::lightGray);
// }
// m_labformat->setPalette(pe);
// }

QString RenameDialog::GetFilePath()
{
Expand All @@ -180,7 +176,7 @@ void RenameDialog::InitDlg()
m_filename = fileinfo.fileName();
QString format = fileinfo.suffix();
QString basename;

Check warning on line 178 in libimageviewer/widgets/renamedialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Unused variable: basename
//basename会过滤掉.,那么1.....png就会出现basename为1,completeBaseName不会,修改bug66356
// basename会过滤掉.,那么1.....png就会出现basename为1,completeBaseName不会,修改bug66356
m_basename = fileinfo.completeBaseName();
m_lineedt->setText(m_basename);
m_labformat->setText("." + format);
Expand All @@ -204,15 +200,13 @@ void RenameDialog::setCurrentTip()
okbtn->setEnabled(true);
m_lineedt->hideAlertMessage();
}

}

void RenameDialog::paintEvent(QPaintEvent *event)
{
QWidget::paintEvent(event);
}


QString RenameDialog::geteElidedText(QFont font, QString str, int MaxWidth)
{
QFontMetrics fontWidth(font);
Expand All @@ -229,6 +223,18 @@ void RenameDialog::slotsFocusChanged(bool onFocus)
m_lineedt->hideAlertMessage();
}
}
void RenameDialog::onThemeChanged(DGuiApplicationHelper::ColorType theme)
{
QPalette palette;
QColor color;
if (theme == DGuiApplicationHelper::ColorType::DarkType) {
color = QColor(179, 179, 179);
} else {
color = QColor(77, 77, 77);
}
palette.setColor(QPalette::WindowText, color);
m_labformat->setPalette(palette);
}

void RenameDialog::slotsUpdate()
{
Expand Down
2 changes: 2 additions & 0 deletions libimageviewer/widgets/renamedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <DPushButton>
#include <DSuggestButton>
#include <DLabel>
#include <DGuiApplicationHelper>

DWIDGET_USE_NAMESPACE
class RenameDialog : public DDialog
Expand All @@ -32,6 +33,7 @@ class RenameDialog : public DDialog
QString geteElidedText(QFont font, QString str, int MaxWidth);
private slots:
void slotsFocusChanged(bool onFocus);
void onThemeChanged(DGuiApplicationHelper::ColorType theme);
public:
void slotsUpdate();
protected:
Expand Down

0 comments on commit 5dc3e9c

Please sign in to comment.