Commit 79f7f38e authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Implement viewing/sending precise pos for synctex

parent 51237a59
......@@ -195,11 +195,12 @@ void Canvas::mousePressEvent(QMouseEvent *event) {
void Canvas::mouseReleaseEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton && event->modifiers() == Qt::ControlModifier) {
// emit synctex signal
pair<int, QPointF> location = cur_layout->get_location_at(event->x(), event->y());
// scale from [0,1] to points
location.second.rx() *= viewer->get_res()->get_page_width(location.first, false);
location.second.ry() *= viewer->get_res()->get_page_height(location.first, false);
int page = cur_layout->get_page();
// FIXME Really get the page that was clicked on
// FIXME Get coordinates
emit synchronize_editor(page, 0, 0);
emit synchronize_editor(location.first, (int) ROUND(location.second.x()), (int) ROUND(location.second.y()));
} else if (click_link_button != Qt::NoButton && event->button() == click_link_button) {
if (mx_down == event->x() && my_down == event->y()) {
int page = cur_layout->get_page();
......
......@@ -17,7 +17,7 @@ SourceCorrelate::SourceCorrelate(Viewer *viewer)
this, SLOT(emit_edit_signal(int, int, int)));
}
void SourceCorrelate::view(QString filename, int page, int x, int y)
void SourceCorrelate::view(QString filename, int page, double x, double y)
{
if (page < 0)
return;
......@@ -34,11 +34,10 @@ void SourceCorrelate::view(QString filename, int page, int x, int y)
// needed to add an entry to the jump list
int current_page = viewer->get_canvas()->get_layout()->get_page();
viewer->get_canvas()->get_layout()->scroll_page(page, false);
// FIXME scroll to offset
if (viewer->get_canvas()->get_layout()->goto_position(page, QPointF(x, y))) {
viewer->update();
}
viewer->get_res()->store_jump(current_page);
viewer->get_canvas()->repaint();
viewer->repaint();
}
void SourceCorrelate::emit_edit_signal(int page, int x, int y)
......
......@@ -19,7 +19,7 @@ public slots:
* The document will not be reloaded if the filename is the same as
* the currently loaded file.
*/
void view(QString filename, int page, int x, int y);
void view(QString filename, int page, double x, double y);
signals:
/** Emitted, if the user requests to edit the source code for a
......@@ -33,7 +33,7 @@ private slots:
void emit_edit_signal(int page, int x, int y);
private:
Viewer *viewer;
Viewer *viewer;
};
#endif /* SOURCE_CORRELATE_H */
......@@ -559,10 +559,10 @@ pair<int, QPointF> GridLayout::get_location_at(int mx, int my) {
bool GridLayout::goto_link_destination(const Poppler::LinkDestination &link) {
int link_page = link.pageNumber() - 1;
float w = res->get_page_width(link_page);
float h = res->get_page_height(link_page);
float w = res->get_page_width(link_page, false);
float h = res->get_page_height(link_page, false);
const QPointF link_point = rotate_point(QPointF(link.left(), link.top()) * h, w, h, res->get_rotation());
const QPointF link_point = rotate_point(QPointF(link.left() * w, link.top() * h), w, h, res->get_rotation());
QPoint p = get_target_page_distance(link_page);
if (link.isChangeLeft()) {
......@@ -574,6 +574,18 @@ bool GridLayout::goto_link_destination(const Poppler::LinkDestination &link) {
return view_point(p);
}
bool GridLayout::goto_position(int page, QPointF pos) {
float w = res->get_page_width(page, false);
float h = res->get_page_height(page, false);
pos = rotate_point(pos, w, h, res->get_rotation());
QPoint p = get_target_page_distance(page);
p.rx() += pos.x() * size - width / 2;
p.ry() += pos.y() * size - height / 2;
return view_point(p);
}
bool GridLayout::goto_page_at(int mx, int my) {
pair<int,QPointF> page = get_location_at(mx, my);
......
......@@ -31,6 +31,7 @@ public:
std::pair<int, QPointF> get_location_at(int pixel_x, int pixel_y);
bool goto_link_destination(const Poppler::LinkDestination &link);
bool goto_position(int page, QPointF pos);
bool goto_page_at(int mx, int my);
bool page_visible(int p) const;
......
......@@ -193,6 +193,10 @@ bool Layout::goto_link_destination(const Poppler::LinkDestination &link) {
return scroll_page(link.pageNumber() - 1, false);
}
bool Layout::goto_position(int page, QPointF /*pos*/) {
return scroll_page(page, false);
}
bool Layout::goto_page_at(int /*mx*/, int /*my*/) {
return false;
}
......
......@@ -41,6 +41,7 @@ public:
virtual std::pair<int, QPointF> get_location_at(int px, int py) = 0;
virtual bool goto_link_destination(const Poppler::LinkDestination &link);
virtual bool goto_position(int page, QPointF pos);
virtual bool goto_page_at(int mx, int my);
virtual bool activate_link(int page, float x, float y);
......
......@@ -20,11 +20,11 @@ const QPointF rotate_point(const QPointF &point, float w, float h, int rotation)
if (rotation == 0) {
return point;
} else if (rotation == 1) {
return QPointF(w - point.y(), point.x());
return QPointF(h - point.y(), point.x());
} else if (rotation == 2) {
return QPointF(w - point.x(), h - point.y());
} else {
return QPointF(point.y(), h - point.x());
return QPointF(point.y(), w - point.x());
}
}
......
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