Skip to content

Commit

Permalink
fix: Debug and Release split path testing
Browse files Browse the repository at this point in the history
and
1. Fix the note of using spdlog & Qt
2. fix shortcut key screenshot failure
3. fix full screen screenshot with topbar under Linux
  • Loading branch information
XMuli committed Nov 3, 2022
1 parent bf16c14 commit c99f346
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 37 deletions.
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/platform/wininfo_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QString>
#include <QLabel>

Expand Down
22 changes: 7 additions & 15 deletions src/screen/screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1492,36 +1492,28 @@ 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)
updateGetWindowsInfo();

// fix: 初次使用全局热键召唤截图窗口,对 Esc 无响应。 考虑跨平台或需参考 https://zhuanlan.zhihu.com/p/161299504
if (!isActiveWindow()) {
XLOG_INFO("---------------@#3----------------");
qDebug() << "---------------@#3----------------";
activateWindow();
}
}
Expand Down
36 changes: 22 additions & 14 deletions src/screen/tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QFileInfoList>
#include <QKeySequence>
#include <QHotkey>
#include <QMetaEnum>

#include "QThread"
//#include "../../pluginsimpl/watemark/pluginwatemark.h"
Expand All @@ -39,7 +40,7 @@ Tray& Tray::instance()
return tray;
}

std::vector<std::tuple<QHotkey*, QString, QString>> Tray::getVHotKeys() const
std::vector<std::tuple<QHotkey*, QString, QString, Tray::ScrnShotType>> Tray::getVHotKeys() const
{
return m_vHotKeys;
}
Expand Down Expand Up @@ -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<Tray::ScrnShotType>();
pHK->setObjectName(enumSst.valueToKey(sst));
connect(pHK, &QHotkey::activated, this, &Tray::onSrnShot);

// qDebug() << "pHK" << pHK << " std::get<0>(it)" << std::get<0>(it);
Expand All @@ -165,8 +166,15 @@ void Tray::onSrnShot()
const auto act = qobject_cast<QAction*>(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<Tray::ScrnShotType>();
sst = metaSst.keyToValue(hk->objectName().toStdString().c_str(), &ok);
}

if (act || sst == Tray::SST_ActionWindow)
m_pSrnShot->getScrnShots();
}

Expand Down
22 changes: 16 additions & 6 deletions src/screen/tray.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,32 @@
#include <QPointer>
#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<std::tuple<QHotkey*, QString, QString>> getVHotKeys() const;
static Tray& instance();
std::vector<std::tuple<QHotkey*, QString, QString, Tray::ScrnShotType>> getVHotKeys() const;

private:
explicit Tray(QObject* parent = nullptr);
Expand All @@ -57,7 +67,7 @@ public slots:
QMenu* m_trayIconMenu;
QPointer<QSystemTrayIcon> m_trayIcon;

std::vector<std::tuple<QHotkey*, QString, QString>> m_vHotKeys;
std::vector<std::tuple<QHotkey*, QString, QString, Tray::ScrnShotType>> m_vHotKeys;
};

#endif // TARY_H

0 comments on commit c99f346

Please sign in to comment.