Skip to content

Commit 5c95fa8

Browse files
Kakueeendeepin-bot[bot]
authored andcommitted
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.
1 parent 72ec090 commit 5c95fa8

5 files changed

Lines changed: 54 additions & 21 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ moc_*.cpp
55
build/
66
*.qm
77
*pro.user
8+
.vscode
9+
.cursor

src/animation.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
Animation::Animation(int x, int y, QPixmap pixmap, QColor color, QWidget *parent) : QWidget(parent)
1414
{
15+
qDebug() << "Initializing animation at position:" << x << y << "with color:" << color.name();
16+
1517
// Init window flags to make window transparent and get correctly behavior.
1618
setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
1719
// 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
4042
renderTimer = new QTimer();
4143
connect(renderTimer, &QTimer::timeout, this, &Animation::renderAnimation);
4244
renderTimer->start(animationDuration);
45+
qDebug() << "Animation timer started with duration:" << animationDuration << "ms";
4346
}
4447

4548
Animation::~Animation()
4649
{
50+
qDebug() << "Destroying animation instance";
4751
delete renderTimer;
4852
}
4953

@@ -75,10 +79,11 @@ void Animation::renderAnimation()
7579
{
7680
if (renderTicker < animationFrames) {
7781
renderTicker++;
78-
82+
qDebug() << "Animation frame:" << renderTicker << "/" << animationFrames;
7983
repaint();
8084
} else {
8185
renderTimer->stop();
86+
qInfo() << "Animation completed, hiding window";
8287
hide(); // hide window when animation finish
8388

8489
emit finish();

src/colormenu.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
ColorMenu::ColorMenu(int x, int y, int size, QColor color, QWidget *parent) : QWidget(parent)
1818
{
19+
qDebug() << "Initializing color menu at position:" << x << y << "with size:" << size << "and color:" << color.name();
20+
1921
// Init window flags.
2022
setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
2123
// setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
@@ -47,6 +49,7 @@ ColorMenu::ColorMenu(int x, int y, int size, QColor color, QWidget *parent) : QW
4749
connect(colorMenu, &QMenu::aboutToHide, this, [&]() {
4850
QTimer::singleShot(200, this, [&]() {
4951
if (!clickMenuItem) {
52+
qDebug() << "Menu closed without selection, exiting";
5053
exit();
5154
}
5255
});
@@ -91,6 +94,7 @@ ColorMenu::ColorMenu(int x, int y, int size, QColor color, QWidget *parent) : QW
9194
// Set menu action check status with color type.
9295
Settings *settings = new Settings();
9396
QString colorType = settings->getOption("color_type", "HEX").toString();
97+
qDebug() << "Loading saved color type preference:" << colorType;
9498

9599
if (colorType == "HEX") {
96100
hexAction->setChecked(true);
@@ -115,6 +119,7 @@ ColorMenu::ColorMenu(int x, int y, int size, QColor color, QWidget *parent) : QW
115119

116120
ColorMenu::~ColorMenu()
117121
{
122+
qDebug() << "Destroying color menu instance";
118123
delete hexAction;
119124
delete rgbAction;
120125
delete rgbFloatAction;

src/cpickermanager.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ DGUI_USE_NAMESPACE
2525
CScreenshotWidget::CScreenshotWidget(CPickerManager *parent): QWidget(nullptr),
2626
_parentManager(parent)
2727
{
28+
qDebug() << "Initializing screenshot widget";
2829
//为顶层窗口
2930
this->setWindowFlags(this->windowFlags() | Qt::Window | Qt::FramelessWindowHint
3031
| Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
@@ -58,6 +59,7 @@ void CScreenshotWidget::keyPressEvent(QKeyEvent *event)
5859
{
5960
//wayland下 DRegionMonitor::keyPress会失效,这里会响应
6061
if (event->matches(QKeySequence::Cancel)) {
62+
qDebug() << "Escape key pressed, exiting application";
6163
QApplication::quit();
6264
}
6365
QWidget::keyPressEvent(event);
@@ -81,11 +83,13 @@ void CScreenshotWidget::wheelEvent(QWheelEvent *event)
8183

8284
CPickerManager::CPickerManager(): QObject(nullptr)
8385
{
86+
qDebug() << "Initializing color picker manager";
8487
const int windowHeight = 236;
8588
const int windowWidth = 236;
8689
qreal radio = qApp->devicePixelRatio();
8790
_shadowPixmap = QPixmap(Utils::getQrcPath("shadow.png"));
8891
if (isWaylandPlatform()) {
92+
qDebug() << "Running on Wayland platform";
8993
_shadowPixmap = _shadowPixmap.scaled(windowWidth, windowHeight);
9094
} else {
9195
_shadowPixmap = _shadowPixmap.scaled(windowWidth / radio, windowHeight / radio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
@@ -98,11 +102,12 @@ CPickerManager::CPickerManager(): QObject(nullptr)
98102
eventMonitor->setWatchedRegion(QRegion(INT_MIN, INT_MIN, INT_MAX * 2, INT_MAX * 2));
99103

100104
QObject::connect(eventMonitor, &DRegionMonitor::keyPress, this, [ = ](const QString & name) {
101-
if (name == "Escape")
105+
if (name == "Escape") {
106+
qDebug() << "Escape key detected from region monitor, exiting application";
102107
QApplication::quit();
108+
}
103109
});
104110

105-
106111
// Binding handler to xrecord signal.
107112
QObject::connect(eventMonitor, &DRegionMonitor::cursorMove, this, [ = ](const QPoint & p) {
108113
onMouseMove(p);
@@ -115,7 +120,7 @@ CPickerManager::CPickerManager(): QObject(nullptr)
115120
eventMonitor->registerRegion();
116121

117122
if (!eventMonitor->registered()) {
118-
qWarning() << "Failed on register monitor";
123+
qWarning() << "Failed to register region monitor, exiting application";
119124
QApplication::quit();
120125
}
121126
ensureDeskTopPixmap();
@@ -124,18 +129,19 @@ CPickerManager::CPickerManager(): QObject(nullptr)
124129
_updateScreenshotTimer->setSingleShot(true);
125130
connect(_updateScreenshotTimer, SIGNAL(timeout()), this, SLOT(handleMouseMove()));
126131

127-
128132
QPixmap pix(16, 16);
129133
pix.fill(Qt::transparent);
130134
qApp->setOverrideCursor(QCursor(pix));
131135
}
132136

133137
CPickerManager::~CPickerManager()
134138
{
139+
qDebug() << "Destroying color picker manager";
135140
}
136141

137142
void CPickerManager::setLanchFlag(CPickerManager::ELanchType tp, const QString &appName)
138143
{
144+
qDebug() << "Setting launch flag:" << tp << "for application:" << appName;
139145
_isLaunchByDBus = tp;
140146
if (_isLaunchByDBus == ELanchedByOtherApp)
141147
_appid = appName;
@@ -153,6 +159,7 @@ void CPickerManager::setLanchFlag(CPickerManager::ELanchType tp, const QString &
153159

154160
void CPickerManager::StartPick(const QString &id)
155161
{
162+
qDebug() << "Starting color pick with ID:" << id;
156163
_appid = id;
157164
}
158165

@@ -174,11 +181,14 @@ void CPickerManager::onMousePress(const QPoint &p, const int flag)
174181
//wayland触摸屏下的点击是DRegionMonitor::Button_Middle,鼠标左键点击DRegionMonitor::Button_Left。无法区分是鼠标左键还是触摸屏,故支持中键点击
175182
//最佳方案是TDK将触摸屏点击修改成左键点击。。。。。。。
176183
if (button != DRegionMonitor::Button_Left && button != DRegionMonitor::Button_Middle) {
184+
qDebug() << "Ignoring non-left/middle button press on Wayland";
177185
return;
178186
}
179187
} else {
180-
if (button != DRegionMonitor::Button_Left)
188+
if (button != DRegionMonitor::Button_Left) {
189+
qDebug() << "Ignoring non-left button press";
181190
return;
191+
}
182192
}
183193

184194
//立即更新坐标
@@ -194,12 +204,15 @@ void CPickerManager::onMousePress(const QPoint &p, const int flag)
194204

195205
// Rest color type to hex if config file not exist.
196206
Settings settings;
207+
QString colorType = settings.getOption("color_type", "HEX").toString();
208+
qDebug() << "Color picked:" << _curColor.name() << "in format:" << colorType;
197209

198210
// Emit copyColor signal to copy color to system clipboard.
199-
copyColor(_curColor, settings.getOption("color_type", "HEX").toString());
211+
copyColor(_curColor, colorType);
200212

201213
// Send colorPicked signal when call by DBus and no empty appid.
202214
if (_appid != "") {
215+
qDebug() << "Sending color picked signal to application:" << _appid;
203216
colorPicked(_appid, Utils::colorToHex(_curColor));
204217
}
205218
}
@@ -213,13 +226,15 @@ void CPickerManager::handleMouseMove()
213226

214227
void CPickerManager::initShotScreenWidgets()
215228
{
229+
qDebug() << "Initializing screen shot widgets";
216230
ensureDeskTopPixmap();
217231
auto screens = QApplication::screens();
218232
//去出复制屏
219233
int i = 0;
220234
while (i < screens.size()) {
221235
for (int j = screens.size() - 1; j > i; j--) {
222236
if (screens.at(i)->geometry().topLeft() == screens.at(j)->geometry().topLeft()) {
237+
qDebug() << "Removing duplicate screen at index:" << j;
223238
screens.removeAt(j);
224239
}
225240
}
@@ -228,7 +243,6 @@ void CPickerManager::initShotScreenWidgets()
228243

229244
foreach (auto screen, screens) {
230245
auto pix = getScreenShotPixmap(screen);
231-
//auto geometry = QRect(screen->geometry().topLeft(), screen->geometry().size() * screen->devicePixelRatio());
232246
CScreenshotWidget *pWidget = new CScreenshotWidget(this);
233247
pWidget->setPixmap(pix);
234248
pWidget->setGeometry(screen->geometry());
@@ -245,6 +259,7 @@ void CPickerManager::initShotScreenWidgets()
245259

246260
// 解决 wayland 下调出取色器后点击 Esc 无法退出取色器
247261
if (isWaylandPlatform()) {
262+
qDebug() << "Setting up Wayland-specific window activation";
248263
// 延迟 200ms 后取得当前背景窗口的焦点,用以捕获 Esc 按键退出
249264
QTimer::singleShot(200, this, [ = ]() {
250265
auto currentWidget = _widgets.value(qApp->screenAt(QCursor::pos()));
@@ -324,27 +339,16 @@ void CPickerManager::updateCursor(const QPixmap &pixMap, const QPoint &posInPixm
324339

325340
_curColor = focusPixmap.toImage().pixelColor(focusPixmap.rect().center());
326341

327-
// painter.setPen(QColor(255, 0, 0, 100));
328-
// QFont f;
329-
// painter.setFont(f);
330-
// QString text = _curColor.name() + QString("w=%1lw=%2").arg(focusPixmap.width()).arg(logicPixelWidth);
331-
// QSize colorNameSz = QSize(QFontMetrics(f).width(text), QFontMetrics(f).height()) ;
332-
333-
// QRectF colorNameRect = QRectF(QPointF((cursorPix.width() - colorNameSz.width()) / 2,
334-
// (cursorPix.height() - colorNameSz.height()) / 2 + colorNameSz.height() + 6), colorNameSz);
335-
// painter.drawText(colorNameRect, text);
336-
337342
//设置当前窗口鼠标样式
338343
_cursorPix = cursorPix;
339344
this->autoUpdate();
340-
341345
}
342346
}
343347

344-
345348
void CPickerManager::ensureDeskTopPixmap()
346349
{
347350
if (_desktopPixmapDirty) {
351+
qDebug() << "Updating desktop pixmap";
348352
_desktopPixmap = getDesktopPixmap();
349353
_desktopPixmapDirty = false;
350354
}
@@ -368,18 +372,19 @@ QRect getDeskTopRect()
368372
QRect deskTopRect(0, 0, 0, 0);
369373
auto screens = QApplication::screens();
370374
foreach (auto screen, screens) {
371-
372375
auto geometry = QRect(screen->geometry().topLeft(), screen->geometry().size() *
373376
screen->devicePixelRatio());
374377
deskTopRect = deskTopRect.united(geometry);
375378
}
376379
return deskTopRect;
377380
}
381+
378382
QPixmap CPickerManager::getDesktopPixmap()
379383
{
380384
QPixmap result;
381385
bool iswayLand = isWaylandPlatform();
382386
if (iswayLand) {
387+
qDebug() << "Getting desktop pixmap via KWin DBus interface";
383388
QPixmap res;
384389
QDBusInterface kwinInterface(QStringLiteral("org.kde.KWin"),
385390
QStringLiteral("/Screenshot"),
@@ -392,6 +397,7 @@ QPixmap CPickerManager::getDesktopPixmap()
392397
}
393398
result = res;
394399
} else {
400+
qDebug() << "Getting desktop pixmap via screen grab";
395401
QPixmap pixs(getDeskTopRect().size());
396402
pixs.fill(Qt::transparent);
397403
QPainter painter(&pixs);

src/main.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ DWIDGET_USE_NAMESPACE
2424

2525
int main(int argc, char *argv[])
2626
{
27+
qDebug() << "Starting Deepin Picker application";
28+
2729
if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin")) {
30+
qDebug() << "Setting XDG_CURRENT_DESKTOP to Deepin";
2831
setenv("XDG_CURRENT_DESKTOP", "Deepin", 1);
2932
}
3033

@@ -42,6 +45,7 @@ int main(int argc, char *argv[])
4245
// Init dtk application's attrubites.
4346
DApplication app(argc, argv);
4447
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
48+
qDebug() << "Initialized DApplication with high DPI pixmaps support";
4549

4650
// 判断窗口特效是否开启
4751
// if (!DWindowManagerHelper::instance()->hasComposite()) {
@@ -50,10 +54,12 @@ int main(int argc, char *argv[])
5054
// }
5155

5256
app.loadTranslator();
57+
qDebug() << "Loaded application translations";
5358

5459
app.setOrganizationName("deepin");
5560
app.setApplicationName("deepin-picker");
5661
app.setApplicationVersion("1.2");
62+
qDebug() << "Set application info - name: deepin-picker, version: 1.2";
5763

5864
app.setProductIcon(QIcon(Utils::getQrcPath("logo_96.svg")));
5965
app.setProductName(DApplication::translate("MainWindow", "Deepin Picker"));
@@ -70,21 +76,30 @@ int main(int argc, char *argv[])
7076
parser.process(app);
7177

7278
bool isLaunchByDBus = parser.isSet(appidOption);
79+
qDebug() << "Application launch mode:" << (isLaunchByDBus ? "DBus" : "Direct");
7380

7481
// Init modules.
82+
qDebug() << "Initializing application modules";
7583
Clipboard clipboard;
7684
QPointer<CPickerManager> picker = new CPickerManager;
7785
picker->setLanchFlag(isLaunchByDBus ? CPickerManager::ELanchedByOtherApp : CPickerManager::ELanchedBySelf);
7886
if (!isLaunchByDBus) {
87+
qDebug() << "Starting color picker in direct mode";
7988
picker->StartPick("");
8089
}
8190
QObject::connect(picker.data(), &CPickerManager::copyColor, &clipboard, &Clipboard::copyToClipboard, Qt::QueuedConnection);
8291

8392
if (isLaunchByDBus) {
93+
qDebug() << "Registering DBus service";
8494
QDBusConnection dbus = QDBusConnection::sessionBus();
8595
if (dbus.registerService("com.deepin.Picker")) {
96+
qDebug() << "Successfully registered DBus service: com.deepin.Picker";
8697
dbus.registerObject("/com/deepin/Picker", picker.data(), QDBusConnection::ExportScriptableSlots | QDBusConnection::ExportScriptableSignals);
98+
} else {
99+
qWarning() << "Failed to register DBus service: com.deepin.Picker";
87100
}
88101
}
102+
103+
qDebug() << "Entering application event loop";
89104
return app.exec();
90105
}

0 commit comments

Comments
 (0)