Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Disable action using enhance image instead of source. #106

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 71 additions & 6 deletions libimageviewer/viewpanel/contents/aienhancefloatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <QVBoxLayout>

#include <DAnchors>
#include <DGuiApplicationHelper>
#include <DPaletteHelper>

const int FLOAT_WDITH = 72;
const int FLOAT_HEIGHT = 122; // 172, 移除保存按钮
Expand All @@ -32,20 +34,38 @@ AIEnhanceFloatWidget::AIEnhanceFloatWidget(QWidget *parent)
anchor->setRightMargin(FLOAT_RIGHT_MARGIN);
}
}

onThemeChanged();
connect(
DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &AIEnhanceFloatWidget::onThemeChanged);
}

void AIEnhanceFloatWidget::initButtton()
{
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setAlignment(Qt::AlignCenter);
mainLayout->setSpacing(10);
QVBoxLayout *backLayout = new QVBoxLayout(this);
backLayout->setSpacing(0);
backLayout->setContentsMargins(0, 0, 0, 0);

bkgBlur = new DBlurEffectWidget(this);
bkgBlur->setBlurRectXRadius(18);
bkgBlur->setBlurRectYRadius(18);
bkgBlur->setRadius(30);
bkgBlur->setBlurEnabled(true);
bkgBlur->setMode(DBlurEffectWidget::GaussianBlur);
QColor maskColor(255, 255, 255, 76);
bkgBlur->setMaskColor(maskColor);
backLayout->addWidget(bkgBlur);

QVBoxLayout *ctxLayout = new QVBoxLayout(bkgBlur);
ctxLayout->setAlignment(Qt::AlignCenter);
ctxLayout->setSpacing(10);

resetBtn = new DIconButton(this);
resetBtn->setFixedSize(FLOAT_BTN_SIZE);
resetBtn->setIcon(QIcon::fromTheme("dcc_reset"));
resetBtn->setIconSize(FLOAT_ICON_SIZE);
resetBtn->setToolTip(tr("Reprovision"));
mainLayout->addWidget(resetBtn);
ctxLayout->addWidget(resetBtn);
connect(resetBtn, &DIconButton::clicked, this, &AIEnhanceFloatWidget::reset);

// 屏蔽Save按钮
Expand All @@ -64,8 +84,53 @@ void AIEnhanceFloatWidget::initButtton()
saveAsBtn->setIcon(QIcon::fromTheme("dcc_file_save_as"));
saveAsBtn->setIconSize(FLOAT_ICON_SIZE);
saveAsBtn->setToolTip(tr("Save as"));
mainLayout->addWidget(saveAsBtn);
ctxLayout->addWidget(saveAsBtn);
connect(saveAsBtn, &DIconButton::clicked, this, &AIEnhanceFloatWidget::saveAs);

setLayout(mainLayout);
setLayout(ctxLayout);
}

/**
@brief 按主题更新界面,使得图像增强侧边栏和底栏效果一致
*/
void AIEnhanceFloatWidget::onThemeChanged()
{
auto themeType = DGuiApplicationHelper::instance()->themeType();
if (DGuiApplicationHelper::LightType == themeType) {
QColor maskColor(247, 247, 247);
maskColor.setAlphaF(0.15);
bkgBlur->setMaskColor(maskColor);

DPalette pa;
pa = resetBtn->palette();
pa.setColor(DPalette::Light, QColor("#FFFFFF"));
pa.setColor(DPalette::Dark, QColor("#FFFFFF"));
// 单个按钮边框
QColor btnframecolor("#000000");
btnframecolor.setAlphaF(0.00);
pa.setColor(DPalette::FrameBorder, btnframecolor);
// 取消阴影
pa.setColor(DPalette::Shadow, btnframecolor);

DPaletteHelper::instance()->setPalette(resetBtn, pa);
DPaletteHelper::instance()->setPalette(saveAsBtn, pa);
} else {
QColor maskColor("#202020");
maskColor.setAlphaF(0.50);
bkgBlur->setMaskColor(maskColor);

DPalette pa;
pa = resetBtn->palette();
pa.setColor(DPalette::Light, QColor("#303030"));
pa.setColor(DPalette::Dark, QColor("#303030"));
// 单个按钮边框
QColor btnframecolor("#000000");
btnframecolor.setAlphaF(0.30);
pa.setColor(DPalette::FrameBorder, btnframecolor);
// 取消阴影
pa.setColor(DPalette::Shadow, btnframecolor);

DPaletteHelper::instance()->setPalette(resetBtn, pa);
DPaletteHelper::instance()->setPalette(saveAsBtn, pa);
}
}
3 changes: 3 additions & 0 deletions libimageviewer/viewpanel/contents/aienhancefloatwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <DFloatingWidget>
#include <DIconButton>
#include <DBlurEffectWidget>

