Skip to content

Commit 40fd9ce

Browse files
修改部分日志
1 parent e5bacab commit 40fd9ce

File tree

11 files changed

+48
-19
lines changed

11 files changed

+48
-19
lines changed

3rd/spdlog/fmt/bundled/format.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ FMT_CONSTEXPR inline size_t compute_width(string_view s) {
570570
*count += detail::to_unsigned(
571571
1 +
572572
(cp >= 0x1100 &&
573-
(cp <= 0x115f || // Hangul Jamo init. consonants
573+
(cp <= 0x115f || // Hangul Jamo CaptureScreen. consonants
574574
cp == 0x2329 || // LEFT-POINTING ANGLE BRACKET
575575
cp == 0x232a || // RIGHT-POINTING ANGLE BRACKET
576576
// CJK ... Yi except IDEOGRAPHIC HALF FILL SPACE:

3rd/spdlog/logger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class SPDLOG_API logger
7272
: logger(std::move(name), {std::move(single_sink)})
7373
{}
7474

75-
// Logger with sinks init list
75+
// Logger with sinks CaptureScreen list
7676
logger(std::string name, sinks_init_list sinks)
7777
: logger(std::move(name), sinks.begin(), sinks.end())
7878
{}

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ set(REQUIRED_LIBS Core Gui Widgets Network)
1515
set(REQUIRED_LIBS_QUALIFIED Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network)
1616

1717
#宏定义在这里添加
18-
#add_definitions(
19-
# -D_ENABLE_LOGGING
20-
#)
21-
add_compile_options(-D USE_SPDLOG_)
18+
add_definitions(
19+
-DPDLOG_ACTIVE_LEVEL=0
20+
)
21+
add_compile_options(-DUSE_SPDLOG_)
2222

2323
if(WIN32)
2424
set(CMAKE_PREFIX_PATH "D:/software/Qt5.13.0/mingw73_64/lib/cmake/Qt5")
@@ -107,6 +107,8 @@ target_sources(
107107
# target_link_libraries(${PROJECT_NAME} xcb xcb-util)
108108
#endif()
109109

110+
message(STATUS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_autogen/include)
111+
110112
target_include_directories(${PROJECT_NAME}
111113
PUBLIC ./
112114
${CMAKE_CURRENT_SOURCE_DIR}/include

core/screen_shot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void ScreenShot::rasie() {
2222

2323
}
2424

25-
void ScreenShot::init(QWidget *parent) {
25+
void ScreenShot::CaptureScreen(QWidget *parent) {
2626

2727
}
2828

core/screen_shot.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <QObject>
99
#include <QWidget>
1010
#include <QList>
11+
#include <memory>
1112
//#include "widget.h"
1213

1314
class FireShot;
@@ -18,7 +19,7 @@ class ScreenShot : public QObject {
1819
explicit ScreenShot(FireShot *lpFireShot);
1920
~ScreenShot() override;
2021

21-
void init(QWidget* parent);
22+
void CaptureScreen(QWidget* parent);
2223

2324
void cleanup();
2425

core/widget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Widget::Widget(QWidget* parent)
2323

2424
Widget::~Widget()
2525
{
26-
SPD_ERROR("{0}", __FUNCTION__);
26+
//SPD_ERROR("{0}", __FUNCTION__);
2727
}
2828

2929
void Widget::start(std::shared_ptr<ScreenList> list, int index)

fireshot.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
#include <QAction>
88
#include <QMenu>
99
#include <QDesktopWidget>
10+
#include <QApplication>
1011

1112
#include "fireshot.h"
1213
#include "utils/spdlog_wrapper.h"
1314
#include "fireshot_errno.h"
15+
#include "core/screen_shot.h"
1416

1517
FireShot::FireShot(QWidget *parent) :
1618
QDialog(parent), m_lpTrayIcon(new QSystemTrayIcon(this)),
@@ -50,12 +52,12 @@ void FireShot::OnShowSetting()
5052

5153
int32_t FireShot::CreateActions() {
5254
// construct tray setting icon
53-
m_lpSettingAction = new QAction(tr("&Settings"), this);
55+
m_lpSettingAction = new QAction(tr("Setting"), this);
5456
QIcon settingIcon(":/icons/icon/menu-setting.png");
5557
m_lpSettingAction->setIcon(settingIcon);
5658
connect(m_lpSettingAction, &QAction::triggered, this, &FireShot::OnShowSetting);
5759
// construct tray shot icon
58-
m_lpShotAction = new QAction(tr("S$hot"), this);
60+
m_lpShotAction = new QAction(tr("Shot"), this);
5961
QIcon shotIcon(":/icons/icon/menu-shot.png");
6062
m_lpShotAction->setIcon(shotIcon);
6163
connect(m_lpShotAction, &QAction::triggered, this, &FireShot::OnStartShot);
@@ -75,6 +77,20 @@ void FireShot::OnStartShot() {
7577
return;
7678
}
7779

80+
SPD_INFO("-----------------------start shot --------------------");
81+
m_bShotting = true;
82+
ScreenShot *lpScreenShot = nullptr;
83+
if (m_screenShoter.empty()) {
84+
lpScreenShot = new ScreenShot(this);
85+
// 通过信号将两个对象之间互通有无
86+
connect(this, &FireShot::StopShot, lpScreenShot, &ScreenShot::ShotDone);
87+
connect(lpScreenShot, &ScreenShot::ShotDone, this, &FireShot::OnShotDone);
88+
} else {
89+
lpScreenShot = m_screenShoter.back();
90+
m_screenShoter.pop_front();
91+
}
92+
93+
lpScreenShot->CaptureScreen(this);
7894

7995
}
8096

@@ -83,7 +99,8 @@ void FireShot::OnShotDone(ScreenShot *starer) {
8399
}
84100

85101
void FireShot::OnExitShot() {
86-
102+
m_lpTrayIcon->hide();
103+
QApplication::exit(0);
87104
}
88105

89106
int32_t FireShot::CreateTrayWithIcon() {

fireshot.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ Q_OBJECT
2727

2828
signals:
2929
void SatrtShot();
30-
void ShotDone(FireShot* starer);
30+
void ShotDone(ScreenShot* starer);
3131
void CheckHotKey(uint32_t value);
32-
void StopShot(FireShot* starter);
32+
void StopShot(ScreenShot* starter);
3333

3434
private slots:
3535
void OnStartShot();
3636
void OnShotDone(ScreenShot* starer);
37+
// 点击退出时能退出截图进程
3738
void OnExitShot();
3839
void OnShowSetting();
3940

@@ -48,6 +49,8 @@ private slots:
4849
SettingDlg *m_lpSettingDlg; // tray settings
4950
bool m_bShotting; // 是否正在截图
5051

52+
std::list<ScreenShot*> m_screenShoter;
53+
5154
};
5255

5356

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(int argc, char *argv[]) {
1616

1717
// 查看系统是否支持托盘功能
1818
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
19-
SPD_ERROR("system tray disabled");
19+
SPD_ERROR("fmt string", "system tray disabled");
2020
return 1;
2121
}
2222

utils/spdlog_wrapper.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Created by wangyz38535 on 2023/10/11.
33
//
44
#include <QDir>
5+
56
#include "spdlog_wrapper.h"
67
#include "spdlog/spdlog.h"
78
#include "spdlog/cfg/env.h" // support for loading levels from the environment variable
@@ -34,7 +35,11 @@ namespace spdlog
3435
logger_->set_level(static_cast<level::level_enum>(lv));
3536
logger_->flush_on(static_cast<level::level_enum>(flv));
3637

37-
set_pattern("[%H:%M:%S %z] [thread %t] %v");
38+
//set_pattern("[%H:%M:%S %z] [thread %t] %v");
39+
logger_->set_pattern("[%Y-%m-%d %H:%M:%S] [%n] [%^%l%$] [%s:%#] %v");
40+
41+
SPDLOG_LOGGER_INFO(logger_, "test3 {}", 3);//会输出文件名和行号
42+
3843
#endif // USE_SPDLOG_
3944

4045
}
@@ -43,4 +48,4 @@ namespace spdlog
4348
{
4449
return logger_;
4550
}
46-
}
51+
}

utils/spdlog_wrapper.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#ifndef QT_CLION_SPDLOG_WRAPPER_H
66
#define QT_CLION_SPDLOG_WRAPPER_H
7-
7+
#define SPDLOG_ACTIVE_LEVEL 0
88
#include "spdlog/spdlog.h"
99

1010
namespace spdlog
@@ -14,7 +14,8 @@ namespace spdlog
1414
} // spdlog
1515

1616
#ifdef USE_SPDLOG_
17-
#define SPD_TRACE(fmt, ...) spdlog::logger_ptr()->trace(fmt, ##__VA_ARGS__);
17+
18+
#define SPD_TRACE(fmt, ...) spdlog::logger_ptr()->trace(fmt, ##__VA_ARGS__);
1819
#define SPD_DEBUG(fmt, ...) spdlog::logger_ptr()->debug(fmt, ##__VA_ARGS__);
1920
#define SPD_INFO(fmt, ...) spdlog::logger_ptr()->info(fmt, ##__VA_ARGS__);
2021
#define SPD_WARN(fmt, ...) spdlog::logger_ptr()->warn(fmt, ##__VA_ARGS__);

0 commit comments

Comments
 (0)