• Flameshot源码及分析3 —— gui函数解析


    接前一篇文章《Flameshot源码及分析2 —— 主函数调用流程》,链接为:

    Flameshot源码及分析2 —— 主函数调用流程_蓝天居士的博客-CSDN博客

    上一回我们讲到了gui函数,这个函数的实现在src/core/flameshot.cpp中,源码如下:

    1. CaptureWidget* Flameshot::gui(const CaptureRequest& req)
    2. {
    3. if (!resolveAnyConfigErrors()) {
    4. return nullptr;
    5. }
    6. #if defined(Q_OS_MACOS)
    7. // This is required on MacOS because of Mission Control. If you'll switch to
    8. // another Desktop you cannot take a new screenshot from the tray, you have
    9. // to switch back to the Flameshot Desktop manually. It is not obvious and a
    10. // large number of users are confused and report a bug.
    11. if (m_captureWindow != nullptr) {
    12. m_captureWindow->close();
    13. delete m_captureWindow;
    14. m_captureWindow = nullptr;
    15. }
    16. #endif
    17. if (nullptr == m_captureWindow) {
    18. // TODO is this unnecessary now?
    19. int timeout = 5000; // 5 seconds
    20. const int delay = 100;
    21. QWidget* modalWidget = nullptr;
    22. for (; timeout >= 0; timeout -= delay) {
    23. modalWidget = qApp->activeModalWidget();
    24. if (nullptr == modalWidget) {
    25. break;
    26. }
    27. modalWidget->close();
    28. modalWidget->deleteLater();
    29. QThread::msleep(delay);
    30. }
    31. if (0 == timeout) {
    32. QMessageBox::warning(
    33. nullptr, tr("Error"), tr("Unable to close active modal widgets"));
    34. return nullptr;
    35. }
    36. m_captureWindow = new CaptureWidget(req);
    37. #ifdef Q_OS_WIN
    38. m_captureWindow->show();
    39. #elif defined(Q_OS_MACOS)
    40. // In "Emulate fullscreen mode"
    41. m_captureWindow->showFullScreen();
    42. m_captureWindow->activateWindow();
    43. m_captureWindow->raise();
    44. #else
    45. m_captureWindow->showFullScreen();
    46. // m_captureWindow->show(); // For CaptureWidget Debugging under Linux
    47. #endif
    48. return m_captureWindow;
    49. } else {
    50. emit captureFailed();
    51. return nullptr;
    52. }
    53. }

    笔者的电脑安装的是Linux系统,因此经过跟踪,代码最终会走到以下分支:

    1. #else
    2. m_captureWindow->showFullScreen();
    3. // m_captureWindow->show(); // For CaptureWidget Debugging under Linux

    showFullScreen()的声明在/usr/include/x86_64-linux-gnu/qt5/QtGui/qwindow.h中:

    void showFullScreen();

    看函数名就能知道,这是Qt中显示全屏的函数。这里引用博客文章Qt窗口全屏方法_Qt君的博客-CSDN博客_qt全屏,给出使用示例:

    Qt窗口全屏方法

    方法一 使用showFullScreen方法显示全屏

    示例:

    QWidget w;
    w.showFullScreen();

    方法二 使用setWindowState方法设置

    示例:

    QWidget w;
    w.setWindowState(w.windowState() ^ Qt::WindowFullScreen);
    w.show();

    注意事项:

    •     适合于父窗口;
    •     设置子窗口全屏需要遵循父窗口全屏。

     

  • 相关阅读:
    构建用户身份基础设施,推动新能源汽车高质量发展
    uni-app解决表格uni-table样式问题
    按键中断控制实验
    牛客网:迷宫问题
    Day07 字符串
    python sqlalchemy db.session 的commit()和colse()对session中的对象的影响
    无代码开发平台选型指南
    基于Python是疫情期间教育领域新闻知识图谱分析
    关于Vue+webpack使用unocss编写CSS,打包后CSS没加前缀
    会计分录-初级会计职称
  • 原文地址:https://blog.csdn.net/phmatthaus/article/details/127905923