Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ moc_*.cpp
build/
*.qm
*pro.user
.vscode
.cursor
7 changes: 6 additions & 1 deletion src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/colormenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
});
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
46 changes: 26 additions & 20 deletions src/cpickermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -124,18 +129,19 @@ 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));
}

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;
Expand All @@ -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;
}

Expand All @@ -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;
}
}

//立即更新坐标
Expand All @@ -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));
}
}
Expand All @@ -213,13 +226,15 @@ void CPickerManager::handleMouseMove()

void CPickerManager::initShotScreenWidgets()
{
qDebug() << "Initializing screen shot widgets";
ensureDeskTopPixmap();
auto screens = QApplication::screens();
//去出复制屏
int i = 0;
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);
}
}
Expand All @@ -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());
Expand All @@ -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()));
Expand Down Expand Up @@ -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;
}
Expand All @@ -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"),
Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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()) {
Expand All @@ -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"));
Expand All @@ -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<CPickerManager> 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();
}