Skip to content

Commit

Permalink
Merge branch 'pr/1022' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrm committed Mar 26, 2024
2 parents b062643 + 9a9b961 commit d091b0a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
9 changes: 9 additions & 0 deletions pdf_viewer/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern bool SHOULD_DRAW_UNRENDERED_PAGES;
extern bool HOVER_OVERVIEW;
//extern bool AUTO_EMBED_ANNOTATIONS;
extern bool DEFAULT_DARK_MODE;
extern bool USE_SYSTEM_THEME;
extern float HIGHLIGHT_COLORS[26 * 3];
extern std::wstring SEARCH_URLS[26];
extern std::wstring EXECUTE_COMMANDS[26];
Expand Down Expand Up @@ -707,6 +708,14 @@ ConfigManager::ConfigManager(const Path& default_path, const Path& auto_path, co
bool_deserializer,
bool_validator
});
configs.push_back({
L"use_system_theme",
ConfigType::Bool,
&USE_SYSTEM_THEME,
bool_serializer,
bool_deserializer,
bool_validator
});
configs.push_back({
L"render_freetext_borders",
ConfigType::Bool,
Expand Down
3 changes: 2 additions & 1 deletion pdf_viewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ bool FLAT_TABLE_OF_CONTENTS = false;
bool SHOULD_USE_MULTIPLE_MONITORS = false;
bool SHOULD_CHECK_FOR_LATEST_VERSION_ON_STARTUP = false;
bool DEFAULT_DARK_MODE = false;
bool USE_SYSTEM_THEME = false;
bool SORT_BOOKMARKS_BY_LOCATION = true;
std::wstring LIBGEN_ADDRESS = L"";
std::wstring GOOGLE_SCHOLAR_ADDRESS = L"";
Expand Down Expand Up @@ -1144,7 +1145,7 @@ int main(int argc, char* args[]) {
});
#endif

if (DEFAULT_DARK_MODE) {
if (DEFAULT_DARK_MODE && !USE_SYSTEM_THEME) {
main_widget->toggle_dark_mode();
}

Expand Down
68 changes: 65 additions & 3 deletions pdf_viewer/main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#ifndef SIOYEK_QT6
#include <qdesktopwidget.h>
#endif
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
#include <QStyleHints>
#endif

#include <qkeyevent.h>
#include <qlabel.h>
Expand Down Expand Up @@ -199,6 +202,7 @@ extern ScratchPad global_scratchpad;
extern int NUM_CACHED_PAGES;
extern bool IGNORE_SCROLL_EVENTS;
extern bool DONT_FOCUS_IF_SYNCTEX_RECT_IS_VISIBLE;
extern bool USE_SYSTEM_THEME;

extern bool SHOW_RIGHT_CLICK_CONTEXT_MENU;
extern std::wstring CONTEXT_MENU_ITEMS;
Expand Down Expand Up @@ -1234,6 +1238,10 @@ MainWidget::MainWidget(fz_context* mupdf_context,
menu_bar->stackUnder(text_command_line_edit_container);
#endif

#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
set_system_mode();
#endif

setFocus();
}

Expand Down Expand Up @@ -4442,6 +4450,13 @@ void MainWidget::changeEvent(QEvent* event) {
//main_window_height = get_current_monitor_height();
}
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
if (event->type() == QEvent::ThemeChange) {
set_system_mode();
}
#endif

QWidget::changeEvent(event);
}

Expand Down Expand Up @@ -6756,17 +6771,56 @@ int MainWidget::get_current_colorscheme_index() {
}

void MainWidget::set_dark_mode() {
opengl_widget->set_dark_mode(true);
if (opengl_widget->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Dark) {
opengl_widget->set_dark_mode(true);
}
if (helper_opengl_widget_) {
if (helper_opengl_widget_->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Dark) {
helper_opengl_widget_->set_dark_mode(true);
}
}
}

void MainWidget::set_light_mode() {
opengl_widget->set_dark_mode(false);
if (opengl_widget->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Normal) {
opengl_widget->set_dark_mode(false);
}
if (helper_opengl_widget_) {
if (helper_opengl_widget_->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Normal) {
helper_opengl_widget_->set_dark_mode(false);
}
}
}

void MainWidget::set_custom_color_mode() {
opengl_widget->set_custom_color_mode(true);
if (opengl_widget->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Custom) {
opengl_widget->set_custom_color_mode(true);
}
if (helper_opengl_widget_) {
if (helper_opengl_widget_->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Custom) {
helper_opengl_widget_->set_custom_color_mode(true);
}
}
}


#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
void MainWidget::set_system_mode() {
if (USE_SYSTEM_THEME) {
QStyleHints *styleHints = QGuiApplication::styleHints();
switch (styleHints->colorScheme()) {
case Qt::ColorScheme::Unknown:
case Qt::ColorScheme::Light:
set_light_mode();
break;
case Qt::ColorScheme::Dark:
set_dark_mode();
break;
}
}
}
#endif

void MainWidget::update_highlight_buttons_position() {
if (selected_highlight_index != -1) {
Highlight hl = main_document_view->get_highlight_with_index(selected_highlight_index);
Expand Down Expand Up @@ -7378,6 +7432,9 @@ void MainWidget::on_configs_changed(std::vector<std::string>* config_names) {
changeTitlebarColor(winId(), MACOS_TITLEBAR_COLOR[0], MACOS_TITLEBAR_COLOR[1], MACOS_TITLEBAR_COLOR[2], 1.0f);
}
#endif
if (confname == "use_system_theme") {
set_system_mode();
}

if (confname == "tts_rate") {
if (is_reading) {
Expand Down Expand Up @@ -9770,6 +9827,11 @@ void MainWidget::initialize_helper(){
helper_opengl_widget_->show();
helper_opengl_widget_->hide();
#endif

#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
set_system_mode();
#endif

helper_opengl_widget_->register_on_link_edit_listener([this](OpenedBookState state) {
this->update_closest_link_with_opened_book_state(state);
});
Expand Down
1 change: 1 addition & 0 deletions pdf_viewer/main_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ class MainWidget : public QMainWindow {
void set_dark_mode();
void set_light_mode();
void set_custom_color_mode();
void set_system_mode();
void toggle_statusbar();
void toggle_titlebar();

Expand Down

0 comments on commit d091b0a

Please sign in to comment.