diff --git a/libimageviewer/viewpanel/contents/imgviewdelegate.cpp b/libimageviewer/viewpanel/contents/imgviewdelegate.cpp index 322a4cea..f6537d0f 100644 --- a/libimageviewer/viewpanel/contents/imgviewdelegate.cpp +++ b/libimageviewer/viewpanel/contents/imgviewdelegate.cpp @@ -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) @@ -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); } }); @@ -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; @@ -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))); @@ -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; @@ -155,7 +150,7 @@ void LibImgViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op pixmapstring = LOCMAP_NOT_SELECTED_LIGHT; } -// 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); @@ -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 { Q_UNUSED(option) return index.data(Qt::SizeHintRole).value(); @@ -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, + QAbstractItemModel *model, + const QStyleOptionViewItem &option, + const QModelIndex &index) { Q_UNUSED(option); Q_UNUSED(event); diff --git a/libimageviewer/widgets/renamedialog.cpp b/libimageviewer/widgets/renamedialog.cpp index 7ff26cb2..97418fff 100644 --- a/libimageviewer/widgets/renamedialog.cpp +++ b/libimageviewer/widgets/renamedialog.cpp @@ -7,7 +7,7 @@ #include "unionimage/imageutils.h" #include "accessibility/ac-desktop-define.h" - +#include #include #include #include @@ -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(); @@ -38,7 +38,7 @@ 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); @@ -46,25 +46,25 @@ RenameDialog::RenameDialog(const QString &filename, QWidget *parent) 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); @@ -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; } @@ -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 { @@ -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() { @@ -180,7 +176,7 @@ void RenameDialog::InitDlg() m_filename = fileinfo.fileName(); QString format = fileinfo.suffix(); QString 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); @@ -204,7 +200,6 @@ void RenameDialog::setCurrentTip() okbtn->setEnabled(true); m_lineedt->hideAlertMessage(); } - } void RenameDialog::paintEvent(QPaintEvent *event) @@ -212,7 +207,6 @@ void RenameDialog::paintEvent(QPaintEvent *event) QWidget::paintEvent(event); } - QString RenameDialog::geteElidedText(QFont font, QString str, int MaxWidth) { QFontMetrics fontWidth(font); @@ -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() { diff --git a/libimageviewer/widgets/renamedialog.h b/libimageviewer/widgets/renamedialog.h index 48cd79a2..ad71d4d4 100644 --- a/libimageviewer/widgets/renamedialog.h +++ b/libimageviewer/widgets/renamedialog.h @@ -13,6 +13,7 @@ #include #include #include +#include DWIDGET_USE_NAMESPACE class RenameDialog : public DDialog @@ -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: