From 511990cee7272e98f4e457ffb676c9898e6d409e Mon Sep 17 00:00:00 2001 From: ffiirree Date: Thu, 13 Apr 2023 21:04:02 +0800 Subject: [PATCH] fixes #40, #36 --- 3rdparty/gflags | 1 - languages/capturer_en_US.ts | 122 ++++++++++++++--------------- languages/capturer_zh_CN.ts | 122 ++++++++++++++--------------- src/capturer.cpp | 46 +++++++---- src/capturer.h | 2 +- src/core/config.cpp | 2 + src/core/config.h | 4 +- src/core/platform/system_linux.cpp | 2 +- src/main.cpp | 2 +- 9 files changed, 159 insertions(+), 144 deletions(-) delete mode 160000 3rdparty/gflags diff --git a/3rdparty/gflags b/3rdparty/gflags deleted file mode 160000 index a738fdf..0000000 --- a/3rdparty/gflags +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a738fdf9338412f83ab3f26f31ac11ed3f3ec4bd diff --git a/languages/capturer_en_US.ts b/languages/capturer_en_US.ts index d67c34e..6af17f6 100644 --- a/languages/capturer_en_US.ts +++ b/languages/capturer_en_US.ts @@ -4,32 +4,32 @@ Capturer - + Screenshot - + Record Video - + Record GIF - + Open Camera - + Settings - + Quit @@ -224,205 +224,205 @@ SettingWindow - + Settings - + General - + Language - + Auto - + Dark - + Light - + Theme - - + + Screenshot - - - + + + Border Width - - - + + + Border Color - - - + + + Line Type - - - + + + Mask Color - + Screen Recording - - - + + + Appearance: - - + + Show Region - - + + Params: - - + + Framerate - + Encoder - - + + High - - + + Medium - - + + Low - - + + Quality - + GIF Recording - + Devices - + Microphones - + Speakers - + Cameras - + Shortcuts - + Paste - + Hide/Show All Images - + Video Recording - + Gif Recording - + About - + Version - + Copyright © 2018 - 2023 ffiirree. All rights reserved - + Run on Startup - + Settings File diff --git a/languages/capturer_zh_CN.ts b/languages/capturer_zh_CN.ts index ec07721..4d0e967 100644 --- a/languages/capturer_zh_CN.ts +++ b/languages/capturer_zh_CN.ts @@ -4,32 +4,32 @@ Capturer - + Screenshot 截图 - + Record Video 录屏 - + Record GIF 录GIF - + Open Camera 打开摄像头 - + Settings 设置 - + Quit 退出 @@ -224,205 +224,205 @@ SettingWindow - + Settings 设置 - + General 通用 - + Language 语言 - + Dark 暗色 - + Light 亮色 - + Theme 主题 - - + + Screenshot 截图 - - + + Params: 参数: - - + + Framerate 帧率 - + Microphones 麦克风 - + Speakers 扬声器 - + Cameras 摄像头 - + Encoder 编码器 - + Screen Recording 录屏 - + Run on Startup 开机启动 - + Settings File 设置文件 - + Auto 跟随系统 - - - + + + Border Width 边框宽度 - - - + + + Border Color 边框颜色 - - - + + + Line Type 线条类型 - - - + + + Mask Color 遮罩颜色 - - - + + + Appearance: 界面: - - + + Show Region 显示区域 - - + + High - - + + Medium - - + + Low - - + + Quality 质量 - + GIF Recording 录制GIF - + Devices 设备 - + Shortcuts 快捷键 - + Paste 粘贴 - + Hide/Show All Images 隐藏/显示全部贴图 - + Video Recording 录制视频 - + Gif Recording 录制GIF - + About 关于 - + Version 版本 - + Copyright © 2018 - 2023 ffiirree. All rights reserved diff --git a/src/capturer.cpp b/src/capturer.cpp index ed3b857..25dbb35 100644 --- a/src/capturer.cpp +++ b/src/capturer.cpp @@ -22,7 +22,7 @@ Capturer::Capturer(QWidget *parent) connect(sniper_, &ScreenShoter::pinSnipped, this, &Capturer::pinPixmap); - sys_tray_icon_ = new QSystemTrayIcon(this); + sys_tray_icon_ = new QSystemTrayIcon(QIcon(":/icon/res/capturer.png"), this); snip_sc_ = new QHotkey(this); connect(snip_sc_, &QHotkey::activated, sniper_, &ScreenShoter::start); @@ -46,10 +46,12 @@ Capturer::Capturer(QWidget *parent) // System tray icon // @attention Must after setting. - setupSystemTrayIcon(); + setupSystemTray(); updateConfig(); + setWindowIcon(QIcon(":/icon/res/capturer.png")); + // show message connect(sniper_, &ScreenShoter::SHOW_MESSAGE, this, &Capturer::showMessage); connect(recorder_, &ScreenRecorder::SHOW_MESSAGE, this, &Capturer::showMessage); @@ -82,31 +84,43 @@ void Capturer::updateConfig() gifcptr_->updateTheme(); } -void Capturer::setupSystemTrayIcon() +void Capturer::setupSystemTray() { - // SystemTrayIcon auto menu = new QMenu(this); menu->setObjectName("tray-menu"); menu->setWindowFlag(Qt::FramelessWindowHint); menu->setWindowFlag(Qt::NoDropShadowWindowHint); menu->setAttribute(Qt::WA_TranslucentBackground); - QString theme = (Config::theme() == "dark") ? "light" : "dark"; + // SystemTrayIcon + auto update_tray_menu = [=]() { + QString icon_color = (Config::theme() == "dark") ? "light" : "dark"; - menu->addAction(QIcon(":/icon/res/screenshot-" + theme), tr("Screenshot"), sniper_, &ScreenShoter::start); - menu->addAction(QIcon(":/icon/res/capture-" + theme), tr("Record Video"), recorder_, &ScreenRecorder::record); - menu->addAction(QIcon(":/icon/res/gif-" + theme), tr("Record GIF"), gifcptr_, &ScreenRecorder::record); - menu->addSeparator(); - menu->addAction(QIcon(":/icon/res/camera-" + theme), tr("Open Camera"), recorder_, &ScreenRecorder::switchCamera); - menu->addSeparator(); - menu->addAction(QIcon(":/icon/res/setting-" + theme), tr("Settings"), setting_dialog_, &SettingWindow::show); - menu->addSeparator(); - menu->addAction(QIcon(":/icon/res/exit-" + theme), tr("Quit"), qApp, &QCoreApplication::exit); +#ifdef __linux__ + // <= ubuntu 2004, system trays are always light + if (platform::system::os_version() <= platform::version_t{ 20, 4, 0, 0 }) { + icon_color = "dark"; + } +#endif + menu->clear(); + menu->addAction(QIcon(":/icon/res/screenshot-" + icon_color), tr("Screenshot"), sniper_, &ScreenShoter::start); + menu->addAction(QIcon(":/icon/res/capture-" + icon_color), tr("Record Video"), recorder_, &ScreenRecorder::record); + menu->addAction(QIcon(":/icon/res/gif-" + icon_color), tr("Record GIF"), gifcptr_, &ScreenRecorder::record); + menu->addSeparator(); + menu->addAction(QIcon(":/icon/res/camera-" + icon_color), tr("Open Camera"), recorder_, &ScreenRecorder::switchCamera); + menu->addSeparator(); + menu->addAction(QIcon(":/icon/res/setting-" + icon_color), tr("Settings"), setting_dialog_, &SettingWindow::show); + menu->addSeparator(); + menu->addAction(QIcon(":/icon/res/exit-" + icon_color), tr("Quit"), qApp, &QCoreApplication::exit); +}; + + // dark / light theme + connect(&Config::instance(), &Config::theme_changed, update_tray_menu); + update_tray_menu(); sys_tray_icon_->setContextMenu(menu); - sys_tray_icon_->setIcon(QIcon(":/icon/res/capturer.png")); - setWindowIcon(QIcon(":/icon/res/capturer.png")); sys_tray_icon_->show(); + sys_tray_icon_->setToolTip("Capturer Settings"); connect(sys_tray_icon_, &QSystemTrayIcon::activated, [this](auto&& r) { if (r == QSystemTrayIcon::DoubleClick) sniper_->start(); }); } diff --git a/src/capturer.h b/src/capturer.h index 3b8f9ee..e836817 100644 --- a/src/capturer.h +++ b/src/capturer.h @@ -48,7 +48,7 @@ private slots: int msecs = 10000); private: - void setupSystemTrayIcon(); + void setupSystemTray(); static std::pair clipboard_data(); static std::pair to_pixmap(const std::pair&); diff --git a/src/core/config.cpp b/src/core/config.cpp index 4a8fa37..a112525 100644 --- a/src/core/config.cpp +++ b/src/core/config.cpp @@ -193,6 +193,8 @@ void Config::load_theme(const std::string& theme) if (_theme != theme) { _theme = theme; + emit theme_changed(); + std::vector files{ ":/qss/capturer.qss", ":/qss/capturer-" + QString::fromStdString(theme) + ".qss", diff --git a/src/core/config.h b/src/core/config.h index db11a14..cfdbed2 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -27,7 +27,7 @@ class Config : public QObject // use this function to set theme void set_theme(const std::string&); - static void load_theme(const std::string&); + void load_theme(const std::string&); template void set(json& key, T value) { @@ -43,6 +43,7 @@ public slots: signals: void changed(); + void theme_changed(); void SYSTEM_THEME_CHANGED(int); private: @@ -60,5 +61,4 @@ public slots: #endif // _WIN32 }; - #endif // CONFIG_H diff --git a/src/core/platform/system_linux.cpp b/src/core/platform/system_linux.cpp index cc3de7a..29c8e63 100644 --- a/src/core/platform/system_linux.cpp +++ b/src/core/platform/system_linux.cpp @@ -63,7 +63,7 @@ namespace platform::system } // TODO : other desktop env - return theme_t::dark; + return theme_t::light; } std::string kernel_name() diff --git a/src/main.cpp b/src/main.cpp index df4e3db..32abb7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ int main(int argc, char *argv[]) LOG(INFO) << " -- Virtual Screen : " << platform::display::virtual_screen_geometry(); LOG(INFO) << " -- Desktop ENV : " << platform::system::desktop_name(platform::system::desktop()); - Config::load_theme(Config::theme()); + Config::instance().load_theme(Config::theme()); auto language = Config::instance()["language"].get(); LOG(INFO) << " -- Language : " << language;