DWIDGET_USE_NAMESPACE

Expand All @@ -22,8 +23,10 @@ class AIEnhanceFloatWidget : public DFloatingWidget

private:
void initButtton();
Q_SLOT void onThemeChanged();

private:
DBlurEffectWidget *bkgBlur = nullptr;
DIconButton *resetBtn = nullptr;
DIconButton *saveBtn = nullptr;
DIconButton *saveAsBtn = nullptr;
Expand Down
20 changes: 15 additions & 5 deletions libimageviewer/viewpanel/viewpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,9 @@ void LibViewPanel::updateMenuContent(const QString &path)
currentPath = m_currentPath;
}

if (AIModelService::instance()->isTemporaryFile(m_currentPath)) {
// AI增强图片特殊处理,部分选项屏蔽
bool enhanceImage = AIModelService::instance()->isTemporaryFile(m_currentPath);
if (enhanceImage) {
currentPath = m_currentPath;
}

Expand Down Expand Up @@ -527,7 +529,7 @@ void LibViewPanel::updateMenuContent(const QString &path)
//如果图片数量大于0才能有幻灯片
appendAction(IdStartSlideShow, QObject::tr("Slide show"), ss("Slide show", "F5"));
//添加到相册
if (isAlbum && isReadable) {
if (isAlbum && isReadable && !enhanceImage) {
//这行代码是在向调用程序寻求album name,根据前面的connect,这里会采用回调的形式执行
emit ImageEngine::instance()->sigGetAlbumName(ItemInfo.path);
m_menu->addSeparator();
Expand Down Expand Up @@ -574,10 +576,18 @@ void LibViewPanel::updateMenuContent(const QString &path)
}
m_menu->addSeparator();

// 处理收藏按钮,AI修图的增强图片不允许点击
if (isAlbum) {
DIconButton *Collection = m_bottomToolbar->getBottomtoolbarButton(imageViewerSpace::ButtonTypeCollection);
if (Collection) {
Collection->setEnabled(!enhanceImage);
}
}

// 添加AI模型选项,仅处理静态图
addAIMenu();

if (isAlbum && isReadable) {
if (isAlbum && isReadable && !enhanceImage) {
appendAction(IdExport, tr("Export"), ss("Export", "Ctrl+E")); //导出
}
if (isReadable) {
Expand Down Expand Up @@ -612,12 +622,12 @@ void LibViewPanel::updateMenuContent(const QString &path)
TrashButton->setEnabled(false);
}
//IdRemoveFromAlbum
if (isAlbum && m_isCustomAlbum && isReadable) {
if (isAlbum && m_isCustomAlbum && isReadable && !enhanceImage) {
appendAction(IdRemoveFromAlbum, tr("Remove from album"), ss("Remove from album", ""));
}
m_menu->addSeparator();
//fav
if (isAlbum && isReadable) {
if (isAlbum && isReadable && !enhanceImage) {
if (m_isFav) {
appendAction(IdRemoveFromFavorites, tr("Unfavorite"), "."); //取消收藏
} else {
Expand Down