Skip to content

Commit

Permalink
Allow configuration of keyboard_* label background and text colors
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrm committed Feb 18, 2023
1 parent 279afd3 commit 6152783
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pdf_viewer/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T>
void* generic_deserializer(std::wstringstream& stream, void* res_) {
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions pdf_viewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"");
Expand Down
13 changes: 11 additions & 2 deletions pdf_viewer/pdf_view_opengl_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

}
Expand Down
7 changes: 7 additions & 0 deletions pdf_viewer/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions pdf_viewer/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,5 @@ void matmul(float m1[], float m2[], float result[]) {
}
}
}

void convert_color4(float* in_color, int* out_color);

0 comments on commit 6152783

Please sign in to comment.