From 61527833ca4e985d62e4f343a41f859b10057519 Mon Sep 17 00:00:00 2001 From: ahrm Date: Sat, 18 Feb 2023 19:45:02 +0330 Subject: [PATCH] Allow configuration of keyboard_* label background and text colors --- pdf_viewer/config.cpp | 4 ++++ pdf_viewer/main.cpp | 2 ++ pdf_viewer/pdf_view_opengl_widget.cpp | 13 +++++++++++-- pdf_viewer/utils.cpp | 7 +++++++ pdf_viewer/utils.h | 2 ++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pdf_viewer/config.cpp b/pdf_viewer/config.cpp index d5ecd302e..6234d8dd5 100644 --- a/pdf_viewer/config.cpp +++ b/pdf_viewer/config.cpp @@ -121,6 +121,8 @@ extern std::wstring DEFAULT_OPEN_FILE_PATH; extern std::wstring STATUS_BAR_FORMAT; extern bool INVERTED_HORIZONTAL_SCROLLING; extern bool TOC_JUMP_ALIGN_TOP; +extern float KEYBOARD_SELECT_BACKGROUND_COLOR[4]; +extern float KEYBOARD_SELECT_TEXT_COLOR[4]; template void* generic_deserializer(std::wstringstream& stream, void* res_) { @@ -434,6 +436,8 @@ ConfigManager::ConfigManager(const Path& default_path, const Path& auto_path ,co configs.push_back({ L"status_bar_format", &STATUS_BAR_FORMAT, string_serializer, string_deserializer, nullptr }); configs.push_back({ L"inverted_horizontal_scrolling", &INVERTED_HORIZONTAL_SCROLLING, bool_serializer, bool_deserializer, bool_validator }); configs.push_back({ L"toc_jump_align_top", &TOC_JUMP_ALIGN_TOP, bool_serializer, bool_deserializer, bool_validator }); + configs.push_back({ L"keyboard_select_background_color", &KEYBOARD_SELECT_BACKGROUND_COLOR, vec4_serializer, vec4_deserializer, nullptr }); + configs.push_back({ L"keyboard_select_text_color", &KEYBOARD_SELECT_TEXT_COLOR, vec4_serializer, vec4_deserializer, nullptr }); std::wstring highlight_config_string = L"highlight_color_a"; diff --git a/pdf_viewer/main.cpp b/pdf_viewer/main.cpp index 47c010bdb..5ac3bdf64 100644 --- a/pdf_viewer/main.cpp +++ b/pdf_viewer/main.cpp @@ -228,6 +228,8 @@ bool TOC_JUMP_ALIGN_TOP = false; float CUSTOM_COLOR_CONTRAST = 0.5f; float HIGHLIGHT_DELETE_THRESHOLD = 0.01f; float SCROLL_VIEW_SENSITIVITY = 1.0f; +float KEYBOARD_SELECT_BACKGROUND_COLOR[] = { 0.9f , 0.75f, 0.0f, 1.0f}; +float KEYBOARD_SELECT_TEXT_COLOR[] = { 0.0f , 0.0f, 0.5f, 1.0f}; Path default_config_path(L""); Path default_keys_path(L""); diff --git a/pdf_viewer/pdf_view_opengl_widget.cpp b/pdf_viewer/pdf_view_opengl_widget.cpp index d77e59712..d821e0ddf 100644 --- a/pdf_viewer/pdf_view_opengl_widget.cpp +++ b/pdf_viewer/pdf_view_opengl_widget.cpp @@ -31,6 +31,8 @@ extern float UNSELECTED_SEARCH_HIGHLIGHT_COLOR[3]; extern int KEYBOARD_SELECT_FONT_SIZE; extern float CUSTOM_COLOR_CONTRAST; extern float DISPLAY_RESOLUTION_SCALE; +extern float KEYBOARD_SELECT_BACKGROUND_COLOR[4]; +extern float KEYBOARD_SELECT_TEXT_COLOR[4]; GLfloat g_quad_vertex[] = { -1.0f, -1.0f, @@ -1654,12 +1656,19 @@ void PdfViewOpenGLWidget::get_overview_size(float* width, float* height) { } void PdfViewOpenGLWidget::setup_text_painter(QPainter* painter) { - QBrush background_brush = QBrush(QColor(236, 200, 0)); + + int bgcolor[4]; + int textcolor[4]; + + convert_color4(KEYBOARD_SELECT_BACKGROUND_COLOR, bgcolor); + convert_color4(KEYBOARD_SELECT_TEXT_COLOR, textcolor); + + QBrush background_brush = QBrush(QColor(bgcolor[0], bgcolor[1], bgcolor[2], bgcolor[3])); QFont font; font.setPixelSize(KEYBOARD_SELECT_FONT_SIZE); painter->setBackgroundMode(Qt::BGMode::OpaqueMode); painter->setBackground(background_brush); - painter->setPen(QColor(0, 0, 128)); + painter->setPen(QColor(textcolor[0], textcolor[1], textcolor[2], textcolor[3])); painter->setFont(font); } diff --git a/pdf_viewer/utils.cpp b/pdf_viewer/utils.cpp index 3ae0982cd..f4f9a8e38 100644 --- a/pdf_viewer/utils.cpp +++ b/pdf_viewer/utils.cpp @@ -2240,3 +2240,10 @@ QString get_selected_stylesheet(bool nofont) { ); } } + +void convert_color4(float* in_color, int* out_color) { + out_color[0] = (int)(in_color[0] * 255); + out_color[1] = (int)(in_color[1] * 255); + out_color[2] = (int)(in_color[2] * 255); + out_color[3] = (int)(in_color[3] * 255); +} diff --git a/pdf_viewer/utils.h b/pdf_viewer/utils.h index 9693819a8..7501a79c0 100644 --- a/pdf_viewer/utils.h +++ b/pdf_viewer/utils.h @@ -207,3 +207,5 @@ void matmul(float m1[], float m2[], float result[]) { } } } + +void convert_color4(float* in_color, int* out_color);