Commit 3d285c0e authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Implement jump list

Every time a jump occurs its origin is saved. You can then move through
those saved positions, e.g. to return to the table of contents after
having read a section.
parent 0236b55b
......@@ -89,6 +89,8 @@ KEY BINDINGS
Focus next/previous search hit that is currently not visible
*u*, *i* ::
Rotate pages left/right
*\^o*, *^i*, *Alt-Left*, *Alt-Right* ::
Move backward/forward through the jump list. Entries are added automatically when jumping
VARIABLES
---------
......
......@@ -47,6 +47,8 @@ previous_invisible_hit=Ctrl+Shift+N
focus_goto=Ctrl+G
rotate_left=U
rotate_right=I
jump_back=Ctrl+O, Alt+Left
jump_forward=Ctrl+I, Alt+Right
toggle_fullscreen=F
close_search=Esc
reload=R
......
......@@ -27,6 +27,8 @@ Canvas::Canvas(Viewer *v, QWidget *parent) :
valid(true) {
setFocusPolicy(Qt::StrongFocus);
clear_jumps();
// load config options
CFG *config = CFG::get_instance();
......@@ -80,6 +82,8 @@ Canvas::Canvas(Viewer *v, QWidget *parent) :
add_action("focus_goto", SLOT(focus_goto()));
add_action("rotate_left", SLOT(rotate_left()));
add_action("rotate_right", SLOT(rotate_right()));
add_action("jump_back", SLOT(jump_back()));
add_action("jump_forward", SLOT(jump_forward()));
// prints the string representation of a key
// cerr << QKeySequence(Qt::Key_Equal).toString().toUtf8().constData() << endl;
......@@ -117,6 +121,55 @@ void Canvas::add_action(const char *action, const char *slot) {
}
}
void Canvas::store_jump(int page) {
map<int,list<int>::iterator>::iterator it = jump_map.find(page);
if (it != jump_map.end()) {
jumplist.erase(it->second);
}
jumplist.push_back(page);
jump_map[page] = --jumplist.end();
cur_jump_pos = jumplist.end();
// cerr << "jumplist: ";
// for (list<int>::iterator it = jumplist.begin(); it != jumplist.end(); ++it) {
// if (it == cur_jump_pos) {
// cerr << "*";
// }
// cerr << *it << " ";
// }
// cerr << endl;
}
void Canvas::clear_jumps() {
jumplist.clear();
jump_map.clear();
cur_jump_pos = jumplist.end();
}
void Canvas::jump_back() {
if (cur_jump_pos == jumplist.begin()) {
return;
}
if (cur_jump_pos == jumplist.end()) {
store_jump(cur_layout->get_page());
--cur_jump_pos;
}
--cur_jump_pos;
if (cur_layout->scroll_page(*cur_jump_pos, false)) {
update();
}
}
void Canvas::jump_forward() {
if (cur_jump_pos == jumplist.end() || cur_jump_pos == --jumplist.end()) {
return;
}
++cur_jump_pos;
if (cur_layout->scroll_page(*cur_jump_pos, false)) {
update();
}
}
const Layout *Canvas::get_layout() const {
return cur_layout;
}
......@@ -162,7 +215,9 @@ void Canvas::mousePressEvent(QMouseEvent *event) {
void Canvas::mouseReleaseEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
if (mx_down == event->x() && my_down == event->y()) {
int page = cur_layout->get_page();
if (cur_layout->click_mouse(mx_down, my_down)) {
store_jump(page); // store old position if a clicked link moved the view
update();
}
}
......@@ -258,13 +313,17 @@ void Canvas::page_down() {
}
void Canvas::page_first() {
int page = cur_layout->get_page();
if (cur_layout->scroll_page(-1, false)) {
store_jump(page);
update();
}
}
void Canvas::page_last() {
int page = cur_layout->get_page();
if (cur_layout->scroll_page(viewer->get_res()->get_page_count(), false)) {
store_jump(page);
update();
}
}
......@@ -393,7 +452,9 @@ void Canvas::search() {
void Canvas::next_hit() {
if (cur_layout->get_search_visible()) {
int page = cur_layout->get_page();
if (cur_layout->advance_hit()) {
store_jump(page);
update();
}
}
......@@ -401,7 +462,9 @@ void Canvas::next_hit() {
void Canvas::previous_hit() {
if (cur_layout->get_search_visible()) {
int page = cur_layout->get_page();
if (cur_layout->advance_hit(false)) {
store_jump(page);
update();
}
}
......@@ -409,7 +472,9 @@ void Canvas::previous_hit() {
void Canvas::next_invisible_hit() {
if (cur_layout->get_search_visible()) {
int page = cur_layout->get_page();
if (cur_layout->advance_invisible_hit()) {
store_jump(page);
update();
}
}
......@@ -417,7 +482,9 @@ void Canvas::next_invisible_hit() {
void Canvas::previous_invisible_hit() {
if (cur_layout->get_search_visible()) {
int page = cur_layout->get_page();
if (cur_layout->advance_invisible_hit(false)) {
store_jump(page);
update();
}
}
......@@ -452,9 +519,11 @@ void Canvas::page_rendered(int page) {
}
void Canvas::goto_page() {
int old_page = cur_layout->get_page();
int page = goto_line->text().toInt() - 1;
goto_line->hide();
if (cur_layout->scroll_page(page, false)) {
store_jump(old_page);
update();
}
}
......
......@@ -28,6 +28,9 @@ public:
bool is_valid() const;
void reload(bool clamp);
void store_jump(int page);
void clear_jumps();
const Layout *get_layout() const;
protected:
......@@ -78,6 +81,8 @@ private slots:
void focus_goto();
void rotate_left();
void rotate_right();
void jump_back();
void jump_forward();
private:
void add_action(const char *action, const char *slot);
......@@ -90,6 +95,10 @@ private:
GotoLine *goto_line;
std::list<int> jumplist;
std::map<int,std::list<int>::iterator> jump_map;
std::list<int>::iterator cur_jump_pos;
int mx, my;
int mx_down, my_down;
......
......@@ -66,6 +66,8 @@ CFG::CFG() :
keys["focus_goto"] = QStringList() << "Ctrl+G";
keys["rotate_left"] = QStringList() << "U";
keys["rotate_right"] = QStringList() << "I";
keys["jump_back"] = QStringList() << "Ctrl+O" << "Alt+Left";
keys["jump_forward"] = QStringList() << "Ctrl+I" << "Alt+Right";
// viewer keys
keys["toggle_fullscreen"] = QStringList() << "F";
keys["close_search"] = QStringList() << "Esc";
......
......@@ -247,6 +247,7 @@ void SearchBar::set_text() {
worker->stop = true;
search_mutex.unlock();
viewer->get_canvas()->store_jump(start_page);
viewer->get_canvas()->setFocus(Qt::OtherFocusReason);
}
......
......@@ -207,6 +207,10 @@ void Viewer::open() {
}
}
#endif
// clear the jumplist - it's not useful in a different file
canvas->clear_jumps();
setWindowTitle(QString::fromUtf8("%1 \u2014 katarakt").arg(info.fileName()));
reload();
}
......
Supports Markdown
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