接前一篇文章《Flameshot源码及分析2 —— 主函数调用流程》,链接为:
Flameshot源码及分析2 —— 主函数调用流程_蓝天居士的博客-CSDN博客
上一回我们讲到了gui函数,这个函数的实现在src/core/flameshot.cpp中,源码如下:
- CaptureWidget* Flameshot::gui(const CaptureRequest& req)
- {
- if (!resolveAnyConfigErrors()) {
- return nullptr;
- }
-
- #if defined(Q_OS_MACOS)
- // This is required on MacOS because of Mission Control. If you'll switch to
- // another Desktop you cannot take a new screenshot from the tray, you have
- // to switch back to the Flameshot Desktop manually. It is not obvious and a
- // large number of users are confused and report a bug.
- if (m_captureWindow != nullptr) {
- m_captureWindow->close();
- delete m_captureWindow;
- m_captureWindow = nullptr;
- }
- #endif
-
- if (nullptr == m_captureWindow) {
- // TODO is this unnecessary now?
- int timeout = 5000; // 5 seconds
- const int delay = 100;
- QWidget* modalWidget = nullptr;
- for (; timeout >= 0; timeout -= delay) {
- modalWidget = qApp->activeModalWidget();
- if (nullptr == modalWidget) {
- break;
- }
- modalWidget->close();
- modalWidget->deleteLater();
- QThread::msleep(delay);
- }
- if (0 == timeout) {
- QMessageBox::warning(
- nullptr, tr("Error"), tr("Unable to close active modal widgets"));
- return nullptr;
- }
-
- m_captureWindow = new CaptureWidget(req);
-
- #ifdef Q_OS_WIN
- m_captureWindow->show();
- #elif defined(Q_OS_MACOS)
- // In "Emulate fullscreen mode"
- m_captureWindow->showFullScreen();
- m_captureWindow->activateWindow();
- m_captureWindow->raise();
- #else
- m_captureWindow->showFullScreen();
- // m_captureWindow->show(); // For CaptureWidget Debugging under Linux
- #endif
- return m_captureWindow;
- } else {
- emit captureFailed();
- return nullptr;
- }
- }
笔者的电脑安装的是Linux系统,因此经过跟踪,代码最终会走到以下分支:
- #else
- m_captureWindow->showFullScreen();
- // 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全屏,给出使用示例:
示例:
QWidget w;
w.showFullScreen();
示例:
QWidget w;
w.setWindowState(w.windowState() ^ Qt::WindowFullScreen);
w.show();