[Okular-devel] idea for activation of inverse search
Jochen Trumpf
Jochen.Trumpf at anu.edu.au
Fri Oct 31 12:15:55 CET 2008
Hi Pino et al.,
I have been thinking a bit about a good activation method for source
references in okular. I think, the shift+left click is generally okay, but
what I would expect to happen in dvi documents, and also in pdf documents
generated from latex (either with pdfsync or synctex), is that such a click
activates the closest source link, even if the point I clicked is not in the
direct vicinity of any such link.
So, probably something like
const ObjectRect * Page::closestObjectRect( ObjectRect::ObjectType type,
double x, double y, double xScale, double yScale ) const
{
QLinkedList< ObjectRect * >::const_iterator it = m_rects.begin(), end =
m_rects.end();
double bestdist = 1000.0; // effectively infinite
ObjectRect *bestrect = 0;
double temp;
for( ; it != end; ++it )
if ( ( (*it)->objectType() == type ) && ( (temp = (*it)-
>distTo(x,y,xScale,yScale)) < bestdist ) )
{
bestdist = temp;
bestrect = *it;
}
return bestrect;
}
with a corresponding implementation of (an overloaded virtual?)
double SourceRefObjectRect::distTo( double, double y, double , double ) const
{
return ( pow( y - m_point.y, 2 ) );
}
Here is a small problem I ran into: this version of distTo does not use x, but
works well for dvi, since there the source links are always centered at x=0.5
in the middle of the line (the DVI_SourceFileAnchors only have vertical
information -- why?). I.e. I do not have to hit close to the center of the
line and still the best link is selected. However, the current pdfsync anchors
also have horizontal information (and I guess the synctex ones will as well).
So, you either need to check the type of file/source anchors in the distTo
function or you need to modify the DVI_SourceFileAnchors.
I also couldn't figure out if I should use xScale and yScale here. It seems
superfluous to me, but maybe I overlooked something.
I don't know if source links are used in other document types and whether
there you wouldn't want the closest link to open. If that is the case, you
could make the choice of objectRect vs. closestObjectRect configurable (per
backend?).
Thanks BTW for the editor config dialog! I had been waiting for that :-) In
case you want to add an emacs/emacsclient default there: the commandline would
be
emacsclient -a emacs --no-wait +%l %f
(this uses emacsclient to open in a running emacs with activated emacs-server,
if that fails it starts a new emacs)
I hope you find this useful. Please cc me directly in replies, I am not
subscribed to this list.
Cheers,
Jochen
More information about the Okular-devel
mailing list