Commit 92e161e5 authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Implement cursor auto-hiding

parent 4f2a01f2
......@@ -162,6 +162,9 @@ VARIABLES
'int' *select_text_button* ::
1: The mouse button used for text selection. Double- and triple-clicking
are supported to select with word/line granularity.
'int' *hide_mouse_timeout* ::
2000: The delay in milliseconds after which the mouse cursor is hidden. Set
to 0 to disable.
'int' *smooth_scroll_delta* ::
30: Pixel offset when moving around.
'float' *screen_scroll_factor* ::
......
......@@ -6,6 +6,7 @@ unrendered_page_color=0x40FFFFFF
click_link_button=1
drag_view_button=2
select_text_button=1
hide_mouse_timeout=2000
smooth_scroll_delta=30
screen_scroll_factor=0.9
jump_padding=0.2
......
......@@ -28,6 +28,7 @@ Canvas::Canvas(Viewer *v, QWidget *parent) :
QWidget(parent),
viewer(v),
triple_click_possible(false),
last_cursor(Qt::BlankCursor),
valid(true) {
setFocusPolicy(Qt::StrongFocus);
......@@ -101,6 +102,7 @@ Canvas::Canvas(Viewer *v, QWidget *parent) :
} else {
setCursor(Qt::IBeamCursor);
}
last_cursor = Qt::BlankCursor;
// prints the string representation of a key
// cerr << QKeySequence(Qt::Key_Equal).toString().toUtf8().constData() << endl;
......@@ -110,6 +112,11 @@ Canvas::Canvas(Viewer *v, QWidget *parent) :
goto_line->hide();
connect(goto_line, SIGNAL(returnPressed()), this, SLOT(goto_page()), Qt::UniqueConnection);
hide_mouse_timeout = config->get_value("Settings/hide_mouse_timeout").toInt();
setMouseTracking(true);
hide_mouse_timer.setSingleShot(true);
connect(&hide_mouse_timer, SIGNAL(timeout()), this, SLOT(hide_mouse_pointer()), Qt::UniqueConnection);
page_overlay = new QLabel(this);
page_overlay->setMargin(1);
page_overlay->setAutoFillBackground(true);
......@@ -193,6 +200,7 @@ void Canvas::mousePressEvent(QMouseEvent *event) {
if (drag_view_button != Qt::NoButton && event->button() == drag_view_button) {
if (cursor().shape() != Qt::PointingHandCursor) { // TODO
setCursor(Qt::ClosedHandCursor);
last_cursor = Qt::BlankCursor;
}
}
if (select_text_button != Qt::NoButton && event->button() == select_text_button) {
......@@ -205,6 +213,7 @@ void Canvas::mousePressEvent(QMouseEvent *event) {
if (cursor().shape() != Qt::PointingHandCursor) { // TODO
setCursor(Qt::IBeamCursor);
last_cursor = Qt::BlankCursor;
}
}
}
......@@ -230,10 +239,20 @@ void Canvas::mouseReleaseEvent(QMouseEvent *event) {
} else {
setCursor(Qt::IBeamCursor);
}
last_cursor = Qt::BlankCursor;
if (select_text_button != Qt::NoButton && event->button() == select_text_button) {
cur_layout->copy_selection_text();
}
// auto-hide mouse pointer
if (event->buttons() == 0) {
if (hide_mouse_timeout > 0) {
hide_mouse_timer.start(hide_mouse_timeout);
}
} else {
hide_mouse_timer.stop();
}
}
void Canvas::mouseMoveEvent(QMouseEvent *event) {
......@@ -261,6 +280,20 @@ void Canvas::mouseMoveEvent(QMouseEvent *event) {
cur_layout->scroll_smooth(0, max(height() - event->y() - margin, -margin) * 2);
}
}
// auto-show mouse pointer
if (last_cursor != Qt::BlankCursor) {
setCursor(last_cursor);
last_cursor = Qt::BlankCursor;
}
// auto-hide mouse pointer
if (event->buttons() == 0) {
if (hide_mouse_timeout > 0) {
hide_mouse_timer.start(hide_mouse_timeout);
}
} else {
hide_mouse_timer.stop();
}
}
void Canvas::wheelEvent(QWheelEvent *event) {
......@@ -360,6 +393,11 @@ void Canvas::disable_triple_click() {
triple_click_possible = false;
}
void Canvas::hide_mouse_pointer() {
last_cursor = cursor().shape();
setCursor(Qt::BlankCursor);
}
void Canvas::swap_selection_and_panning_buttons() {
Qt::MouseButton tmp = drag_view_button;
drag_view_button = select_text_button;
......@@ -370,6 +408,7 @@ void Canvas::swap_selection_and_panning_buttons() {
} else {
setCursor(Qt::IBeamCursor);
}
last_cursor = Qt::BlankCursor;
}
......
......@@ -66,6 +66,7 @@ private slots:
void focus_goto();
void disable_triple_click();
void hide_mouse_pointer();
void swap_selection_and_panning_buttons();
......@@ -84,7 +85,10 @@ private:
int mx, my;
int mx_down, my_down;
bool triple_click_possible;
QTimer scroll_timer;
int hide_mouse_timeout;
QTimer hide_mouse_timer;
Qt::CursorShape last_cursor;
bool valid;
......
......@@ -27,6 +27,7 @@ void CFG::init_defaults() {
vd.push_back("Settings/click_link_button"); defaults[vd.back()] = 1;
vd.push_back("Settings/drag_view_button"); defaults[vd.back()] = 2;
vd.push_back("Settings/select_text_button"); defaults[vd.back()] = 1;
vd.push_back("Settings/hide_mouse_timeout"); defaults[vd.back()] = 2000;
vd.push_back("Settings/smooth_scroll_delta"); defaults[vd.back()] = 30; // pixel scroll offset
vd.push_back("Settings/screen_scroll_factor"); defaults[vd.back()] = 0.9; // creates overlap for scrolling 1 screen down, should be <= 1
vd.push_back("Settings/jump_padding"); defaults[vd.back()] = 0.2; // must be <= 0.5
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment