From b32ed8c677cc6ad067fc0148f4beb559509bd7c0 Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Fri, 23 May 2025 13:12:32 +0800 Subject: [PATCH] feat: Add debug logging - Introduced debug logging in animation, color menu, and picker manager classes to enhance traceability during execution. - Updated .gitignore to exclude .vscode and .cursor files. --- .gitignore | 2 ++ src/animation.cpp | 7 ++++++- src/colormenu.cpp | 5 +++++ src/cpickermanager.cpp | 46 ++++++++++++++++++++++++------------------ src/main.cpp | 15 ++++++++++++++ 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 720cb6e..2730c1f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ moc_*.cpp build/ *.qm *pro.user +.vscode +.cursor diff --git a/src/animation.cpp b/src/animation.cpp index 4f60d0d..85ce56d 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -12,6 +12,8 @@ Animation::Animation(int x, int y, QPixmap pixmap, QColor color, QWidget *parent) : QWidget(parent) { + qDebug() << "Initializing animation at position:" << x << y << "with color:" << color.name(); + // Init window flags to make window transparent and get correctly behavior. setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); // setWindowFlags(Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool); @@ -40,10 +42,12 @@ Animation::Animation(int x, int y, QPixmap pixmap, QColor color, QWidget *parent renderTimer = new QTimer(); connect(renderTimer, &QTimer::timeout, this, &Animation::renderAnimation); renderTimer->start(animationDuration); + qDebug() << "Animation timer started with duration:" << animationDuration << "ms"; } Animation::~Animation() { + qDebug() << "Destroying animation instance"; delete renderTimer; } @@ -75,10 +79,11 @@ void Animation::renderAnimation() { if (renderTicker < animationFrames) { renderTicker++; - + qDebug() << "Animation frame:" << renderTicker << "/" << animationFrames; repaint(); } else { renderTimer->stop(); + qInfo() << "Animation completed, hiding window"; hide(); // hide window when animation finish emit finish(); diff --git a/src/colormenu.cpp b/src/colormenu.cpp index aea44e0..776ab95 100644 --- a/src/colormenu.cpp +++ b/src/colormenu.cpp @@ -16,6 +16,8 @@ ColorMenu::ColorMenu(int x, int y, int size, QColor color, QWidget *parent) : QWidget(parent) { + qDebug() << "Initializing color menu at position:" << x << y << "with size:" << size << "and color:" << color.name(); + // Init window flags. setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); // setWindowFlags(Qt::FramelessWindowHint | Qt::Tool); @@ -47,6 +49,7 @@ ColorMenu::ColorMenu(int x, int y, int size, QColor color, QWidget *parent) : QW connect(colorMenu, &QMenu::aboutToHide, this, [&]() { QTimer::singleShot(200, this, [&]() { if (!clickMenuItem) { + qDebug() << "Menu closed without selection, exiting"; exit(); } }); @@ -91,6 +94,7 @@ ColorMenu::ColorMenu(int x, int y, int size, QColor color, QWidget *parent) : QW // Set menu action check status with color type. Settings *settings = new Settings(); QString colorType = settings->getOption("color_type", "HEX").toString(); + qDebug() << "Loading saved color type preference:" << colorType; if (colorType == "HEX") { hexAction->setChecked(true); @@ -115,6 +119,7 @@ ColorMenu::ColorMenu(int x, int y, int size, QColor color, QWidget *parent) : QW ColorMenu::~ColorMenu() { + qDebug() << "Destroying color menu instance"; delete hexAction; delete rgbAction; delete rgbFloatAction; diff --git a/src/cpickermanager.cpp b/src/cpickermanager.cpp index 7a30c21..c931478 100644 --- a/src/cpickermanager.cpp +++ b/src/cpickermanager.cpp @@ -25,6 +25,7 @@ DGUI_USE_NAMESPACE CScreenshotWidget::CScreenshotWidget(CPickerManager *parent): QWidget(nullptr), _parentManager(parent) { + qDebug() << "Initializing screenshot widget"; //为顶层窗口 this->setWindowFlags(this->windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint); @@ -58,6 +59,7 @@ void CScreenshotWidget::keyPressEvent(QKeyEvent *event) { //wayland下 DRegionMonitor::keyPress会失效,这里会响应 if (event->matches(QKeySequence::Cancel)) { + qDebug() << "Escape key pressed, exiting application"; QApplication::quit(); } QWidget::keyPressEvent(event); @@ -81,11 +83,13 @@ void CScreenshotWidget::wheelEvent(QWheelEvent *event) CPickerManager::CPickerManager(): QObject(nullptr) { + qDebug() << "Initializing color picker manager"; const int windowHeight = 236; const int windowWidth = 236; qreal radio = qApp->devicePixelRatio(); _shadowPixmap = QPixmap(Utils::getQrcPath("shadow.png")); if (isWaylandPlatform()) { + qDebug() << "Running on Wayland platform"; _shadowPixmap = _shadowPixmap.scaled(windowWidth, windowHeight); } else { _shadowPixmap = _shadowPixmap.scaled(windowWidth / radio, windowHeight / radio, Qt::KeepAspectRatio, Qt::SmoothTransformation); @@ -98,11 +102,12 @@ CPickerManager::CPickerManager(): QObject(nullptr) eventMonitor->setWatchedRegion(QRegion(INT_MIN, INT_MIN, INT_MAX * 2, INT_MAX * 2)); QObject::connect(eventMonitor, &DRegionMonitor::keyPress, this, [ = ](const QString & name) { - if (name == "Escape") + if (name == "Escape") { + qDebug() << "Escape key detected from region monitor, exiting application"; QApplication::quit(); + } }); - // Binding handler to xrecord signal. QObject::connect(eventMonitor, &DRegionMonitor::cursorMove, this, [ = ](const QPoint & p) { onMouseMove(p); @@ -115,7 +120,7 @@ CPickerManager::CPickerManager(): QObject(nullptr) eventMonitor->registerRegion(); if (!eventMonitor->registered()) { - qWarning() << "Failed on register monitor"; + qWarning() << "Failed to register region monitor, exiting application"; QApplication::quit(); } ensureDeskTopPixmap(); @@ -124,7 +129,6 @@ CPickerManager::CPickerManager(): QObject(nullptr) _updateScreenshotTimer->setSingleShot(true); connect(_updateScreenshotTimer, SIGNAL(timeout()), this, SLOT(handleMouseMove())); - QPixmap pix(16, 16); pix.fill(Qt::transparent); qApp->setOverrideCursor(QCursor(pix)); @@ -132,10 +136,12 @@ CPickerManager::CPickerManager(): QObject(nullptr) CPickerManager::~CPickerManager() { + qDebug() << "Destroying color picker manager"; } void CPickerManager::setLanchFlag(CPickerManager::ELanchType tp, const QString &appName) { + qDebug() << "Setting launch flag:" << tp << "for application:" << appName; _isLaunchByDBus = tp; if (_isLaunchByDBus == ELanchedByOtherApp) _appid = appName; @@ -153,6 +159,7 @@ void CPickerManager::setLanchFlag(CPickerManager::ELanchType tp, const QString & void CPickerManager::StartPick(const QString &id) { + qDebug() << "Starting color pick with ID:" << id; _appid = id; } @@ -174,11 +181,14 @@ void CPickerManager::onMousePress(const QPoint &p, const int flag) //wayland触摸屏下的点击是DRegionMonitor::Button_Middle,鼠标左键点击DRegionMonitor::Button_Left。无法区分是鼠标左键还是触摸屏,故支持中键点击 //最佳方案是TDK将触摸屏点击修改成左键点击。。。。。。。 if (button != DRegionMonitor::Button_Left && button != DRegionMonitor::Button_Middle) { + qDebug() << "Ignoring non-left/middle button press on Wayland"; return; } } else { - if (button != DRegionMonitor::Button_Left) + if (button != DRegionMonitor::Button_Left) { + qDebug() << "Ignoring non-left button press"; return; + } } //立即更新坐标 @@ -194,12 +204,15 @@ void CPickerManager::onMousePress(const QPoint &p, const int flag) // Rest color type to hex if config file not exist. Settings settings; + QString colorType = settings.getOption("color_type", "HEX").toString(); + qDebug() << "Color picked:" << _curColor.name() << "in format:" << colorType; // Emit copyColor signal to copy color to system clipboard. - copyColor(_curColor, settings.getOption("color_type", "HEX").toString()); + copyColor(_curColor, colorType); // Send colorPicked signal when call by DBus and no empty appid. if (_appid != "") { + qDebug() << "Sending color picked signal to application:" << _appid; colorPicked(_appid, Utils::colorToHex(_curColor)); } } @@ -213,6 +226,7 @@ void CPickerManager::handleMouseMove() void CPickerManager::initShotScreenWidgets() { + qDebug() << "Initializing screen shot widgets"; ensureDeskTopPixmap(); auto screens = QApplication::screens(); //去出复制屏 @@ -220,6 +234,7 @@ void CPickerManager::initShotScreenWidgets() while (i < screens.size()) { for (int j = screens.size() - 1; j > i; j--) { if (screens.at(i)->geometry().topLeft() == screens.at(j)->geometry().topLeft()) { + qDebug() << "Removing duplicate screen at index:" << j; screens.removeAt(j); } } @@ -228,7 +243,6 @@ void CPickerManager::initShotScreenWidgets() foreach (auto screen, screens) { auto pix = getScreenShotPixmap(screen); - //auto geometry = QRect(screen->geometry().topLeft(), screen->geometry().size() * screen->devicePixelRatio()); CScreenshotWidget *pWidget = new CScreenshotWidget(this); pWidget->setPixmap(pix); pWidget->setGeometry(screen->geometry()); @@ -245,6 +259,7 @@ void CPickerManager::initShotScreenWidgets() // 解决 wayland 下调出取色器后点击 Esc 无法退出取色器 if (isWaylandPlatform()) { + qDebug() << "Setting up Wayland-specific window activation"; // 延迟 200ms 后取得当前背景窗口的焦点,用以捕获 Esc 按键退出 QTimer::singleShot(200, this, [ = ]() { auto currentWidget = _widgets.value(qApp->screenAt(QCursor::pos())); @@ -324,27 +339,16 @@ void CPickerManager::updateCursor(const QPixmap &pixMap, const QPoint &posInPixm _curColor = focusPixmap.toImage().pixelColor(focusPixmap.rect().center()); -// painter.setPen(QColor(255, 0, 0, 100)); -// QFont f; -// painter.setFont(f); -// QString text = _curColor.name() + QString("w=%1lw=%2").arg(focusPixmap.width()).arg(logicPixelWidth); -// QSize colorNameSz = QSize(QFontMetrics(f).width(text), QFontMetrics(f).height()) ; - -// QRectF colorNameRect = QRectF(QPointF((cursorPix.width() - colorNameSz.width()) / 2, -// (cursorPix.height() - colorNameSz.height()) / 2 + colorNameSz.height() + 6), colorNameSz); -// painter.drawText(colorNameRect, text); - //设置当前窗口鼠标样式 _cursorPix = cursorPix; this->autoUpdate(); - } } - void CPickerManager::ensureDeskTopPixmap() { if (_desktopPixmapDirty) { + qDebug() << "Updating desktop pixmap"; _desktopPixmap = getDesktopPixmap(); _desktopPixmapDirty = false; } @@ -368,18 +372,19 @@ QRect getDeskTopRect() QRect deskTopRect(0, 0, 0, 0); auto screens = QApplication::screens(); foreach (auto screen, screens) { - auto geometry = QRect(screen->geometry().topLeft(), screen->geometry().size() * screen->devicePixelRatio()); deskTopRect = deskTopRect.united(geometry); } return deskTopRect; } + QPixmap CPickerManager::getDesktopPixmap() { QPixmap result; bool iswayLand = isWaylandPlatform(); if (iswayLand) { + qDebug() << "Getting desktop pixmap via KWin DBus interface"; QPixmap res; QDBusInterface kwinInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), @@ -392,6 +397,7 @@ QPixmap CPickerManager::getDesktopPixmap() } result = res; } else { + qDebug() << "Getting desktop pixmap via screen grab"; QPixmap pixs(getDeskTopRect().size()); pixs.fill(Qt::transparent); QPainter painter(&pixs); diff --git a/src/main.cpp b/src/main.cpp index c6fb33f..658b0b9 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,10 @@ DWIDGET_USE_NAMESPACE int main(int argc, char *argv[]) { + qDebug() << "Starting Deepin Picker application"; + if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin")) { + qDebug() << "Setting XDG_CURRENT_DESKTOP to Deepin"; setenv("XDG_CURRENT_DESKTOP", "Deepin", 1); } @@ -42,6 +45,7 @@ int main(int argc, char *argv[]) // Init dtk application's attrubites. DApplication app(argc, argv); app.setAttribute(Qt::AA_UseHighDpiPixmaps); + qDebug() << "Initialized DApplication with high DPI pixmaps support"; // 判断窗口特效是否开启 // if (!DWindowManagerHelper::instance()->hasComposite()) { @@ -50,10 +54,12 @@ int main(int argc, char *argv[]) // } app.loadTranslator(); + qDebug() << "Loaded application translations"; app.setOrganizationName("deepin"); app.setApplicationName("deepin-picker"); app.setApplicationVersion("1.2"); + qDebug() << "Set application info - name: deepin-picker, version: 1.2"; app.setProductIcon(QIcon(Utils::getQrcPath("logo_96.svg"))); app.setProductName(DApplication::translate("MainWindow", "Deepin Picker")); @@ -70,21 +76,30 @@ int main(int argc, char *argv[]) parser.process(app); bool isLaunchByDBus = parser.isSet(appidOption); + qDebug() << "Application launch mode:" << (isLaunchByDBus ? "DBus" : "Direct"); // Init modules. + qDebug() << "Initializing application modules"; Clipboard clipboard; QPointer picker = new CPickerManager; picker->setLanchFlag(isLaunchByDBus ? CPickerManager::ELanchedByOtherApp : CPickerManager::ELanchedBySelf); if (!isLaunchByDBus) { + qDebug() << "Starting color picker in direct mode"; picker->StartPick(""); } QObject::connect(picker.data(), &CPickerManager::copyColor, &clipboard, &Clipboard::copyToClipboard, Qt::QueuedConnection); if (isLaunchByDBus) { + qDebug() << "Registering DBus service"; QDBusConnection dbus = QDBusConnection::sessionBus(); if (dbus.registerService("com.deepin.Picker")) { + qDebug() << "Successfully registered DBus service: com.deepin.Picker"; dbus.registerObject("/com/deepin/Picker", picker.data(), QDBusConnection::ExportScriptableSlots | QDBusConnection::ExportScriptableSignals); + } else { + qWarning() << "Failed to register DBus service: com.deepin.Picker"; } } + + qDebug() << "Entering application event loop"; return app.exec(); }