diff --git a/src/RecorderRegionShow.cpp b/src/RecorderRegionShow.cpp index dcf0449d0..d8a06acfe 100644 --- a/src/RecorderRegionShow.cpp +++ b/src/RecorderRegionShow.cpp @@ -174,24 +174,28 @@ void RecorderRegionShow::paintEvent(QPaintEvent *event) m_painter->begin(&pixmap); m_painter->setRenderHints(QPainter::Antialiasing, true); +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QPen pen(Qt::white, 2.0); pen.setStyle(Qt::DashLine); QVector dashes; dashes << 1 << 2; pen.setDashPattern(dashes); pen.setDashOffset(0); +// LCOV_EXCL_STOP m_painter->setPen(pen); m_painter->setOpacity(1); m_painter->drawRect(0, 0, width(), height()); m_painter->end(); +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env m_painter->begin(this); m_painter->drawPixmap(QPoint(0, 0), pixmap); m_painter->end(); setMask(pixmap.mask()); event->accept(); } +// LCOV_EXCL_STOP void RecorderRegionShow::updateMultiKeyBoardPos() { diff --git a/src/camera/devnummonitor.cpp b/src/camera/devnummonitor.cpp index e5f3ead8c..9156c3222 100644 --- a/src/camera/devnummonitor.cpp +++ b/src/camera/devnummonitor.cpp @@ -73,6 +73,7 @@ void DevNumMonitor::timeOutSlot() //v23特有处理,由于QCameraInfo::availableCameras().count()在v23上无法获取正确结果故更换为此方式 int isExistAvailableCameras = 0; //qCDebug(dsrApp) << "m_canUse: " << m_canUse; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_canUse) { qCDebug(dsrApp) << "Log: DevNumMonitor::timeOutSlot - m_canUse is true. Checking available cameras."; for (int i = 0; i < get_device_list()->num_devices; i++) { @@ -83,9 +84,11 @@ void DevNumMonitor::timeOutSlot() qCDebug(dsrApp) << "Log: DevNumMonitor::timeOutSlot - Device is available:" << get_device_list()->list_devices[i].device; isExistAvailableCameras++; m_availableCamera = get_device_list()->list_devices[i].device; +// LCOV_EXCL_STOP } } } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_canUse && isExistAvailableCameras == 0) { qCDebug(dsrApp) << "Log: DevNumMonitor::timeOutSlot - m_canUse is true and no available cameras found. Emitting existDevice(false)."; emit existDevice(false); @@ -95,6 +98,7 @@ void DevNumMonitor::timeOutSlot() qCDebug(dsrApp) << "Log: DevNumMonitor::timeOutSlot - Available cameras found. Emitting existDevice(true)."; m_noDevice = false; emit existDevice(true); +// LCOV_EXCL_STOP //qCDebug(dsrApp) << "There are " << isExistAvailableCameras << " camera connected and free!"; } } diff --git a/src/dbusinterface/dbusnotify.h b/src/dbusinterface/dbusnotify.h index 6475144b2..65f20ec83 100755 --- a/src/dbusinterface/dbusnotify.h +++ b/src/dbusinterface/dbusnotify.h @@ -26,6 +26,7 @@ class DBusNotify: public QDBusAbstractInterface QList arguments = msg.arguments(); if (3 != arguments.count()) return; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QString interfaceName = msg.arguments().at(0).toString(); if (interfaceName !="org.freedesktop.Notifications") return; @@ -37,6 +38,7 @@ class DBusNotify: public QDBusAbstractInterface QMetaProperty p = self->property(i); if (p.name() == prop) { Q_EMIT p.notifySignal().invoke(this); +// LCOV_EXCL_STOP } } } diff --git a/src/dde-dock-plugins/recordtime/recordtimeplugin.cpp b/src/dde-dock-plugins/recordtime/recordtimeplugin.cpp index ac91c371e..3d5857030 100644 --- a/src/dde-dock-plugins/recordtime/recordtimeplugin.cpp +++ b/src/dde-dock-plugins/recordtime/recordtimeplugin.cpp @@ -60,6 +60,7 @@ bool RecordTimePlugin::pluginIsDisable() void RecordTimePlugin::pluginStateSwitched() { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "pluginStateSwitched method called."; const bool disabledNew = !pluginIsDisable(); qCInfo(dsrApp) << "Plugin state switched, new disabled state:" << disabledNew; @@ -67,6 +68,7 @@ void RecordTimePlugin::pluginStateSwitched() if (disabledNew) { qCDebug(dsrApp) << "Removing plugin item"; m_proxyInter->itemRemoved(this, pluginName()); +// LCOV_EXCL_STOP } else { qCDebug(dsrApp) << "Adding plugin item"; m_proxyInter->itemAdded(this, pluginName()); @@ -174,12 +176,14 @@ void RecordTimePlugin::onRecording() "com.deepin.ScreenRecorder", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForUnregistration, +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env this); connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [this](const QString &) { qCInfo(dsrApp) << "main recorder service unregistered, stopping plugin"; onStop(); }); +// LCOV_EXCL_STOP } } qCDebug(dsrApp) << "onRecording method finished."; diff --git a/src/dde-dock-plugins/recordtime/timewidget.cpp b/src/dde-dock-plugins/recordtime/timewidget.cpp index 751a6fea6..ed36eaa06 100644 --- a/src/dde-dock-plugins/recordtime/timewidget.cpp +++ b/src/dde-dock-plugins/recordtime/timewidget.cpp @@ -235,12 +235,14 @@ void TimeWidget::paintEvent(QPaintEvent *e) qCDebug(dsrApp) << "Height is greater than PLUGIN_BACKGROUND_MIN_SIZE."; QColor color; if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env color = Qt::black; painter.setOpacity(0); qCDebug(dsrApp) << "Theme is LightType, setting color to black and opacity to 0."; if (m_hover) { painter.setOpacity(0.6); qCDebug(dsrApp) << "Hover is true, setting opacity to 0.6."; +// LCOV_EXCL_STOP } if (m_pressed) { @@ -353,6 +355,7 @@ void TimeWidget::mouseReleaseEvent(QMouseEvent *e) { qCDebug(dsrApp) << "Mouse release event received"; if(e->button() == Qt::LeftButton && m_pressed && m_hover){ +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Left button released while pressed and hovered. Resetting flags."; m_pressed = false; m_hover = false; @@ -360,6 +363,7 @@ void TimeWidget::mouseReleaseEvent(QMouseEvent *e) QWidget::mouseReleaseEvent(e); qCDebug(dsrApp) << "mouseReleaseEvent method finished (early exit)."; return; +// LCOV_EXCL_STOP } int width = rect().width(); bool flag = true; diff --git a/src/event_monitor.cpp b/src/event_monitor.cpp index f0eed9eb2..039bae590 100755 --- a/src/event_monitor.cpp +++ b/src/event_monitor.cpp @@ -207,12 +207,14 @@ void EventMonitor::handleEvent(XRecordInterceptData *data) case KeyRelease: qCDebug(dsrApp) << "KeyRelease event detected. Key:" << (reinterpret_cast(data->data))[1]; //键盘按键释放 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env emit keyboardRelease((reinterpret_cast(data->data))[1]); qCDebug(dsrApp) << "Keyboard release event emitted."; break; default: qCDebug(dsrApp) << "Unknown event type:" << event->u.u.type; break; +// LCOV_EXCL_STOP } } diff --git a/src/ext-image-capture/extcaptureintegration.cpp b/src/ext-image-capture/extcaptureintegration.cpp index 079ae1aeb..36e22f5cf 100644 --- a/src/ext-image-capture/extcaptureintegration.cpp +++ b/src/ext-image-capture/extcaptureintegration.cpp @@ -83,6 +83,7 @@ bool ExtCaptureIntegration::startScreenRecording(QScreen *screen, bool includeCu } // 连接会话信号 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env connect(m_session, &ExtCaptureSession::ready, this, &ExtCaptureIntegration::onSessionReady); connect(m_session, &ExtCaptureSession::stopped, @@ -91,6 +92,7 @@ bool ExtCaptureIntegration::startScreenRecording(QScreen *screen, bool includeCu this, &ExtCaptureIntegration::onSessionError); connect(m_session, &ExtCaptureSession::frameReady, this, &ExtCaptureIntegration::onFrameReady); +// LCOV_EXCL_STOP // qCWarning(dsrApp) << "ExtCaptureIntegration: Session signals connected, session state:" << m_session->state(); diff --git a/src/ext-image-capture/multiscreencapturecoordinator.cpp b/src/ext-image-capture/multiscreencapturecoordinator.cpp index 0c095ce02..2f8b4f256 100644 --- a/src/ext-image-capture/multiscreencapturecoordinator.cpp +++ b/src/ext-image-capture/multiscreencapturecoordinator.cpp @@ -97,12 +97,14 @@ bool MultiScreenCaptureCoordinator::startMultiScreenCapture(const QListname() << screen->geometry(); // 创建ExtCaptureSession +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env ExtCaptureSession* session = m_manager->createScreenCaptureSession(screen, includeCursor); if (!session) { qCWarning(dsrApp) << "MultiScreenCaptureCoordinator: Failed to create session for screen" << screen->name(); continue; } +// LCOV_EXCL_STOP // 查找对应的布局信息 ScreenLayout* layout = nullptr; @@ -113,12 +115,14 @@ bool MultiScreenCaptureCoordinator::startMultiScreenCapture(const QListname(); session->deleteLater(); continue; } +// LCOV_EXCL_STOP // 设置会话信息 layout->session = session; diff --git a/src/ext-image-capture/session/extcapturesession.cpp b/src/ext-image-capture/session/extcapturesession.cpp index a02dd9765..e25eb3799 100644 --- a/src/ext-image-capture/session/extcapturesession.cpp +++ b/src/ext-image-capture/session/extcapturesession.cpp @@ -84,12 +84,14 @@ class ExtCaptureSession::Private : public QtWayland::ext_image_copy_capture_sess q_ptr->handleDmabufDevice(deviceData); } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env void ext_image_copy_capture_session_v1_dmabuf_format(uint32_t format, wl_array *modifiers) override { QList modifierList; uint64_t *modData = static_cast(modifiers->data); size_t count = modifiers->size / sizeof(uint64_t); for (size_t i = 0; i < count; ++i) { modifierList.append(modData[i]); +// LCOV_EXCL_STOP } q_ptr->handleDmabufFormat(format, modifierList); } diff --git a/src/gstrecord/gstinterface.cpp b/src/gstrecord/gstinterface.cpp index 685d92a88..a8148f7e7 100644 --- a/src/gstrecord/gstinterface.cpp +++ b/src/gstrecord/gstinterface.cpp @@ -124,12 +124,14 @@ void gstInterface::unloadFunctions() { qCDebug(dsrApp) << "unloadFunctions method called."; if (m_isInitFunction) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env m_libgstreamer.unload(); qCDebug(dsrApp) << "libgstreamer-1.0 unloaded."; m_libglib.unload(); qCDebug(dsrApp) << "libglib-2.0 unloaded."; m_libgobject.unload(); qCDebug(dsrApp) << "libgobject-2.0 unloaded."; +// LCOV_EXCL_STOP } qCDebug(dsrApp) << "unloadFunctions method finished."; } diff --git a/src/gstrecord/gstrecordx.cpp b/src/gstrecord/gstrecordx.cpp index d53d5d33c..43fa9b283 100644 --- a/src/gstrecord/gstrecordx.cpp +++ b/src/gstrecord/gstrecordx.cpp @@ -498,6 +498,7 @@ void GstRecordX::stopPipeline() Q_UNUSED(msg); qCDebug(dsrApp) << "Bus timed pop filtered for EOS message."; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env GstStateChangeReturn ret ; Q_UNUSED(ret); ret = gstInterface::m_gst_element_set_state(m_pipeline, GST_STATE_PAUSED); @@ -512,6 +513,7 @@ void GstRecordX::stopPipeline() gstInterface::m_gst_object_unref(m_pipeline); qCInfo(dsrApp) << "Pipeline stopped and cleaned up"; } +// LCOV_EXCL_STOP //格式化输出gstreamer命令 diff --git a/src/main_window.cpp b/src/main_window.cpp index 72b19a770..833b0fc39 100755 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -1001,12 +1001,14 @@ void MainWindow::initDynamicLibPath() QString MainWindow::libPath(const QString &strlib) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QDir dir; QString path = QLibraryInfo::location(QLibraryInfo::LibrariesPath); dir.setPath(path); qCDebug(dsrApp) << " where is libs? where is " << dir; QStringList list = dir.entryList(QStringList() << (strlib + "*"), QDir::NoDotAndDotDot | QDir::Files); // filter name with strlib +// LCOV_EXCL_STOP qCDebug(dsrApp) << strlib << " Is it in there? there is " << list; @@ -1501,6 +1503,7 @@ void MainWindow::initScreenRecorder() isReleaseMouseLeftButton = false; if (m_firstShot == 1) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "initScreenRecorder m_firstShot == 1"; if (recordWidth < 580) { qCDebug(dsrApp) << "initScreenRecorder recordWidth < 580"; @@ -1508,6 +1511,7 @@ void MainWindow::initScreenRecorder() if (recordX >= m_screenWidth - 580) { qCDebug(dsrApp) << "initScreenRecorder recordX >= m_screenWidth - 580"; recordX = m_screenWidth - 581; +// LCOV_EXCL_STOP } } @@ -1753,6 +1757,7 @@ void MainWindow::moveToolBars(QPoint startPoint, QPoint moveDistance) if (m_sideBar->isVisible()) { qCDebug(dsrApp) << "moveToolBars m_sideBar->isVisible()"; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_currentToolShape == "aiassistant") { QPoint aiBtnGlobalCenter = m_toolBar->getAiButtonGlobalCenter(); int aiPanelWidth = m_sideBar->width(); @@ -1760,6 +1765,7 @@ void MainWindow::moveToolBars(QPoint startPoint, QPoint moveDistance) int finalTop = m_toolBar->y() + SIDEBAR_Y_SPACING + m_toolBar->height(); QPoint aiSidebarPoint(finalLeft, finalTop); movePoint = limitToolbarScope(aiSidebarPoint, 1); +// LCOV_EXCL_STOP } else { movePoint = limitToolbarScope(m_sideBarStartPressPoint + moveDistance, 1); } @@ -1824,6 +1830,7 @@ QPoint MainWindow::limitToolbarScope(QPoint movePoint, int type) qCDebug(dsrApp) << "limitToolbarScope m_currentToolShape == rectangle"; minX = m_toolBar->x(); maxX = m_toolBar->width(); +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env } else if (m_currentToolShape == "aiassistant") { qCDebug(dsrApp) << "limitToolbarScope m_currentToolShape == aiassistant"; QPoint aiBtnGlobalCenter = m_toolBar->getAiButtonGlobalCenter(); @@ -1831,6 +1838,7 @@ QPoint MainWindow::limitToolbarScope(QPoint movePoint, int type) const int targetLeft = aiBtnGlobalCenter.x() - (sidebarWidth / 2); minX = targetLeft; maxX = sidebarWidth; +// LCOV_EXCL_STOP } else { qCDebug(dsrApp) << "limitToolbarScope m_currentToolShape == other"; if (m_toolBar->getFuncSubToolX(m_currentToolShape) > -1) { @@ -2643,6 +2651,7 @@ bool MainWindow::saveImg(const QPixmap &pix, const QString &fileName, const char int quality = -1; // qt5环境,经测试quality值对png效果明显,对jpg和bmp不明显 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (pix.width() * pix.height() > 1920 * 1080 && QString("PNG") == QString(format).toUpper()) { if (QSysInfo::currentCpuArchitecture().startsWith("x86") && !m_isZhaoxin) { qCInfo(dsrApp) << "x86 not zhaoxin, qaulity=60"; @@ -2656,6 +2665,7 @@ bool MainWindow::saveImg(const QPixmap &pix, const QString &fileName, const char } else if (QSysInfo::currentCpuArchitecture().startsWith("mips")) { qCInfo(dsrApp) << "mips, qaulity=80"; quality = 80; +// LCOV_EXCL_STOP } } if (QSysInfo::currentCpuArchitecture().startsWith("loongarch64")) { @@ -3368,6 +3378,7 @@ void MainWindow::updateCameraWidgetPos() x = recordX; y = recordY + recordHeight - cameraWidgetHeight; break; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env case CameraWidget::Position::rightTop: x = recordX + recordWidth - cameraWidgetWidth; y = recordY; @@ -3376,6 +3387,7 @@ void MainWindow::updateCameraWidgetPos() x = recordX + recordWidth - cameraWidgetWidth; y = recordY + recordHeight - cameraWidgetHeight; break; +// LCOV_EXCL_STOP } m_cameraWidget->setRecordRect(recordX, recordY, recordWidth, recordHeight); m_cameraWidget->resize(cameraWidgetWidth, cameraWidgetHeight); @@ -3412,6 +3424,7 @@ QPoint MainWindow::getTwoScreenIntersectPos(QPoint rawPos) return static_cast(v / ratio); }; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env const int s1x = toLogicalPos(tmp_screenInfo.at(0).x); const int s1y = toLogicalPos(tmp_screenInfo.at(0).y); const int s1w = toLogicalSize(tmp_screenInfo.at(0).width); @@ -3420,6 +3433,7 @@ QPoint MainWindow::getTwoScreenIntersectPos(QPoint rawPos) const int s2y = toLogicalPos(tmp_screenInfo.at(1).y); const int s2w = toLogicalSize(tmp_screenInfo.at(1).width); const int s2h = toLogicalSize(tmp_screenInfo.at(1).height); +// LCOV_EXCL_STOP // 2. get the cross area double area_1 = 0, area_2 = 0; @@ -3628,12 +3642,14 @@ void MainWindow::changeFunctionButton(QString type) if (status::shot == m_functionType) { return; } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env m_sizeTips->setRecorderTipsInfo(false); m_sizeTips->updateTips(QPoint(recordX, recordY), QSize(recordWidth, recordHeight)); m_toolBar->setVideoButtonInit(); if (m_cameraWidget && m_cameraWidget->isVisible()) { m_cameraWidget->cameraStop(); m_cameraWidget->hide(); +// LCOV_EXCL_STOP } // m_recordButton->hide(); // updateShotButtonPos(); @@ -3756,12 +3772,14 @@ void MainWindow::changeCameraSelectEvent(bool checked) if (cameraWidgetWidth > CAMERA_WIDGET_MAX_WIDTH) cameraWidgetWidth = CAMERA_WIDGET_MAX_WIDTH; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env int cameraWidgetHeight = recordHeight * 1 / 4; if (cameraWidgetHeight > CAMERA_WIDGET_MAX_HEIGHT) cameraWidgetHeight = CAMERA_WIDGET_MAX_HEIGHT; int tempHeight = cameraWidgetWidth * 9 / 16; int tempWidth = cameraWidgetHeight * 16 / 9; if (tempHeight <= CAMERA_WIDGET_MAX_HEIGHT && tempHeight >= CAMERA_WIDGET_MIN_HEIGHT && tempHeight <= recordHeight) { +// LCOV_EXCL_STOP cameraWidgetHeight = tempHeight; } else { cameraWidgetWidth = tempWidth; @@ -3801,6 +3819,7 @@ void MainWindow::updateMultiKeyBoardPos() {-2.5f, -(0.5f + 1 / 1.5f), (1 / 1.5f - 0.5f), 1.5, 0}, {-3.1f, -1.8f, -0.5, 0.8f, 2.1f}}; if (!m_keyButtonList.isEmpty()) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env int count = m_keyButtonList.count(); for (int j = 0; j < count; ++j) { m_keyButtonList.at(j)->hide(); @@ -3809,6 +3828,7 @@ void MainWindow::updateMultiKeyBoardPos() std::max(recordY + recordHeight - INDICATOR_WIDTH, 0)); m_keyButtonList.at(j)->move(t_keyPoint[j].x(), t_keyPoint[j].y()); m_keyButtonList.at(j)->show(); +// LCOV_EXCL_STOP } } } @@ -3847,6 +3867,7 @@ void MainWindow::changeShotToolEvent(const QString &func) qCDebug(dsrApp) << "MainWindow::changeShotToolEvent >> func: " << func; // 调用ocr功能时先截图后,退出截图录屏,将刚截图的图片串递到ocr识别界面; if (func == "ocr") { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env { QJsonObject obj{{"tid", EventLogUtils::Start}, {"version", QCoreApplication::applicationVersion()}, @@ -3854,6 +3875,7 @@ void MainWindow::changeShotToolEvent(const QString &func) {"startup_mode", "B4"}}; EventLogUtils::get().writeLogs(obj); } +// LCOV_EXCL_STOP // 调起OCR识别界面, 传入截图路径 m_ocrInterface = new OcrInterface("com.deepin.Ocr", "/com/deepin/Ocr", QDBusConnection::sessionBus(), this); int delayTime = 0; @@ -3875,6 +3897,7 @@ void MainWindow::changeShotToolEvent(const QString &func) }); } } else if (func == "pinScreenshots") { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env { QJsonObject obj{{"tid", EventLogUtils::Start}, {"version", QCoreApplication::applicationVersion()}, @@ -3885,7 +3908,9 @@ void MainWindow::changeShotToolEvent(const QString &func) m_functionType = status::pinscreenshots; m_pinInterface = new PinScreenShotsInterface( "com.deepin.PinScreenShots", "/com/deepin/PinScreenShots", QDBusConnection::sessionBus(), this); +// LCOV_EXCL_STOP // 保存贴图到剪贴板 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env saveScreenShot(); QImage pinImage = m_resultPixmap.toImage(); QDBusPendingCall pendingCall = m_pinInterface->openImageAndName(pinImage, m_saveFileName, QPoint(recordX, recordY)); @@ -3895,6 +3920,7 @@ void MainWindow::changeShotToolEvent(const QString &func) qCWarning(dsrApp) << "[PIN_DIAG] D-Bus openImageAndName failed:" << watcher->error().name() << watcher->error().message(); +// LCOV_EXCL_STOP } else { qCWarning(dsrApp) << "[PIN_DIAG] D-Bus openImageAndName succeeded"; } @@ -3903,6 +3929,7 @@ void MainWindow::changeShotToolEvent(const QString &func) }); } else if (func == "scrollShot") { // 点击滚动截图 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env { QJsonObject obj{{"tid", EventLogUtils::Start}, {"version", QCoreApplication::applicationVersion()}, @@ -3910,6 +3937,7 @@ void MainWindow::changeShotToolEvent(const QString &func) {"startup_mode", "B5"}}; EventLogUtils::get().writeLogs(obj); } +// LCOV_EXCL_STOP // 捕捉区域的固件不显示 drawDragPoint = false; m_toolBar->hide(); @@ -3925,12 +3953,14 @@ void MainWindow::changeShotToolEvent(const QString &func) changeFunctionButton(func); } else { if (func == QStringLiteral("aiassistant")) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QJsonObject obj{{"tid", EventLogUtils::Start}, {"version", QCoreApplication::applicationVersion()}, {"mode", 1}, {"startup_mode", "B9"}}; EventLogUtils::get().writeLogs(obj); } +// LCOV_EXCL_STOP m_currentToolShape = func; // if (!m_sideBar->isVisible()) { updateSideBarPos(); @@ -3989,6 +4019,7 @@ void MainWindow::captureScreenshotImage() // 滚动截图模式下保存图片 if (status::scrollshot == m_functionType && m_scrollShotStatus != 0) { #ifdef OCR_SCROLL_FLAGE_ON +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env bool ok; QRect rect(recordX + m_scrollShotOffsetXY, recordY + m_scrollShotOffsetXY, @@ -3998,6 +4029,7 @@ void MainWindow::captureScreenshotImage() m_scrollShot->addLastPixmap(img); m_resultPixmap = QPixmap::fromImage(m_scrollShot->savePixmap()); if (m_resultPixmap.isNull()) { +// LCOV_EXCL_STOP // 普通截图保存图片 shotCurrentImg(); } @@ -4088,12 +4120,14 @@ void MainWindow::onAiAssistantSelected(int func) ConfigSettings::instance()->setValue("shot", "save_ways", static_cast(originalSaveWays)); if (!saveResult || m_saveFileName.isEmpty()) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCWarning(dsrApp) << "AI: failed to save screenshot"; isHideToolBar = originalHideToolBar; m_functionType = originalFunctionType; m_saveIndex = originalSaveIndex; exitApp(); return; +// LCOV_EXCL_STOP } qCWarning(dsrApp) << "AI: screenshot saved to:" << m_saveFileName; @@ -4241,6 +4275,7 @@ void MainWindow::saveScreenShot() // 滚动截图模式下保存图片 if (status::scrollshot == m_functionType && m_scrollShotStatus != 0) { #ifdef OCR_SCROLL_FLAGE_ON +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env bool ok; QRect rect(recordX + m_scrollShotOffsetXY, recordY + m_scrollShotOffsetXY, @@ -4250,6 +4285,7 @@ void MainWindow::saveScreenShot() m_scrollShot->addLastPixmap(img); m_resultPixmap = QPixmap::fromImage(m_scrollShot->savePixmap()); if (m_resultPixmap.isNull()) { +// LCOV_EXCL_STOP // 普通截图保存图片 shotCurrentImg(); } @@ -4297,12 +4333,14 @@ void MainWindow::sendNotify(SaveAction saveAction, QString saveFilePath, const b if (status::pinscreenshots == m_functionType) return; if (Utils::is3rdInterfaceStart) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QDBusMessage msg = QDBusMessage::createSignal("/com/deepin/Screenshot", "com.deepin.Screenshot", "Done"); msg << saveFilePath; QDBusConnection::sessionBus().send(msg); exitApp(); return; } +// LCOV_EXCL_STOP if (m_noNotify || Utils::isRootUser) { exitApp(); return; @@ -4461,6 +4499,7 @@ bool MainWindow::saveAction(const QPixmap &pix) m_saveFileName = QFileDialog::getSaveFileName( this, tr("Save"), defaultFileName, tr("PNG (*.png);;JPEG (*.jpg *.jpeg);;BMP (*.bmp)")); break; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env case 1: defaultFileName = QString("%1/%2.jpg").arg(lastSavePath).arg(fileName); m_saveFileName = QFileDialog::getSaveFileName( @@ -4476,6 +4515,7 @@ bool MainWindow::saveAction(const QPixmap &pix) m_saveFileName = QFileDialog::getSaveFileName( this, tr("Save"), defaultFileName, tr("PNG (*.png);;JPEG (*.jpg *.jpeg);;BMP (*.bmp)")); break; +// LCOV_EXCL_STOP } if (Utils::isWaylandMode) { @@ -4495,6 +4535,7 @@ bool MainWindow::saveAction(const QPixmap &pix) // 处理文件扩展名 QString fileSuffix = QFileInfo(m_saveFileName).completeSuffix(); if (fileSuffix.isEmpty()) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env switch (t_pictureFormat) { case 0: m_saveFileName = m_saveFileName + ".png"; @@ -4508,9 +4549,11 @@ bool MainWindow::saveAction(const QPixmap &pix) default: m_saveFileName = m_saveFileName + ".png"; break; +// LCOV_EXCL_STOP } } else if (!BaseUtils::isValidFormat(fileSuffix)) { //检查后缀是以.png|.jpg|.jpeg|.bmp中的一种进行结尾 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env bool flag = checkSuffix(fileSuffix); if (!flag) { qWarning() << "The fileName has invalid suffix! fileSuffix: " << fileSuffix; @@ -4527,6 +4570,7 @@ bool MainWindow::saveAction(const QPixmap &pix) default: m_saveFileName = m_saveFileName + ".png"; break; +// LCOV_EXCL_STOP } } } @@ -4590,6 +4634,7 @@ bool MainWindow::saveAction(const QPixmap &pix) m_saveFileName = isChangeSpecificDir ? QFileDialog::getSaveFileName( +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env this, tr("Save"), lastFileName, tr("PNG (*.png);;JPEG (*.jpg *.jpeg);;BMP (*.bmp)")) : lastFileName; break; @@ -4597,7 +4642,9 @@ bool MainWindow::saveAction(const QPixmap &pix) lastFileName = QString("%1/%2.jpg").arg(path).arg(fileName); m_saveFileName = isChangeSpecificDir ? +// LCOV_EXCL_STOP QFileDialog::getSaveFileName( +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env this, tr("Save"), lastFileName, tr("JPEG (*.jpg *.jpeg);;PNG (*.png);;BMP (*.bmp)")) : lastFileName; break; @@ -4605,7 +4652,9 @@ bool MainWindow::saveAction(const QPixmap &pix) lastFileName = QString("%1/%2.bmp").arg(path).arg(fileName); m_saveFileName = isChangeSpecificDir ? +// LCOV_EXCL_STOP QFileDialog::getSaveFileName( +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env this, tr("Save"), lastFileName, tr("BMP (*.bmp);;JPEG (*.jpg *.jpeg);;PNG (*.png)")) : lastFileName; break; @@ -4613,6 +4662,7 @@ bool MainWindow::saveAction(const QPixmap &pix) lastFileName = QString("%1/%2.png").arg(path).arg(fileName); m_saveFileName = isChangeSpecificDir ? +// LCOV_EXCL_STOP QFileDialog::getSaveFileName( this, tr("Save"), lastFileName, tr("PNG (*.png);;JPEG (*.jpg *.jpeg);;BMP (*.bmp)")) : lastFileName; @@ -4638,6 +4688,7 @@ bool MainWindow::saveAction(const QPixmap &pix) if (fileSuffix.isEmpty()) { // m_saveFileName = m_saveFileName + ".png"; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env switch (t_pictureFormat) { case 0: m_saveFileName = m_saveFileName + ".png"; @@ -4651,9 +4702,11 @@ bool MainWindow::saveAction(const QPixmap &pix) default: m_saveFileName = m_saveFileName + ".png"; break; +// LCOV_EXCL_STOP } } else if (!BaseUtils::isValidFormat(fileSuffix)) { //检查后缀是以.png|.jpg|.jpeg|.bmp中的一种进行结尾。false:否 true:是 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env bool flag = checkSuffix(fileSuffix); if (!flag) { qWarning() << "The fileName has invalid suffix! fileSuffix: " << fileSuffix; @@ -4670,12 +4723,14 @@ bool MainWindow::saveAction(const QPixmap &pix) default: m_saveFileName = m_saveFileName + ".png"; break; +// LCOV_EXCL_STOP } } } else { qCDebug(dsrApp) << "The fileSuffix is right! " << fileSuffix; } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCInfo(dsrApp) << __FUNCTION__ << __LINE__ << "保存到指定文件夹!"; qCDebug(dsrApp) << "The fileName is: " << m_saveFileName; ConfigSettings::instance()->setValue("shot", "save_dir", QFileInfo(m_saveFileName).dir().absolutePath()); @@ -4688,6 +4743,7 @@ bool MainWindow::saveAction(const QPixmap &pix) qCInfo(dsrApp) << __FUNCTION__ << __LINE__ << "保存到剪切板!"; qCDebug(dsrApp) << SaveToClipboard << "SaveToClipboard"; break; +// LCOV_EXCL_STOP } default: break; @@ -4714,12 +4770,14 @@ bool MainWindow::saveAction(const QPixmap &pix) if (!saveImg(pix, m_saveFileName, QFileInfo(m_saveFileName).suffix().toLocal8Bit())) return false; } else if (saveOption != QStandardPaths::TempLocation && m_saveFileName.isEmpty()) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QString savePath; if (m_shotWithPath == true) { savePath = m_shotSavePath; } else if (m_saveIndex == SaveToImage) { savePath = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first() + QDir::separator() + "Screenshots"; +// LCOV_EXCL_STOP } else { savePath = QStandardPaths::writableLocation(saveOption); } @@ -4730,12 +4788,14 @@ bool MainWindow::saveAction(const QPixmap &pix) savePath = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first(); } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QString t_formatStr; QString t_formatBuffix; switch (t_pictureFormat) { case 0: t_formatStr = "PNG"; t_formatBuffix = "png"; +// LCOV_EXCL_STOP break; case 1: t_formatStr = "JPEG"; @@ -4792,12 +4852,14 @@ bool MainWindow::saveAction(const QPixmap &pix) qCInfo(dsrApp) << __FUNCTION__ << __LINE__ << "AutoSave: 使用用户指定的完整文件路径"; // 确保目录存在 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QDir saveDir(m_shotSavePath); if (!saveDir.exists()) { bool mkdirSucc = saveDir.mkpath("."); if (!mkdirSucc) { qCritical() << "AutoSave: 无法创建目录:" << m_shotSavePath; return false; +// LCOV_EXCL_STOP } } @@ -4816,12 +4878,14 @@ bool MainWindow::saveAction(const QPixmap &pix) QString savePath = m_shotSavePath; // 确保目录存在 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QDir saveDir(savePath); if (!saveDir.exists()) { bool mkdirSucc = saveDir.mkpath("."); if (!mkdirSucc) { qCritical() << "AutoSave: 无法创建目录:" << savePath; return false; +// LCOV_EXCL_STOP } } @@ -4854,12 +4918,14 @@ bool MainWindow::saveAction(const QPixmap &pix) QString("%1/%2_%3_%4.%5").arg(savePath, functionTypeStr, selectAreaName, currentTime, t_formatBuffix); } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (!saveImg(pix, m_saveFileName, t_formatStr.toLatin1().data())) return false; } } else if (m_saveIndex == SaveToClipboard) { if (selectAreaName.isEmpty()) { tempFileName = QString("%1_%2_%3").arg(tr("Clipboard"), functionTypeStr, currentTime); +// LCOV_EXCL_STOP } else { tempFileName = QString("%1_%2_%3_%4").arg(tr("Clipboard"), functionTypeStr, selectAreaName, currentTime); } @@ -4952,6 +5018,7 @@ void MainWindow::paintEvent(QPaintEvent *event) // 录屏/滚动截图模式:只在模糊面板精确圆角区域绘制背景截图,供 InWidgetBlend 模糊采样。 // 使用 ToolBarWidget/SideBarWidget 的 contentsRect 配合 DFloatingWidget 圆角半径(18) // 裁剪,避免脏截图在阴影区域和圆角外泄漏。 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_toolBar && m_toolBar->isVisible()) { QPainterPath clipPath; QRect innerRect = m_toolBar->getInnerWidgetRect(); @@ -4961,14 +5028,17 @@ void MainWindow::paintEvent(QPaintEvent *event) QRect sideInner = m_sideBar->getInnerWidgetRect(); sideInner.translate(m_sideBar->pos()); clipPath.addRoundedRect(sideInner, 18, 18); +// LCOV_EXCL_STOP } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env painter.setRenderHint(QPainter::Antialiasing, true); m_backgroundPixmap.setDevicePixelRatio(m_pixelRatio); painter.setClipPath(clipPath); painter.drawPixmap(backgroundRect, m_backgroundPixmap); painter.setClipping(false); } +// LCOV_EXCL_STOP } @@ -4989,6 +5059,7 @@ void MainWindow::paintEvent(QPaintEvent *event) // << "m_adjustArea.width(): " << m_adjustArea.width() // << "m_adjustArea.height(): " << m_adjustArea.height(); // 画可调整的捕捉区域位置及大小 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env painter.setRenderHint(QPainter::Antialiasing, false); QPen framePen(QColor("#01bdff")); framePen.setStyle(Qt::SolidLine); @@ -5003,6 +5074,7 @@ void MainWindow::paintEvent(QPaintEvent *event) std::min(static_cast(m_adjustArea.height()) - 1, rootWindowRect.height() - 2))); painter.setRenderHint(QPainter::Antialiasing, true); } +// LCOV_EXCL_STOP // Draw background. 画背景 painter.setBrush(QBrush("#000000")); @@ -5509,6 +5581,7 @@ int MainWindow::mouseMoveEF(QMouseEvent *mouseEvent, bool &needRepaint) << m_screenInfo[index].name << " (" << m_screenInfo[index].x << m_screenInfo[index].y << m_screenInfo[index].width << m_screenInfo[index].height << ") 上"; // 可以准确的定位到在哪块屏幕上 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_screenInfo[index].x == 0 && m_screenInfo[index].y == 0) { recordX = static_cast(x); recordY = static_cast(y); @@ -5523,6 +5596,7 @@ int MainWindow::mouseMoveEF(QMouseEvent *mouseEvent, bool &needRepaint) static_cast((x - m_screenInfo[index].x) + m_screenInfo[index].x / m_pixelRatio); recordY = static_cast(y); qCDebug(dsrApp) << "1.1.3 >>>> recordX: " << recordX << " , recordY: " << recordY; +// LCOV_EXCL_STOP } else { recordX = static_cast((x - m_screenInfo[index].x) + m_screenInfo[index].x / m_pixelRatio); @@ -5543,6 +5617,7 @@ int MainWindow::mouseMoveEF(QMouseEvent *mouseEvent, bool &needRepaint) bool yIsInScreen = false; for (int index = 0; index < m_screenCount; ++index) { // x坐标及其投影是否在某块屏幕内部 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env bool xIndex = x >= m_screenInfo[index].x && x < (m_screenInfo[index].x + m_screenInfo[index].width); if (xIndex) { @@ -5550,6 +5625,7 @@ int MainWindow::mouseMoveEF(QMouseEvent *mouseEvent, bool &needRepaint) << "窗口 " << windowNames[i] << "(" << x << "," << y << ") x坐标或投影在屏幕" << m_screenInfo[index].name << " (" << m_screenInfo[index].x << m_screenInfo[index].y << m_screenInfo[index].width << m_screenInfo[index].height << ") 上"; +// LCOV_EXCL_STOP // 判读当前屏幕是否从(0,0)开始,如果是则不需要进行屏幕之间的缩放计算 if (m_screenInfo[index].x == 0) { recordX = static_cast(x / m_pixelRatio); @@ -5567,6 +5643,7 @@ int MainWindow::mouseMoveEF(QMouseEvent *mouseEvent, bool &needRepaint) } for (int index = 0; index < m_screenCount; ++index) { // y坐标及其投影是否在某块屏幕内部 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env bool yIndex = y >= m_screenInfo[index].y && y < (m_screenInfo[index].y + m_screenInfo[index].height); if (yIndex) { @@ -5574,6 +5651,7 @@ int MainWindow::mouseMoveEF(QMouseEvent *mouseEvent, bool &needRepaint) << "窗口 " << windowNames[i] << "(" << x << "," << y << ") y坐标或投影在屏幕" << m_screenInfo[index].name << " (" << m_screenInfo[index].x << m_screenInfo[index].y << m_screenInfo[index].width << m_screenInfo[index].height << ") 上"; +// LCOV_EXCL_STOP // 判读当前屏幕是否从(0,0)开始,如果是则不需要进行屏幕之间的缩放计算 if (m_screenInfo[index].y == 0) { recordY = static_cast(y / m_pixelRatio); @@ -5657,6 +5735,7 @@ int MainWindow::keyPressEF(QKeyEvent *keyEvent, bool &needRepaint) } if (keyEvent->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (keyEvent->key() == Qt::Key_Left) { m_shapesWidget->microAdjust("Ctrl+Shift+Left"); } else if (keyEvent->key() == Qt::Key_Right) { @@ -5665,8 +5744,10 @@ int MainWindow::keyPressEF(QKeyEvent *keyEvent, bool &needRepaint) m_shapesWidget->microAdjust("Ctrl+Shift+Up"); } else if (keyEvent->key() == Qt::Key_Down) { m_shapesWidget->microAdjust("Ctrl+Shift+Down"); +// LCOV_EXCL_STOP } } else if (qApp->keyboardModifiers() & Qt::ControlModifier) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (keyEvent->key() == Qt::Key_Left) { m_shapesWidget->microAdjust("Ctrl+Left"); } else if (keyEvent->key() == Qt::Key_Right) { @@ -5676,6 +5757,7 @@ int MainWindow::keyPressEF(QKeyEvent *keyEvent, bool &needRepaint) } else if (keyEvent->key() == Qt::Key_Down) { m_shapesWidget->microAdjust("Ctrl+Down"); } else if (keyEvent->key() == Qt::Key_C) { +// LCOV_EXCL_STOP // ConfigSettings::instance()->setValue("save", "save_op", // SaveAction::SaveToClipboard); // m_copyToClipboard = true; @@ -5707,12 +5789,14 @@ int MainWindow::keyPressEF(QKeyEvent *keyEvent, bool &needRepaint) if (m_shotStatus == ShotMouseStatus::Normal) { // 是否按住 shift+ctrl if (keyEvent->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (keyEvent->key() == Qt::Key_Left) { if (recordWidth > RECORD_MIN_SHOT_SIZE) { recordX = std::max(0, recordX + 1); recordWidth = std::max(std::min(recordWidth - 1, m_backgroundRect.width()), RECORD_MIN_SHOT_SIZE); needRepaint = true; selectAreaName = tr("select-area"); +// LCOV_EXCL_STOP } } else if (keyEvent->key() == Qt::Key_Right) { @@ -5848,12 +5932,14 @@ int MainWindow::keyPressEF(QKeyEvent *keyEvent, bool &needRepaint) // } } // 调整捕捉区域快捷键 shift+ctrl+up/down/left/right +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (keyEvent->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { if (keyEvent->key() == Qt::Key_Left) { if (recordWidth > RECORD_MIN_SIZE) { recordX = std::max(0, recordX + 1); recordWidth = std::max(std::min(recordWidth - 1, m_backgroundRect.width()), RECORD_MIN_SIZE); needRepaint = true; +// LCOV_EXCL_STOP } } else if (keyEvent->key() == Qt::Key_Right) { @@ -6520,6 +6606,7 @@ void MainWindow::onLockScreenEvent(QDBusMessage msg) // qCDebug(dsrApp) << "Locked:" << changedProps[prop]; isLocked = changedProps[prop].toBool(); } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env } } qCDebug(dsrApp) << ">>>>>>>>> isLocked: " << isLocked; @@ -6528,6 +6615,7 @@ void MainWindow::onLockScreenEvent(QDBusMessage msg) scrollShotLockScreen(isLocked); } else if (status::shot == m_functionType) { pinScreenshotsLockScreen(isLocked); +// LCOV_EXCL_STOP } } @@ -7185,12 +7273,14 @@ void MainWindow::addCursorToImage() const int dataSize = m_CursorImage->width * m_CursorImage->height * 4; uchar *pixels = new uchar[dataSize]; int index = 0; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env for (int j = 0; j < m_CursorImage->width * m_CursorImage->height; ++j) { unsigned long curValue = m_CursorImage->pixels[j]; pixels[index++] = static_cast(curValue >> 0); pixels[index++] = static_cast(curValue >> 8); pixels[index++] = static_cast(curValue >> 16); pixels[index++] = static_cast(curValue >> 24); +// LCOV_EXCL_STOP } QImage cursorImage = QImage(pixels, m_CursorImage->width, m_CursorImage->height, QImage::Format_ARGB32_Premultiplied); painter.drawImage(QRect(x - recordX - m_CursorImage->width / 2, @@ -7198,12 +7288,14 @@ void MainWindow::addCursorToImage() m_CursorImage->width, m_CursorImage->height), cursorImage); +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env delete[] pixels; XFree(m_CursorImage); } qCInfo(dsrApp) << __FUNCTION__ << __LINE__ << "已在图片中添加光标!"; return; } +// LCOV_EXCL_STOP void MainWindow::shotFullScreen(bool isFull) { @@ -7544,6 +7636,7 @@ void MainWindow::startCountdown() // 两个屏幕之间会出现逻辑坐标间隙,导致 screenAt/contains 判断不准确。 // 因此在 Qt6+XCB 下使用物理坐标检测跨屏。 if (Utils::isQt6XcbEnv) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env bool found = false; for (QScreen *screen : allScreens) { qreal dpr = screen->devicePixelRatio(); @@ -7555,6 +7648,7 @@ void MainWindow::startCountdown() if (screenPhysical.contains(recordRect)) { found = true; break; +// LCOV_EXCL_STOP } } isRecordAreaCrossScreen = !found; @@ -7601,6 +7695,7 @@ void MainWindow::startCountdown() } // Qt6+XCB: geometry().x()/y() 是物理位置,需要除以 DPR 转为 MainWindow 本地坐标 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QRect targetLocal; if (Utils::isQt6XcbEnv) { targetLocal = QRect( @@ -7608,6 +7703,7 @@ void MainWindow::startCountdown() static_cast(targetScreen->geometry().y() / m_pixelRatio), targetScreen->geometry().width(), targetScreen->geometry().height()); +// LCOV_EXCL_STOP } else { targetLocal = targetScreen->geometry(); } @@ -7788,12 +7884,14 @@ void MainWindow::exitApp() // treeland 退出:避免直接销毁 Wayland proxy,改为取消并让进程退出清理 if (Utils::isTreelandMode) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_pRecorderRegion) m_pRecorderRegion->hide(); if (m_shapesWidget) m_shapesWidget->hide(); if (m_sideBar) m_sideBar->hide(); +// LCOV_EXCL_STOP if (auto manager = TreelandCaptureManager::instance()) { qCInfo(dsrApp) << __FUNCTION__ << __LINE__ << "treeland cancelCapture"; diff --git a/src/record_process.cpp b/src/record_process.cpp index d6bf70ade..07391f0b7 100644 --- a/src/record_process.cpp +++ b/src/record_process.cpp @@ -164,12 +164,14 @@ void RecordProcess::onStartTranscode() QString captureTempDir = saveTempDir; QString captureSavePath = savePath; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QThreadPool::globalInstance()->start([ = ](){ QString cachePalette = captureTempDir + QDir::separator() + "deepin_screen_recorder_palette.png"; QProcess paletteProcess; qCDebug(dsrApp) << "Starting palette generation process."; paletteProcess.start("ffmpeg", {"-i", captureSavePath, "-vf", "select=not(mod(n\\,30)),palettegen=stats_mode=diff", cachePalette, "-y"}); qCDebug(dsrApp) << "Palette process command:" << paletteProcess.program() << paletteProcess.arguments().join(' '); +// LCOV_EXCL_STOP if (!paletteProcess.waitForFinished(10 * 60 * 1000)) { qCWarning(dsrApp) << "Convert palette failed!" << paletteProcess.errorString(); @@ -242,12 +244,14 @@ void RecordProcess::onTranscodePaletteFinished(const QString &palettePng) arg << savePath; qCDebug(dsrApp) << "Transcoding arguments setup. Input path:" << savePath; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (!palettePng.isEmpty()) { qCDebug(dsrApp) << "Palette PNG is not empty, adding as input."; arg << "-i"; arg << palettePng; arg << "-filter_complex"; arg << "fps=12,paletteuse=dither=none:diff_mode=rectangle"; +// LCOV_EXCL_STOP } arg << "-r"; @@ -270,6 +274,7 @@ void RecordProcess::onTranscodePaletteFinished(const QString &palettePng) //转码完成后通知栏弹出提示 void RecordProcess::onTranscodeFinish() { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Transcoding finished callback."; QString path = savePath; QString gifOldPath = path.replace("mp4", "gif"); @@ -279,12 +284,14 @@ void RecordProcess::onTranscodeFinish() qCDebug(dsrApp) << "GIF file renamed."; exitRecord(gifNewPath); } +// LCOV_EXCL_STOP //录屏结束后弹出通知 void RecordProcess::onRecordFinish() { qCDebug(dsrApp) << "Record finish callback: Ending screen recording..."; //x11录屏结束 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (!Utils::isWaylandMode) { qCDebug(dsrApp) << "X11 recording mode."; if (QProcess::ProcessState::NotRunning != m_recorderProcess->exitCode()) { @@ -292,6 +299,7 @@ void RecordProcess::onRecordFinish() foreach (auto line, (m_recorderProcess->readAllStandardError().split('\n'))) { qCDebug(dsrApp) << "Recorder process error output:" << line; } +// LCOV_EXCL_STOP } else { qCDebug(dsrApp) << "Recorder process exited normally. Output:" << m_recorderProcess->readAllStandardOutput() << ", Error:" << m_recorderProcess->readAllStandardError(); } @@ -316,12 +324,14 @@ void RecordProcess::recordVideo() if (t_currentAudioChannel == "-1") { qCWarning(dsrApp) << "Current system audio channel error!"; //系统音频通道获取错误时,要么不录制声音,要么只录制麦克风音频 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_audioType == Utils::kSystemAudio) { m_audioType = Utils::kNoAudio; qCWarning(dsrApp) << "Selected audio changed: System audio changed to no audio!"; } else if (m_audioType == Utils::kMicAndSystemAudio) { m_audioType = Utils::kMic; qCWarning(dsrApp) << "Selected audio changed: Mix audio changed to microphone only!"; +// LCOV_EXCL_STOP } } qCDebug(dsrApp) << "Current system audio channel:" << t_currentAudioChannel; @@ -418,6 +428,7 @@ void RecordProcess::recordVideo() #else if (m_audioType == Utils::kSystemAudio || m_audioType == Utils::kMicAndSystemAudio) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "X11 FFmpeg recording system audio: true."; arguments << QString("-thread_queue_size"); arguments << QString("2048"); @@ -431,6 +442,7 @@ void RecordProcess::recordVideo() arguments << QString("44100"); arguments << QString("-i"); arguments << QString("%1").arg(t_currentAudioChannel); +// LCOV_EXCL_STOP } if (m_audioType == Utils::kMic || m_audioType == Utils::kMicAndSystemAudio) { qCDebug(dsrApp) << "X11 FFmpeg recording microphone: true."; @@ -480,6 +492,7 @@ void RecordProcess::recordVideo() } if (m_audioType == Utils::kMicAndSystemAudio) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "X11 FFmpeg recording mixed audio: true."; arguments << QString("-filter_complex"); if ((arch.startsWith("ARM", Qt::CaseInsensitive))) { @@ -488,6 +501,7 @@ void RecordProcess::recordVideo() arguments << QString("2:v"); arguments << QString("-map"); arguments << QString("[out]"); +// LCOV_EXCL_STOP } else { arguments << QString("amerge"); } @@ -707,6 +721,7 @@ void RecordProcess::GstStartRecord() { int argc = 1; //gstreamer接口初始化 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCInfo(dsrApp) << "正在加载gstreamer依赖库..."; gstInterface::initFunctions(); qCInfo(dsrApp) << "gstreamer依赖库已加载"; @@ -715,6 +730,7 @@ void RecordProcess::GstStartRecord() GstRecordX::VideoType videoType = GstRecordX::VideoType::webm; GstRecordX::AudioType audioType = GstRecordX::AudioType::None; m_gstRecordX = new GstRecordX(this); +// LCOV_EXCL_STOP //设置参数 m_gstRecordX->setFramerate(m_framerate); m_gstRecordX->setRecordArea(m_recordRect); @@ -730,12 +746,14 @@ void RecordProcess::GstStartRecord() } else if (m_audioType == Utils::kSystemAudio) { audioType = GstRecordX::AudioType::Sys; } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env m_gstRecordX->setAudioType(audioType); QDateTime date = QDateTime::currentDateTime(); QString fileExtension = "webm"; if (m_recordType == Utils::kMKV) { videoType = GstRecordX::VideoType::ogg; fileExtension = "ogg"; +// LCOV_EXCL_STOP } else { videoType = GstRecordX::VideoType::webm; fileExtension = "webm"; diff --git a/src/screenshot.cpp b/src/screenshot.cpp index 1fb7bdde9..fe276729a 100755 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -101,6 +101,7 @@ void Screenshot::delayScreenshot(double num) timer->start(int(1000 * num)); qCDebug(dsrApp) << "Main delay timer started."; connect(timer, &QTimer::timeout, this, [ = ] { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env m_window.initAttributes(); m_window.initLaunchMode("screenShot"); m_window.showFullScreen(); @@ -108,6 +109,7 @@ void Screenshot::delayScreenshot(double num) m_window.createWinId(); qCDebug(dsrApp) << "Screenshot window initialized and shown after delay."; }); +// LCOV_EXCL_STOP } void Screenshot::fullscreenScreenshot() diff --git a/src/utils.cpp b/src/utils.cpp index ad4a8a44b..0e50284e1 100755 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -377,12 +377,14 @@ bool Utils::isSysHighVersion1040() qCDebug(dsrApp) << "System version (Professional/Education/Military) is >= 1040, returning true."; return true; } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "System version (Professional/Education/Military) is < 1040 or incorrect, returning false."; } else if (DSysInfo::UosHome == DSysInfo::uosEditionType()) { const float versionHome = 21.3f; if (correct && (version >= versionHome)) { qCDebug(dsrApp) << "System version (Home) is >= 21.3, returning true."; return true; +// LCOV_EXCL_STOP } qCDebug(dsrApp) << "System version (Home) is < 21.3 or incorrect, returning false."; } else if (DSysInfo::UosCommunity == DSysInfo::uosEditionType()) { @@ -561,12 +563,14 @@ void Utils::getAllWindowInfo( t_tempHeight = window->frameGeometry().height() + window->frameGeometry().y(); // windowRects << Dtk::Wm::WindowRect {0, 0, t_tempWidth, t_tempHeight}; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env windowRects << QRect(0, 0, t_tempWidth, t_tempHeight); windowNames << window->wmClass(); qCDebug(dsrApp) << "Added window:" << window->wmClass() << ", rect:(" << 0 << "," << 0 << "," << t_tempWidth << "," << t_tempHeight << ")."; continue; } else if (window->frameGeometry().y() >= 0 && window->frameGeometry().y() <= height - window->frameGeometry().height()) { +// LCOV_EXCL_STOP // x为负坐标,y在正常屏幕区间内 t_tempWidth = window->frameGeometry().width() + window->frameGeometry().x(); t_tempHeight = window->frameGeometry().height(); @@ -710,6 +714,7 @@ QString Utils::getCpuModelName() void Utils::notSupportWarn() { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCInfo(dsrApp) << "notSupportWarn() called."; DDialog warnDlg; warnDlg.setIcon(QIcon::fromTheme("deepin-screen-recorder")); @@ -718,6 +723,7 @@ void Utils::notSupportWarn() warnDlg.addButton(tr("Exit")); warnDlg.exec(); } +// LCOV_EXCL_STOP // 传入屏幕上理论未经缩放的点,获取缩放后实际的点 QPoint Utils::getPosWithScreen(QPoint pos) diff --git a/src/utils/baseutils.cpp b/src/utils/baseutils.cpp index c9ae8992e..e9ad58389 100755 --- a/src/utils/baseutils.cpp +++ b/src/utils/baseutils.cpp @@ -180,12 +180,14 @@ bool BaseUtils::isCommandExist(QString command) qCWarning(dsrApp) << "Failed to create QProcess for command check:" << command; return false; } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QString cm = QString("which %1\n").arg(command); proc->start(cm); proc->waitForFinished(1000); int ret = proc->exitCode() == 0; delete proc; proc = nullptr; +// LCOV_EXCL_STOP if (!ret) { qCWarning(dsrApp) << "Command not found:" << command; diff --git a/src/utils/configsettings.cpp b/src/utils/configsettings.cpp index 5e4ddaeb7..a59ec0ff5 100755 --- a/src/utils/configsettings.cpp +++ b/src/utils/configsettings.cpp @@ -120,6 +120,7 @@ QVariant ConfigSettings::getDefaultValue(const QString &group, const QString &ke QStringList ConfigSettings::keys(const QString &group) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Getting keys for group: " << group; QStringList v; m_settings->beginGroup(group); @@ -128,6 +129,7 @@ QStringList ConfigSettings::keys(const QString &group) qCDebug(dsrApp) << "Returning keys: " << v; return v; } +// LCOV_EXCL_STOP ConfigSettings::~ConfigSettings() { diff --git a/src/utils/dbusutils.cpp b/src/utils/dbusutils.cpp index 7d7e4dae1..ae1e379e1 100644 --- a/src/utils/dbusutils.cpp +++ b/src/utils/dbusutils.cpp @@ -57,6 +57,7 @@ QVariant DBusUtils::redDBusMethod(const QString &service, const QString &path, c if (reply.isValid()) { qCDebug(dsrApp) << "DBus method call successful. Returning value."; // return reply.value(); +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QVariant v(0) ; return v; } else { @@ -64,6 +65,7 @@ QVariant DBusUtils::redDBusMethod(const QString &service, const QString &path, c QVariant v(0) ; return v; } +// LCOV_EXCL_STOP } bool DBusUtils::isAiAssistantAvailable() diff --git a/src/utils/screengrabber.cpp b/src/utils/screengrabber.cpp index 81dc7d1f6..9fb9f3131 100644 --- a/src/utils/screengrabber.cpp +++ b/src/utils/screengrabber.cpp @@ -287,6 +287,7 @@ QPixmap ScreenGrabber::grabMultipleScreens(bool &ok, const QRect &rect, const QL int minX = INT_MAX, minY = INT_MAX, maxX = INT_MIN, maxY = INT_MIN; QList geometries; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env for (QScreen *screen : screens) { QRect geo = screen->geometry(); geometries.append(geo); @@ -294,6 +295,7 @@ QPixmap ScreenGrabber::grabMultipleScreens(bool &ok, const QRect &rect, const QL minY = qMin(minY, geo.y()); maxX = qMax(maxX, geo.x() + geo.width()); maxY = qMax(maxY, geo.y() + geo.height()); +// LCOV_EXCL_STOP } int totalWidth = maxX - minX; @@ -334,6 +336,7 @@ QPixmap ScreenGrabber::grabMultipleScreens(bool &ok, const QRect &rect, const QL << "Overlap:" << hasOverlap; // Determine layout type based on analysis +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (hasOverlap) { isComplexLayout = true; qCDebug(dsrApp) << "Detected complex layout with overlapping screens"; @@ -344,13 +347,16 @@ QPixmap ScreenGrabber::grabMultipleScreens(bool &ok, const QRect &rect, const QL isHorizontalLayout = true; qCDebug(dsrApp) << "Detected pure horizontal layout"; } else if (hasVerticalAlignment && hasHorizontalAlignment) { +// LCOV_EXCL_STOP // Both vertical and horizontal alignment detected, determine main direction +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (aspectRatio > 1.2) { isVerticalLayout = true; qCDebug(dsrApp) << "Detected mixed layout, primarily vertical"; } else if (aspectRatio < 0.8) { isHorizontalLayout = true; qCDebug(dsrApp) << "Detected mixed layout, primarily horizontal"; +// LCOV_EXCL_STOP } else { isComplexLayout = true; qCDebug(dsrApp) << "Detected complex mixed layout"; @@ -377,6 +383,7 @@ QPixmap ScreenGrabber::grabMultipleScreens(bool &ok, const QRect &rect, const QL qCDebug(dsrApp) << "Clone mode - using original screen geometries"; } else if (isComplexLayout) { // Complex layout: keep original coordinate system, no remapping +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env int minX = INT_MAX, minY = INT_MAX, maxX = INT_MIN, maxY = INT_MIN; for (QScreen *screen : sortedScreens) { QRect geo = screen->geometry(); @@ -385,6 +392,7 @@ QPixmap ScreenGrabber::grabMultipleScreens(bool &ok, const QRect &rect, const QL minY = qMin(minY, geo.y()); maxX = qMax(maxX, geo.x() + geo.width()); maxY = qMax(maxY, geo.y() + geo.height()); +// LCOV_EXCL_STOP } actualDesktopRect = QRect(minX, minY, maxX - minX, maxY - minY); qCDebug(dsrApp) << "Complex layout - preserving original coordinate system"; @@ -397,6 +405,7 @@ QPixmap ScreenGrabber::grabMultipleScreens(bool &ok, const QRect &rect, const QL }); // Create continuous vertical coordinate mapping +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env int logicalY = 0; int maxWidth = 0; for (QScreen *screen : sortedScreens) { @@ -404,6 +413,7 @@ QPixmap ScreenGrabber::grabMultipleScreens(bool &ok, const QRect &rect, const QL QRect mappedGeometry(originalGeometry.x(), logicalY, originalGeometry.width(), originalGeometry.height()); screenMappings[screen] = mappedGeometry; +// LCOV_EXCL_STOP qCDebug(dsrApp) << "Vertical mapping - Screen" << screen->name() << "Original:" << originalGeometry << "Mapped:" << mappedGeometry; @@ -580,12 +590,14 @@ QPixmap ScreenGrabber::grabWithXGetImage(bool &ok, const QRect &rect) if (needCoordinateConversion) { // 获取Qt逻辑虚拟桌面边界 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QList screens = QGuiApplication::screens(); QRect logicalVirtualDesktop; for (auto screen : screens) { QRect logicalGeom = screen->geometry(); if (logicalVirtualDesktop.isNull()) { logicalVirtualDesktop = logicalGeom; +// LCOV_EXCL_STOP } else { logicalVirtualDesktop = logicalVirtualDesktop.united(logicalGeom); } diff --git a/src/utils/shortcut.cpp b/src/utils/shortcut.cpp index 3bf08361b..c6b04a007 100755 --- a/src/utils/shortcut.cpp +++ b/src/utils/shortcut.cpp @@ -111,6 +111,7 @@ QString Shortcut::getSysShortcuts(const QString type) QMap shortcutsMap; for (QJsonValue shortcut : shorts) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env const QString Id = shortcut["Id"].toString(); if (Id == type) { QJsonArray Accels = shortcut["Accels"].toArray(); @@ -126,6 +127,7 @@ QString Shortcut::getSysShortcuts(const QString type) return AccelsString; } } +// LCOV_EXCL_STOP qCDebug(dsrApp) << "Shortcut not found for type " << type << ", returning default value."; return getDefaultValue(type); } diff --git a/src/utils/voicevolumewatcher.cpp b/src/utils/voicevolumewatcher.cpp index cd0076d4f..c062a4ba7 100755 --- a/src/utils/voicevolumewatcher.cpp +++ b/src/utils/voicevolumewatcher.cpp @@ -262,6 +262,7 @@ bool voiceVolumeWatcher::Port::isLoopback() const QDebug &operator<<(QDebug &out, const voiceVolumeWatcher::Port &port) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env out << "\n Port { " << "portId=" << port.portId << "," << "portName=" << port.portName << "," @@ -270,6 +271,7 @@ QDebug &operator<<(QDebug &out, const voiceVolumeWatcher::Port &port) << "cardName=" << port.cardName << "," << "cardId=" << port.cardId << "," << " }\n"; +// LCOV_EXCL_STOP return out; } diff --git a/src/utils/x_multi_screen_info.cpp b/src/utils/x_multi_screen_info.cpp index c5b5bd7ea..8cfaf42c1 100644 --- a/src/utils/x_multi_screen_info.cpp +++ b/src/utils/x_multi_screen_info.cpp @@ -25,12 +25,14 @@ bool XMultiScreenInfo::screenNeedResetScale() return false; } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env bool needResetScale = false; do { int event_base, error_base; if (!XineramaQueryExtension(display, &event_base, &error_base)) { qCWarning(dsrApp) << "Xinerama extension not available."; break; +// LCOV_EXCL_STOP } if (!XineramaIsActive(display)) { @@ -45,6 +47,7 @@ bool XMultiScreenInfo::screenNeedResetScale() break; } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Found" << num_screens << "screens."; int xOffset = 0; int yOffset = 0; @@ -53,6 +56,7 @@ bool XMultiScreenInfo::screenNeedResetScale() i, screens[i].x_org, screens[i].y_org, screens[i].width, screens[i].height); qCDebug(dsrApp) << "Screen" << i << ": x=" << screens[i].x_org << ", y=" << screens[i].y_org << ", width=" << screens[i].width << ", height=" << screens[i].height; +// LCOV_EXCL_STOP xOffset += screens[i].x_org; yOffset += screens[i].y_org; diff --git a/src/widgets/camerawidget.cpp b/src/widgets/camerawidget.cpp index 8113a49f2..40fd4d605 100755 --- a/src/widgets/camerawidget.cpp +++ b/src/widgets/camerawidget.cpp @@ -103,6 +103,7 @@ void CameraWidget::initUI() void CameraWidget::cameraStart() { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "cameraStart called"; if (!m_isInitCamera) { qCDebug(dsrApp) << "First time initializing camera..."; @@ -112,6 +113,7 @@ void CameraWidget::cameraStart() m_imgPrcThread->setParent(this); m_imgPrcThread->setObjectName("MajorThread"); connect(m_imgPrcThread, SIGNAL(SendMajorImageProcessing(QPixmap)), +// LCOV_EXCL_STOP this, SLOT(onReceiveMajorImage(QPixmap))); } m_isInitCamera = true; @@ -167,6 +169,7 @@ void CameraWidget::restartDevices() close_v4l2_device_handler(); } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env v4l2_device_list_t *devlist = get_device_list(); qCDebug(dsrApp) << "Number of devices found:" << devlist->num_devices; if (devlist->num_devices == 2) { @@ -178,10 +181,12 @@ void CameraWidget::restartDevices() if (E_OK == startCameraV4l2(devlist->list_devices[i].device)) { qCDebug(dsrApp) << "Camera started successfully for device:" << str1; break; +// LCOV_EXCL_STOP } } } } else { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Handling multiple devices"; for (int i = 0 ; i < devlist->num_devices; i++) { QString str1 = QString(devlist->list_devices[i].device); @@ -190,6 +195,7 @@ void CameraWidget::restartDevices() if (i == devlist->num_devices - 1) { qCDebug(dsrApp) << "Current device is last, starting first device"; startCameraV4l2(devlist->list_devices[0].device); +// LCOV_EXCL_STOP } else { qCDebug(dsrApp) << "Starting next device in list"; startCameraV4l2(devlist->list_devices[i + 1].device); diff --git a/src/widgets/filter.cpp b/src/widgets/filter.cpp index b90c9ad1f..3f0c756e2 100644 --- a/src/widgets/filter.cpp +++ b/src/widgets/filter.cpp @@ -89,12 +89,14 @@ void HintFilterPrivate::showHint(QWidget *hint) hintWidget->show(); hintWidget->adjustSize(); +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env auto sz = hintWidget->size(); centerPos.setX(centerPos.x() - sz.width() / 2 + 2); centerPos.setY(centerPos.y() - 32 - sz.height()); if (centerPos.y() - 32 - sz.height() <= 0) { qCDebug(dsrApp) << "Adjusting hint position due to screen boundary"; centerPos.setY(centerPos.y() + w->height() + 22 + sz.height()); +// LCOV_EXCL_STOP } centerPos = hintWidget->mapFromGlobal(centerPos); centerPos = hintWidget->mapToParent(centerPos); diff --git a/src/widgets/imagemenu.cpp b/src/widgets/imagemenu.cpp index 3b77daf1b..91671877e 100755 --- a/src/widgets/imagemenu.cpp +++ b/src/widgets/imagemenu.cpp @@ -228,6 +228,7 @@ void ActionWidget::setActionState(const bool isChecked) void ActionWidget::paintEvent(QPaintEvent *event) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env Q_UNUSED(event); qCDebug(dsrApp) << "ActionWidget::paintEvent called"; QPainter painter(this); @@ -242,6 +243,7 @@ void ActionWidget::paintEvent(QPaintEvent *event) painter.end(); event->accept(); } +// LCOV_EXCL_STOP ImageBorderHelper *ImageBorderHelper::m_imageBorderHelper = nullptr; ImageBorderHelper *ImageBorderHelper::instance() diff --git a/src/widgets/maintoolwidget.cpp b/src/widgets/maintoolwidget.cpp index acfaa372b..0427bd05b 100755 --- a/src/widgets/maintoolwidget.cpp +++ b/src/widgets/maintoolwidget.cpp @@ -155,12 +155,14 @@ void MainToolWidget::installTipHint(QWidget *w, const QString &hintstr) { qCDebug(dsrApp) << "installTipHint called for widget:" << w->objectName() << ", hint string:" << hintstr; // TODO: parent must be mainframe +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env auto hintWidget = new ToolTips("", this->parentWidget()->parentWidget()->parentWidget()); hintWidget->hide(); hintWidget->setText(hintstr); hintWidget->setFixedHeight(32); installHint(w, hintWidget); } +// LCOV_EXCL_STOP void MainToolWidget::installHint(QWidget *w, QWidget *hint) { diff --git a/src/widgets/previewwidget.cpp b/src/widgets/previewwidget.cpp index ff2a0f90e..2fa8614ed 100644 --- a/src/widgets/previewwidget.cpp +++ b/src/widgets/previewwidget.cpp @@ -191,13 +191,16 @@ QRect PreviewWidget::calculatePreviewPosition(int previewWidth, int previewHeigh qCDebug(dsrApp) << "Calculated positions and margins: rightX=" << rightX << ", leftX=" << leftX << ", rightMargin=" << rightMargin << ", leftMargin=" << leftMargin; //判断位置是左还是右 if (rightMargin >= leftMargin && rightMargin >= previewWidth + 1) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Positioning preview to the RIGHT"; rt.setX(rightX); rt.setY(previewY); rt.setWidth(previewWidth); rt.setHeight(previewHeight); setPreviewWidgetStatusPos(RIGHT);//设置位置状态 +// LCOV_EXCL_STOP } else if (rightMargin < leftMargin && leftMargin >= previewWidth + 1) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Right margin is less than left margin"; if (rightMargin >= previewWidth + 1) { //默认优先显示在右边 qCDebug(dsrApp) << "Right margin allows, positioning to the RIGHT (default)"; @@ -206,13 +209,16 @@ QRect PreviewWidget::calculatePreviewPosition(int previewWidth, int previewHeigh rt.setWidth(previewWidth); rt.setHeight(previewHeight); setPreviewWidgetStatusPos(RIGHT); +// LCOV_EXCL_STOP } else { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Positioning preview to the LEFT"; rt.setX(leftX); rt.setY(previewY); rt.setWidth(previewWidth); rt.setHeight(previewHeight); setPreviewWidgetStatusPos(LEFT); +// LCOV_EXCL_STOP } } else { qCDebug(dsrApp) << "Positioning preview INSIDE"; diff --git a/src/widgets/savemenumanager.cpp b/src/widgets/savemenumanager.cpp index 02ae0d65a..09ed2951e 100644 --- a/src/widgets/savemenumanager.cpp +++ b/src/widgets/savemenumanager.cpp @@ -177,12 +177,14 @@ void SaveMenuManager::initializeFromConfig() qCWarning(dsrApp) << "SaveMenuManager::initializeFromConfig - 保存到桌面"; // 检查是否有历史自定义路径 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (!savedPath.isEmpty() && QFileInfo::exists(savedPath) && savedPath != getStandardPath(LocationState::Desktop) && savedPath != getStandardPath(LocationState::Pictures)) { m_currentCustomPath = savedPath; updateSubMenuForExistingPath(); qCWarning(dsrApp) << "SaveMenuManager::initializeFromConfig - 保留历史路径:" << savedPath; +// LCOV_EXCL_STOP } else { updateSubMenuForFirstTime(); qCWarning(dsrApp) << "SaveMenuManager::initializeFromConfig - 无历史路径"; @@ -195,12 +197,14 @@ void SaveMenuManager::initializeFromConfig() qCWarning(dsrApp) << "SaveMenuManager::initializeFromConfig - 保存到图片"; // 检查是否有历史自定义路径 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (!savedPath.isEmpty() && QFileInfo::exists(savedPath) && savedPath != getStandardPath(LocationState::Desktop) && savedPath != getStandardPath(LocationState::Pictures)) { m_currentCustomPath = savedPath; updateSubMenuForExistingPath(); qCWarning(dsrApp) << "SaveMenuManager::initializeFromConfig - 保留历史路径:" << savedPath; +// LCOV_EXCL_STOP } else { updateSubMenuForFirstTime(); qCWarning(dsrApp) << "SaveMenuManager::initializeFromConfig - 无历史路径"; diff --git a/src/widgets/shapeswidget.cpp b/src/widgets/shapeswidget.cpp index 1bd42a536..d27b15ffe 100755 --- a/src/widgets/shapeswidget.cpp +++ b/src/widgets/shapeswidget.cpp @@ -105,6 +105,7 @@ void ShapesWidget::updateSelectedShape(const QString &group, if (m_selectedIndex != -1 && m_selectedOrder != -1 && m_selectedOrder < m_shapes.length()) { qCDebug(dsrApp) << "Updating shape properties for selected shape at order:" << m_selectedOrder; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if ((m_selectedShape.type == "arrow" || m_selectedShape.type == "line") && key != "color_index") { m_selectedShape.lineWidth = LINEWIDTH(index); } else if (m_selectedShape.type == group && key == "line_width") { @@ -115,14 +116,17 @@ void ShapesWidget::updateSelectedShape(const QString &group, m_selectedShape.colorIndex = index; m_editMap.value(tmpIndex)->setColor(BaseUtils::colorIndexOf(index)); m_editMap.value(tmpIndex)->update(); +// LCOV_EXCL_STOP } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env } else if (group == "text" && m_selectedShape.type == group && key == "fontsize") { qDebug() << "change font size"; int tmpIndex = m_shapes[m_selectedOrder].index; if (m_editMap.contains(tmpIndex)) { m_editMap.value(tmpIndex)->setFontSize(index); m_editMap.value(tmpIndex)->update(); +// LCOV_EXCL_STOP } } else if (group != "text" && m_selectedShape.type == group && key == "color_index") { m_selectedShape.colorIndex = index; @@ -225,6 +229,7 @@ void ShapesWidget::setNoChangedTextEditRemove() } for (int i = 0; i < m_shapes.length(); i++) { if (m_shapes[i].type == "text") { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env int t_tempIndex = m_shapes[i].index; if (m_editMap.value(t_tempIndex)->document()->toPlainText() == QString(tr("Input text here")) || m_editMap.value(t_tempIndex)->document()->toPlainText().isEmpty()) { @@ -232,6 +237,7 @@ void ShapesWidget::setNoChangedTextEditRemove() m_shapes.removeAt(i); m_editMap.value(t_tempIndex)->clear(); m_editMap.remove(t_tempIndex); +// LCOV_EXCL_STOP break; } @@ -464,12 +470,14 @@ bool ShapesWidget::clickedOnRect(FourPoints rectPoints, QPointF pos, bool isBlur m_pressedPoint = pos; return true; } else if (rotateOnPoint(rectPoints, pos)) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env m_isSelected = true; m_isRotated = true; m_isResize = false; m_resizeDirection = Rotate; m_pressedPoint = pos; return true; +// LCOV_EXCL_STOP } else if (pointOnLine(rectPoints[0], rectPoints[1], pos) || pointOnLine(rectPoints[1], rectPoints[3], pos) || pointOnLine(rectPoints[3], rectPoints[2], pos) || @@ -569,6 +577,7 @@ bool ShapesWidget::clickedOnEllipse(FourPoints mainPoints, QPointF pos, bool isB m_pressedPoint = pos; return true; } else if (rotateOnPoint(mainPoints, pos)) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Clicked on rotate point."; m_isSelected = true; m_isRotated = true; @@ -576,6 +585,7 @@ bool ShapesWidget::clickedOnEllipse(FourPoints mainPoints, QPointF pos, bool isB m_resizeDirection = Rotate; m_pressedPoint = pos; return true; +// LCOV_EXCL_STOP } else if (pointOnEllipse(mainPoints, pos)) { qCDebug(dsrApp) << "Clicked on ellipse boundary."; m_isSelected = true; @@ -729,6 +739,7 @@ bool ShapesWidget::clickedOnLine(FourPoints mainPoints, m_pressedPoint = pos; return true; } else if (rotateOnPoint(mainPoints, pos)) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Clicked on rotate point."; m_isSelected = true; m_isRotated = true; @@ -736,6 +747,7 @@ bool ShapesWidget::clickedOnLine(FourPoints mainPoints, m_resizeDirection = Rotate; m_pressedPoint = pos; return true; +// LCOV_EXCL_STOP } else if (pointOnArLine(points, pos)) { qCDebug(dsrApp) << "Clicked on arrow line."; m_isSelected = true; @@ -1074,12 +1086,14 @@ bool ShapesWidget::textEditIsReadOnly() QMap::iterator i = m_editMap.begin(); while (i != m_editMap.end()) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_editing || !i.value()->isReadOnly()) { setAllTextEditReadOnly(); m_editing = false; m_currentShape.type = ""; update(); return true; +// LCOV_EXCL_STOP } ++i; } @@ -1132,6 +1146,7 @@ void ShapesWidget::handleRotate(QPointF pos) return; } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_selectedShape.type == "arrow" || m_selectedShape.type == "line") { qCDebug(dsrApp) << "Rotating arrow or line type shape."; if (m_isArrowRotated == false) { @@ -1143,6 +1158,7 @@ void ShapesWidget::handleRotate(QPointF pos) if (m_clickedKey == First) { qCDebug(dsrApp) << "Adjusting first point (vertical)."; m_shapes[m_selectedOrder].points[0] = QPointF(m_shapes[m_selectedOrder].points[1].x(), +// LCOV_EXCL_STOP pos.y()); } else if (m_clickedKey == Second) { qCDebug(dsrApp) << "Adjusting second point (vertical)."; @@ -1150,12 +1166,14 @@ void ShapesWidget::handleRotate(QPointF pos) pos.y()); } } else { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Arrow/line is horizontal."; if (m_clickedKey == First) { qCDebug(dsrApp) << "Adjusting first point (horizontal)."; m_shapes[m_selectedOrder].points[0] = QPointF(pos.x(), m_shapes[m_selectedOrder].points[1].y()); } else if (m_clickedKey == Second) { m_shapes[m_selectedOrder].points[1] = QPointF(pos.x(), m_shapes[m_selectedOrder].points[0].y()); +// LCOV_EXCL_STOP } } } else { @@ -1189,6 +1207,7 @@ void ShapesWidget::handleRotate(QPointF pos) return; } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QPointF centerInPoint = QPointF((m_selectedShape.mainPoints[0].x() + m_selectedShape.mainPoints[3].x()) / 2, (m_selectedShape.mainPoints[0].y() + @@ -1199,22 +1218,27 @@ void ShapesWidget::handleRotate(QPointF pos) if (0 == static_cast(m_lastAngle)) { m_lastAngle = pressedAngle; angle = 0; +// LCOV_EXCL_STOP } else { angle = pressedAngle - m_lastAngle; } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (angle < -100) { m_lastAngle = pressedAngle - m_lastAngle + 360; angle = m_lastAngle; } else if (angle > 100) { m_lastAngle = pressedAngle - m_lastAngle - 360; angle = m_lastAngle; +// LCOV_EXCL_STOP } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qreal rotationDelta = (angle * M_PI) / 180; qreal centerX = (m_shapes[m_selectedOrder].mainPoints[0].x() + m_shapes[m_selectedOrder].mainPoints[3].x()) / 2; qreal centerY = (m_shapes[m_selectedOrder].mainPoints[0].y() + m_shapes[m_selectedOrder].mainPoints[3].y()) / 2; for (int i = 0; i < m_shapes[m_selectedOrder].mainPoints.size(); ++i) { qreal x = centerX + (m_shapes[m_selectedOrder].mainPoints[i].x() - centerX) * cos(rotationDelta) - (m_shapes[m_selectedOrder].mainPoints[i].y() - centerY) * sin(rotationDelta); qreal y = centerY + (m_shapes[m_selectedOrder].mainPoints[i].x() - centerX) * sin(rotationDelta) + (m_shapes[m_selectedOrder].mainPoints[i].y() - centerY) * cos(rotationDelta); +// LCOV_EXCL_STOP //图形 m_shapes[m_selectedOrder].mainPoints[i].setX(x); m_shapes[m_selectedOrder].mainPoints[i].setY(y); @@ -1301,6 +1325,7 @@ void ShapesWidget::mousePressEvent(QMouseEvent *e) if (nullptr != m_editMap.value(m_lastEditMapKey)) { qCDebug(dsrApp) << "Text edit exists at lastEditMapKey."; // 点击鼠标左键时,去掉未更改的textEdit文本框 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_editMap.value(m_lastEditMapKey)->toPlainText() == QString(tr("Input text here")) || m_editMap.value(m_lastEditMapKey)->toPlainText().isEmpty()) { qCDebug(dsrApp) << "Text edit is empty or default. Clearing selection and setting read-only."; @@ -1312,6 +1337,7 @@ void ShapesWidget::mousePressEvent(QMouseEvent *e) m_selectedShape.type = ""; update(); DFrame::mousePressEvent(e); +// LCOV_EXCL_STOP } } } @@ -1321,6 +1347,7 @@ void ShapesWidget::mousePressEvent(QMouseEvent *e) && m_selectedIndex != -1 && !clickedShapes(e->pos()) && "text" != m_currentType) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env clearSelected(); setAllTextEditReadOnly(); m_editing = false; @@ -1329,6 +1356,7 @@ void ShapesWidget::mousePressEvent(QMouseEvent *e) m_selectedShape.type = ""; update(); DFrame::mousePressEvent(e); +// LCOV_EXCL_STOP //return; @@ -1336,6 +1364,7 @@ void ShapesWidget::mousePressEvent(QMouseEvent *e) if (m_selectedIndex != -1) { if (!(clickedOnShapes(e->pos()) && m_isRotated) && m_selectedIndex == -1 && "text" == m_currentType) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env clearSelected(); setAllTextEditReadOnly(); m_editing = false; @@ -1345,6 +1374,7 @@ void ShapesWidget::mousePressEvent(QMouseEvent *e) update(); DFrame::mousePressEvent(e); return; +// LCOV_EXCL_STOP } } @@ -1444,6 +1474,7 @@ void ShapesWidget::mousePressEvent(QMouseEvent *e) connect(edit, &TextEdit::repaintTextRect, this, &ShapesWidget::updateTextRect); connect(edit, &TextEdit::clickToEditing, this, [ = ](int index) { // setAllTextEditReadOnly(); +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env for (int k = 0; k < m_shapes.length(); k++) { if (m_shapes[k].type == "text" && m_shapes[k].index == index) { m_selectedIndex = index; @@ -1451,6 +1482,7 @@ void ShapesWidget::mousePressEvent(QMouseEvent *e) m_selectedOrder = k; m_currentShape = m_selectedShape; break; +// LCOV_EXCL_STOP } } QMap::iterator i = m_editMap.begin(); @@ -1461,6 +1493,7 @@ void ShapesWidget::mousePressEvent(QMouseEvent *e) } else { i.value()->setEditing(true); } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QTextCursor textCursor = i.value()->textCursor(); textCursor.clearSelection(); i.value()->setTextCursor(textCursor); @@ -1469,6 +1502,7 @@ void ShapesWidget::mousePressEvent(QMouseEvent *e) m_editing = true; m_isSelectedText = false; emit shapeClicked("text"); +// LCOV_EXCL_STOP }); @@ -1583,6 +1617,7 @@ void ShapesWidget::mouseReleaseEvent(QMouseEvent *e) if (m_isRecording && !m_isSelected && m_pos2 != QPointF(0, 0)) { qCDebug(dsrApp) << "Recording active, no shape selected, and pos2 is not (0,0). Finalizing shape."; if (m_currentType == "arrow" || m_currentType == "line") { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Finalizing arrow or line."; if (m_currentShape.points.length() == 2) { qCDebug(dsrApp) << "Arrow/line has 2 points."; @@ -1592,6 +1627,7 @@ void ShapesWidget::mouseReleaseEvent(QMouseEvent *e) * 180 / M_PI < 45) { m_pos2 = QPointF(m_pos2.x(), m_pos1.y()); qCDebug(dsrApp) << "Snapped to horizontal."; +// LCOV_EXCL_STOP } else { m_pos2 = QPointF(m_pos1.x(), m_pos2.y()); qCDebug(dsrApp) << "Snapped to vertical."; @@ -1660,6 +1696,7 @@ void ShapesWidget::mouseMoveEvent(QMouseEvent *e) updateCursorShape(); if (m_currentShape.type == "arrow" || m_currentShape.type == "line") { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Moving arrow or line shape."; if (m_currentShape.points.length() <= 1) { qCDebug(dsrApp) << "Adding second point to arrow/line."; @@ -1669,6 +1706,7 @@ void ShapesWidget::mouseMoveEvent(QMouseEvent *e) std::abs(m_pos2.x() - m_pos1.x())) * 180 / M_PI < 45) { m_currentShape.points.append(QPointF(m_pos2.x(), m_pos1.y())); qCDebug(dsrApp) << "Snapped to horizontal."; +// LCOV_EXCL_STOP } else { m_currentShape.points.append(QPointF(m_pos1.x(), m_pos2.y())); qCDebug(dsrApp) << "Snapped to vertical."; @@ -1678,6 +1716,7 @@ void ShapesWidget::mouseMoveEvent(QMouseEvent *e) qCDebug(dsrApp) << "Appended pos2 to arrow/line points."; } } else { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Updating second point of arrow/line."; if (m_isShiftPressed) { qCDebug(dsrApp) << "Shift pressed, snapping arrow/line to axis."; @@ -1685,6 +1724,7 @@ void ShapesWidget::mouseMoveEvent(QMouseEvent *e) std::abs(m_pos2.x() - m_pos1.x())) * 180 / M_PI < 45) { m_currentShape.points[1] = QPointF(m_pos2.x(), m_pos1.y()); qCDebug(dsrApp) << "Snapped to horizontal."; +// LCOV_EXCL_STOP } else { m_currentShape.points[1] = QPointF(m_pos1.x(), m_pos2.y()); qCDebug(dsrApp) << "Snapped to vertical."; @@ -1703,12 +1743,14 @@ void ShapesWidget::mouseMoveEvent(QMouseEvent *e) } // 模糊笔 if (m_currentShape.type == "effect" && m_currentShape.isOval == 2) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env double distance = getDistance(m_currentShape.points[m_currentShape.points.length() - 1], m_pos2); if (distance > 14) { QList interpolationPoints = getInterpolationPoints(m_currentShape.points[m_currentShape.points.length() - 1], m_pos2, (distance / 7)); for (int i = 0; i < interpolationPoints.size(); ++i) { m_currentShape.points.append(interpolationPoints[i]); +// LCOV_EXCL_STOP } m_currentShape.points.append(m_pos2); qCDebug(dsrApp) << "Effect type: distance > 14, appending interpolated points and pos2."; @@ -1910,6 +1952,7 @@ void ShapesWidget::updateTextRect(TextEdit *edit, QRectF newRect) // qDebug() << "updateTextRect:" << newRect << index; for (int j = 0; j < m_shapes.length(); j++) { // qDebug() << "updateTextRect updating:" << j << m_shapes[j].index << index; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_shapes[j].type == "text" && m_shapes[j].index == index) { m_shapes[j].mainPoints[0] = QPointF(newRect.x(), newRect.y()); m_shapes[j].mainPoints[1] = QPointF(newRect.x(), newRect.y() + newRect.height()); @@ -1920,6 +1963,7 @@ void ShapesWidget::updateTextRect(TextEdit *edit, QRectF newRect) m_selectedShape = m_shapes[j]; m_selectedIndex = m_shapes[j].index; m_selectedOrder = j; +// LCOV_EXCL_STOP } } update(); @@ -2088,6 +2132,7 @@ void ShapesWidget::paintText(QPainter &painter, FourPoints rectFPoints) void ShapesWidget::paintText(QPainter &painter, FourPoints rectFPoints, const QString &text, int fontsize) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qDebug() << "fontsize: " << fontsize; QFont font = painter.font() ; font.setPixelSize(fontsize); @@ -2098,6 +2143,7 @@ void ShapesWidget::paintText(QPainter &painter, FourPoints rectFPoints, const QS static_cast(rectFPoints[3].y() - rectFPoints[0].y())); painter.drawText(rect, Qt::AlignLeft, text); } +// LCOV_EXCL_STOP void ShapesWidget::paintEvent(QPaintEvent *) { @@ -2212,6 +2258,7 @@ void ShapesWidget::handlePaint(QPainter &painter) //绘制悬停状态的图形 if ((m_hoveredShape.mainPoints[0] != QPointF(0, 0) || m_hoveredShape.points.length() != 0) && m_hoveredIndex != -1) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env pen.setWidthF(0.5); pen.setColor("#01bdff"); if (m_hoveredShape.type == "rectangle") { @@ -2239,6 +2286,7 @@ void ShapesWidget::handlePaint(QPainter &painter) pen.setJoinStyle(Qt::RoundJoin); painter.setPen(pen); paintLine(painter, m_hoveredShape.points); +// LCOV_EXCL_STOP } else { // qDebug() << "hoveredShape type:" << m_hoveredShape.type; } @@ -2262,12 +2310,14 @@ void ShapesWidget::handlePaint(QPainter &painter) m_selectedShape.mainPoints[2], m_selectedShape.mainPoints[3]); +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (m_selectedShape.type == "oval" || m_selectedShape.type == "pen" || (m_selectedShape.type == "effect" && m_selectedShape.isOval == 2)) { pen.setJoinStyle(Qt::MiterJoin); pen.setWidth(1); pen.setColor(QColor("#01bdff")); painter.setPen(pen); paintRect(painter, m_selectedShape.mainPoints, -1); +// LCOV_EXCL_STOP } QPixmap rotatePointImg; @@ -2315,12 +2365,14 @@ void ShapesWidget::enterEvent(QEvent *e) if (m_currentType == "pen") { qApp->setOverrideCursor(BaseUtils::setCursorShape("pen", BaseUtils::colorIndex(m_penColor))); } else if (m_currentType == "effect") { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env int isOval = ConfigSettings::instance()->getValue("effect", "isOval").toInt(); QCursor setCursorValue; if (isOval == 0) { setCursorValue = BaseUtils::setCursorShape("oval"); } else if (isOval == 1) { setCursorValue = BaseUtils::setCursorShape("rectangle"); +// LCOV_EXCL_STOP } else { setCursorValue = BaseUtils::setCursorShape("pen", 0); } @@ -2334,6 +2386,7 @@ void ShapesWidget::pinchTriggered(QPinchGesture *pinch) { if (-1 == m_selectedIndex || "text" == m_currentType) return; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QPinchGesture::ChangeFlags changeFlags = pinch->changeFlags(); if (changeFlags & QPinchGesture::RotationAngleChanged) { qreal rotationDelta = (pinch->rotationAngle() - pinch->lastRotationAngle()) * 0.01; @@ -2342,6 +2395,7 @@ void ShapesWidget::pinchTriggered(QPinchGesture *pinch) for (int i = 0; i < m_shapes[m_selectedOrder].mainPoints.size(); ++i) { qreal x = centerX + (m_shapes[m_selectedOrder].mainPoints[i].x() - centerX) * cos(rotationDelta) - (m_shapes[m_selectedOrder].mainPoints[i].y() - centerY) * sin(rotationDelta); qreal y = centerY + (m_shapes[m_selectedOrder].mainPoints[i].x() - centerX) * sin(rotationDelta) + (m_shapes[m_selectedOrder].mainPoints[i].y() - centerY) * cos(rotationDelta); +// LCOV_EXCL_STOP //图形 m_shapes[m_selectedOrder].mainPoints[i].setX(x); m_shapes[m_selectedOrder].mainPoints[i].setY(y); @@ -2363,6 +2417,7 @@ void ShapesWidget::pinchTriggered(QPinchGesture *pinch) m_shapes[m_selectedOrder].points[k].setY(y); } } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (changeFlags & QPinchGesture::ScaleFactorChanged) { qreal scale = pinch->scaleFactor(); qreal ascanle = (scale - 1) * 0.3 + 1; @@ -2373,7 +2428,9 @@ void ShapesWidget::pinchTriggered(QPinchGesture *pinch) qreal y = m_shapes[m_selectedOrder].mainPoints[i].y() * ascanle + centerY * (1 - ascanle); m_shapes[m_selectedOrder].mainPoints[i].setX(x); m_shapes[m_selectedOrder].mainPoints[i].setY(y); +// LCOV_EXCL_STOP } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qreal centerMainX = (m_selectedShape.mainPoints[0].x() + m_selectedShape.mainPoints[3].x()) / 2; qreal centerMainY = (m_selectedShape.mainPoints[0].y() + m_selectedShape.mainPoints[3].y()) / 2; for (int i = 0; i < m_selectedShape.mainPoints.length(); i ++) { @@ -2381,6 +2438,7 @@ void ShapesWidget::pinchTriggered(QPinchGesture *pinch) qreal y = m_selectedShape.mainPoints[i].y() * ascanle + centerMainY * (1 - ascanle); m_selectedShape.mainPoints[i].setX(x); m_selectedShape.mainPoints[i].setY(y); +// LCOV_EXCL_STOP } for (int k = 0; k < m_selectedShape.points.length(); k++) { qreal x = m_shapes[m_selectedOrder].points[k].x() * ascanle + centerMainX * (1 - ascanle); @@ -2394,6 +2452,7 @@ void ShapesWidget::pinchTriggered(QPinchGesture *pinch) void ShapesWidget::tapTriggered(QTapGesture *tap) { if (tap->state() == Qt::GestureState::GestureFinished && !clickedOnShapes(m_movingPoint) && -1 != m_selectedIndex && "text" != m_currentType) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env m_isPressed = false; m_isMoving = false; clearSelected(); @@ -2402,6 +2461,7 @@ void ShapesWidget::tapTriggered(QTapGesture *tap) m_selectedIndex = -1; m_selectedOrder = -1; m_selectedShape.type = ""; +// LCOV_EXCL_STOP } } @@ -2437,6 +2497,7 @@ void ShapesWidget::deleteCurrentShape() void ShapesWidget::undoDrawShapes() { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env textEditIsReadOnly(); qDebug() << "undoDrawShapes m_selectedIndex:" << m_selectedIndex << m_shapes.length(); if (m_selectedOrder < m_shapes.length() && m_selectedIndex != -1) { @@ -2447,6 +2508,7 @@ void ShapesWidget::undoDrawShapes() m_editMap.value(tmpIndex)->clear(); delete m_editMap.value(tmpIndex); m_editMap.remove(tmpIndex); +// LCOV_EXCL_STOP } m_shapes.removeLast(); @@ -2462,6 +2524,7 @@ void ShapesWidget::undoDrawShapes() } void ShapesWidget::undoAllDrawShapes() { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qDebug() << "undoAllDrawShapes undoDrawShapes m_selectedIndex:" << m_selectedIndex << m_shapes.length(); if (m_selectedOrder < m_shapes.length() && m_selectedIndex != -1) { deleteCurrentShape(); @@ -2472,6 +2535,7 @@ void ShapesWidget::undoAllDrawShapes() m_editMap.value(tmpIndex)->clear(); delete m_editMap.value(tmpIndex); m_editMap.remove(tmpIndex); +// LCOV_EXCL_STOP } m_shapes.removeLast(); @@ -2561,12 +2625,14 @@ void ShapesWidget::microAdjust(QString direction) qreal scaleY = newRect.height() / oldRect.height(); // 对每个点应用缩放和偏移 +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env for (int j = 0; j < currentShape.points.length(); j++) { QPointF point = currentShape.points[j]; QPointF relativePos = point - oldCenter; relativePos.setX(relativePos.x() * scaleX); relativePos.setY(relativePos.y() * scaleY); currentShape.points[j] = newCenter + relativePos; +// LCOV_EXCL_STOP } } } diff --git a/src/widgets/shapetoolwidget.cpp b/src/widgets/shapetoolwidget.cpp index 4495a43fa..6c278ea50 100644 --- a/src/widgets/shapetoolwidget.cpp +++ b/src/widgets/shapetoolwidget.cpp @@ -90,6 +90,7 @@ void ShapeToolWidget::initShapeButtons() // 连接信号槽 connect(m_shapeBtnGroup, QOverload::of(&QButtonGroup::buttonClicked), [=](QAbstractButton *button) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (button == m_rectButton) { qCDebug(dsrApp) << "Rectangle button clicked."; emit shapeSelected("rectangle"); @@ -98,6 +99,7 @@ void ShapeToolWidget::initShapeButtons() qCDebug(dsrApp) << "Oval button clicked."; emit shapeSelected("oval"); ConfigSettings::instance()->setValue("shape", "current", "oval"); +// LCOV_EXCL_STOP } }); diff --git a/src/widgets/shottoolwidget.cpp b/src/widgets/shottoolwidget.cpp index a0f7e4c04..977971cea 100755 --- a/src/widgets/shottoolwidget.cpp +++ b/src/widgets/shottoolwidget.cpp @@ -236,12 +236,14 @@ void ShotToolWidget::initEffectLabel() connect(effectTypeBtnGroup, QOverload::of(&QButtonGroup::buttonClicked), [ = ] { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Effect type button clicked."; ConfigSettings::instance()->setValue("effect", "isBlur", blurBut->isChecked()); if (blurBut->isChecked()) { qCDebug(dsrApp) << "Blur button checked, setting blur icons."; t_radiusSize->setLeftIcon(QIcon::fromTheme(QString("effect_pen1"))); t_radiusSize->setRightIcon(QIcon::fromTheme(QString("effect_pen2"))); +// LCOV_EXCL_STOP } else { qCDebug(dsrApp) << "Mosaic button checked, setting mosaic icons."; t_radiusSize->setLeftIcon(QIcon::fromTheme(QString("mosaic1"))); diff --git a/src/widgets/subtoolwidget.cpp b/src/widgets/subtoolwidget.cpp index bdaf2c0f3..d95ec1b45 100755 --- a/src/widgets/subtoolwidget.cpp +++ b/src/widgets/subtoolwidget.cpp @@ -136,12 +136,14 @@ void SubToolWidget::initRecordLabel() m_shotButton->setFixedSize(TOOL_BUTTON_SIZE); btnList.append(m_shotButton); connect(m_shotButton, &DPushButton::clicked, this, [ = ] { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "Screenshot button clicked."; m_pMainWindow->getToolBarPoint(); qInfo() << "shotbutton is clicked"; switchContent("shot"); if (Utils::isTreelandMode) { m_pMainWindow->onTreelandSwitchToShotUI(); +// LCOV_EXCL_STOP } qInfo() << "emit changeShotToolFunc(shot)"; emit changeShotToolFunc("shot"); @@ -377,6 +379,7 @@ void SubToolWidget::initRecordOption() } connect(gifAction, &QAction::triggered, this, [ = ](bool checked) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "GIF format selected:" << checked; Q_UNUSED(checked); t_settings->setValue("recorder", "format", 0); @@ -388,8 +391,10 @@ void SubToolWidget::initRecordOption() m_microphoneAction->setEnabled(false); m_sysAudioAction->setEnabled(false); }); +// LCOV_EXCL_STOP connect(mp4Action, &QAction::triggered, this, [ = ](bool checked) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "MP4 format selected:" << checked; Q_UNUSED(checked); t_settings->setValue("recorder", "format", 1); @@ -401,8 +406,10 @@ void SubToolWidget::initRecordOption() m_microphoneAction->setEnabled(true); m_sysAudioAction->setEnabled(true); }); +// LCOV_EXCL_STOP connect(mkvAction, &QAction::triggered, this, [ = ](bool checked) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env qCDebug(dsrApp) << "MKV format selected:" << checked; Q_UNUSED(checked); t_settings->setValue("recorder", "format", 2); @@ -414,6 +421,7 @@ void SubToolWidget::initRecordOption() m_microphoneAction->setEnabled(true); m_sysAudioAction->setEnabled(true); }); +// LCOV_EXCL_STOP connect(t_fpsGroup, QOverload::of(&QActionGroup::triggered), [ = ](QAction * t_act) { @@ -432,6 +440,7 @@ void SubToolWidget::initRecordOption() t_settings->setValue("recorder", "frame_rate", t_frameRate); }); switch (frame_rate) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env case 5: fps5Action->triggered(); fps5Action->setChecked(true); @@ -444,10 +453,12 @@ void SubToolWidget::initRecordOption() fps20Action->triggered(); fps20Action->setChecked(true); break; +// LCOV_EXCL_STOP case 24: fps24Action->triggered(); fps24Action->setChecked(true); break; +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env case 30: fps30Action->triggered(); fps30Action->setChecked(true); @@ -456,6 +467,7 @@ void SubToolWidget::initRecordOption() fps24Action->triggered(); fps24Action->setChecked(true); break; +// LCOV_EXCL_STOP } //t_settings->setValue("recorder", "audio", 0); @@ -1312,24 +1324,28 @@ void SubToolWidget::initShotOption() int t_pictureFormat = ConfigSettings::instance()->getValue("shot", "format").toInt(); switch (t_pictureFormat) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env case 1: jpgAction->setChecked(true); break; case 2: bmpAction->setChecked(true); break; +// LCOV_EXCL_STOP default: pngAction->setChecked(true); } connect(t_formatGroup, QOverload::of(&QActionGroup::triggered), [ = ](QAction * t_act) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (t_act == pngAction) { ConfigSettings::instance()->setValue("shot", "format", 0); } else if (t_act == jpgAction) { ConfigSettings::instance()->setValue("shot", "format", 1); } else if (t_act == bmpAction) { ConfigSettings::instance()->setValue("shot", "format", 2); +// LCOV_EXCL_STOP } }); @@ -1350,12 +1366,14 @@ void SubToolWidget::initShotOption() ImageBorderHelper::BorderType borderType = static_cast(border_index >> 8); switch (borderType) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env case ImageBorderHelper::BorderType::External: externalBorderMenu->menuAction()->setChecked(true); break; case ImageBorderHelper::BorderType::Prototype: borderPrototypeMenu->menuAction()->setChecked(true); break; +// LCOV_EXCL_STOP case ImageBorderHelper::BorderType::Projection: borderProjectionMenu->menuAction()->setChecked(true); break; @@ -1376,6 +1394,7 @@ void SubToolWidget::initShotOption() int border_index = ImageBorderHelper::instance()->getBorderTypeDetail(); ImageBorderHelper::BorderType borderType = static_cast(border_index >> 8); +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env switch (borderType) { case ImageBorderHelper::BorderType::External: externalBorderMenu->menuAction()->setChecked(true); @@ -1386,6 +1405,7 @@ void SubToolWidget::initShotOption() case ImageBorderHelper::BorderType::Projection: borderProjectionMenu->menuAction()->setChecked(true); break; +// LCOV_EXCL_STOP default: break; } @@ -1407,6 +1427,7 @@ void SubToolWidget::initShotOption() if (current_border_index == 0) { noBorderAction->setChecked(true); } else { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env ImageBorderHelper::BorderType currentType = static_cast(current_border_index >> 8); switch (currentType) { case ImageBorderHelper::BorderType::External: @@ -1421,6 +1442,7 @@ void SubToolWidget::initShotOption() default: noBorderAction->setChecked(true); break; +// LCOV_EXCL_STOP } } } @@ -1843,6 +1865,7 @@ void SubToolWidget::initScrollLabel() // 格式选项的信号连接 connect(t_formatGroup, QOverload::of(&QActionGroup::triggered), [ = ](QAction * t_act) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if (t_act == pngAction) { ConfigSettings::instance()->setValue("shot", "format", 0); m_scrollOptionMenu->hide(); // 关闭菜单 @@ -1852,6 +1875,7 @@ void SubToolWidget::initScrollLabel() } else if (t_act == bmpAction) { ConfigSettings::instance()->setValue("shot", "format", 2); m_scrollOptionMenu->hide(); // 关闭菜单 +// LCOV_EXCL_STOP } }); // updateSaveButtonTip(); @@ -1983,12 +2007,14 @@ bool SubToolWidget::eventFilter(QObject *watched, QEvent *event) } if (watched == m_saveToSpecialPathMenu) { +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env if(event->type() == QEvent::ToolTip){ QHelpEvent* he = dynamic_cast(event); QAction *action = static_cast(watched)->actionAt(he->pos()); if (action != nullptr) { if (action == m_saveToSpecialPathAction) { QToolTip::showText(he->globalPos(), action->toolTip(), this); +// LCOV_EXCL_STOP } if (action == m_changeSaveToSpecialPath) { QToolTip::hideText(); @@ -2171,6 +2197,7 @@ QRect SubToolWidget::getShotOptionRect(){ qCDebug(dsrApp) << "Shot option menu is not visible."; return QRect(); } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QRect shotOptionRect { static_cast(m_shotOptionButton->menu()->x()), static_cast(m_shotOptionButton->menu()->y()), @@ -2179,6 +2206,7 @@ QRect SubToolWidget::getShotOptionRect(){ }; qCDebug(dsrApp) << "Shot option rect:" << shotOptionRect; return shotOptionRect; +// LCOV_EXCL_STOP } /* diff --git a/src/widgets/toolbutton.cpp b/src/widgets/toolbutton.cpp index 4ec92c608..aa622c139 100644 --- a/src/widgets/toolbutton.cpp +++ b/src/widgets/toolbutton.cpp @@ -266,12 +266,14 @@ void ToolButton::paintEvent(QPaintEvent *event) tinted.fill(Qt::transparent); tinted.setDevicePixelRatio(devicePixelRatio); +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env QPainter ip(&tinted); ip.setRenderHint(QPainter::Antialiasing); ip.drawPixmap(0, 0, base); ip.setCompositionMode(QPainter::CompositionMode_SourceIn); ip.fillRect(tinted.rect(), palette().highlight().color()); ip.end(); +// LCOV_EXCL_STOP opt.icon = QIcon(tinted); } @@ -374,6 +376,7 @@ void ToolButton::mouseReleaseEvent(QMouseEvent *e) if (!isCheckable() || !isChecked()) { setDown(false); } +// LCOV_EXCL_START // hard-to-cover in offscreen/unit-test env update(); m_menuActive = true; QMenu *m = menu(); @@ -381,6 +384,7 @@ void ToolButton::mouseReleaseEvent(QMouseEvent *e) QObject::connect(m, &QMenu::aboutToHide, this, [this]() { m_menuActive = false; update(); +// LCOV_EXCL_STOP }, Qt::SingleShotConnection); } this->showMenu();