Commit ad8d57e5 authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Implement focus next invisible search hit.

parent 704606fd
......@@ -54,6 +54,8 @@ Canvas::Canvas(Viewer *v, QWidget *parent) :
add_action("search", SLOT(search()));
add_action("next_hit", SLOT(next_hit()));
add_action("previous_hit", SLOT(previous_hit()));
add_action("next_invisible_hit", SLOT(next_invisible_hit()));
add_action("previous_invisible_hit", SLOT(previous_invisible_hit()));
add_action("rotate_left", SLOT(rotate_left()));
add_action("rotate_right", SLOT(rotate_right()));
......@@ -315,6 +317,20 @@ void Canvas::previous_hit() {
}
}
void Canvas::next_invisible_hit() {
if (layout->get_search_visible()) {
layout->advance_invisible_hit();
update();
}
}
void Canvas::previous_invisible_hit() {
if (layout->get_search_visible()) {
layout->advance_invisible_hit(false);
update();
}
}
void Canvas::focus_goto() {
goto_line->setFocus();
goto_line->setText(QString::number(layout->get_page() + 1));
......
......@@ -68,6 +68,8 @@ private slots:
void search();
void next_hit();
void previous_hit();
void next_invisible_hit();
void previous_invisible_hit();
void focus_goto();
void rotate_left();
void rotate_right();
......
......@@ -48,6 +48,8 @@ CFG::CFG() :
keys["search"] = QStringList() << "/";
keys["next_hit"] = QStringList() << "N";
keys["previous_hit"] = QStringList() << "Shift+N";
keys["next_invisible_hit"] = QStringList() << "Ctrl+N";
keys["previous_invisible_hit"] = QStringList() << "Ctrl+Shift+N";
keys["rotate_left"] = QStringList() << "U";
keys["rotate_right"] = QStringList() << "I";
// viewer keys
......
......@@ -69,6 +69,8 @@ KEY BINDINGS
Show search bar
*n*, *N* ::
Focus next/previous search hit
*\^n*, *^N* ::
Focus next/previous search hit that is currently not visible
*u*, *i* ::
Rotate pages left/right
......
......@@ -186,6 +186,7 @@ int PresentationLayout::calculate_fit_width(int page) {
}
void PresentationLayout::render(QPainter *painter) {
// TODO duplicate code
int page_width = width, page_height = height;
int center_x = 0, center_y = 0;
......@@ -286,6 +287,17 @@ void PresentationLayout::advance_hit(bool forward) {
view_hit();
}
void PresentationLayout::advance_invisible_hit(bool forward) {
if (forward) {
hit_it = hits[hit_page]->end();
--hit_it;
} else {
hit_it = hits[hit_page]->begin();
}
Layout::advance_hit(forward);
view_hit();
}
void PresentationLayout::view_hit() {
scroll_page(hit_page, false);
}
......@@ -698,7 +710,59 @@ void GridLayout::advance_hit(bool forward) {
view_hit();
}
void GridLayout::advance_invisible_hit(bool forward) {
QRect r;
list<Result>::const_iterator it = hit_it;
do {
Layout::advance_hit(forward);
r = get_hit_rect();
if (r.x() < 0 || r.y() < 0 ||
r.x() + r.width() >= width ||
r.y() + r.height() >= height) {
break; // TODO always breaks for boxes larger than the viewport
}
} while (it != hit_it);
view_hit(r);
}
void GridLayout::view_hit() {
QRect r = get_hit_rect();
view_hit(r);
}
void GridLayout::view_hit(const QRect &r) {
// move view horizontally
if (r.width() <= width * (1 - 2 * search_padding)) {
if (r.x() < width * search_padding) {
scroll_smooth(width * search_padding - r.x(), 0);
} else if (r.x() + r.width() > width * (1 - search_padding)) {
scroll_smooth(width * (1 - search_padding) - r.x() - r.width(), 0);
}
} else {
int center = (width - r.width()) / 2;
if (center < 0) {
center = 0;
}
scroll_smooth(center - r.x(), 0);
}
// vertically
if (r.height() <= height * (1 - 2 * search_padding)) {
if (r.y() < height * search_padding) {
scroll_smooth(0, height * search_padding - r.y());
} else if (r.y() + r.height() > height * (1 - search_padding)) {
scroll_smooth(0, height * (1 - search_padding) - r.y() - r.height());
}
} else {
int center = (height - r.height()) / 2;
if (center < 0) {
center = 0;
}
scroll_smooth(0, center - r.y());
}
}
QRect GridLayout::get_hit_rect() {
// calculate offsets
int page_width = res->get_page_width(hit_page) * size;
int page_height = ROUND(res->get_page_height(hit_page) * size);
......@@ -729,37 +793,9 @@ void GridLayout::view_hit() {
}
}
// get search rect coordinates relative to the current view
QRect r = hit_it->scale_translate(size,
return hit_it->scale_translate(size,
res->get_page_width(hit_page), res->get_page_height(hit_page),
wpos + center_x, hpos + center_y, res->get_rotation());
// move view horizontally
if (r.width() <= width * (1 - 2 * search_padding)) {
if (r.x() < width * search_padding) {
scroll_smooth(width * search_padding - r.x(), 0);
} else if (r.x() + r.width() > width * (1 - search_padding)) {
scroll_smooth(width * (1 - search_padding) - r.x() - r.width(), 0);
}
} else {
int center = (width - r.width()) / 2;
if (center < 0) {
center = 0;
}
scroll_smooth(center - r.x(), 0);
}
// vertically
if (r.height() <= height * (1 - 2 * search_padding)) {
if (r.y() < height * search_padding) {
scroll_smooth(0, height * search_padding - r.y());
} else if (r.y() + r.height() > height * (1 - search_padding)) {
scroll_smooth(0, height * (1 - search_padding) - r.y() - r.height());
}
} else {
int center = (height - r.height()) / 2;
if (center < 0) {
center = 0;
}
scroll_smooth(0, center - r.y());
}
}
pair<int,QPointF> GridLayout::get_page_at(int mx, int my) {
......
......@@ -31,6 +31,7 @@ public:
virtual void set_hits(int page, std::list<Result> *l);
virtual void set_search_visible(bool visible);
virtual void advance_hit(bool forward = true);
virtual void advance_invisible_hit(bool forward = true) = 0;
virtual bool click_mouse(int mx, int my);
virtual bool goto_page_at(int mx, int my);
......@@ -73,6 +74,7 @@ public:
void render(QPainter *painter);
void advance_hit(bool forward = true);
void advance_invisible_hit(bool forward = true);
bool click_mouse(int mx, int my);
......@@ -99,6 +101,7 @@ public:
void render(QPainter *painter);
void advance_hit(bool forward = true);
void advance_invisible_hit(bool forward = true);
bool click_mouse(int mx, int my);
bool goto_page_at(int mx, int my);
......@@ -109,6 +112,8 @@ private:
void initialize(int columns);
void set_constants();
void view_hit();
void view_hit(const QRect &r);
QRect get_hit_rect();
std::pair<int,QPointF> get_page_at(int x, int y);
Grid *grid;
......
......@@ -34,6 +34,8 @@ quit=Q, "W,E,E,E"
search=/
next_hit=N
previous_hit=Shift+N
next_invisible_hit=Ctrl+N
previous_invisible_hit=Ctrl+Shift+N
rotate_left=U
rotate_right=I
toggle_fullscreen=F
......
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