Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/ahrm/sioyek into dev…
Browse files Browse the repository at this point in the history
…elopment
  • Loading branch information
ahrm committed Oct 1, 2024
2 parents ae6efea + 8b064f9 commit dac86a4
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 7 deletions.
2 changes: 2 additions & 0 deletions pdf_viewer/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ float HIGHLIGHT_COLORS[26 * 3] = { \

float DARK_MODE_CONTRAST = 0.8f;
float ZOOM_INC_FACTOR = 1.2f;
float SCROLL_ZOOM_INC_FACTOR = 1.2f;
float VERTICAL_MOVE_AMOUNT = 1.0f;
float HORIZONTAL_MOVE_AMOUNT = 1.0f;
float MOVE_SCREEN_PERCENTAGE = 0.5f;
Expand Down Expand Up @@ -899,6 +900,7 @@ ConfigManager::ConfigManager(const Path& default_path, const Path& auto_path, co
add_float(L"freetext_bookmark_font_size", &FREETEXT_BOOKMARK_FONT_SIZE, FloatExtras{0.0f, 100.0f});
add_float(L"custom_color_contrast", &CUSTOM_COLOR_CONTRAST, FloatExtras{0.0f, 1.0f});
add_float(L"zoom_inc_factor", &ZOOM_INC_FACTOR, FloatExtras{1.0f, 2.0f});
add_float(L"scroll_zoom_inc_factor", &SCROLL_ZOOM_INC_FACTOR, FloatExtras{1.0f, 2.0f});
add_float(L"vertical_move_amount", &VERTICAL_MOVE_AMOUNT, FloatExtras{0.1f, 10.0f});
add_float(L"horizontal_move_amount", &HORIZONTAL_MOVE_AMOUNT, FloatExtras{0.1f, 10.0f});
add_float(L"move_screen_percentage", &MOVE_SCREEN_PERCENTAGE, FloatExtras{0.0f, 1.0f});
Expand Down
1 change: 1 addition & 0 deletions pdf_viewer/document_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "book.h"

extern float ZOOM_INC_FACTOR;
extern float SCROLL_ZOOM_INC_FACTOR;

class CachedChecksummer;
class Document;
Expand Down
2 changes: 1 addition & 1 deletion pdf_viewer/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7296,7 +7296,7 @@ std::unique_ptr<Command> InputHandler::get_menu_command(MainWidget* w, QKeyEvent
int InputHandler::get_event_key(QKeyEvent* key_event, bool* shift_pressed, bool* control_pressed, bool* command_pressed, bool* alt_pressed) {
int key = 0;
if (!USE_LEGACY_KEYBINDS) {
std::vector<QString> special_texts = { "\b", "\t", " ", "\r", "\n" };
std::vector<QString> special_texts = { "\b", "\u007F", "\t", " ", "\r", "\n" };
if (((key_event->key() >= 'A') && (key_event->key() <= 'Z')) || ((key_event->text().size() > 0) &&
(std::find(special_texts.begin(), special_texts.end(), key_event->text()) == special_texts.end()))) {
if (!(*control_pressed) && !(*alt_pressed) && !(*command_pressed)) {
Expand Down
11 changes: 7 additions & 4 deletions pdf_viewer/main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3035,9 +3035,11 @@ void MainWidget::wheelEvent(QWheelEvent* wevent) {

bool is_control_pressed = QApplication::queryKeyboardModifiers().testFlag(Qt::ControlModifier) ||
QApplication::queryKeyboardModifiers().testFlag(Qt::MetaModifier);
bool zoom_p = is_control_pressed;

bool is_shift_pressed = QApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier);
bool is_visual_mark_mode = main_document_view->is_ruler_mode() && visual_scroll_mode;
bool scroll_horizontally_p = is_shift_pressed;


#ifdef SIOYEK_QT6
Expand Down Expand Up @@ -3072,7 +3074,8 @@ void MainWidget::wheelEvent(QWheelEvent* wevent) {

bool is_touchpad = wevent->pointingDevice()->pointerType() == QPointingDevice::PointerType::Finger;

if ((!is_control_pressed) && (!is_shift_pressed)) {

if ((!zoom_p) && (!scroll_horizontally_p)) {
if (opengl_widget->get_overview_page()) {
if (opengl_widget->is_window_point_in_overview({ normal_x, normal_y })) {
if (is_touchpad){
Expand Down Expand Up @@ -3183,12 +3186,12 @@ void MainWidget::wheelEvent(QWheelEvent* wevent) {
}
}

if (is_control_pressed) {
float zoom_factor = 1.0f + num_repeats_f_y * (ZOOM_INC_FACTOR - 1.0f);
if (zoom_p) {
float zoom_factor = 1.0f + num_repeats_f_y * (SCROLL_ZOOM_INC_FACTOR - 1.0f);
zoom(mouse_window_pos, zoom_factor, wevent->angleDelta().y() > 0);
return;
}
if (is_shift_pressed) {
if (scroll_horizontally_p) {
float inverse_factor = INVERTED_HORIZONTAL_SCROLLING ? -1.0f : 1.0f;

bool is_macos = false;
Expand Down
1 change: 1 addition & 0 deletions pdf_viewer/pdf_view_opengl_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern float DARK_MODE_BACKGROUND_COLOR[3];
extern float CUSTOM_COLOR_MODE_EMPTY_BACKGROUND_COLOR[3];
extern float DARK_MODE_CONTRAST;
extern float ZOOM_INC_FACTOR;
extern float SCROLL_ZOOM_INC_FACTOR;
extern float VERTICAL_MOVE_AMOUNT;
extern float HIGHLIGHT_COLORS[26 * 3];
extern bool SHOULD_DRAW_UNRENDERED_PAGES;
Expand Down
4 changes: 2 additions & 2 deletions pdf_viewer/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ bool BaseSelectorWidget::eventFilter(QObject* obj, QEvent* event) {
#ifdef SIOYEK_QT6
if (event->type() == QEvent::KeyRelease) {
QKeyEvent* key_event = static_cast<QKeyEvent*>(event);
if (key_event->key() == Qt::Key_Delete) {
if (should_trigger_delete(key_event)) {
handle_delete();
}
else if (key_event->key() == Qt::Key_Insert) {
Expand Down Expand Up @@ -1748,7 +1748,7 @@ void BaseSelectorWidget::handle_edit() {

#ifndef SIOYEK_QT6
void BaseSelectorWidget::keyReleaseEvent(QKeyEvent* event) {
if (event->key() == Qt::Key_Delete) {
if (should_trigger_delete(event)) {
handle_delete();
}
QWidget::keyReleaseEvent(event);
Expand Down
26 changes: 26 additions & 0 deletions pdf_viewer/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4184,6 +4184,32 @@ bool is_doc_valid(fz_context* ctx, std::string path) {
}

return is_valid;
}

bool should_trigger_delete(QKeyEvent *key_event) {
if (!key_event) {
return false;
}

// Check for the Delete key
if (key_event->key() == Qt::Key_Delete) {
return true;
}

// On macOS, treat Shift+Backspace as Delete as well
#ifdef Q_OS_MAC
auto key = key_event->key();
bool backspace_p = (key == Qt::Key_Backspace);

bool is_control_cmd_pressed = key_event->modifiers().testFlag(Qt::ControlModifier) || key_event->modifiers().testFlag(Qt::MetaModifier);
// I did extensive tests on trying to detect Shift+Backspace on QT 6.6 on macOS 14. But the event for Shift+Backspace was simply not sent to us. I tested both =event->type() == QEvent::KeyRelease= and =event->type() == QEvent::KeyPress=.

if (backspace_p && is_control_cmd_pressed) {
return true;
}
#endif

return false;

}

Expand Down
1 change: 1 addition & 0 deletions pdf_viewer/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ QString get_ui_font_face_name();
QString get_status_font_face_name();
std::vector<fz_stext_char*> reorder_stext_line(fz_stext_line* line);
std::vector<fz_stext_char*> reorder_mixed_stext_line(fz_stext_line* line);
bool should_trigger_delete(QKeyEvent *key_event);

class TextToSpeechHandler {
public:
Expand Down

0 comments on commit dac86a4

Please sign in to comment.