diff --git a/plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp b/plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp index ef7be0cf..206a7ecf 100644 --- a/plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp +++ b/plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include SettingLabel::SettingLabel(QString text, QWidget *parent) : QWidget(parent) @@ -253,6 +255,9 @@ void BluetoothApplet::initUi() m_airplaneModeWidget->setFixedWidth(ItemWidth); m_mainLayout->addWidget(m_airplaneModeWidget); + // Install event filter to handle Enter event for link hover detection + m_airplaneModeLabel->installEventFilter(this); + QToolButton *disableIcon = new QToolButton(m_disableWidget); disableIcon->setAttribute(Qt::WA_TransparentForMouseEvents); disableIcon->setIcon(QIcon::fromTheme("bluetooth_disable")); @@ -373,3 +378,41 @@ void BluetoothApplet::updateMinHeight(int minHeight) m_minHeight = minHeight; updateSize(); } + +bool BluetoothApplet::eventFilter(QObject *watched, QEvent *event) +{ + // Use eventFilter because standard linkHovered signal is unreliable for vertical movement + if (watched == m_airplaneModeLabel) { + if (event->type() == QEvent::Leave) { + m_airplaneModeLabel->setCursor(Qt::ArrowCursor); + } else if (event->type() == QEvent::MouseMove) { + QMouseEvent *mouseEvent = static_cast(event); + QLabel *label = qobject_cast(watched); + if (label) { + // Manual hit test using a temporary QTextDocument + QTextDocument doc; + doc.setDefaultFont(label->font()); + doc.setMarkdown(label->text()); + + // Adjust for alignment and margins if necessary. + // DTipLabel/DLabel might have specific internal layouts, but assuming standard QLabel behavior: + // Width must be set for word wrap to match + doc.setTextWidth(label->contentsRect().width()); + + // Map mouse position to document coordinates + // Assuming text starts at contentsRect().topLeft() + QPoint textPos = mouseEvent->pos() - label->contentsRect().topLeft(); + + const QString anchor = doc.documentLayout()->anchorAt(textPos); + + if (!anchor.isEmpty()) { + m_airplaneModeLabel->setCursor(Qt::PointingHandCursor); + } else { + m_airplaneModeLabel->setCursor(Qt::ArrowCursor); + } + } + } + } + + return QWidget::eventFilter(watched, event); +} diff --git a/plugins/dde-dock/bluetooth/componments/bluetoothapplet.h b/plugins/dde-dock/bluetooth/componments/bluetoothapplet.h index c3d154d5..92450232 100644 --- a/plugins/dde-dock/bluetooth/componments/bluetoothapplet.h +++ b/plugins/dde-dock/bluetooth/componments/bluetoothapplet.h @@ -96,6 +96,9 @@ public slots: // 更新蓝牙插件主界面大小 void updateSize(); +protected: + bool eventFilter(QObject *watched, QEvent *event) override; + private: QScrollArea *m_scrollArea; QWidget *m_contentWidget;