From a48aaa399754b51eaacec43981a29a55715fc124 Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Wed, 21 May 2025 16:07:32 +0800 Subject: [PATCH] feat: Enhance logging throughout image processing components - Added extensive debug and warning logs to various image processing and UI components to improve traceability and error handling. - Updated initialization and destruction logs for widgets and graphics items. - Enhanced logging for image loading, thumbnail generation, and event handling. Log: Improve logging for better debugging and maintainability. --- libimageviewer/unionimage/imgoperate.cpp | 37 ++- libimageviewer/unionimage/pluginbaseutils.cpp | 37 ++- .../unionimage/snifferimageformat.cpp | 23 +- libimageviewer/unionimage/unionimage.cpp | 56 +++- .../viewpanel/contents/bottomtoolbar.cpp | 44 +++- .../viewpanel/contents/imageinfowidget.cpp | 35 ++- .../viewpanel/contents/imgviewlistview.cpp | 80 +++--- .../viewpanel/contents/imgviewwidget.cpp | 240 ++++++++---------- libimageviewer/viewpanel/lockwidget.cpp | 51 +++- libimageviewer/viewpanel/navigationwidget.cpp | 81 +++--- .../viewpanel/scen/graphicsitem.cpp | 30 ++- .../viewpanel/scen/imagegraphicsview.cpp | 36 ++- .../viewpanel/scen/imagesvgitem.cpp | 33 ++- libimageviewer/viewpanel/thumbnailwidget.cpp | 58 +++-- libimageviewer/viewpanel/viewpanel.cpp | 39 ++- 15 files changed, 574 insertions(+), 306 deletions(-) diff --git a/libimageviewer/unionimage/imgoperate.cpp b/libimageviewer/unionimage/imgoperate.cpp index 2fcb80d6..7c950570 100644 --- a/libimageviewer/unionimage/imgoperate.cpp +++ b/libimageviewer/unionimage/imgoperate.cpp @@ -23,15 +23,17 @@ LibImgOperate::LibImgOperate(QObject *parent) { Q_UNUSED(parent); + qDebug() << "Initializing LibImgOperate"; } LibImgOperate::~LibImgOperate() { - + qDebug() << "Destroying LibImgOperate"; } void LibImgOperate::slotMakeImgThumbnail(QString thumbnailSavePath, QStringList paths, int makeCount, bool remake) { + qDebug() << "Starting thumbnail generation for" << paths.size() << "images, makeCount:" << makeCount << "remake:" << remake; QString path; imageViewerSpace::ItemInfo itemInfo; QImage tImg; @@ -39,18 +41,22 @@ void LibImgOperate::slotMakeImgThumbnail(QString thumbnailSavePath, QStringList for (int i = 0; i < paths.size(); i++) { //达到制作数量则停止 if (i == makeCount) { + qDebug() << "Reached makeCount limit, stopping thumbnail generation"; break; } path = paths.at(i); + qDebug() << "Processing image:" << path; itemInfo.path = path; //获取路径类型 itemInfo.pathType = getPathType(path); + qDebug() << "Path type:" << itemInfo.pathType; //获取原图分辨率 QImageReader imagreader(path); itemInfo.imgOriginalWidth = imagreader.size().width(); itemInfo.imgOriginalHeight = imagreader.size().height(); + qDebug() << "Original image size:" << itemInfo.imgOriginalWidth << "x" << itemInfo.imgOriginalHeight; //缩略图保存路径 QString savePath = thumbnailSavePath + path; @@ -59,6 +65,7 @@ void LibImgOperate::slotMakeImgThumbnail(QString thumbnailSavePath, QStringList QFileInfo file(savePath); //缩略图已存在,执行下一个路径 if (file.exists() && !remake && itemInfo.imgOriginalWidth > 0 && itemInfo.imgOriginalHeight > 0) { + qDebug() << "Using existing thumbnail:" << savePath; tImg = QImage(savePath); itemInfo.image = tImg; //获取图片类型 @@ -69,11 +76,12 @@ void LibImgOperate::slotMakeImgThumbnail(QString thumbnailSavePath, QStringList QString errMsg; if (!LibUnionImage_NameSpace::loadStaticImageFromFile(path, tImg, errMsg)) { - qDebug() << errMsg; + qWarning() << "Failed to load image:" << path << "Error:" << errMsg; continue; } itemInfo.imgOriginalWidth = tImg.width(); itemInfo.imgOriginalHeight = tImg.height(); + qDebug() << "Loaded image size:" << itemInfo.imgOriginalWidth << "x" << itemInfo.imgOriginalHeight; if (0 != tImg.height() && 0 != tImg.width() && (tImg.height() / tImg.width()) < 10 && (tImg.width() / tImg.height()) < 10) { bool cache_exist = false; @@ -93,44 +101,65 @@ void LibImgOperate::slotMakeImgThumbnail(QString thumbnailSavePath, QStringList tImg = tImg.scaledToHeight(200, Qt::FastTransformation); } } + qDebug() << "Scaled thumbnail size:" << tImg.width() << "x" << tImg.height(); } + //创建路径 - pluginUtils::base::mkMutiDir(savePath.mid(0, savePath.lastIndexOf('/'))); + QString dirPath = savePath.mid(0, savePath.lastIndexOf('/')); + qDebug() << "Creating directory for thumbnail:" << dirPath; + pluginUtils::base::mkMutiDir(dirPath); + if (tImg.save(savePath)) { + qDebug() << "Successfully saved thumbnail:" << savePath; itemInfo.image = tImg; + } else { + qWarning() << "Failed to save thumbnail:" << savePath; } + if (itemInfo.image.isNull()) { + qWarning() << "Generated thumbnail is null for:" << path; itemInfo.imageType = imageViewerSpace::ImageTypeDamaged; } else { //获取图片类型 itemInfo.imageType = getImageType(path); + qDebug() << "Image type:" << itemInfo.imageType; } emit sigOneImgReady(path, itemInfo); } + qDebug() << "Finished thumbnail generation"; } imageViewerSpace::ImageType LibImgOperate::getImageType(const QString &imagepath) { + qDebug() << "Getting image type for:" << imagepath; return LibUnionImage_NameSpace::getImageType(imagepath); } imageViewerSpace::PathType LibImgOperate::getPathType(const QString &imagepath) { + qDebug() << "Getting path type for:" << imagepath; //判断文件路径来自于哪里 imageViewerSpace::PathType type = imageViewerSpace::PathType::PathTypeLOCAL; if (imagepath.indexOf("smb-share:server=") != -1) { type = imageViewerSpace::PathTypeSMB; + qDebug() << "Path type: SMB share"; } else if (imagepath.indexOf("mtp:host=") != -1) { type = imageViewerSpace::PathTypeMTP; + qDebug() << "Path type: MTP device"; } else if (imagepath.indexOf("gphoto2:host=") != -1) { type = imageViewerSpace::PathTypePTP; + qDebug() << "Path type: PTP device"; } else if (imagepath.indexOf("gphoto2:host=Apple") != -1) { type = imageViewerSpace::PathTypeAPPLE; + qDebug() << "Path type: Apple device"; } else if (Libutils::image::isVaultFile(imagepath)) { type = imageViewerSpace::PathTypeSAFEBOX; + qDebug() << "Path type: Safe box"; } else if (imagepath.contains(QDir::homePath() + "/.local/share/Trash")) { type = imageViewerSpace::PathTypeRECYCLEBIN; + qDebug() << "Path type: Recycle bin"; + } else { + qDebug() << "Path type: Local file"; } - //todo return type; } diff --git a/libimageviewer/unionimage/pluginbaseutils.cpp b/libimageviewer/unionimage/pluginbaseutils.cpp index 3850de6e..58996f8e 100644 --- a/libimageviewer/unionimage/pluginbaseutils.cpp +++ b/libimageviewer/unionimage/pluginbaseutils.cpp @@ -172,11 +172,14 @@ const QString DATETIME_FORMAT_EXIF = "yyyy:MM:dd HH:mm:ss"; bool checkMimeData(const QMimeData *mimeData) { + qDebug() << "Checking mime data for drag and drop"; if (!mimeData->hasUrls()) { + qDebug() << "No URLs found in mime data"; return false; } QList urlList = mimeData->urls(); if (1 > urlList.size()) { + qDebug() << "Empty URL list in mime data"; return false; } @@ -189,12 +192,15 @@ bool checkMimeData(const QMimeData *mimeData) if (path.isEmpty()) { path = url.path(); } + qDebug() << "Processing URL path:" << path; QFileInfo fileinfo(path); if (fileinfo.isDir()) { if (LibCommonService::instance()->getImgViewerType() == imageViewerSpace::ImgViewerType::ImgViewerTypeAlbum) { //相册模式的时候额外允许文件夹拖入 + qDebug() << "Album mode: Directory drag allowed"; result = true; break; } else { + qDebug() << "Non-album mode: Directory drag not allowed"; continue; } } else { @@ -203,18 +209,23 @@ bool checkMimeData(const QMimeData *mimeData) QMimeType mt = db.mimeTypeForFile(info.filePath(), QMimeDatabase::MatchContent); QMimeType mt1 = db.mimeTypeForFile(info.filePath(), QMimeDatabase::MatchExtension); QString str = info.suffix().toLower(); + qDebug() << "File suffix:" << str << "MIME type (content):" << mt.name() << "MIME type (extension):" << mt1.name(); + if (str.isEmpty()) { if (mt.name().startsWith("image/") || mt.name().startsWith("video/x-mng")) { if (supportedImageFormats().contains(str, Qt::CaseInsensitive)) { + qDebug() << "Empty suffix but supported format found"; result = true; break; } else if (str.isEmpty()) { + qDebug() << "Empty suffix but valid image MIME type"; result = true; break; } } } else { if (mt1.name().startsWith("image/") || mt1.name().startsWith("video/x-mng")) { + qDebug() << "Valid image format with extension"; result = true; break; } @@ -223,6 +234,7 @@ bool checkMimeData(const QMimeData *mimeData) } } + qDebug() << "Mime data check result:" << result; return result; } @@ -248,45 +260,56 @@ bool checkMimeData(const QMimeData *mimeData) QString mkMutiDir(const QString &path) //创建多级目录 { + qDebug() << "Creating directory structure for:" << path; QDir dir(path); if (dir.exists(path)) { + qDebug() << "Directory already exists:" << path; return path; } QString parentDir = mkMutiDir(path.mid(0, path.lastIndexOf('/'))); QString dirname = path.mid(path.lastIndexOf('/') + 1); QDir parentPath(parentDir); - if (!dirname.isEmpty()) + if (!dirname.isEmpty()) { + qDebug() << "Creating subdirectory:" << dirname << "in" << parentDir; parentPath.mkpath(dirname); + } return parentDir + "/" + dirname; } bool imageSupportRead(const QString &path) { + qDebug() << "Checking if image format is supported for:" << path; const QString suffix = QFileInfo(path).suffix(); // take them here for good. QStringList errorList; errorList << "X3F"; if (errorList.indexOf(suffix.toUpper()) != -1) { + qWarning() << "Unsupported format:" << suffix; return false; } - //return QImageReader::supportedImageFormats().contains(suffix.toUtf8()); - return LibUnionImage_NameSpace::unionImageSupportFormat().contains(suffix.toUpper()); + bool supported = LibUnionImage_NameSpace::unionImageSupportFormat().contains(suffix.toUpper()); + qDebug() << "Format support check result:" << supported; + return supported; } const QFileInfoList getImagesInfo(const QString &dir, bool recursive) { + qDebug() << "Getting image information from directory:" << dir << "recursive:" << recursive; QFileInfoList infos; if (! recursive) { + qDebug() << "Non-recursive directory scan"; auto nsl = QDir(dir).entryInfoList(QDir::Files); for (QFileInfo info : nsl) { if (imageSupportRead(info.absoluteFilePath())) { infos << info; } } + qDebug() << "Found" << infos.size() << "images in directory"; return infos; } + qDebug() << "Recursive directory scan"; QDirIterator dirIterator(dir, QDir::Files, QDirIterator::Subdirectories); @@ -297,12 +320,16 @@ const QFileInfoList getImagesInfo(const QString &dir, bool recursive) } } + qDebug() << "Found" << infos.size() << "images in directory and subdirectories"; return infos; } -// + QStringList supportedImageFormats() { - return LibUnionImage_NameSpace::unionImageSupportFormat(); + qDebug() << "Getting list of supported image formats"; + QStringList formats = LibUnionImage_NameSpace::unionImageSupportFormat(); + qDebug() << "Supported formats:" << formats; + return formats; } } // namespace base diff --git a/libimageviewer/unionimage/snifferimageformat.cpp b/libimageviewer/unionimage/snifferimageformat.cpp index 2bf15643..b31116d2 100755 --- a/libimageviewer/unionimage/snifferimageformat.cpp +++ b/libimageviewer/unionimage/snifferimageformat.cpp @@ -11,95 +11,114 @@ // https://en.wikipedia.org/wiki/Image_file_formats QString DetectImageFormat(const QString &filepath) { + qDebug() << "Starting image format detection for:" << filepath; QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { - qWarning() << "DetectImageFormat() failed to open file:" << filepath; + qWarning() << "Failed to open file for format detection:" << filepath; return ""; } const QByteArray data = file.read(1024); + qDebug() << "Read" << data.size() << "bytes for format detection"; // Check bmp file. if (data.startsWith("BM")) { + qDebug() << "Detected BMP format"; return "bmp"; } // Check dds file. if (data.startsWith("DDS")) { + qDebug() << "Detected DDS format"; return "dds"; } // Check gif file. if (data.startsWith("GIF8")) { + qDebug() << "Detected GIF format"; return "gif"; } // Check Max OS icons file. if (data.startsWith("icns")) { + qDebug() << "Detected ICNS format"; return "icns"; } // Check jpeg file. if (data.startsWith("\xff\xd8")) { + qDebug() << "Detected JPEG format"; return "jpg"; } // Check mng file. if (data.startsWith("\x8a\x4d\x4e\x47\x0d\x0a\x1a\x0a")) { + qDebug() << "Detected MNG format"; return "mng"; } // Check net pbm file (BitMap). if (data.startsWith("P1") || data.startsWith("P4")) { + qDebug() << "Detected PBM format"; return "pbm"; } // Check pgm file (GrayMap). if (data.startsWith("P2") || data.startsWith("P5")) { + qDebug() << "Detected PGM format"; return "pgm"; } // Check ppm file (PixMap). if (data.startsWith("P3") || data.startsWith("P6")) { + qDebug() << "Detected PPM format"; return "ppm"; } // Check png file. if (data.startsWith("\x89PNG\x0d\x0a\x1a\x0a")) { + qDebug() << "Detected PNG format"; return "png"; } // Check svg file. if (data.indexOf(" -1) { + qDebug() << "Detected SVG format"; return "svg"; } // TODO(xushaohua): tga file is not supported yet. + qDebug() << "TGA format detection not implemented yet"; // Check tiff file. if (data.startsWith("MM\x00\x2a") || data.startsWith("II\x2a\x00")) { // big-endian, little-endian. + qDebug() << "Detected TIFF format"; return "tiff"; } // TODO(xushaohua): Support wbmp file. + qDebug() << "WBMP format detection not implemented yet"; // Check webp file. if (data.startsWith("RIFFr\x00\x00\x00WEBPVP")) { + qDebug() << "Detected WebP format"; return "webp"; } // Check xbm file. if (data.indexOf("#define max_width ") > -1 && data.indexOf("#define max_height ") > -1) { + qDebug() << "Detected XBM format"; return "xbm"; } // Check xpm file. if (data.startsWith("/* XPM */")) { + qDebug() << "Detected XPM format"; return "xpm"; } - + qDebug() << "No supported image format detected"; return ""; } diff --git a/libimageviewer/unionimage/unionimage.cpp b/libimageviewer/unionimage/unionimage.cpp index 0588d989..3b7f248f 100644 --- a/libimageviewer/unionimage/unionimage.cpp +++ b/libimageviewer/unionimage/unionimage.cpp @@ -42,6 +42,7 @@ class UnionImage_Private public: UnionImage_Private() { + qDebug() << "Initializing UnionImage_Private with supported formats"; /* * 由于原设计方案采用多个key对应一个value的方案,在判断可读可写的过程中是通过value去找key因此造成了多种情况而在下方变量中未将key,写完整因此补全 * */ @@ -99,6 +100,8 @@ class UnionImage_Private << "EPS" << "SR2" << "AVIFS"; + qDebug() << "Added" << m_qtSupported.size() << "supported formats"; + m_canSave << "BMP" << "JPG" << "JPEG" @@ -108,7 +111,8 @@ class UnionImage_Private << "XPM" << "ICO" << "ICNS"; - /*<< "PGM" << "PBM"*/ + qDebug() << "Added" << m_canSave.size() << "saveable formats"; + m_qtrotate << "BMP" << "JPG" << "JPEG" @@ -118,9 +122,11 @@ class UnionImage_Private << "XPM" << "ICO" << "ICNS"; + qDebug() << "Added" << m_qtrotate.size() << "rotatable formats"; } ~UnionImage_Private() { + qDebug() << "Destroying UnionImage_Private"; } QStringList m_qtSupported; QHash m_movie_formats; @@ -136,16 +142,19 @@ static UnionImage_Private union_image_private; */ UNIONIMAGESHARED_EXPORT QImage noneQImage() { + qDebug() << "Creating empty QImage"; static QImage none(0, 0, QImage::Format_Invalid); return none; } UNIONIMAGESHARED_EXPORT const QStringList unionImageSupportFormat() { + qDebug() << "Getting supported image formats"; static QStringList res; if (res.empty()) { QStringList list = union_image_private.m_qtSupported; res.append(list); + qDebug() << "Added" << list.size() << "supported formats"; } return res; } @@ -235,14 +244,18 @@ UNIONIMAGESHARED_EXPORT QString unionImageVersion() QString PrivateDetectImageFormat(const QString &filepath); UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage &res, QString &errorMsg, const QString &format_bar) { + qDebug() << "Loading static image from file:" << path; QFileInfo file_info(path); if (file_info.size() == 0) { + qWarning() << "Empty file:" << path; res = QImage(); errorMsg = "error file!"; return false; } + QMap dataMap = getAllMetaData(path); QString file_suffix_upper = dataMap.value("FileFormat").toUpper(); + qDebug() << "File format:" << file_suffix_upper; QByteArray temp_path; temp_path.append(path.toUtf8()); @@ -259,9 +272,11 @@ UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage reader.setFormat(format_bar.toLatin1()); } reader.setAutoTransform(true); + if (reader.imageCount() > 0 || file_suffix_upper != "ICNS") { res_qt = reader.read(); if (res_qt.isNull()) { + qWarning() << "Failed to read image with QImageReader, trying alternative method"; //try old loading method QString format = PrivateDetectImageFormat(path); QImageReader readerF(path, format.toLatin1()); @@ -271,22 +286,25 @@ UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage try_res = readerF.read(); } else { errorMsg = "can't read image:" + readerF.errorString() + format; + qWarning() << errorMsg; try_res = QImage(path); } // 单独处理TIF格式情况 if (try_res.isNull() && (file_suffix_upper == "TIF" || file_suffix_upper == "TIFF")) { // 读取失败,tif需要单独处理,尝试通过转换函数处理 + qDebug() << "Processing TIFF format with special handling"; QFileInfo imageFile(path); QString cacheFile = Libutils::image::getCacheImagePath() + QDir::separator() + imageFile.fileName(); // 判断是否存在缓存图片数据 if (Libutils::image::checkCacheImage(imageFile.fileName())) { + qDebug() << "Using cached TIFF image"; try_res = QImage(cacheFile); } else { // 由于多线程调用,可能同时访问文件,使用临时文件处理,防止部分线程读取未转码完成的图片文件 QString tempFile = Libutils::image::getCacheImagePath() + QDir::separator() + QUuid::createUuid().toString() + imageFile.fileName(); - qDebug() << "convert" << imageFile.absoluteFilePath() << cacheFile << tempFile; + qDebug() << "Converting TIFF image:" << imageFile.absoluteFilePath() << "to" << tempFile; // 转换图像编码格式 int nRet = convertOldStyleImage(imageFile.absoluteFilePath().toUtf8().data(), tempFile.toUtf8().data()); @@ -303,12 +321,15 @@ UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage QFile::rename(tempFile, cacheFile); } } + } else { + qWarning() << "Failed to convert TIFF image, error code:" << nRet; } } } if (try_res.isNull()) { errorMsg = "load image by qt failed, use format:" + reader.format() + " ,path:" + path; + qWarning() << errorMsg; res = QImage(); return false; } @@ -319,11 +340,13 @@ UNIONIMAGESHARED_EXPORT bool loadStaticImageFromFile(const QString &path, QImage errorMsg = "use QImage"; res = res_qt; } else { + qWarning() << "No images found in file:" << path; res = QImage(); return false; } return true; } + qWarning() << "Unsupported image format:" << file_suffix_upper; return false; } @@ -432,9 +455,13 @@ UNIONIMAGESHARED_EXPORT bool isNoneQImage(const QImage &qi) UNIONIMAGESHARED_EXPORT bool rotateImage(int angel, QImage &image) { - if (angel % 90 != 0) + qDebug() << "Rotating image by" << angel << "degrees"; + if (angel % 90 != 0) { + qWarning() << "Unsupported rotation angle:" << angel; return false; + } if (image.isNull()) { + qWarning() << "Cannot rotate null image"; return false; } QImage image_copy(image); @@ -442,8 +469,10 @@ UNIONIMAGESHARED_EXPORT bool rotateImage(int angel, QImage &image) QTransform rotatematrix; rotatematrix.rotate(angel); image = image_copy.transformed(rotatematrix, Qt::SmoothTransformation); + qDebug() << "Image rotated successfully"; return true; } + qWarning() << "Failed to create image copy for rotation"; return false; } @@ -485,15 +514,21 @@ QImage adjustImageToRealPosition(const QImage &image, int orientation) UNIONIMAGESHARED_EXPORT bool rotateImageFIle(int angel, const QString &path, QString &erroMsg) { + qDebug() << "Rotating image file:" << path << "by" << angel << "degrees"; if (angel % 90 != 0) { erroMsg = "unsupported angel"; + qWarning() << erroMsg; return false; } QString format = detectImageFormat(path); + qDebug() << "Image format:" << format; + if (format == "SVG") { + qDebug() << "Processing SVG rotation"; QImage image_copy; if (!loadStaticImageFromFile(path, image_copy, erroMsg)) { erroMsg = "rotate load QImage failed, path:" + path + " ,format:+" + format; + qWarning() << erroMsg; return false; } QSvgGenerator generator; @@ -519,9 +554,11 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIle(int angel, const QString &path, QSt rotatePainter.resetTransform(); generator.setSize(QSize(image_copy.width(), image_copy.height())); rotatePainter.end(); + qDebug() << "SVG rotation completed successfully"; return true; } else if (union_image_private.m_qtrotate.contains(format)) { //由于Qt内部不会去读图片的EXIF信息来判断当前的图像矩阵的真实位置,同时回写数据的时候会丢失全部的EXIF数据 + qDebug() << "Processing standard image rotation"; int orientation = getOrientation(path); QImage image_copy(path); image_copy = adjustImageToRealPosition(image_copy, orientation); @@ -532,12 +569,15 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIle(int angel, const QString &path, QSt // 调整图片质量,不再默认使用满质量 SAVE_QUAITY_VALUE if (image_copy.save(path, format.toLatin1().data(), -1)) { + qDebug() << "Image rotation and save completed successfully"; return true; } } erroMsg = "rotate by qt failed"; + qWarning() << erroMsg; return false; } + qWarning() << "Unsupported format for rotation:" << format; return false; } @@ -643,23 +683,30 @@ UNIONIMAGESHARED_EXPORT bool creatNewImage(QImage &res, int width, int height, i } imageViewerSpace::ImageType getImageType(const QString &imagepath) { + qDebug() << "Getting image type for:" << imagepath; imageViewerSpace::ImageType type = imageViewerSpace::ImageType::ImageTypeBlank; //新增获取图片是属于静态图还是动态图还是多页图 if (!imagepath.isEmpty()) { QFileInfo fi(imagepath); QString strType = fi.suffix().toLower(); + qDebug() << "File suffix:" << strType; + //解决bug57394 【专业版1031】【看图】【5.6.3.74】【修改引入】pic格式图片变为翻页状态,不为动图且首张显示序号为0 QMimeDatabase db; QMimeType mt = db.mimeTypeForFile(imagepath, QMimeDatabase::MatchContent); QMimeType mt1 = db.mimeTypeForFile(imagepath, QMimeDatabase::MatchExtension); QString path1 = mt.name(); QString path2 = mt1.name(); + qDebug() << "MIME types - Content:" << path1 << "Extension:" << path2; + int nSize = -1; QImageReader imgreader(imagepath); nSize = imgreader.imageCount(); + qDebug() << "Image count:" << nSize; if (strType == "svg" && QSvgRenderer().load(imagepath)) { type = imageViewerSpace::ImageTypeSvg; + qDebug() << "Detected SVG image type"; } else if ((strType == "mng") || ((strType == "gif") && nSize > 1) || (strType == "webp" && nSize > 1) @@ -668,13 +715,16 @@ imageViewerSpace::ImageType getImageType(const QString &imagepath) || ((mt.name().startsWith("video/x-mng"))) || ((mt1.name().startsWith("video/x-mng")))) { type = imageViewerSpace::ImageTypeDynamic; + qDebug() << "Detected dynamic image type"; } else if (nSize > 1) { type = imageViewerSpace::ImageTypeMulti; + qDebug() << "Detected multi-page image type"; } else if (mt.name().startsWith("image/") || mt.name().startsWith("video/x-mng") || mt1.name().startsWith("image/") || mt1.name().startsWith("video/x-mng")) { type = imageViewerSpace::ImageTypeStatic; + qDebug() << "Detected static image type"; } } return type; diff --git a/libimageviewer/viewpanel/contents/bottomtoolbar.cpp b/libimageviewer/viewpanel/contents/bottomtoolbar.cpp index 6f4a944c..5bdd9bb8 100644 --- a/libimageviewer/viewpanel/contents/bottomtoolbar.cpp +++ b/libimageviewer/viewpanel/contents/bottomtoolbar.cpp @@ -62,7 +62,9 @@ const int LOAD_LEFT_RIGHT = 25; //前后加载图片数(动态) LibBottomToolbar::LibBottomToolbar(QWidget *parent) : DFloatingWidget(parent) { + qDebug() << "Initializing LibBottomToolbar"; m_ocrIsExists = Libutils::base::checkCommandExist("deepin-ocr"); + qDebug() << "OCR feature" << (m_ocrIsExists ? "available" : "not available"); this->setBlurBackgroundEnabled(true); initUI(); initConnection(); @@ -73,7 +75,7 @@ LibBottomToolbar::LibBottomToolbar(QWidget *parent) : DFloatingWidget(parent) LibBottomToolbar::~LibBottomToolbar() { - + qDebug() << "Destroying LibBottomToolbar"; } int LibBottomToolbar::getAllFileCount() @@ -258,15 +260,20 @@ void LibBottomToolbar::checkAdaptScreenBtn() void LibBottomToolbar::deleteImage() { + qDebug() << "Starting image deletion process"; //移除正在展示照片 if (m_imgListWidget) { - if (m_imgListWidget->getImgCount() == 0) + if (m_imgListWidget->getImgCount() == 0) { + qWarning() << "No images to delete"; return; + } QString path = getCurrentItemInfo().path; + qDebug() << "Deleting image:" << path; QFile file(path); if (!file.exists()) { + qWarning() << "File does not exist:" << path; return; } //文件是否被删除的判断bool值 @@ -274,18 +281,24 @@ void LibBottomToolbar::deleteImage() if (LibCommonService::instance()->getImgViewerType() == imageViewerSpace::ImgViewerTypeLocal) { //先删除文件,需要判断文件是否删除,如果删除了,再决定看图软件的显示 //不再采用默认删除,使用utils里面的删除 + qDebug() << "Deleting local file"; Libutils::base::trashFile(path); QFile fileRemove(path); if (!fileRemove.exists()) { iRetRemove = true; + qDebug() << "File successfully moved to trash"; } } else if (LibCommonService::instance()->getImgViewerType() == imageViewerSpace::ImgViewerTypeAlbum) { iRetRemove = true; + qDebug() << "Album file marked for deletion"; } if (iRetRemove) { m_imgListWidget->removeCurrent(); + qDebug() << "Remaining images count:" << m_imgListWidget->getImgCount(); + if (m_imgListWidget->getImgCount() == 1) { + qDebug() << "Last image remaining, adjusting UI"; if (m_preButton) { setButtonVisible(imageViewerSpace::ButtonTypePre, false); } @@ -305,11 +318,14 @@ void LibBottomToolbar::deleteImage() m_trashBtn->clearFocus(); //当图片不存在的时候,回到初始界面 if (!QFileInfo(m_imgListWidget->getCurrentImgInfo().path).isFile()) { + qDebug() << "Current image no longer exists, emitting sigPicCountIsNull"; emit ImageEngine::instance()->sigPicCountIsNull(); - }; + } } else if (m_imgListWidget->getImgCount() == 0) { + qDebug() << "No images remaining, emitting sigPicCountIsNull"; emit ImageEngine::instance()->sigPicCountIsNull(); } + if (m_imgListWidget->getCurrentCount() >= m_imgListWidget->getImgCount() - 1) { m_nextButton->setEnabled(false); } @@ -324,7 +340,6 @@ void LibBottomToolbar::deleteImage() PermissionConfig::instance()->triggerAction(PermissionConfig::TidDelete, path); } } - } void LibBottomToolbar::onBackButtonClicked() @@ -336,6 +351,7 @@ void LibBottomToolbar::onBackButtonClicked() void LibBottomToolbar::onAdaptImageBtnClicked() { + qDebug() << "Adapt image button clicked"; emit resetTransform(false); m_adaptImageBtn->setChecked(true); if (!badaptImageBtnChecked) { @@ -345,6 +361,7 @@ void LibBottomToolbar::onAdaptImageBtnClicked() void LibBottomToolbar::onAdaptScreenBtnClicked() { + qDebug() << "Adapt screen button clicked"; emit resetTransform(true); m_adaptScreenBtn->setChecked(true); if (!badaptScreenBtnChecked) { @@ -364,17 +381,20 @@ void LibBottomToolbar::onclBTClicked() void LibBottomToolbar::onRotateLBtnClicked() { + qDebug() << "Rotate left button clicked"; emit rotateClockwise(); } void LibBottomToolbar::onRotateRBtnClicked() { + qDebug() << "Rotate right button clicked"; emit rotateCounterClockwise(); } void LibBottomToolbar::onTrashBtnClicked() { //更换删除顺序,相册需要现在显示删除,再删除本体 + qDebug() << "Trash button clicked"; QString path; if (m_imgListWidget) { path = getCurrentItemInfo().path; @@ -385,6 +405,7 @@ void LibBottomToolbar::onTrashBtnClicked() if (LibCommonService::instance()->getImgViewerType() == imageViewerSpace::ImgViewerType::ImgViewerTypeAlbum) { // 相册浏览图片-删除按钮逻辑处理 + qDebug() << "Album mode - sending delete signal for:" << path; #ifdef DELETE_CONFIRM // 新流程,相册会弹出删除确认提示框,点击确认,相册才给imageeditor发送sigDeleteImage信号删除图片 emit ImageEngine::instance()->sigDel(path); @@ -395,6 +416,7 @@ void LibBottomToolbar::onTrashBtnClicked() #endif } else { //本地图片浏览-删除图片,直接删除 + qDebug() << "Local mode - deleting file:" << path; deleteImage(); emit ImageEngine::instance()->sigDel(path); } @@ -402,6 +424,7 @@ void LibBottomToolbar::onTrashBtnClicked() void LibBottomToolbar::slotThemeChanged(int type) { + qDebug() << "Theme changed to:" << (type == 1 ? "light" : "dark"); QString rStr; if (type == 1) { QColor maskColor(247, 247, 247); @@ -465,6 +488,7 @@ void LibBottomToolbar::slotThemeChanged(int type) void LibBottomToolbar::slotOpenImage(int index, QString path) { + qDebug() << "Opening image at index:" << index << "path:" << path; if (index == 0) { m_preButton->setEnabled(false); } else { @@ -475,7 +499,6 @@ void LibBottomToolbar::slotOpenImage(int index, QString path) } else { m_nextButton->setEnabled(true); } -// qDebug() << index << m_imgListWidget->getImgCount(); //BUG#93143 QFileInfo info(path); @@ -488,24 +511,26 @@ void LibBottomToolbar::slotOpenImage(int index, QString path) m_ocrBtn->setToolTip(QObject::tr("Extract text")); } else { m_ocrBtn->setToolTip(QObject::tr("Extract text") + QObject::tr("(Disabled)")); - } - } + } + } //左转右转的控制不在这里 if (!info.isFile() || !info.exists()) { + qWarning() << "File does not exist or is not a file:" << path; m_adaptImageBtn->setEnabled(false); m_adaptImageBtn->setChecked(false); m_adaptScreenBtn->setEnabled(false); - m_trashBtn->setEnabled(false); if (m_ocrIsExists) { m_ocrBtn->setEnabled(false); } } else { + qDebug() << "File exists, enabling controls"; m_adaptImageBtn->setEnabled(true); m_adaptScreenBtn->setEnabled(true); if (!PermissionConfig::instance()->checkAuthFlag(PermissionConfig::EnableEdit)) { + qWarning() << "Edit permission not granted"; return; } @@ -618,14 +643,17 @@ void LibBottomToolbar::leaveEvent(QEvent *e) void LibBottomToolbar::setAllFile(QString path, QStringList paths) { //每次打开清空一下缩略图 + qDebug() << "Setting all files, count:" << paths.size() << "current path:" << path; m_imgListWidget->clearListView(); if (paths.size() <= 1) { + qDebug() << "Single image mode, hiding navigation controls"; setButtonVisible(imageViewerSpace::ButtonTypePre, false); setButtonVisible(imageViewerSpace::ButtonTypeNext, false); m_spaceWidget->setVisible(false); m_spaceWidget_thumbnailLeft->setVisible(false); m_spaceWidget_thumbnailRight->setVisible(false); } else { + qDebug() << "Multiple images mode, showing navigation controls"; setButtonVisible(imageViewerSpace::ButtonTypePre, true); setButtonVisible(imageViewerSpace::ButtonTypeNext, true); m_spaceWidget->setVisible(true); diff --git a/libimageviewer/viewpanel/contents/imageinfowidget.cpp b/libimageviewer/viewpanel/contents/imageinfowidget.cpp index 0e69040f..9243f268 100644 --- a/libimageviewer/viewpanel/contents/imageinfowidget.cpp +++ b/libimageviewer/viewpanel/contents/imageinfowidget.cpp @@ -134,6 +134,7 @@ LibImageInfoWidget::LibImageInfoWidget(const QString &darkStyle, const QString & , m_maxFieldWidth(0) , m_currentFontSize(0) { + qDebug() << "Initializing LibImageInfoWidget"; #ifdef OPENACCESSIBLE setObjectName(IMAGE_WIDGET); setAccessibleName(IMAGE_WIDGET); @@ -173,16 +174,19 @@ LibImageInfoWidget::LibImageInfoWidget(const QString &darkStyle, const QString & m_mainLayout->addWidget(m_exif_base); m_mainLayout->addWidget(m_exif_details); this->setLayout(m_mainLayout); + qDebug() << "LibImageInfoWidget initialization completed"; } LibImageInfoWidget::~LibImageInfoWidget() { + qDebug() << "Destroying LibImageInfoWidget"; clearLayout(m_exifLayout_base); clearLayout(m_exifLayout_details); } void updateFileTime(QMap &data, const QString &path) { + qDebug() << "Updating file time for:" << path; QFileInfo info(path); if (data.contains("DateTime")) { QDateTime time = QDateTime::fromString(data["DateTime"], "yyyy:MM:dd hh:mm:ss"); @@ -195,8 +199,13 @@ void updateFileTime(QMap &data, const QString &path) void LibImageInfoWidget::setImagePath(const QString &path, bool forceUpdate) { + qDebug() << "Setting image path:" << path << "forceUpdate:" << forceUpdate; + // MTP文件需调整文件路径 bool needMtpProxy = MtpFileProxy::instance()->contains(path); + if (needMtpProxy) { + qDebug() << "MTP file detected, using proxy"; + } // 根据forceUpdate标志判断使用本函数进行整个image info弹窗的整体强制重刷 if (!forceUpdate && m_path == path) { @@ -207,6 +216,7 @@ void LibImageInfoWidget::setImagePath(const QString &path, bool forceUpdate) // 检测数据是否存在变更 if (m_metaData == metaData) { + qDebug() << "Metadata unchanged, skipping update"; return; } } else { @@ -224,6 +234,7 @@ void LibImageInfoWidget::setImagePath(const QString &path, bool forceUpdate) QStringList titleList; QVBoxLayout *layout = qobject_cast(this->layout()); if (nullptr != layout) { + qDebug() << "Clearing existing layout"; QLayoutItem *child; while ((child = layout->takeAt(0)) != nullptr) { if (child->widget()) { @@ -243,9 +254,11 @@ void LibImageInfoWidget::setImagePath(const QString &path, bool forceUpdate) // Wayland 下延迟首次动画展示 if (Libutils::base::checkWayland()) { firstExpand = isVisible(); + qDebug() << "Wayland detected, first expand:" << firstExpand; } if (m_isBaseInfo == true && m_isDetailsInfo == true) { + qDebug() << "Adding both basic info and details sections"; titleList << tr("Basic info"); titleList << tr("Details"); m_expandGroup = addExpandWidget(titleList); @@ -255,6 +268,7 @@ void LibImageInfoWidget::setImagePath(const QString &path, bool forceUpdate) m_expandGroup.at(1)->setExpand(firstExpand); } else if (m_isBaseInfo == true && m_isDetailsInfo == false) { + qDebug() << "Adding basic info section only"; titleList << tr("Basic info"); m_expandGroup = addExpandWidget(titleList); m_expandGroup.at(0)->setContent(m_exif_base); @@ -271,6 +285,7 @@ void LibImageInfoWidget::showEvent(QShowEvent *e) // Note: Wayland 下默认动画和应用动画重叠,同时可能导致 wayland 未正确取得 // 控件信息,显示花屏,调整应用动画在 wayland 动画后 if (Libutils::base::checkWayland()) { + qDebug() << "Wayland detected, scheduling delayed animation"; const int waylandAnimationDuration = 250; QTimer::singleShot(waylandAnimationDuration, this, [this]() { for (auto expand : m_expandGroup) { @@ -297,6 +312,7 @@ void LibImageInfoWidget::paintEvent(QPaintEvent *event) int currentSize = DFontSizeManager::instance()->fontPixelSize(font); // LMH0609判断与上次自体的大小是否一样,不一样则刷新 if (currentSize != m_currentFontSize) { + qDebug() << "Font size changed from" << m_currentFontSize << "to" << currentSize; m_currentFontSize = currentSize; TITLE_MAXCNWIDETH = currentSize * 4; updateInfo(); @@ -333,6 +349,7 @@ const QString LibImageInfoWidget::trLabel(const char *str) void LibImageInfoWidget::updateInfo() { + qDebug() << "Updating image info display"; // Minus layout margins // m_maxFieldWidth = width() - m_maxTitleWidth - 20*2; // solve bug 1623 根据中英文系统语言设置Title宽度 shuwenzhi 20200313 @@ -342,9 +359,11 @@ void LibImageInfoWidget::updateInfo() if (lan == QLocale::Language::Chinese) { m_maxFieldWidth = width() - TITLE_MAXCNWIDETH /* - 20 * 2 */ - 10 * 2 - 10; CNflag = true; + qDebug() << "Using Chinese layout with width:" << m_maxFieldWidth; } else { m_maxFieldWidth = width() - TITLE_MAXOTHERWIDETH /* - 20 * 2 */ - 10 * 2 - 10; CNflag = false; + qDebug() << "Using other language layout with width:" << m_maxFieldWidth; } updateBaseInfo(m_metaData, CNflag); @@ -353,6 +372,7 @@ void LibImageInfoWidget::updateInfo() void LibImageInfoWidget::updateBaseInfo(const QMap &infos, bool CNflag) { + qDebug() << "Updating basic info section"; using namespace Libutils::image; using namespace Libutils::base; clearLayout(m_exifLayout_base); @@ -374,11 +394,13 @@ void LibImageInfoWidget::updateBaseInfo(const QMap &infos, boo //部分图片采用meta data的形式无法正确读取大小,此处改成使用已缓存的图片大小数据 if (i->key == "Dimension") { value = QString("%1x%2").arg(info.imgOriginalWidth).arg(info.imgOriginalHeight); + qDebug() << "Using cached dimensions:" << value; } /*lmh0825真实格式,没有真格式采用后缀名*/ if (i->key == "FileFormat" && !suffix.isEmpty() && infos.value(i->key).isNull()) { value = fi.suffix(); + qDebug() << "Using file suffix as format:" << value; } // value必须为小写 if (i->key == "FileFormat") { @@ -397,8 +419,10 @@ void LibImageInfoWidget::updateBaseInfo(const QMap &infos, boo if (i->key == "DateTimeOriginal" || i->key == "DateTimeDigitized") { if (CNflag) { QDateTime tmpTime = QDateTime::fromString(value, "yyyy/MM/dd hh:mm:ss"); - if (!tmpTime.isNull()) + if (!tmpTime.isNull()) { value = tmpTime.toString("yyyy年MM月dd日 hh:mm:ss"); + qDebug() << "Converting date format to Chinese:" << value; + } } } @@ -433,6 +457,7 @@ void LibImageInfoWidget::updateBaseInfo(const QMap &infos, boo void LibImageInfoWidget::updateDetailsInfo(const QMap &infos, bool CNflag) { + qDebug() << "Updating details info section"; using namespace Libutils::image; using namespace Libutils::base; clearLayout(m_exifLayout_details); @@ -475,12 +500,12 @@ void LibImageInfoWidget::updateDetailsInfo(const QMap &infos, QList LibImageInfoWidget::addExpandWidget(const QStringList &titleList) { + qDebug() << "Adding expand widgets for titles:" << titleList; QVBoxLayout *layout = qobject_cast(this->layout()); QList group; for (const QString &title : titleList) { - // DFMDArrowLineExpand *expand = new DFMDArrowLineExpand; // DArrowLineExpand; - DArrowLineDrawer *expand = new DArrowLineDrawer; // DArrowLineExpand; + DArrowLineDrawer *expand = new DArrowLineDrawer; expand->setTitle(title); initExpand(layout, expand); group.push_back(expand); @@ -504,8 +529,8 @@ void LibImageInfoWidget::initExpand(QVBoxLayout *layout, DDrawer *expand) QRect rc1 = geometry(); rc1.setHeight(contentHeight() + ArrowLineExpand_SPACING * 2); setGeometry(rc1); - - emit extensionPanelHeight(contentHeight() /*+ ArrowLineExpand_SPACING*/); + qDebug() << "Expand widget height changed to:" << rc1.height(); + emit extensionPanelHeight(contentHeight()); }); } diff --git a/libimageviewer/viewpanel/contents/imgviewlistview.cpp b/libimageviewer/viewpanel/contents/imgviewlistview.cpp index e8e406db..63f09fae 100644 --- a/libimageviewer/viewpanel/contents/imgviewlistview.cpp +++ b/libimageviewer/viewpanel/contents/imgviewlistview.cpp @@ -25,6 +25,7 @@ LibImgViewListView::LibImgViewListView(QWidget *parent) : DListView(parent) { + qDebug() << "Initializing LibImgViewListView"; m_model = new QStandardItemModel(this); m_delegate = new LibImgViewDelegate(this); setResizeMode(QListView::Adjust); @@ -39,28 +40,24 @@ LibImgViewListView::LibImgViewListView(QWidget *parent) setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->verticalScrollBar()->setDisabled(true); // 禁用滚动 -// setAttribute(Qt::WA_TransparentForMouseEvents, true); -// QScroller::grabGesture(viewport(), QScroller::LeftMouseButtonGesture); - -// setUniformItemSizes(true); + qDebug() << "Scroll bars disabled"; setItemDelegate(m_delegate); setModel(m_model); -// installEventFilter(viewport()); + qDebug() << "Model and delegate set up"; -// setMouseTracking(true); -// this->viewport()->setMouseTracking(true); connect(ImageEngine::instance(), &ImageEngine::sigOneImgReady, this, &LibImgViewListView::slotOneImgReady, Qt::QueuedConnection); + qDebug() << "LibImgViewListView initialization completed"; } LibImgViewListView::~LibImgViewListView() { - qDebug() << "~-------------------ImgViewListView"; + qDebug() << "Destroying LibImgViewListView"; } void LibImgViewListView::setAllFile(QList itemInfos, QString path) { - qDebug() << "---" << __FUNCTION__ << "---path = " << path; + qDebug() << "Setting all files, count:" << itemInfos.size() << "current path:" << path; m_model->clear(); m_currentPath = path; int count = itemInfos.size(); @@ -70,6 +67,7 @@ void LibImgViewListView::setAllFile(QList itemInfos, info.imgWidth = ITEM_CURRENT_WH; info.imgHeight = ITEM_CURRENT_WH; m_currentRow = i; + qDebug() << "Current item found at index:" << i; } else { info.imgWidth = ITEM_NORMAL_WIDTH; info.imgHeight = ITEM_NORMAL_HEIGHT; @@ -86,6 +84,7 @@ void LibImgViewListView::setAllFile(QList itemInfos, doItemsLayout(); this->setFixedSize((2 * (count + 1) + ITEM_NORMAL_WIDTH * count + ITEM_CURRENT_WH - ITEM_NORMAL_WIDTH), 80); + qDebug() << "List view size set to:" << this->size(); } int LibImgViewListView::getSelectIndexByPath(QString path) @@ -111,20 +110,25 @@ void LibImgViewListView::setSelectCenter() void LibImgViewListView::openNext() { if (m_currentRow == (m_model->rowCount() - 1)) { + qDebug() << "Already at last item, cannot open next"; return; } QModelIndex currentIndex = m_model->index(m_currentRow, 0); QModelIndex nextIndex = m_model->index((m_currentRow + 1), 0); if (!nextIndex.isValid()) { + qWarning() << "Next index is invalid"; return; } imageViewerSpace::ItemInfo info = nextIndex.data(Qt::DisplayRole).value(); if (info.path.isEmpty()) { + qWarning() << "Next item path is empty"; return; } + qDebug() << "Opening next item at index:" << (m_currentRow + 1) << "path:" << info.path; + if (currentIndex.isValid()) { //重置前一个选中项的宽高 m_model->setData(currentIndex, @@ -135,7 +139,6 @@ void LibImgViewListView::openNext() //重置新选中项的宽高 m_model->setData(nextIndex, QVariant(QSize(LibImgViewListView::ITEM_CURRENT_WH, LibImgViewListView::ITEM_CURRENT_WH)), Qt::SizeHintRole); - } doItemsLayout(); @@ -143,7 +146,6 @@ void LibImgViewListView::openNext() m_currentPath = info.path; loadFiftyRight(); - startMoveToLeftAnimation(); emit openImg(m_currentRow, m_currentPath); @@ -152,20 +154,25 @@ void LibImgViewListView::openNext() void LibImgViewListView::openPre() { if (m_currentRow <= 0) { + qDebug() << "Already at first item, cannot open previous"; return; } QModelIndex currentIndex = m_model->index(m_currentRow, 0); QModelIndex preIndex = m_model->index((m_currentRow - 1), 0); if (!preIndex.isValid()) { + qWarning() << "Previous index is invalid"; return; } imageViewerSpace::ItemInfo info = preIndex.data(Qt::DisplayRole).value(); if (info.path.isEmpty()) { + qWarning() << "Previous item path is empty"; return; } + qDebug() << "Opening previous item at index:" << (m_currentRow - 1) << "path:" << info.path; + if (currentIndex.isValid()) { //重置前一个选中项的宽高 m_model->setData(currentIndex, @@ -176,7 +183,6 @@ void LibImgViewListView::openPre() //重置新选中项的宽高 m_model->setData(preIndex, QVariant(QSize(LibImgViewListView::ITEM_CURRENT_WH, LibImgViewListView::ITEM_CURRENT_WH)), Qt::SizeHintRole); - } doItemsLayout(); @@ -194,6 +200,7 @@ void LibImgViewListView::removeCurrent() qDebug() << "---" << __FUNCTION__ << "---m_currentRow = " << m_currentRow; qDebug() << "---" << __FUNCTION__ << "---m_model->rowCount() = " << m_model->rowCount(); if (m_currentRow == (m_model->rowCount() - 1)) { + qDebug() << "Removing last item, switching to previous"; QModelIndex index; if (m_currentRow >= 1) { index = m_model->index(m_currentRow - 1, 0); @@ -208,6 +215,7 @@ void LibImgViewListView::removeCurrent() } } else { //显示下一张 + qDebug() << "Removing current item, switching to next"; QModelIndex index = m_model->index((m_currentRow + 1), 0); onClicked(index); m_currentRow = m_currentRow - 1; @@ -216,6 +224,7 @@ void LibImgViewListView::removeCurrent() } } else if (m_model->rowCount() == 1) { //数量只有一张 + qDebug() << "Removing last remaining item"; m_model->clear(); m_currentRow = -1; m_currentPath = ""; @@ -247,11 +256,6 @@ QStringList LibImgViewListView::getAllPath() int LibImgViewListView::getCurrentItemX() { QModelIndex currentIndex = m_model->index(m_currentRow, 0); -// qDebug() << this->visualRect(currentIndex).x(); -// qDebug() << this->visualRect(currentIndex).x(); -// qDebug() << 2 * (count + 1) + ITEM_NORMAL_WIDTH *count + ITEM_CURRENT_WH - ITEM_NORMAL_WIDTH; -// qDebug() << (2 * (m_currentRow + 1) + ITEM_NORMAL_WIDTH * m_currentRow + ITEM_CURRENT_WH - ITEM_NORMAL_WIDTH); -// qDebug() << this->visualRect(currentIndex).x(); return this->visualRect(currentIndex).x(); } @@ -261,28 +265,9 @@ int LibImgViewListView::getRowWidth() return 2 * (count + 1) + ITEM_NORMAL_WIDTH * count + ITEM_CURRENT_WH - ITEM_NORMAL_WIDTH; } - - -//void ImgViewListView::mousePressEvent(QMouseEvent *event) -//{ -// qDebug() << "mousePressEvent"; -// return DListView::mousePressEvent(event); -//} - -//void ImgViewListView::mouseMoveEvent(QMouseEvent *event) -//{ -// qDebug() << "mouseMoveEvent"; -// return DListView::mouseMoveEvent(event); -//} - -//void ImgViewListView::mouseReleaseEvent(QMouseEvent *event) -//{ -// qDebug() << "mouseReleaseEvent"; -// return DListView::mouseReleaseEvent(event); -//} - void LibImgViewListView::slotOneImgReady(QString path, imageViewerSpace::ItemInfo pix) { + qDebug() << "Image ready for path:" << path; for (int i = 0; i < m_model->rowCount(); i++) { QModelIndex index = m_model->index(i, 0); imageViewerSpace::ItemInfo data = index.data(Qt::DisplayRole).value(); @@ -297,6 +282,7 @@ void LibImgViewListView::slotOneImgReady(QString path, imageViewerSpace::ItemInf // 判断当前的文件路径是否变更(重命名时),若变更则更新 if (path == m_currentPath && pix.path != m_currentPath) { + qDebug() << "Updating current path from" << m_currentPath << "to" << pix.path; m_currentPath = pix.path; } @@ -309,6 +295,7 @@ void LibImgViewListView::slotOneImgReady(QString path, imageViewerSpace::ItemInf void LibImgViewListView::slotCurrentImgFlush(QPixmap pix, const QSize &originalSize) { + qDebug() << "Flushing current image, original size:" << originalSize; QModelIndex currentIndex = m_model->index(m_currentRow, 0); imageViewerSpace::ItemInfo data = currentIndex.data(Qt::DisplayRole).value(); @@ -319,6 +306,7 @@ void LibImgViewListView::slotCurrentImgFlush(QPixmap pix, const QSize &originalS // FIX:暂时修复,用于解决某些场景下初始化,图片全数据还未处理完成(多线程处理) // data.imageType 还未设置的情况 if (data.imageType == imageViewerSpace::ImageTypeBlank) { + qDebug() << "Setting image type for blank image"; data.imageType = LibUnionImage_NameSpace::getImageType(data.path); } @@ -336,14 +324,19 @@ void LibImgViewListView::onClicked(const QModelIndex &index) //重新点击,m_currentPath需要重新赋值 imageViewerSpace::ItemInfo info = index.data(Qt::DisplayRole).value(); m_currentPath = info.path; + if (index.row() == m_currentRow) { + qDebug() << "Clicked on current item, no action needed"; return; } if (info.path.isEmpty()) { + qWarning() << "Clicked item path is empty"; return; } + qDebug() << "Item clicked at index:" << index.row() << "path:" << info.path; + QModelIndex currentIndex = m_model->index(m_currentRow, 0); if (currentIndex.isValid()) { //重置前一个选中项的宽高 @@ -355,9 +348,6 @@ void LibImgViewListView::onClicked(const QModelIndex &index) QVariant(QSize(LibImgViewListView::ITEM_CURRENT_WH, LibImgViewListView::ITEM_CURRENT_WH)), Qt::SizeHintRole); m_currentRow = index.row(); - qDebug() << "---" << __FUNCTION__ << "---m_currentRow = " << m_currentRow; - qDebug() << "---" << __FUNCTION__ << "---info.path = " << info.path; - //刷新界面 doItemsLayout(); //如果点击的是最后一个则向前移动 startMoveToLeftAnimation(); @@ -388,19 +378,17 @@ void LibImgViewListView::cutPixmap(imageViewerSpace::ItemInfo &iteminfo) } } } -//加载后50张 + void LibImgViewListView::loadFiftyRight() { + qDebug() << "Loading next 50 images starting from index:" << m_currentRow; int count = 0; for (int i = m_currentRow; i < m_model->rowCount(); i++) { count++; QModelIndex indexImg = m_model->index(i, 0); imageViewerSpace::ItemInfo infoImg = indexImg.data(Qt::DisplayRole).value(); if (infoImg.image.isNull()) { -// if (!ImageEngineApi::instance()->m_imgLoaded.contains(infoImg.path)) { -// emit ImageEngineApi::instance()->sigLoadThumbnailIMG(infoImg.path); -// ImageEngineApi::instance()->m_imgLoaded.append(infoImg.path); -// } + qDebug() << "Loading thumbnail for image at index:" << i; } if (count == 50) { break; @@ -410,6 +398,7 @@ void LibImgViewListView::loadFiftyRight() void LibImgViewListView::startMoveToLeftAnimation() { + qDebug() << "Starting move to left animation"; if (m_moveAnimation == nullptr) { m_moveAnimation = new QPropertyAnimation(this->horizontalScrollBar(), "value", this); } @@ -425,6 +414,7 @@ void LibImgViewListView::startMoveToLeftAnimation() m_moveAnimation->stop(); } m_moveAnimation->start(); + qDebug() << "Animation started, current position:" << rect.x(); } } diff --git a/libimageviewer/viewpanel/contents/imgviewwidget.cpp b/libimageviewer/viewpanel/contents/imgviewwidget.cpp index 1e00b522..64938468 100644 --- a/libimageviewer/viewpanel/contents/imgviewwidget.cpp +++ b/libimageviewer/viewpanel/contents/imgviewwidget.cpp @@ -8,6 +8,7 @@ #include "unionimage/unionimage.h" #include "imgviewlistview.h" #include "accessibility/ac-desktop-define.h" +#include "service/imagedataservice.h" #include #include @@ -33,6 +34,7 @@ DWIDGET_USE_NAMESPACE MyImageListWidget::MyImageListWidget(QWidget *parent) : QWidget(parent) { + qDebug() << "Initializing MyImageListWidget"; QHBoxLayout *hb = new QHBoxLayout(this); hb->setContentsMargins(0, 0, 0, 0); hb->setSpacing(0); @@ -40,98 +42,91 @@ MyImageListWidget::MyImageListWidget(QWidget *parent) m_listview = new LibImgViewListView(this); m_listview->setObjectName("ImgViewListView"); - // hb->addWidget(m_listview); m_listview->viewport()->installEventFilter(this); // 设置一个可以放置的高度 m_listview->viewport()->setFixedHeight(90); - connect(m_listview, &LibImgViewListView::clicked, this, &MyImageListWidget::onClicked); - // connect(m_listview->selectionModel(), &QItemSelectionModel::selectionChanged, - // this, &MyImageListWidget::ONselectionChanged); + qDebug() << "ListView initialized with fixed height:" << m_listview->viewport()->height(); + connect(m_listview, &LibImgViewListView::clicked, this, &MyImageListWidget::onClicked); connect(m_listview, &LibImgViewListView::openImg, this, &MyImageListWidget::openImg); connect(m_listview->horizontalScrollBar(), &QScrollBar::valueChanged, this, &MyImageListWidget::onScrollBarValueChanged); + initAnimation(); + qDebug() << "Animation initialized"; // 解决释放到程序外,不会动画的问题 - connect(LibCommonService::instance(), &LibCommonService::sigRightMousePress, this, [=] - { + connect(LibCommonService::instance(), &LibCommonService::sigRightMousePress, this, [=] { qint64 currentTime = QDateTime::currentMSecsSinceEpoch(); - if (currentTime - 100 > m_lastReleaseTime) - { + if (currentTime - 100 > m_lastReleaseTime) { m_lastReleaseTime = currentTime; + qDebug() << "Right mouse press detected, starting animation"; animationStart(true, 0, 400); - } }); + } + }); + qDebug() << "MyImageListWidget initialization completed"; } -#include "service/imagedataservice.h" + bool MyImageListWidget::eventFilter(QObject *obj, QEvent *e) { - if (e->type() == QEvent::Leave) - { - qDebug() << "QEvent::Leave" << obj; + if (e->type() == QEvent::Leave) { + qDebug() << "Mouse leave event on object:" << obj; } - if (e->type() == QEvent::MouseButtonPress) - { - if (!isEnabled()) - { + + if (e->type() == QEvent::MouseButtonPress) { + if (!isEnabled()) { + qDebug() << "Widget disabled, ignoring mouse press"; return true; } QMouseEvent *mouseEvent = dynamic_cast(e); m_pressPoint = mouseEvent->globalPos(); m_movePoint = mouseEvent->globalPos(); - qDebug() << m_movePoint; m_moveViewPoint = mouseEvent->globalPos(); + qDebug() << "Mouse press at position:" << m_pressPoint; m_timer->start(); m_movePoints.clear(); - m_preListGeometryLeft = m_listview->geometry().left(); - m_listview->update(); - qDebug() << "------------getCount = " << LibImageDataService::instance()->getCount(); + qDebug() << "Image count:" << LibImageDataService::instance()->getCount(); } - if (e->type() == QEvent::MouseButtonRelease) - { - if (!isEnabled()) - { + + if (e->type() == QEvent::MouseButtonRelease) { + if (!isEnabled()) { + qDebug() << "Widget disabled, ignoring mouse release"; return true; } - if (m_movePoints.size() > 0) - { + if (m_movePoints.size() > 0) { int endPos = m_movePoints.last().x() - m_movePoints.first().x(); + qDebug() << "Mouse release, movement distance:" << endPos; // 过滤掉触屏点击时的move误操作 - if (abs(m_movePoints.last().x() - m_movePoints.first().x()) > 15) - { + if (abs(m_movePoints.last().x() - m_movePoints.first().x()) > 15) { + qDebug() << "Starting inertia animation"; animationStart(false, endPos, 500); - } - else - { + } else { + qDebug() << "Starting reset animation"; animationStart(true, 0, 400); } } - // 松手,动画重置按钮应该所在的位置 - // animationStart(true, 0, 400); } - if (e->type() == QEvent::MouseMove || e->type() == QEvent::TouchUpdate) - { - if (!isEnabled()) - { + + if (e->type() == QEvent::MouseMove || e->type() == QEvent::TouchUpdate) { + if (!isEnabled()) { + qDebug() << "Widget disabled, ignoring mouse/touch move"; return true; } QMouseEvent *mouseEvent = dynamic_cast(e); - if (!mouseEvent) - { + if (!mouseEvent) { + qWarning() << "Invalid mouse event"; return false; } + QPoint p = mouseEvent->globalPos(); - if (m_movePoints.size() < 20) - { + if (m_movePoints.size() < 20) { m_movePoints.push_back(p); - } - else - { + } else { m_movePoints.pop_front(); m_movePoints.push_back(p); } @@ -141,67 +136,58 @@ bool MyImageListWidget::eventFilter(QObject *obj, QEvent *e) int offsetRowMove = rowWidth - ((rowWidth / RIGHT_LISTVIEW_MOVE_UPDATE) > 14 ? 12 : (rowWidth / RIGHT_LISTVIEW_MOVE_UPDATE - 3)) * RIGHT_LISTVIEW_MOVE_UPDATE; moveRangeX = moveRangeX > LEFT_LISTVIEW_MOVE_MAXLEN ? LEFT_LISTVIEW_MOVE_MAXLEN : moveRangeX; moveRangeX = moveRangeX < (LEFT_LISTVIEW_MOVE_MAXLEN - offsetRowMove) ? (LEFT_LISTVIEW_MOVE_MAXLEN - offsetRowMove) : moveRangeX; + m_listview->move(moveRangeX, m_listview->y()); m_moveViewPoint = p; + qDebug() << "List view moved to position:" << moveRangeX; // 目的为了获取moveX的值,中心离当前位置的差值 int moveX = 0; int middle = (this->geometry().right() - this->geometry().left()) / 2; int itemX = m_listview->x() + m_listview->getCurrentItemX() + 31; - if (rowWidth - m_listview->getCurrentItemX() < (this->geometry().width() / 2)) - { + + if (rowWidth - m_listview->getCurrentItemX() < (this->geometry().width() / 2)) { moveX = this->geometry().width() - rowWidth - m_listview->x(); - } - else if (m_listview->getCurrentItemX() < (this->geometry().width() / 2)) - { + } else if (m_listview->getCurrentItemX() < (this->geometry().width() / 2)) { moveX = 0 - m_listview->pos().x(); - } - else if (m_listview->geometry().width() <= this->width()) - { + } else if (m_listview->geometry().width() <= this->width()) { moveX = 0; - } - else - { + } else { moveX = middle - itemX; } + // moveX > 32或moveX <- 32则滑动两次(代表没有居中) // 如果这一次的移动并没有超过很大范围32-50,向右切换,并且m_movePoint位置记录为移动了32,这样的话可以保证每次切换流畅 - if (m_listview->x() < 0 && m_movePoint.x() - p.x() >= 32 && m_movePoint.x() - p.x() <= 50) - { + if (m_listview->x() < 0 && m_movePoint.x() - p.x() >= 32 && m_movePoint.x() - p.x() <= 50) { + qDebug() << "Switching to next item (small movement)"; m_listview->openNext(); m_movePoint = QPoint(m_movePoint.x() - 32, m_movePoint.y()); - if (moveX > 32) - { + if (moveX > 32) { m_listview->openNext(); } - } - // 如果这一次的移动并超过很大范围>50,向右切换,并且m_movePoint位置记录为移动了到了当前的位置,目的是在最前面滑动的时候做到始终显示在屏幕上,到开头才滑动 - else if (m_listview->x() < 0 && m_movePoint.x() - p.x() > 32) - { + } else if (m_listview->x() < 0 && m_movePoint.x() - p.x() > 32) { + // 如果这一次的移动并超过很大范围>50,向右切换,并且m_movePoint位置记录为移动了到了当前的位置, + // 目的是在最前面滑动的时候做到始终显示在屏幕上,到开头才滑动 + qDebug() << "Switching to next item (large movement)"; m_listview->openNext(); m_movePoint = QPoint(p.x(), m_movePoint.y()); - if (moveX > 32) - { + if (moveX > 32) { m_listview->openNext(); } - } - // 同上,32-50之间则m_movePoint移动32 - else if ((rowWidth - m_listview->getCurrentItemX() - moveX) > 0 && m_movePoint.x() - p.x() <= -32 && m_movePoint.x() - p.x() >= -50) - { + } else if ((rowWidth - m_listview->getCurrentItemX() - moveX) > 0 && m_movePoint.x() - p.x() <= -32 && m_movePoint.x() - p.x() >= -50) { + // 同上,32-50之间则m_movePoint移动32 + qDebug() << "Switching to previous item (small movement)"; m_listview->openPre(); m_movePoint = QPoint(m_movePoint.x() + 32, m_movePoint.y()); - if (moveX < -32) - { + if (moveX < -32) { m_listview->openPre(); } - } - //>50,超过边界则不移动,框框要在屏幕范围内 - else if ((rowWidth - m_listview->getCurrentItemX() - moveX) > 0 && m_movePoint.x() - p.x() <= -32) - { + } else if ((rowWidth - m_listview->getCurrentItemX() - moveX) > 0 && m_movePoint.x() - p.x() <= -32) { + //>50,超过边界则不移动,框框要在屏幕范围内 + qDebug() << "Switching to previous item (large movement)"; m_listview->openPre(); m_movePoint = QPoint(p.x(), m_movePoint.y()); - if (moveX < -32) - { + if (moveX < -32) { m_listview->openPre(); } } @@ -232,6 +218,7 @@ MyImageListWidget::~MyImageListWidget() void MyImageListWidget::setAllFile(QList itemInfos, QString path) { + qDebug() << "Setting all files, count:" << itemInfos.size() << "current path:" << path; m_listview->setAllFile(itemInfos, path); this->setVisible(itemInfos.size() > 1); setSelectCenter(); @@ -283,15 +270,18 @@ void MyImageListWidget::clearListView() void MyImageListWidget::initAnimation() { + qDebug() << "Initializing animation components"; m_timer = new QTimer(this); m_timer->setInterval(200); m_timer->setSingleShot(true); - if (m_listview) - { + + if (m_listview) { m_resetAnimation = new QPropertyAnimation(m_listview, "pos", nullptr); // 和上层m_obj的销毁绑在一起 } + connect(m_resetAnimation, SIGNAL(finished()), this, SLOT(animationFinished())); connect(m_resetAnimation, SIGNAL(valueChanged(const QVariant)), this, SLOT(animationValueChanged(const QVariant))); + qDebug() << "Animation components initialized"; } QString MyImageListWidget::getCurrentPath() @@ -328,13 +318,12 @@ QStringList MyImageListWidget::getAllPath() void MyImageListWidget::animationFinished() { // 设置type标志用来判断是惯性动画还是复位动画 - if (m_resetAnimation->property("type") == "500") - { + qDebug() << "Animation finished, type:" << m_resetAnimation->property("type").toString(); + if (m_resetAnimation->property("type") == "500") { m_resetFinish = false; animationStart(true, 0, 400); } - if (m_resetAnimation->property("type") == "400") - { + if (m_resetAnimation->property("type") == "400") { m_resetFinish = true; } } @@ -352,8 +341,10 @@ void MyImageListWidget::animationValueChanged(const QVariant value) void MyImageListWidget::animationStart(bool isReset, int endPos, int duration) { - if (m_resetAnimation->state() == QPropertyAnimation::State::Running) - { + qDebug() << "Starting animation, isReset:" << isReset << "endPos:" << endPos << "duration:" << duration; + + if (m_resetAnimation->state() == QPropertyAnimation::State::Running) { + qDebug() << "Stopping existing animation"; m_resetAnimation->stop(); } @@ -362,34 +353,25 @@ void MyImageListWidget::animationStart(bool isReset, int endPos, int duration) int middle = (this->geometry().right() - this->geometry().left()) / 2; int itemX = m_listview->x() + m_listview->getCurrentItemX() + 31; int rowWidth = m_listview->getRowWidth(); - if (rowWidth - m_listview->getCurrentItemX() < (this->geometry().width() / 2)) - { + + if (rowWidth - m_listview->getCurrentItemX() < (this->geometry().width() / 2)) { moveX = this->geometry().width() - rowWidth - m_listview->x(); - } - else if (m_listview->getCurrentItemX() < (this->geometry().width() / 2)) - { + } else if (m_listview->getCurrentItemX() < (this->geometry().width() / 2)) { moveX = 0 - m_listview->pos().x(); - } - else if (m_listview->geometry().width() <= this->width()) - { + } else if (m_listview->geometry().width() <= this->width()) { moveX = 0; - } - else - { + } else { moveX = middle - itemX; } - if (!isReset) - { + if (!isReset) { moveX = endPos; } + m_resetAnimation->setDuration(duration); - if (duration == 500) - { + if (duration == 500) { m_resetAnimation->setProperty("type", "500"); - } - else - { + } else { m_resetAnimation->setProperty("type", "400"); } m_resetAnimation->setEasingCurve(QEasingCurve::OutQuad); @@ -399,8 +381,10 @@ void MyImageListWidget::animationStart(bool isReset, int endPos, int duration) int offsetRowMove = rowWidth - ((rowWidth / RIGHT_LISTVIEW_MOVE_UPDATE) >= 12 ? 9 : (rowWidth / RIGHT_LISTVIEW_MOVE_UPDATE - 3)) * RIGHT_LISTVIEW_MOVE_UPDATE; moveRangeX = moveRangeX > LEFT_LISTVIEW_MOVE_MAXLEN ? LEFT_LISTVIEW_MOVE_MAXLEN : moveRangeX; moveRangeX = moveRangeX < (LEFT_LISTVIEW_MOVE_MAXLEN - offsetRowMove) ? (LEFT_LISTVIEW_MOVE_MAXLEN - offsetRowMove) : moveRangeX; + m_resetAnimation->setEndValue(QPoint(moveRangeX, m_listview->pos().y())); m_resetAnimation->start(); + qDebug() << "Animation started with end position:" << moveRangeX; } void MyImageListWidget::stopAnimation() @@ -413,52 +397,43 @@ void MyImageListWidget::stopAnimation() void MyImageListWidget::thumbnailIsMoving() { - if (m_resetAnimation->state() == QPropertyAnimation::State::Running && m_resetAnimation->duration() == 400) - { + if (m_resetAnimation->state() == QPropertyAnimation::State::Running && m_resetAnimation->duration() == 400) { return; } - // int endPos = m_movePoints.last().x() - m_movePoints.first().x(); + int offsetLimit = m_listview->geometry().left() - m_preListGeometryLeft; - if (abs(offsetLimit) <= 32) - { + if (abs(offsetLimit) <= 32) { return; } - qDebug() << offsetLimit; + qDebug() << "Thumbnail moving, offset:" << offsetLimit; + // 目的为了获取moveX的值,中心离当前位置的差值 int moveX = 0; int middle = (this->geometry().right() - this->geometry().left()) / 2; int itemX = m_listview->x() + m_listview->getCurrentItemX() + 31; int rowWidth = m_listview->getRowWidth(); - if (rowWidth - m_listview->getCurrentItemX() < (this->geometry().width() / 2)) - { + + if (rowWidth - m_listview->getCurrentItemX() < (this->geometry().width() / 2)) { moveX = this->geometry().width() - rowWidth - m_listview->x(); - } - else if (m_listview->getCurrentItemX() < (this->geometry().width() / 2)) - { + } else if (m_listview->getCurrentItemX() < (this->geometry().width() / 2)) { moveX = 0 - m_listview->pos().x(); - } - else if (m_listview->geometry().width() <= this->width()) - { + } else if (m_listview->geometry().width() <= this->width()) { moveX = 0; - } - else - { + } else { moveX = middle - itemX; } + // 如果图片没居中,会切换两次 - if (offsetLimit > 0) - { + if (offsetLimit > 0) { + qDebug() << "Moving to previous item"; m_listview->openPre(); - if (moveX < -32) - { + if (moveX < -32) { m_listview->openPre(); } - } - else - { + } else { + qDebug() << "Moving to next item"; m_listview->openNext(); - if (moveX > 32) - { + if (moveX > 32) { m_listview->openNext(); } } @@ -516,9 +491,8 @@ void MyImageListWidget::openPre() void MyImageListWidget::onClicked(const QModelIndex &index) { - qDebug() << "---------"; - if (m_timer->isActive()) - { + qDebug() << "Item clicked at index:" << index.row(); + if (m_timer->isActive()) { m_listview->onClicked(index); } animationStart(true, 0, 400); diff --git a/libimageviewer/viewpanel/lockwidget.cpp b/libimageviewer/viewpanel/lockwidget.cpp index 400c7544..a878955c 100644 --- a/libimageviewer/viewpanel/lockwidget.cpp +++ b/libimageviewer/viewpanel/lockwidget.cpp @@ -21,27 +21,37 @@ LockWidget::LockWidget(const QString &darkFile, : ThemeWidget(darkFile, lightFile, parent), m_picString("") { + qDebug() << "Initializing LockWidget with dark file:" << darkFile << "and light file:" << lightFile; setMouseTracking(true); this->setAttribute(Qt::WA_AcceptTouchEvents); grabGesture(Qt::PinchGesture); grabGesture(Qt::SwipeGesture); grabGesture(Qt::PanGesture); + qDebug() << "Touch gestures initialized"; + //修复style问题 if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType) { m_picString = ICON_PIXMAP_DARK; m_theme = true; + qDebug() << "Using dark theme icon:" << ICON_PIXMAP_DARK; } else { m_picString = ICON_PIXMAP_LIGHT; m_theme = false; + qDebug() << "Using light theme icon:" << ICON_PIXMAP_LIGHT; } + m_bgLabel = new DLabel(this); m_bgLabel->setFixedSize(151, 151); m_bgLabel->setObjectName("BgLabel"); + qDebug() << "Background label created with size:" << QSize(151, 151); + #ifdef OPENACCESSIBLE setObjectName(Lock_Widget); setAccessibleName(Lock_Widget); m_bgLabel->setAccessibleName("BgLabel"); + qDebug() << "Accessibility names set"; #endif + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [ = ]() { DGuiApplicationHelper::ColorType themeType = @@ -50,20 +60,26 @@ LockWidget::LockWidget(const QString &darkFile, if (themeType == DGuiApplicationHelper::DarkType) { m_picString = ICON_PIXMAP_DARK; m_theme = true; + qDebug() << "Theme changed to dark"; } else { m_picString = ICON_PIXMAP_LIGHT; m_theme = false; + qDebug() << "Theme changed to light"; } QPixmap logo_pix = Libutils::base::renderSVG(m_picString, THUMBNAIL_SIZE); if (m_bgLabel) { m_bgLabel->setPixmap(logo_pix); + qDebug() << "Updated background label with new theme icon"; } }); + m_lockTips = new DLabel(this); m_lockTips->setObjectName("LockTips"); m_lockTips->setVisible(false); setContentText(tr("You have no permission to view the image")); + qDebug() << "Lock tips label created and initialized"; + QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); @@ -71,9 +87,8 @@ LockWidget::LockWidget(const QString &darkFile, QPixmap logo_pix = Libutils::base::renderSVG(m_picString, THUMBNAIL_SIZE); m_bgLabel->setPixmap(logo_pix); layout->addWidget(m_bgLabel, 0, Qt::AlignHCenter); - //layout->addSpacing(18); - //layout->addWidget(m_lockTips, 0, Qt::AlignHCenter); layout->addStretch(1); + qDebug() << "Layout initialized with background label"; connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::paletteTypeChanged, this, &LockWidget::onThemeChanged); @@ -81,25 +96,29 @@ LockWidget::LockWidget(const QString &darkFile, void LockWidget::setContentText(const QString &text) { + qDebug() << "Setting lock tips text:" << text; m_lockTips->setText(text); int textHeight = Libutils::base::stringHeight(m_lockTips->font(), m_lockTips->text()); m_lockTips->setMinimumHeight(textHeight + 2); + qDebug() << "Lock tips height set to:" << (textHeight + 2); } void LockWidget::handleGestureEvent(QGestureEvent *gesture) { - /* if (QGesture *swipe = gesture->gesture(Qt::SwipeGesture)) - swipeTriggered(static_cast(swipe)); - else */if (QGesture *pinch = gesture->gesture(Qt::PinchGesture)) + if (QGesture *pinch = gesture->gesture(Qt::PinchGesture)) { + qDebug() << "Handling pinch gesture"; pinchTriggered(static_cast(pinch)); + } } void LockWidget::mouseDoubleClickEvent(QMouseEvent *e) { //非平板才能双击,其他是单击全屏 - if (e->button() == Qt::LeftButton) + if (e->button() == Qt::LeftButton) { + qDebug() << "Double click detected, emitting showfullScreen signal"; emit showfullScreen(); + } ThemeWidget::mouseDoubleClickEvent(e); } @@ -120,11 +139,11 @@ void LockWidget::mouseReleaseEvent(QMouseEvent *e) int offset = e->globalPos().x() - m_startx; if (qAbs(offset) > 200) { if (offset > 0) { + qDebug() << "Swipe right detected, emitting previousRequested signal"; emit previousRequested(); - qDebug() << "zy------ThumbnailWidget::event previousRequested"; } else { + qDebug() << "Swipe left detected, emitting nextRequested signal"; emit nextRequested(); - qDebug() << "zy------ThumbnailWidget::event nextRequested"; } } } @@ -141,6 +160,7 @@ void LockWidget::mousePressEvent(QMouseEvent *e) #endif QWidget::mousePressEvent(e); m_startx = e->globalPos().x(); + qDebug() << "Mouse press at x position:" << m_startx; } void LockWidget::mouseMoveEvent(QMouseEvent *event) @@ -155,11 +175,13 @@ bool LockWidget::event(QEvent *event) if (evType == QEvent::TouchBegin || evType == QEvent::TouchUpdate || evType == QEvent::TouchEnd) { if (evType == QEvent::TouchBegin) { - qDebug() << "QEvent::TouchBegin"; + qDebug() << "Touch begin event detected"; m_maxTouchPoints = 1; } - } else if (event->type() == QEvent::Gesture) + } else if (event->type() == QEvent::Gesture) { + qDebug() << "Gesture event detected"; handleGestureEvent(static_cast(event)); + } return QWidget::event(event); } @@ -167,23 +189,28 @@ void LockWidget::pinchTriggered(QPinchGesture *gesture) { Q_UNUSED(gesture); m_maxTouchPoints = 2; + qDebug() << "Pinch gesture triggered, max touch points set to 2"; } void LockWidget::onThemeChanged(DGuiApplicationHelper::ColorType theme) { + qDebug() << "Theme changed to:" << (theme == DGuiApplicationHelper::DarkType ? "Dark" : "Light"); ThemeWidget::onThemeChanged(theme); update(); } LockWidget::~LockWidget() { + qDebug() << "Destroying LockWidget"; if (m_bgLabel) { m_bgLabel->deleteLater(); m_bgLabel = nullptr; + qDebug() << "Background label deleted"; } if (m_lockTips) { m_lockTips->deleteLater(); m_lockTips = nullptr; + qDebug() << "Lock tips label deleted"; } } @@ -191,11 +218,11 @@ void LockWidget::wheelEvent(QWheelEvent *event) { if ((event->modifiers() == Qt::ControlModifier)) { if (event->angleDelta().y() > 0) { + qDebug() << "Control + wheel up detected, emitting previousRequested signal"; emit previousRequested(); } else if (event->angleDelta().y() < 0) { + qDebug() << "Control + wheel down detected, emitting nextRequested signal"; emit nextRequested(); } - qDebug() << "control++"; - } } diff --git a/libimageviewer/viewpanel/navigationwidget.cpp b/libimageviewer/viewpanel/navigationwidget.cpp index 54688e01..1af07fb7 100644 --- a/libimageviewer/viewpanel/navigationwidget.cpp +++ b/libimageviewer/viewpanel/navigationwidget.cpp @@ -39,8 +39,10 @@ using namespace Dtk::Widget; NavigationWidget::NavigationWidget(QWidget *parent) : QWidget(parent) { + qDebug() << "Initializing NavigationWidget"; hide(); resize(150, 112); + qDebug() << "NavigationWidget size set to:" << QSize(150, 112); ImageButton *closeBtn_light = new ImageButton(ICON_CLOSE_NORMAL_LIGHT, ICON_CLOSE_HOVER_LIGHT, ICON_CLOSE_PRESS_LIGHT, " ", this); closeBtn_light->setTooltipVisible(true); @@ -70,6 +72,7 @@ NavigationWidget::NavigationWidget(QWidget *parent) //修复style问题 if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType) { + qDebug() << "Setting up dark theme"; closeBtn_light->hide(); closeBtn_dark->show(); m_bgImgUrl = Libutils::view::naviwindow::DARK_BG_IMG ; @@ -78,6 +81,7 @@ NavigationWidget::NavigationWidget(QWidget *parent) m_mrBorderColor = Libutils::view::naviwindow::DARK_MR_BORDER_Color; m_imgRBorderColor = Libutils::view::naviwindow:: DARK_IMG_R_BORDER_COLOR; } else { + qDebug() << "Setting up light theme"; closeBtn_dark->hide(); closeBtn_light->show(); m_bgImgUrl = Libutils::view::naviwindow::LIGHT_BG_IMG ; @@ -90,6 +94,7 @@ NavigationWidget::NavigationWidget(QWidget *parent) QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [ = ]() { DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType(); if (themeType == DGuiApplicationHelper::DarkType) { + qDebug() << "Theme changed to dark"; closeBtn_light->hide(); closeBtn_dark->show(); m_bgImgUrl = Libutils::view::naviwindow::DARK_BG_IMG ; @@ -98,6 +103,7 @@ NavigationWidget::NavigationWidget(QWidget *parent) m_mrBorderColor = Libutils::view::naviwindow::DARK_MR_BORDER_Color; m_imgRBorderColor = Libutils::view::naviwindow:: DARK_IMG_R_BORDER_COLOR; } else { + qDebug() << "Theme changed to light"; closeBtn_dark->hide(); closeBtn_light->show(); m_bgImgUrl = Libutils::view::naviwindow::LIGHT_BG_IMG ; @@ -112,7 +118,7 @@ NavigationWidget::NavigationWidget(QWidget *parent) rect().y() + IMAGE_MARGIN_BOTTOM, rect().width() - IMAGE_MARGIN * 2, rect().height() - IMAGE_MARGIN_BOTTOM * 2); - + qDebug() << "Main rectangle set to:" << m_mainRect; // connect(dApp->viewerTheme, &ViewerThemeManager::viewerThemeChanged, this, // &NavigationWidget::onThemeChanged); @@ -120,6 +126,7 @@ NavigationWidget::NavigationWidget(QWidget *parent) void NavigationWidget::setAlwaysHidden(bool value) { + qDebug() << "Setting always hidden to:" << value; LibConfigSetter::instance()->setValue(SETTINGS_GROUP, SETTINGS_ALWAYSHIDDEN_KEY, QVariant(value)); if (isAlwaysHidden()) @@ -141,17 +148,18 @@ QPoint NavigationWidget::transImagePos(QPoint pos) void NavigationWidget::setImage(const QImage &img) { + qDebug() << "Setting navigation image, original size:" << img.size(); const qreal ratio = devicePixelRatioF(); QRect tmpImageRect = QRect(m_mainRect.x(), m_mainRect.y(), qRound(m_mainRect.width() * ratio), qRound(m_mainRect.height() * ratio)); -// QRect tmpImageRect = m_mainRect; m_originRect = img.rect(); // 只在图片比可显示区域大时才缩放 if (tmpImageRect.width() < m_originRect.width() || tmpImageRect.height() < m_originRect.height()) { + qDebug() << "Scaling image to fit display area"; m_img = img.scaled(tmpImageRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); } else { m_img = img; @@ -161,8 +169,10 @@ void NavigationWidget::setImage(const QImage &img) //适应缩放比例 if (m_img.height() > (tmpImageRect.height() - 20) && m_img.width() >= (tmpImageRect.width() - 10)) { + qDebug() << "Adjusting image height to fit display area"; m_img = m_img.scaled(m_img.width(), tmpImageRect.height() - 20); } else if (m_img.height() > (tmpImageRect.height() - 10) && m_img.width() > (tmpImageRect.width() - 25)) { + qDebug() << "Adjusting image width to fit display area"; m_img = m_img.scaled((tmpImageRect.width() - 25), m_img.height()); } @@ -172,25 +182,23 @@ void NavigationWidget::setImage(const QImage &img) m_pix.setDevicePixelRatio(ratio); m_imageScale = qMax(1.0, qMax(qreal(img.width()) / qreal(m_img.width()), qreal(img.height()) / qreal(m_img.height()))); -// m_r = QRectF(0, 0, m_img.width() / ratio, m_img.height() / ratio); -// m_widthScale = img.width() / m_img.width(); -// m_heightScale = img.height() / m_img.height(); - m_r = QRectF(0, 0, m_img.width(), m_img.height()); - - imageDrawRect = QRect((m_mainRect.width() - m_img.width() / ratio) / 2 + IMAGE_MARGIN, (m_mainRect.height() - m_img.height() / ratio) / 2 + Libutils::common::BORDER_WIDTH, m_img.width() / ratio, m_img.height() / ratio); + qDebug() << "Image processing completed, final size:" << m_img.size() << "scale:" << m_imageScale; update(); } void NavigationWidget::setRectInImage(const QRect &r) { - if (m_img.isNull()) + if (m_img.isNull()) { + qWarning() << "Cannot set rect in image: image is null"; return; + } + qDebug() << "Setting rect in image:" << r; m_r.setX(qreal(r.x()) / m_imageScale / m_heightScale); m_r.setY(qreal(r.y()) / m_imageScale / m_widthScale); m_r.setWidth(qreal(r.width()) / m_imageScale / m_heightScale); @@ -201,43 +209,36 @@ void NavigationWidget::setRectInImage(const QRect &r) void NavigationWidget::mousePressEvent(QMouseEvent *e) { - if (e->button() == Qt::LeftButton) + if (e->button() == Qt::LeftButton) { + qDebug() << "Mouse press at position:" << e->pos(); tryMoveRect(transImagePos(e->pos())); + } } void NavigationWidget::mouseMoveEvent(QMouseEvent *e) { + qDebug() << "Mouse move to position:" << e->pos(); tryMoveRect(transImagePos(e->pos())); } void NavigationWidget::tryMoveRect(const QPoint &p) { -// int x0 = (m_mainRect.width() - m_img.width()) / 2 / devicePixelRatioF(); -// int y0 = (m_mainRect.height() - m_img.height()) / 2 / devicePixelRatioF(); -// const QRect imageRect(x0, y0, m_img.width(), m_img.height()); -// if (! imageRect.contains(p)) -// return; - - if (!m_mainRect.contains(p)) + if (!m_mainRect.contains(p)) { + qDebug() << "Point" << p << "is outside main rectangle"; return; + } -// const qreal x = 1.0 * (p.x() / devicePixelRatioF() - x0) / m_img.width() * m_originRect.width(); -// const qreal y = 1.0 * (p.y() / devicePixelRatioF() - y0) / m_img.height() * m_originRect.height(); //修复鼠标位置存在出入的问题 qreal x = p.x() * m_imageScale * m_heightScale; qreal y = p.y() * m_imageScale * m_widthScale; - -// qDebug() << p ; -// qDebug() << x << y; -// qDebug() << m_r; - + qDebug() << "Moving rect to position:" << QPointF(x, y); Q_EMIT requestMove(x, y); } bool NavigationWidget::checkbgisdark(QImage &img) const { - //long l = m_r.toRect().width() * m_r.toRect().height() / 100; + qDebug() << "Checking if background is dark"; int npixcntx, npixcnty; bool numlessflag; m_r.toRect().width() * m_r.toRect().height() < 50 ? numlessflag = true : numlessflag = false; @@ -248,6 +249,7 @@ bool NavigationWidget::checkbgisdark(QImage &img) const npixcntx = m_r.toRect().width() / 5; npixcnty = m_r.toRect().height() / 5; } + int total = 0; int darktotal = 0; for (int i = 0; i < npixcntx; i++) { @@ -268,29 +270,29 @@ bool NavigationWidget::checkbgisdark(QImage &img) const } } } - if (darktotal / (total * 1.00) > 0.95) - return true; - else - return false; + bool isDark = darktotal / (total * 1.00) > 0.95; + qDebug() << "Background darkness check result:" << isDark << "dark pixels:" << darktotal << "total pixels:" << total; + return isDark; } void NavigationWidget::paintEvent(QPaintEvent *) { QImage img(m_img); if (m_img.isNull()) { + qDebug() << "Painting empty navigation widget"; QPainter p(this); p.fillRect(m_r, m_BgColor); return; } -// const qreal ratio = devicePixelRatioF(); - + qDebug() << "Painting navigation widget with image size:" << img.size(); QPainter p(&img); p.fillRect(m_r, m_mrBgColor); -// p.setPen(m_mrBorderColor); if (checkbgisdark(img)) { + qDebug() << "Using gray pen for dark background"; p.setPen(QPen(Qt::gray)); } else { + qDebug() << "Using white pen for light background"; p.setPen(QColor(Qt::white)); } @@ -303,24 +305,9 @@ void NavigationWidget::paintEvent(QPaintEvent *) p.begin(this); QImage background(m_bgImgUrl); p.drawImage(this->rect(), background); - - //**draw transparent background -// QPixmap pm(12, 12); -// QPainter pmp(&pm); -// //TODO: the transparent box -// //should not be scaled with the image -// pmp.fillRect(0, 0, 6, 6, LIGHT_CHECKER_COLOR); -// pmp.fillRect(6, 6, 6, 6, LIGHT_CHECKER_COLOR); -// pmp.fillRect(0, 6, 6, 6, DARK_CHECKER_COLOR); -// pmp.fillRect(6, 0, 6, 6, DARK_CHECKER_COLOR); -// pmp.end(); - -// p.fillRect(imageDrawRect, QBrush(pm)); p.drawImage(imageDrawRect, img); QRect borderRect = QRect(imageDrawRect.x(), imageDrawRect.y() + 1, imageDrawRect.width(), imageDrawRect.height() + 1); -// p.setPen(m_imgRBorderColor); p.setPen(QColor(0, 0, 0, 0)); - //p.setPen(QPen(Qt::red)); p.drawRect(borderRect); p.end(); } diff --git a/libimageviewer/viewpanel/scen/graphicsitem.cpp b/libimageviewer/viewpanel/scen/graphicsitem.cpp index 1c939661..d08de4e3 100644 --- a/libimageviewer/viewpanel/scen/graphicsitem.cpp +++ b/libimageviewer/viewpanel/scen/graphicsitem.cpp @@ -14,22 +14,27 @@ DGUI_USE_NAMESPACE LibGraphicsMovieItem::LibGraphicsMovieItem(const QString &fileName, const QString &suffix, QGraphicsItem *parent) : QGraphicsPixmapItem(fileName, parent) { + qDebug() << "Initializing LibGraphicsMovieItem with file:" << fileName; Q_UNUSED(suffix); setTransformationMode(Qt::SmoothTransformation); m_movie = new QMovie(fileName); QObject::connect(m_movie, &QMovie::frameChanged, this, [=] { - if (m_movie.isNull()) + if (m_movie.isNull()) { + qWarning() << "Movie object is null during frame change"; return; + } setPixmap(m_movie->currentPixmap()); }); //自动执行播放 m_movie->start(); + qDebug() << "Movie started for file:" << fileName; } LibGraphicsMovieItem::~LibGraphicsMovieItem() { + qDebug() << "Destroying LibGraphicsMovieItem"; // Prepares the item for a geometry change. Call this function // before changing the bounding rect of an item to keep // QGraphicsScene's index up to date. @@ -39,6 +44,7 @@ LibGraphicsMovieItem::~LibGraphicsMovieItem() m_movie->stop(); m_movie->deleteLater(); m_movie = nullptr; + qDebug() << "Movie stopped and resources cleaned up"; } /*! @@ -49,31 +55,38 @@ LibGraphicsMovieItem::~LibGraphicsMovieItem() */ bool LibGraphicsMovieItem::isValid() const { - return m_movie->frameCount() > 1; + bool valid = m_movie->frameCount() > 1; + qDebug() << "Checking movie validity, frame count:" << m_movie->frameCount() << "is valid:" << valid; + return valid; } void LibGraphicsMovieItem::start() { + qDebug() << "Starting movie playback"; m_movie->start(); } void LibGraphicsMovieItem::stop() { + qDebug() << "Stopping movie playback"; m_movie->stop(); } LibGraphicsPixmapItem::LibGraphicsPixmapItem(const QPixmap &pixmap) : QGraphicsPixmapItem(pixmap, nullptr) { + qDebug() << "Initializing LibGraphicsPixmapItem with pixmap size:" << pixmap.size(); } LibGraphicsPixmapItem::~LibGraphicsPixmapItem() { + qDebug() << "Destroying LibGraphicsPixmapItem"; prepareGeometryChange(); } void LibGraphicsPixmapItem::setPixmap(const QPixmap &pixmap) { + qDebug() << "Setting new pixmap with size:" << pixmap.size(); cachePixmap = qMakePair(cachePixmap.first, pixmap); QGraphicsPixmapItem::setPixmap(pixmap); } @@ -85,6 +98,7 @@ void LibGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsI if (ts.type() == QTransform::TxScale && ts.m11() < 1) { QPixmap currentPixmap = pixmap(); if (currentPixmap.width() < 10000 && currentPixmap.height() < 10000) { + qDebug() << "Painting scaled pixmap, scale factor:" << ts.m11(); painter->setRenderHint(QPainter::SmoothPixmapTransform, (transformationMode() == Qt::SmoothTransformation)); Q_UNUSED(option); @@ -93,8 +107,10 @@ void LibGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsI QPixmap pixmap; if (qIsNull(cachePixmap.first - ts.m11())) { + qDebug() << "Using cached pixmap"; pixmap = cachePixmap.second; } else { + qDebug() << "Transforming pixmap for new scale"; pixmap = currentPixmap.transformed(painter->transform(), transformationMode()); cachePixmap = qMakePair(ts.m11(), pixmap); } @@ -104,6 +120,7 @@ void LibGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsI painter->drawPixmap(offset() + QPointF(ts.dx(), ts.dy()), pixmap); painter->setTransform(ts); } else { + qWarning() << "Pixmap too large for optimized painting, using default paint method"; QGraphicsPixmapItem::paint(painter, option, widget); } } else { @@ -114,19 +131,25 @@ void LibGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsI LibGraphicsMaskItem::LibGraphicsMaskItem(QGraphicsItem *parent) : QGraphicsRectItem(parent) { + qDebug() << "Initializing LibGraphicsMaskItem"; onThemeChange(DGuiApplicationHelper::instance()->themeType()); conn = QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, - [this](DGuiApplicationHelper::ColorType themeType) { this->onThemeChange(themeType); }); + [this](DGuiApplicationHelper::ColorType themeType) { + qDebug() << "Theme changed to:" << (themeType == DGuiApplicationHelper::DarkType ? "Dark" : "Light"); + this->onThemeChange(themeType); + }); } LibGraphicsMaskItem::~LibGraphicsMaskItem() { + qDebug() << "Destroying LibGraphicsMaskItem"; QObject::disconnect(conn); } void LibGraphicsMaskItem::onThemeChange(int theme) { + qDebug() << "Updating mask color for theme:" << (theme == DGuiApplicationHelper::DarkType ? "Dark" : "Light"); QColor maskColor; if (DGuiApplicationHelper::ColorType::DarkType == theme) { maskColor = QColor(Qt::black); @@ -141,4 +164,5 @@ void LibGraphicsMaskItem::onThemeChange(int theme) setPen(curPen); setBrush(maskColor); update(); + qDebug() << "Mask color updated with alpha:" << maskColor.alphaF(); } diff --git a/libimageviewer/viewpanel/scen/imagegraphicsview.cpp b/libimageviewer/viewpanel/scen/imagegraphicsview.cpp index bf11b787..eaa732a4 100644 --- a/libimageviewer/viewpanel/scen/imagegraphicsview.cpp +++ b/libimageviewer/viewpanel/scen/imagegraphicsview.cpp @@ -113,6 +113,7 @@ LibImageGraphicsView::LibImageGraphicsView(QWidget *parent) , m_movieItem(nullptr) , m_pixmapItem(nullptr) { + qDebug() << "Initializing LibImageGraphicsView"; this->setObjectName("ImageView"); // onThemeChanged(dApp->viewerTheme->getCurrentTheme()); setScene(new QGraphicsScene(this)); @@ -134,6 +135,7 @@ LibImageGraphicsView::LibImageGraphicsView(QWidget *parent) grabGesture(Qt::PinchGesture); grabGesture(Qt::SwipeGesture); grabGesture(Qt::PanGesture); + qDebug() << "Touch gestures initialized"; connect(&m_watcher, &QFutureWatcherBase::finished, this, &LibImageGraphicsView::onCacheFinish); // connect(dApp->viewerTheme, &ViewerThemeManager::viewerThemeChanged, this, &ImageView::onThemeChanged); @@ -146,14 +148,17 @@ LibImageGraphicsView::LibImageGraphicsView(QWidget *parent) QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &LibImageGraphicsView::onThemeTypeChanged); //初始化主题 onThemeTypeChanged(); + qDebug() << "Theme initialized"; m_imgFileWatcher = new QFileSystemWatcher(this); connect(m_imgFileWatcher, &QFileSystemWatcher::fileChanged, this, &LibImageGraphicsView::onImgFileChanged); m_isChangedTimer = new QTimer(this); QObject::connect(m_isChangedTimer, &QTimer::timeout, this, &LibImageGraphicsView::onIsChangedTimerTimeout); + qDebug() << "File watchers initialized"; // MTP文件加载完成通知, 使用 QueuedConnection 确保不在 setImage 时触发,保证先后顺序。 QObject::connect(MtpFileProxy::instance(), &MtpFileProxy::createProxyFileFinished, this, [ this ](const QString &proxyFile, bool){ if (proxyFile == m_loadPath) { + qDebug() << "MTP proxy file created:" << proxyFile; // SVG/TIF/GIF 需重新加载 imageViewerSpace::ImageType Type = LibUnionImage_NameSpace::getImageType(m_loadPath); if (imageViewerSpace::ImageTypeDynamic == Type @@ -226,6 +231,7 @@ void LibImageGraphicsView::setWindowIsFullScreen(bool bRet) LibImageGraphicsView::~LibImageGraphicsView() { + qDebug() << "Destroying LibImageGraphicsView"; if (m_imgFileWatcher) { // m_imgFileWatcher->clear(); // m_imgFileWatcher->quit(); @@ -255,6 +261,7 @@ LibImageGraphicsView::~LibImageGraphicsView() } //保存旋转状态 slotRotatePixCurrent(); + qDebug() << "LibImageGraphicsView destroyed"; } void LibImageGraphicsView::clear() @@ -269,6 +276,7 @@ void LibImageGraphicsView::clear() void LibImageGraphicsView::setImage(const QString &path, const QImage &image) { + qDebug() << "Setting image:" << path; // m_spinner 生命周期由 scene() 管理 hideSpinner(); @@ -285,6 +293,7 @@ void LibImageGraphicsView::setImage(const QString &path, const QImage &image) // 判断是否需要等待 MTP 代理文件加载完成,失败同样无需等待加载 MtpFileProxy::FileState state = MtpFileProxy::instance()->state(path); bool needProxyLoad = MtpFileProxy::instance()->contains(path) && (MtpFileProxy::Loading == state); + qDebug() << "MTP proxy state:" << state << "needProxyLoad:" << needProxyLoad; bool delayLoad = needProxyLoad; // 判断是否为AI模型处理图片,需要延迟加载 @@ -292,11 +301,13 @@ void LibImageGraphicsView::setImage(const QString &path, const QImage &image) bool imageEnhance = (AIModelService::None != enhanceState); delayLoad |= (AIModelService::Loading == enhanceState); QString sourceFile = AIModelService::instance()->sourceFilePath(path); + qDebug() << "Image enhance state:" << enhanceState << "delayLoad:" << delayLoad; //检测数据缓存,如果存在,则使用缓存 imageViewerSpace::ItemInfo info; if (needProxyLoad) { // 不获取数据 + qDebug() << "Skipping cache for proxy load"; } else if (imageEnhance) { info = LibCommonService::instance()->getImgInfoByPath(sourceFile); } else { @@ -304,10 +315,12 @@ void LibImageGraphicsView::setImage(const QString &path, const QImage &image) } m_bRoate = ImageEngine::instance()->isRotatable(path); //是否可旋转 + qDebug() << "Image is rotatable:" << m_bRoate; m_loadPath = path; // Empty path will cause crash in release-build mode if (path.isEmpty()) { + qWarning() << "Empty path provided to setImage"; return; } @@ -346,6 +359,7 @@ void LibImageGraphicsView::setImage(const QString &path, const QImage &image) //ImageTypeDynamic if (Type == imageViewerSpace::ImageTypeDynamic) { + qDebug() << "Loading dynamic image (GIF/MNG)"; m_pixmapItem = nullptr; m_movieItem = nullptr; m_imgSvgItem = nullptr; @@ -355,7 +369,7 @@ void LibImageGraphicsView::setImage(const QString &path, const QImage &image) // m_movieItem->start(); // Make sure item show in center of view after reload setSceneRect(m_movieItem->boundingRect()); - qDebug() << "m_movieItem->boundingRect() = " << m_movieItem->boundingRect(); + qDebug() << "Movie item bounding rect:" << m_movieItem->boundingRect(); s->addItem(m_movieItem); emit imageChanged(path); QMetaObject::invokeMethod(this, [ = ]() { @@ -364,6 +378,7 @@ void LibImageGraphicsView::setImage(const QString &path, const QImage &image) }, Qt::QueuedConnection); m_newImageLoadPhase = FullFinish; } else if (Type == imageViewerSpace::ImageTypeSvg) { + qDebug() << "Loading SVG image"; m_pixmapItem = nullptr; m_movieItem = nullptr; m_imgSvgItem = nullptr; @@ -387,6 +402,7 @@ void LibImageGraphicsView::setImage(const QString &path, const QImage &image) }, Qt::QueuedConnection); m_newImageLoadPhase = FullFinish; } else { + qDebug() << "Loading static image"; QPixmap previousPix; if (imageEnhance && m_pixmapItem) { previousPix = m_pixmapItem->pixmap(); @@ -510,12 +526,15 @@ void LibImageGraphicsView::setImage(const QString &path, const QImage &image) void LibImageGraphicsView::setScaleValue(qreal v) { //预先计算需要的缩放比 + qDebug() << "Setting scale value:" << v << "current scale:" << m_scal; double temp = m_scal * v; double scaleFactor = -1.0; if (v < 1 && temp <= MIN_SCALE_FACTOR) { scaleFactor = MIN_SCALE_FACTOR / m_scal; + qDebug() << "Scale limited to minimum:" << MIN_SCALE_FACTOR; } else if (v > 1 && temp >= MAX_SCALE_FACTOR) { scaleFactor = MAX_SCALE_FACTOR / m_scal; + qDebug() << "Scale limited to maximum:" << MAX_SCALE_FACTOR; } else { scaleFactor = v; m_isFitImage = false; @@ -525,7 +544,7 @@ void LibImageGraphicsView::setScaleValue(qreal v) //执行缩放 m_scal *= scaleFactor; scale(scaleFactor, scaleFactor); - qDebug() << m_scal; + qDebug() << "New scale value:" << m_scal; //1:1高亮按钮 if (m_scal - 1 > -0.01 && m_scal - 1 < 0.01) { @@ -638,10 +657,11 @@ void LibImageGraphicsView::fitImage() void LibImageGraphicsView::rotateClockWise() { + qDebug() << "Rotating image clockwise"; QString errMsg; QImage rotateResult; if (!LibUnionImage_NameSpace::rotateImageFIleWithImage(90, rotateResult, m_path, errMsg)) { - qDebug() << errMsg; + qWarning() << "Failed to rotate image:" << errMsg; return; } // dApp->m_imageloader->updateImageLoader(QStringList(m_path), QList({rotateResult})); @@ -650,10 +670,11 @@ void LibImageGraphicsView::rotateClockWise() void LibImageGraphicsView::rotateCounterclockwise() { + qDebug() << "Rotating image counterclockwise"; QString errMsg; QImage rotateResult; if (!LibUnionImage_NameSpace::rotateImageFIleWithImage(-90, rotateResult, m_path, errMsg)) { - qDebug() << errMsg; + qWarning() << "Failed to rotate image:" << errMsg; return; } // dApp->m_imageloader->updateImageLoader(QStringList(m_path), QList({rotateResult})); @@ -765,6 +786,7 @@ void LibImageGraphicsView::slotSavePic() void LibImageGraphicsView::onImgFileChanged(const QString &ddfFile) { + qDebug() << "Image file changed:" << ddfFile; // 判断是否为MTP原始路径文件,若为则同步更新代理文件状态 MtpFileProxy::instance()->triggerOriginFileChanged(ddfFile); @@ -775,6 +797,7 @@ void LibImageGraphicsView::onImgFileChanged(const QString &ddfFile) QString lastProcImage = AIModelService::instance()->lastProcOutput(); QString lastSource = AIModelService::instance()->sourceFilePath(lastProcImage); if (lastSource == ddfFile) { + qDebug() << "Cancelling AI processing for changed file"; AIModelService::instance()->cancelProcess(lastProcImage); } } @@ -782,6 +805,7 @@ void LibImageGraphicsView::onImgFileChanged(const QString &ddfFile) void LibImageGraphicsView::onLoadTimerTimeout() { + qDebug() << "Load timer timeout, starting image cache"; QFuture f = QtConcurrent::run(m_pool, cachePixmap, m_loadPath); if (m_watcher.isRunning()) { m_watcher.cancel(); @@ -1207,6 +1231,7 @@ bool LibImageGraphicsView::event(QEvent *event) void LibImageGraphicsView::onCacheFinish() { + qDebug() << "Image cache finished"; hideSpinner(); QVariantList vl = m_watcher.result(); @@ -1214,6 +1239,7 @@ void LibImageGraphicsView::onCacheFinish() const QString path = vl.first().toString(); if (path == m_path) { if (!m_pixmapItem) { + qWarning() << "No pixmap item available for cache update"; return; } QPixmap pixmap = vl.last().value(); @@ -1223,6 +1249,7 @@ void LibImageGraphicsView::onCacheFinish() pixmap = tmpPixmap; } if (m_newImageRotateAngle != 0) { + qDebug() << "Applying rotation angle:" << m_newImageRotateAngle; QTransform rotate; rotate.rotate(m_newImageRotateAngle); pixmap = pixmap.transformed(rotate, Qt::SmoothTransformation); @@ -1241,6 +1268,7 @@ void LibImageGraphicsView::onCacheFinish() //刷新缩略图 if (!pixmap.isNull() && !currentImageEnhance) { + qDebug() << "Generating thumbnail for cached image"; QPixmap thumbnailPixmap; if (0 != pixmap.height() && 0 != pixmap.width() && (pixmap.height() / pixmap.width()) < 10 && (pixmap.width() / pixmap.height()) < 10) { bool cache_exist = false; diff --git a/libimageviewer/viewpanel/scen/imagesvgitem.cpp b/libimageviewer/viewpanel/scen/imagesvgitem.cpp index cb16028a..93555a84 100755 --- a/libimageviewer/viewpanel/scen/imagesvgitem.cpp +++ b/libimageviewer/viewpanel/scen/imagesvgitem.cpp @@ -21,16 +21,19 @@ QT_BEGIN_NAMESPACE LibImageSvgItem::LibImageSvgItem(QGraphicsItem *parent) : QGraphicsObject(parent) { + qDebug() << "Initializing LibImageSvgItem with parent"; setParentItem(parent); m_renderer = new QSvgRenderer(this); setCacheMode(QGraphicsItem::DeviceCoordinateCache); setMaximumCacheSize(QSize(1024, 768)); + qDebug() << "SVG renderer initialized with cache size:" << QSize(1024, 768); } LibImageSvgItem::LibImageSvgItem(const QString &fileName, QGraphicsItem *parent) //:QGraphicsSvgItem(parent) : QGraphicsObject(parent) { + qDebug() << "Initializing LibImageSvgItem with file:" << fileName; setParentItem(parent); m_renderer = new QSvgRenderer(this); setCacheMode(QGraphicsItem::DeviceCoordinateCache); @@ -41,6 +44,7 @@ LibImageSvgItem::LibImageSvgItem(const QString &fileName, QGraphicsItem *parent) LibImageSvgItem::~LibImageSvgItem() { + qDebug() << "Destroying LibImageSvgItem"; } QSvgRenderer *LibImageSvgItem::renderer() const @@ -107,19 +111,25 @@ static void qt_graphicsItem_highlightSelected(QGraphicsItem *item, QPainter *pai void LibImageSvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - // Q_UNUSED(option); Q_UNUSED(widget); - if (!m_renderer->isValid()) + if (!m_renderer->isValid()) { + qWarning() << "SVG renderer is not valid, skipping paint"; return; + } - if (m_elemId.isEmpty()) + if (m_elemId.isEmpty()) { + qDebug() << "Rendering entire SVG"; m_renderer->render(painter, m_boundingRect); - else + } else { + qDebug() << "Rendering SVG element:" << m_elemId; m_renderer->render(painter, m_elemId, m_boundingRect); + } - if (option->state & QStyle::State_Selected) + if (option->state & QStyle::State_Selected) { + qDebug() << "Drawing selection highlight"; qt_graphicsItem_highlightSelected(this, painter, option); + } } int LibImageSvgItem::type() const @@ -129,13 +139,17 @@ int LibImageSvgItem::type() const void LibImageSvgItem::updateDefaultSize() { + qDebug() << "Updating default size"; QRectF bounds; if (m_elemId.isEmpty()) { bounds = QRectF(QPointF(0, 0), m_renderer->defaultSize()); + qDebug() << "Using default size:" << m_renderer->defaultSize(); } else { bounds = m_renderer->boundsOnElement(m_elemId); + qDebug() << "Using element bounds for:" << m_elemId << "size:" << bounds.size(); } if (m_boundingRect.size() != bounds.size()) { + qDebug() << "Bounding rect size changed from" << m_boundingRect.size() << "to" << bounds.size(); prepareGeometryChange(); m_boundingRect.setSize(bounds.size()); } @@ -143,18 +157,19 @@ void LibImageSvgItem::updateDefaultSize() void LibImageSvgItem::setMaximumCacheSize(const QSize &size) { + qDebug() << "Setting maximum cache size to:" << size; Q_UNUSED(size); -// QGraphicsItem::d_ptr->setExtra(QGraphicsItemPrivate::ExtraMaxDeviceCoordCacheSize, size); update(); } QSize LibImageSvgItem::maximumCacheSize() const { - return QSize();//QGraphicsItem::d_ptr->extra(QGraphicsItemPrivate::ExtraMaxDeviceCoordCacheSize).toSize(); + return QSize(); } void LibImageSvgItem::setElementId(const QString &id) { + qDebug() << "Setting element ID to:" << id; m_elemId = id; updateDefaultSize(); update(); @@ -167,15 +182,15 @@ QString LibImageSvgItem::elementId() const void LibImageSvgItem::setSharedRenderer(QSvgRenderer *renderer) { + qDebug() << "Setting shared renderer"; m_renderer = renderer; - updateDefaultSize(); - update(); } void LibImageSvgItem::setCachingEnabled(bool caching) { + qDebug() << "Setting caching" << (caching ? "enabled" : "disabled"); setCacheMode(caching ? QGraphicsItem::DeviceCoordinateCache : QGraphicsItem::NoCache); } diff --git a/libimageviewer/viewpanel/thumbnailwidget.cpp b/libimageviewer/viewpanel/thumbnailwidget.cpp index af060f68..0c082b4a 100644 --- a/libimageviewer/viewpanel/thumbnailwidget.cpp +++ b/libimageviewer/viewpanel/thumbnailwidget.cpp @@ -29,25 +29,32 @@ ThumbnailWidget::ThumbnailWidget(const QString &darkFile, const QString &lightFi : ThemeWidget(darkFile, lightFile, parent), m_picString("") { + qDebug() << "Initializing ThumbnailWidget with dark file:" << darkFile << "and light file:" << lightFile; #ifdef OPENACCESSIBLE setObjectName(Thumbnail_Widget); setAccessibleName(Thumbnail_Widget); + qDebug() << "Accessibility names set for ThumbnailWidget"; #endif this->setAttribute(Qt::WA_AcceptTouchEvents); grabGesture(Qt::PinchGesture); grabGesture(Qt::SwipeGesture); grabGesture(Qt::PanGesture); + qDebug() << "Touch gestures initialized"; + //修复style问题 if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType) { m_picString = ICON_IMPORT_PHOTO_DARK; m_theme = true; + qDebug() << "Using dark theme icon:" << ICON_IMPORT_PHOTO_DARK; } else { m_picString = ICON_IMPORT_PHOTO_LIGHT; m_theme = false; + qDebug() << "Using light theme icon:" << ICON_IMPORT_PHOTO_LIGHT; } QPixmap logo_pix = Libutils::base::renderSVG(m_picString, THUMBNAIL_SIZE); m_logo = logo_pix; + qDebug() << "Logo rendered with size:" << THUMBNAIL_SIZE; QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [ = ]() { @@ -57,9 +64,11 @@ ThumbnailWidget::ThumbnailWidget(const QString &darkFile, const QString &lightFi if (themeType == DGuiApplicationHelper::DarkType) { m_picString = ICON_IMPORT_PHOTO_DARK; m_theme = true; + qDebug() << "Theme changed to dark"; } else { m_picString = ICON_IMPORT_PHOTO_LIGHT; m_theme = false; + qDebug() << "Theme changed to light"; } //修复style风格错误 @@ -67,22 +76,23 @@ ThumbnailWidget::ThumbnailWidget(const QString &darkFile, const QString &lightFi if (m_isDefaultThumbnail) { //这里之前修复风格错误,导致bug68248,现在已经修复 m_defaultImage = m_logo; + qDebug() << "Updated default thumbnail with new theme logo"; } update(); }); setMouseTracking(true); m_thumbnailLabel = new QLbtoDLabel(this); - // m_thumbnailLabel->setObjectName("ThumbnailLabel"); m_thumbnailLabel->setFixedSize(THUMBNAIL_BORDERSIZE); + qDebug() << "Thumbnail label created with size:" << THUMBNAIL_BORDERSIZE; onThemeChanged(DGuiApplicationHelper::instance()->themeType()); #ifndef LITE_DIV m_tips = new QLabel(this); m_tips->setObjectName("ThumbnailTips"); m_tips->setText(tr("No image files found")); + qDebug() << "Tips label created with text: No image files found"; #else - m_tips = new DLabel(this); m_tips->setText(tr("Image file not found")); m_tips->show(); @@ -138,6 +148,7 @@ ThumbnailWidget::ThumbnailWidget(const QString &darkFile, const QString &lightFi layout->addWidget(m_tips, 0, Qt::AlignCenter); layout->addStretch(); setLayout(layout); + qDebug() << "Layout initialized with thumbnail label and tips"; QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &ThumbnailWidget::onThemeChanged); @@ -145,6 +156,7 @@ ThumbnailWidget::ThumbnailWidget(const QString &darkFile, const QString &lightFi void ThumbnailWidget::onThemeChanged(DGuiApplicationHelper::ColorType theme) { + qDebug() << "Theme changed to:" << (theme == DGuiApplicationHelper::ColorType::DarkType ? "Dark" : "Light"); if (theme == DGuiApplicationHelper::ColorType::DarkType) { m_inBorderColor = Libutils::common::DARK_BORDER_COLOR; if (m_isDefaultThumbnail) @@ -161,6 +173,7 @@ void ThumbnailWidget::onThemeChanged(DGuiApplicationHelper::ColorType theme) void ThumbnailWidget::setThumbnailImageAndText(const QPixmap thumbnail, DisplayType type) { + qDebug() << "Setting thumbnail image and text, type:" << type; switch (type) { default: break; @@ -168,9 +181,11 @@ void ThumbnailWidget::setThumbnailImageAndText(const QPixmap thumbnail, DisplayT if (thumbnail.isNull()) { m_defaultImage = m_logo; m_isDefaultThumbnail = true; + qDebug() << "Using default logo for damaged image"; } else { m_defaultImage = thumbnail; m_isDefaultThumbnail = false; + qDebug() << "Using provided thumbnail for damaged image"; } m_tips->setText(tr("Image file not found")); DFontSizeManager::instance()->bind(m_tips, DFontSizeManager::T6); @@ -182,6 +197,7 @@ void ThumbnailWidget::setThumbnailImageAndText(const QPixmap thumbnail, DisplayT m_tips->setText(tr("You have no permission to view the file")); DFontSizeManager::instance()->bind(m_tips, DFontSizeManager::T6); m_tips->setForegroundRole(DPalette::TextTitle); + qDebug() << "Setting cannot read type message"; break; } @@ -192,6 +208,7 @@ void ThumbnailWidget::paintEvent(QPaintEvent *event) { Q_UNUSED(event); if (m_defaultImage.isNull() && !m_isDefaultThumbnail) { + qDebug() << "Painting empty thumbnail"; QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); QIcon m_icon(m_defaultImage); @@ -200,10 +217,12 @@ void ThumbnailWidget::paintEvent(QPaintEvent *event) } if (m_defaultImage.isNull() && m_isDefaultThumbnail) { + qDebug() << "Using default logo for empty thumbnail"; m_defaultImage = m_logo; } if (m_defaultImage.size() != THUMBNAIL_SIZE) { + qDebug() << "Scaling thumbnail to size:" << THUMBNAIL_SIZE; m_defaultImage = m_defaultImage.scaled(THUMBNAIL_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation); } @@ -212,6 +231,7 @@ void ThumbnailWidget::paintEvent(QPaintEvent *event) QPoint imgStartPoint = QPoint(startPoint.x() + (THUMBNAIL_SIZE.width() - 128) / 2 + 1, startPoint.y() + (THUMBNAIL_SIZE.height() - 128) / 2 + 1); QRect imgRect = QRect(imgStartPoint.x(), imgStartPoint.y(), 128, 128); + qDebug() << "Painting thumbnail at rect:" << imgRect; QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); @@ -226,11 +246,11 @@ void ThumbnailWidget::mouseReleaseEvent(QMouseEvent *e) int offset = e->globalPos().x() - m_startx; if (qAbs(offset) > 200) { if (offset > 0) { + qDebug() << "Swipe right detected, emitting previousRequested signal"; emit previousRequested(); - qDebug() << "zy------ThumbnailWidget::event previousRequested"; } else { + qDebug() << "Swipe left detected, emitting nextRequested signal"; emit nextRequested(); - qDebug() << "zy------ThumbnailWidget::event nextRequested"; } } } @@ -241,31 +261,31 @@ void ThumbnailWidget::mousePressEvent(QMouseEvent *e) { QWidget::mousePressEvent(e); m_startx = e->globalPos().x(); + qDebug() << "Mouse press at x position:" << m_startx; } void ThumbnailWidget::mouseMoveEvent(QMouseEvent *event) { Q_UNUSED(event) emit sigMouseMove(); - // QWidget::mouseMoveEvent(event); - - // emit mouseHoverMoved(); } void ThumbnailWidget::mouseDoubleClickEvent(QMouseEvent *e) { //非平板才能双击,其他是单击全屏 - if (e->button() == Qt::LeftButton) + if (e->button() == Qt::LeftButton) { + qDebug() << "Double click detected, emitting showfullScreen signal"; emit showfullScreen(); + } ThemeWidget::mouseDoubleClickEvent(e); } void ThumbnailWidget::handleGestureEvent(QGestureEvent *gesture) { - /* if (QGesture *swipe = gesture->gesture(Qt::SwipeGesture)) - swipeTriggered(static_cast(swipe)); - else */if (QGesture *pinch = gesture->gesture(Qt::PinchGesture)) + if (QGesture *pinch = gesture->gesture(Qt::PinchGesture)) { + qDebug() << "Handling pinch gesture"; pinchTriggered(static_cast(pinch)); + } } bool ThumbnailWidget::event(QEvent *event) @@ -274,11 +294,13 @@ bool ThumbnailWidget::event(QEvent *event) if (evType == QEvent::TouchBegin || evType == QEvent::TouchUpdate || evType == QEvent::TouchEnd) { if (evType == QEvent::TouchBegin) { - qDebug() << "QEvent::TouchBegin"; + qDebug() << "Touch begin event detected"; m_maxTouchPoints = 1; } - } else if (event->type() == QEvent::Gesture) + } else if (event->type() == QEvent::Gesture) { + qDebug() << "Gesture event detected"; handleGestureEvent(static_cast(event)); + } return QWidget::event(event); } @@ -286,19 +308,23 @@ void ThumbnailWidget::pinchTriggered(QPinchGesture *gesture) { Q_UNUSED(gesture); m_maxTouchPoints = 2; + qDebug() << "Pinch gesture triggered, max touch points set to 2"; } -ThumbnailWidget::~ThumbnailWidget() {} +ThumbnailWidget::~ThumbnailWidget() +{ + qDebug() << "Destroying ThumbnailWidget"; +} void ThumbnailWidget::wheelEvent(QWheelEvent *event) { if ((event->modifiers() == Qt::ControlModifier)) { if (event->angleDelta().y() > 0) { + qDebug() << "Control + wheel up detected, emitting previousRequested signal"; emit previousRequested(); } else if (event->angleDelta().y() < 0) { + qDebug() << "Control + wheel down detected, emitting nextRequested signal"; emit nextRequested(); } - qDebug() << "control++"; - } } diff --git a/libimageviewer/viewpanel/viewpanel.cpp b/libimageviewer/viewpanel/viewpanel.cpp index 94f4291e..3de5aa35 100644 --- a/libimageviewer/viewpanel/viewpanel.cpp +++ b/libimageviewer/viewpanel/viewpanel.cpp @@ -179,6 +179,7 @@ LibViewPanel::~LibViewPanel() void LibViewPanel::loadImage(const QString &path, QStringList paths) { + qInfo() << "Loading image:" << path; // 初始化图像缓存目录 Libutils::image::initCacheImageFolder(); @@ -729,6 +730,7 @@ void LibViewPanel::updateMenuContent(const QString &path) void LibViewPanel::toggleFullScreen() { + qInfo() << "Toggling fullscreen mode"; // m_view->setFitState(false, false); if (window()->isFullScreen()) { showNormal(); @@ -746,6 +748,7 @@ void LibViewPanel::toggleFullScreen() void LibViewPanel::showFullScreen() { + qInfo() << "Entering fullscreen mode"; m_windowSize = window()->size(); m_windowX = window()->x(); m_windowY = window()->y(); @@ -768,18 +771,14 @@ void LibViewPanel::showFullScreen() pAn->setEndValue(1); pAn->setStartValue(0); pAn->start(QAbstractAnimation::DeleteWhenStopped); - //增加切换全屏和默认大小下方工具栏的移动 -// connect(pAn, &QPropertyAnimation::destroyed, this, [ = ] { -// slotBottomMove(); -// }); window()->showFullScreen(); m_hideCursorTid = startTimer(DELAY_HIDE_CURSOR_INTERVAL); - } void LibViewPanel::showNormal() { + qInfo() << "Exiting fullscreen mode"; if (m_view) { m_view->setWindowIsFullScreen(false); } @@ -897,10 +896,10 @@ void LibViewPanel::setWallpaper(const QImage &img) tmpImage.setFileTemplate(tempPathTemplate); // 使用JPG压缩而不是PNG以压缩减少缓存图片大小 if (!tmpImage.open() || !img.save(tmpImage.fileName(), "JPG")) { - qWarning() << QString("Copy image set wallpaper failed! path: %1").arg(tmpImage.fileName()); + qWarning() << "Failed to save temporary wallpaper image:" << tmpImage.fileName(); return; } - qInfo() << QString("Copy image set wallpaper, path: %1").arg(tmpImage.fileName()); + qInfo() << "Saving temporary wallpaper image:" << tmpImage.fileName(); setWallpaperWithDBus(tmpImage.fileName()); }); @@ -912,6 +911,7 @@ void LibViewPanel::setWallpaper(const QImage &img) void LibViewPanel::setWallpaper(const QString &imgPath) { if (!imgPath.isEmpty()) { + qInfo() << "Setting wallpaper from file:" << imgPath; QThread *th1 = QThread::create([ = ]() { setWallpaperWithDBus(imgPath); }); connect(th1, &QThread::finished, th1, &QObject::deleteLater); th1->start(); @@ -920,6 +920,7 @@ void LibViewPanel::setWallpaper(const QString &imgPath) bool LibViewPanel::startdragImage(const QStringList &paths, const QString &firstPath) { + qInfo() << "Starting drag image operation with" << paths.size() << "images"; // 若为 MTP 挂载文件,转换为目录加载 QStringList realPaths = paths; QString realPath = firstPath; @@ -927,13 +928,16 @@ bool LibViewPanel::startdragImage(const QStringList &paths, const QString &first bool bRet = false; QStringList image_list = realPaths; - if (image_list.isEmpty()) + if (image_list.isEmpty()) { + qWarning() << "No images to drag"; return false; + } // 判断是否允许切换图片 (首次进入同样判断) bool enableSwitch = PermissionConfig::instance()->checkAuthFlag(PermissionConfig::EnableSwitch, image_list.first()); if (!enableSwitch) { if (image_list.first() != PermissionConfig::instance()->targetImage()) { + qWarning() << "Image switching not allowed by permission config"; return false; } } @@ -980,6 +984,7 @@ bool LibViewPanel::startdragImage(const QStringList &paths, const QString &first if (image_list.count() > 0) { bRet = true; } else { + qWarning() << "No valid images found in directory"; bRet = false; } @@ -1506,6 +1511,7 @@ void LibViewPanel::slotChangeShowTopBottom() bool LibViewPanel::slotOcrPicture() { if (!m_ocrInterface) { + qInfo() << "Initializing OCR interface"; initOcr(); } QString path = m_bottomToolbar->getCurrentItemInfo().path; @@ -1516,14 +1522,16 @@ bool LibViewPanel::slotOcrPicture() QImage image = m_view->image(); if (image.width() > 2500) { + qInfo() << "Resizing image width from" << image.width() << "to 2500 for OCR"; image = image.scaledToWidth(2500, Qt::SmoothTransformation); } if (image.height() > 2500) { + qInfo() << "Resizing image height from" << image.height() << "to 2500 for OCR"; image = image.scaledToHeight(2500, Qt::SmoothTransformation); } //替换为了保存为文件,用路径去打开ocr QFileInfo info(path); - qDebug() << info.completeBaseName(); + qDebug() << "OCR base name:" << info.completeBaseName(); QString savePath = IMAGE_TMPPATH + info.completeBaseName() + ".png"; image.save(savePath); //采用路径,以防止名字出错 @@ -1996,6 +2004,7 @@ void LibViewPanel::slotOneImgReady(QString path, imageViewerSpace::ItemInfo item void LibViewPanel::startSlideShow(const ViewInfo &info) { + qInfo() << "Starting slideshow"; //判断旋转图片本体是否旋转 if (m_view) { m_view->slotRotatePixCurrent(); @@ -2005,6 +2014,7 @@ void LibViewPanel::startSlideShow(const ViewInfo &info) } //todo,幻灯片 if (!m_sliderPanel) { + qDebug() << "Initializing slideshow panel"; initSlidePanel(); } m_sliderPanel->startSlideShow(info); @@ -2049,16 +2059,19 @@ void LibViewPanel::resetBottomToolbarGeometry(bool visible) void LibViewPanel::openImg(int index, QString path) { + qInfo() << "Opening image:" << path; if (AIModelService::instance()->isValid()) { // 判断当前图片是否为图像增强图片 bool previousEnhanced = AIModelService::instance()->isTemporaryFile(m_currentPath); if (previousEnhanced) { if (AIModelService::instance()->isWaitSave()) { + qWarning() << "Previous enhanced image is waiting to be saved, cannot open new image"; return; } // 提示是否保存 if (!notNeedNotifyEnhanceSave) { + qInfo() << "Prompting to save enhanced image before opening new image"; AIModelService::instance()->saveFileDialog(m_currentPath, this); } } @@ -2091,6 +2104,7 @@ void LibViewPanel::openImg(int index, QString path) void LibViewPanel::slotRotateImage(int angle) { + qInfo() << "Rotating image by" << angle << "degrees"; if (m_view) { if (m_view->loadPhase() == LibImageGraphicsView::ThumbnailFinish) { m_view->setNewImageRotateAngle(angle); @@ -2111,6 +2125,7 @@ void LibViewPanel::slotRotateImage(int angle) void LibViewPanel::slotResetTransform(bool bRet) { + qInfo() << "Resetting image transform, fit to window:" << bRet; if (bRet && m_view) { m_view->fitWindow(); } else if (!bRet && m_view) { @@ -2479,7 +2494,7 @@ void LibViewPanel::onEnhanceEnd(const QString &source, const QString &output, in // 仅会处理当前图片 if (source != AIModelService::instance()->sourceFilePath(m_currentPath)) { if (m_AIEnhancing) { - qWarning() << qPrintable("Detect error! receive previous procssing file but still in enhancing state."); + qWarning() << "Detect error! receive previous processing file but still in enhancing state."; blockInputControl(false); } return; @@ -2490,21 +2505,25 @@ void LibViewPanel::onEnhanceEnd(const QString &source, const QString &output, in switch (state) { case AIModelService::LoadSucc: { procPath = output; + qInfo() << "AI enhancement completed successfully"; break; } case AIModelService::LoadFailed: { procPath = source; error = AIModelService::LoadFiledError; + qWarning() << "AI enhancement failed to load image"; break; } case AIModelService::NotDetectPortrait: { procPath = source; error = AIModelService::NotDetectPortraitError; + qWarning() << "No portrait detected in image for AI enhancement"; break; } default: // 其它错误,默认还原图片 procPath = source; + qWarning() << "Unknown error occurred during AI enhancement"; break; }