From c99f346874efc649a2aa27db177563a152203d36 Mon Sep 17 00:00:00 2001 From: XMuli Date: Thu, 3 Nov 2022 14:21:57 +0800 Subject: [PATCH] fix: Debug and Release split path testing and 1. Fix the note of using spdlog & Qt 2. fix shortcut key screenshot failure 3. fix full screen screenshot with topbar under Linux --- src/main.cpp | 1 + src/platform/wininfo_x11.cpp | 3 +-- src/screen/screenshot.cpp | 22 +++++++--------------- src/screen/tray.cpp | 36 ++++++++++++++++++++++-------------- src/screen/tray.h | 22 ++++++++++++++++------ 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1ffa133..9e3b7b1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,6 +73,7 @@ int main(int argc, char *argv[]) else qmPath += "/translations/" + lanuage + ".qm"; #elif defined(Q_OS_LINUX) + qmPath += "/translations/" + lanuage + ".qm"; #endif trans.load(qmPath); qApp->installTranslator(&trans); diff --git a/src/platform/wininfo_x11.cpp b/src/platform/wininfo_x11.cpp index d212a4c..48e1dff 100644 --- a/src/platform/wininfo_x11.cpp +++ b/src/platform/wininfo_x11.cpp @@ -8,9 +8,8 @@ * Date: 2022.05.11 * Description: Linux 系统下智能窗口识别 ******************************************************************/ +#include "../core/xlog.h" // !!! NOTE:Qt headers must be placed in front of X11 headers #include "wininfo_x11.h" -#include "../core/xlog.h" - #include #include diff --git a/src/screen/screenshot.cpp b/src/screen/screenshot.cpp index d43d0fc..a8c88aa 100644 --- a/src/screen/screenshot.cpp +++ b/src/screen/screenshot.cpp @@ -92,7 +92,7 @@ ScreenShot::ScreenShot(QWidget *parent) // 注意显示器摆放的位置不相同~;最大化的可能异常修复 #if defined(Q_OS_WIN) || defined(Q_OS_LINUX) - setWindowFlags(Qt::FramelessWindowHint | windowFlags()); // | Qt::WindowStaysOnTopHint + setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | windowFlags()); // | Qt::WindowStaysOnTopHint #ifdef _MYDEBUG setWindowFlag(Qt::WindowStaysOnTopHint, false); // 删除置顶 m_virGeom = currentScreen(QCursor::pos())->geometry(); @@ -1492,28 +1492,20 @@ void ScreenShot::wheelEvent(QWheelEvent* event) void ScreenShot::getScrnShots() { - XLOG_INFO("---------------@#1----------------"); + qDebug() << "---------------@#1----------------"; m_specifyRts.clear(); m_specifyRts.insert(m_virGeom); for (const auto& it : m_scrns) m_specifyRts.insert(it->geometry()); -#ifdef Q_OS_WIN - //WinInfoWin::instance().getAllWinInfoCache(); - //if (m_rtCalcu.bSmartMonitor) // 存储所需要全部窗口信息 - //m_vec = WinInfoWin::instance().m_vWinInfo; -#elif defined(Q_OS_MAC) -#elif defined(Q_OS_LINUX) -#endif - getScrnInfo(); - XLOG_INFO("---------------@#2----------------"); + qDebug() << "---------------@#2----------------"; getVirScrnPixmap(); // 因 QWidget 启动后 事件执行顺序,sizeHint() -> showEvent() -> paintEvent();故全屏 show() 之前先获取桌面截图 -#ifdef Q_OS_MAC - showFullScreen(); -#else +#ifdef Q_OS_WIN show(); +#else + showFullScreen(); // Linux supports virtual multi-screen, Mac only one screen #endif if (m_bSmartWin) @@ -1521,7 +1513,7 @@ void ScreenShot::getScrnShots() // fix: 初次使用全局热键召唤截图窗口,对 Esc 无响应。 考虑跨平台或需参考 https://zhuanlan.zhihu.com/p/161299504 if (!isActiveWindow()) { - XLOG_INFO("---------------@#3----------------"); + qDebug() << "---------------@#3----------------"; activateWindow(); } } diff --git a/src/screen/tray.cpp b/src/screen/tray.cpp index 4caf1c2..ee7620f 100644 --- a/src/screen/tray.cpp +++ b/src/screen/tray.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "QThread" //#include "../../pluginsimpl/watemark/pluginwatemark.h" @@ -39,7 +40,7 @@ Tray& Tray::instance() return tray; } -std::vector> Tray::getVHotKeys() const +std::vector> Tray::getVHotKeys() const { return m_vHotKeys; } @@ -125,26 +126,26 @@ void Tray::init() void Tray::initGlobalHotKeys() { m_vHotKeys = { - std::make_tuple(nullptr, "Ctrl+Shift+Y", tr("Active Window")), // 截图相关 - std::make_tuple(nullptr, "Ctrl+Shift+W", tr("Scrolling Window")), - std::make_tuple(nullptr, "Ctrl+Shift+L", tr("Delay Capture")), - std::make_tuple(nullptr, "Ctrl+Shift+S", tr("Full Screen")), - std::make_tuple(nullptr, "Ctrl+Shift+F", tr("Fixd-Size Region")), - - std::make_tuple(nullptr, "Ctrl+Shift+T", tr("Paste")), // 贴图相关 - std::make_tuple(nullptr, "Ctrl+Shift+H", tr("Hide/Show all images")), - std::make_tuple(nullptr, "Ctrl+Shift+X", tr("Switch current group")) }; + std::make_tuple(nullptr, "Ctrl+Shift+Y", tr("Active Window"), ScrnShotType::SST_ActionWindow), + std::make_tuple(nullptr, "Ctrl+Shift+W", tr("Scrolling Window"), ScrnShotType::SST_ScrollingWindow), + std::make_tuple(nullptr, "Ctrl+Shift+L", tr("Delay Capture"), ScrnShotType::SST_DelayCapture), + std::make_tuple(nullptr, "Ctrl+Shift+S", tr("Full Screen"), ScrnShotType::SST_FullScreen), + std::make_tuple(nullptr, "Ctrl+Shift+F", tr("Fixd-Size Region"), ScrnShotType::SST_FixdSizeRegion), + std::make_tuple(nullptr, "Ctrl+Shift+T", tr("Paste"), ScrnShotType::SST_Paste), + std::make_tuple(nullptr, "Ctrl+Shift+H", tr("Hide/Show all images"), ScrnShotType::SST_HideShowAllImages), + std::make_tuple(nullptr, "Ctrl+Shift+X", tr("Switch current group"), ScrnShotType::SST_SwitchCurrentGroup)}; insSettings->beginGroup(INIT_HOTKEYS); for (auto& it : m_vHotKeys) { auto& pHK = std::get<0>(it); // QHotkey*& 指针的引用类型 QString& hotkey = std::get<1>(it); QString& describe = std::get<2>(it); + const ScrnShotType sst = std::get<3>(it); hotkey = insSettings->value(describe, hotkey).toString(); // 读取配置文件 - pHK = new QHotkey(QKeySequence(hotkey), true, qApp); - pHK->setObjectName(describe); + QMetaEnum enumSst = QMetaEnum::fromType(); + pHK->setObjectName(enumSst.valueToKey(sst)); connect(pHK, &QHotkey::activated, this, &Tray::onSrnShot); // qDebug() << "pHK" << pHK << " std::get<0>(it)" << std::get<0>(it); @@ -165,8 +166,15 @@ void Tray::onSrnShot() const auto act = qobject_cast(sender()); if (!hk && !act) return; - - if (act || hk->objectName() == "Active Window") // TODO 2022.07.17: 替换为枚举 + + int sst = Tray::SST_Unknow; + if (hk) { + bool ok = false; + QMetaEnum metaSst = QMetaEnum::fromType(); + sst = metaSst.keyToValue(hk->objectName().toStdString().c_str(), &ok); + } + + if (act || sst == Tray::SST_ActionWindow) m_pSrnShot->getScrnShots(); } diff --git a/src/screen/tray.h b/src/screen/tray.h index 298a822..8be9f8d 100644 --- a/src/screen/tray.h +++ b/src/screen/tray.h @@ -16,22 +16,32 @@ #include #include "screenshot.h" -QT_BEGIN_NAMESPACE class QSystemTrayIcon; class QAction; class QMenu; -QT_END_NAMESPACE - class QHotkey; class Preference; + class Tray : public QObject { Q_OBJECT public: - static Tray& instance(); + enum ScrnShotType { + SST_ActionWindow, + SST_ScrollingWindow, + SST_DelayCapture, + SST_FullScreen, + SST_FixdSizeRegion, + SST_Paste, + SST_HideShowAllImages, + SST_SwitchCurrentGroup, + SST_Unknow + }; + Q_ENUM(ScrnShotType) - std::vector> getVHotKeys() const; + static Tray& instance(); + std::vector> getVHotKeys() const; private: explicit Tray(QObject* parent = nullptr); @@ -57,7 +67,7 @@ public slots: QMenu* m_trayIconMenu; QPointer m_trayIcon; - std::vector> m_vHotKeys; + std::vector> m_vHotKeys; }; #endif // TARY_H