source_correlate.cpp 1.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#include "source_correlate.h"

#include "../viewer.h"
#include "../canvas.h"
#include "../layout/layout.h"
#include "../resourcemanager.h"

#include <QUrl>
#include <QFileInfo>

using namespace std;

Philipp Erhardt's avatar
Philipp Erhardt committed
13
14
SourceCorrelate::SourceCorrelate(Viewer *viewer) :
		QDBusAbstractAdaptor(viewer), viewer(viewer) {
15
16
	connect(viewer->get_canvas(), SIGNAL(synchronize_editor(int, int, int)),
	        this, SLOT(emit_edit_signal(int, int, int)));
Philipp Erhardt's avatar
Philipp Erhardt committed
17
}
18

Philipp Erhardt's avatar
Philipp Erhardt committed
19
20
void SourceCorrelate::view(QString filename, int page, double x, double y) {
	if (page < 0) {
21
		return;
Philipp Erhardt's avatar
Philipp Erhardt committed
22
23
	}

24
25
26
27
28
29
30
31
32
33
34
35
	QFileInfo oldFile = QFileInfo(viewer->get_res()->get_file());
	QFileInfo newFile = QFileInfo(filename);
	QUrl url(filename);
	if ((url.isLocalFile() || url.isRelative())
	    && newFile.canonicalFilePath() != oldFile.canonicalFilePath()) {
		// only open, if file is different from the already loaded one
		viewer->open(filename);
	}

	// needed to add an entry to the jump list
	int current_page = viewer->get_canvas()->get_layout()->get_page();

36
37
38
	if (viewer->get_canvas()->get_layout()->goto_position(page, QPointF(x, y))) {
		viewer->update();
	}
39
40
41
	viewer->get_res()->store_jump(current_page);
}

Philipp Erhardt's avatar
Philipp Erhardt committed
42
void SourceCorrelate::emit_edit_signal(int page, int x, int y) {
43
	QString file = viewer->get_res()->get_file();
Philipp Erhardt's avatar
Philipp Erhardt committed
44
#ifdef DEBUG
45
	qDebug("Emitting the edit signal");
Philipp Erhardt's avatar
Philipp Erhardt committed
46
#endif
47
48
	emit edit(file, page, x, y);
}