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: Copy may cause program lag #123

Merged
merged 1 commit into from
Jan 24, 2024
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
27 changes: 22 additions & 5 deletions libimageviewer/unionimage/baseutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ void showInFileManager(const QString &path)
// }
}

void copyImageToClipboard(const QStringList &paths)
/**
@brief 拷贝图片信息到剪贴板,若 `sourceImage` 不为空,则在 wayland 下设置缩略图数据
*/
void copyImageToClipboard(const QStringList &paths, const QImage &sourceImage)
{
if (paths.isEmpty()) {
return;
Expand Down Expand Up @@ -214,10 +217,8 @@ void copyImageToClipboard(const QStringList &paths)
newMimeData->setData("x-special/gnome-copied-files", gnomeFormat);

// Copy Image Data
QImage img;
QString errMsg;
if (LibUnionImage_NameSpace::loadStaticImageFromFile(paths.first(), img, errMsg)) {
newMimeData->setImageData(img);
if (!sourceImage.isNull() && checkWayland()) {
newMimeData->setImageData(sourceImage.scaled(200, 200, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
}

// Set the mimedata
Expand Down Expand Up @@ -486,6 +487,22 @@ bool checkCommandExist(const QString &command)
}
}

/**
@brief 判断当前是否为 wayland 环境
*/
bool checkWayland()
{
auto e = QProcessEnvironment::systemEnvironment();
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));

if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive))
return true;
else {
return false;
}
}

} // namespace base

} // namespace utils
5 changes: 4 additions & 1 deletion libimageviewer/unionimage/baseutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QObject>
#include <QTimer>
#include <QColor>
#include <QImage>

#if QT_VERSION >= 0x050500
#define TIMER_SINGLESHOT(Time, Code, captured...){ \
Expand Down Expand Up @@ -123,7 +124,7 @@ namespace widgets {
}
namespace base {
void copyOneImageToClipboard(const QString &path);
void copyImageToClipboard(const QStringList &paths);
void copyImageToClipboard(const QStringList &paths, const QImage &sourceImage = QImage());
void showInFileManager(const QString &path);
int stringWidth(const QFont &f, const QString &str);
int stringHeight(const QFont &f, const QString &str);
Expand All @@ -146,6 +147,8 @@ bool onMountDevice(const QString &path);
bool mountDeviceExist(const QString &path);
bool checkCommandExist(const QString &command);
//bool isCommandExist(const QString &command);

bool checkWayland();
} // namespace base

} // namespace utils
Expand Down
4 changes: 2 additions & 2 deletions libimageviewer/viewpanel/viewpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1838,9 +1838,9 @@ void LibViewPanel::onMenuItemClicked(QAction *action)

// 判断当前是否为AI增强图片,若为设置增强后的图片
if (AIModelService::instance()->isTemporaryFile(m_currentPath)) {
Libutils::base::copyImageToClipboard({m_currentPath});
Libutils::base::copyImageToClipboard(QStringList(m_currentPath), m_view->image());
} else {
Libutils::base::copyImageToClipboard(QStringList(m_bottomToolbar->getCurrentItemInfo().path));
Libutils::base::copyImageToClipboard(QStringList(m_bottomToolbar->getCurrentItemInfo().path), m_view->image());
}

PermissionConfig::instance()->triggerAction(PermissionConfig::TidCopy, m_bottomToolbar->getCurrentItemInfo().path);
Expand Down