mirror of
https://invent.kde.org/graphics/okular
synced 2024-10-06 16:09:12 +00:00
Make Okular able to distinguish the LilyPond "Point and click" links,
and make them act as source references when activated. FEATURE: 163569 svn path=/trunk/KDE/kdegraphics/okular/; revision=863572
This commit is contained in:
parent
6e48adde56
commit
d3b0b62cfc
|
@ -14,6 +14,7 @@
|
|||
|
||||
// local includes
|
||||
#include "document.h"
|
||||
#include "sourcereference_p.h"
|
||||
#include "sound.h"
|
||||
|
||||
using namespace Okular;
|
||||
|
@ -174,6 +175,12 @@ Action::ActionType BrowseAction::actionType() const
|
|||
QString BrowseAction::actionTip() const
|
||||
{
|
||||
Q_D( const Okular::BrowseAction );
|
||||
QString source;
|
||||
int row = 0, col = 0;
|
||||
if ( extractLilyPondSourceReference( d->m_url, &source, &row, &col ) )
|
||||
{
|
||||
return sourceReferenceToolTip( source, row, col );
|
||||
}
|
||||
return d->m_url;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
#include "scripter.h"
|
||||
#include "settings.h"
|
||||
#include "sourcereference.h"
|
||||
#include "sourcereference_p.h"
|
||||
#include "view.h"
|
||||
#include "view_p.h"
|
||||
|
||||
|
@ -2740,9 +2741,16 @@ void Document::processAction( const Action * action )
|
|||
|
||||
case Action::Browse: {
|
||||
const BrowseAction * browse = static_cast< const BrowseAction * >( action );
|
||||
QString lilySource;
|
||||
int lilyRow = 0, lilyCol = 0;
|
||||
// if the url is a mailto one, invoke mailer
|
||||
if ( browse->url().startsWith( "mailto:", Qt::CaseInsensitive ) )
|
||||
KToolInvocation::invokeMailer( browse->url() );
|
||||
else if ( extractLilyPondSourceReference( browse->url(), &lilySource, &lilyRow, &lilyCol ) )
|
||||
{
|
||||
const SourceReference ref( lilySource, lilyRow, lilyCol );
|
||||
processSourceReference( &ref );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString url = browse->url();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
|
||||
* Copyright (C) 2007,2008 by Pino Toscano <pino@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
|
@ -8,8 +8,10 @@
|
|||
***************************************************************************/
|
||||
|
||||
#include "sourcereference.h"
|
||||
#include "sourcereference_p.h"
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <klocale.h>
|
||||
|
||||
using namespace Okular;
|
||||
|
||||
|
@ -54,3 +56,37 @@ int SourceReference::column() const
|
|||
return d->column;
|
||||
}
|
||||
|
||||
bool Okular::extractLilyPondSourceReference( const QString &url, QString *file, int *row, int *col )
|
||||
{
|
||||
if ( !url.startsWith( QLatin1String( "textedit://" ) ) )
|
||||
return false;
|
||||
|
||||
*row = 0;
|
||||
*col = 0;
|
||||
int lilyChar = 0;
|
||||
typedef int *IntPtr;
|
||||
const IntPtr int_data[] = { row, &lilyChar, col };
|
||||
int int_index = sizeof( int_data ) / sizeof( int* ) - 1;
|
||||
int index_last = -1;
|
||||
int index = url.lastIndexOf( QLatin1Char( ':' ), index_last );
|
||||
while ( index != -1 && int_index >= 0 )
|
||||
{
|
||||
// read the current "chunk"
|
||||
const QStringRef ref = url.midRef( index + 1, index_last - index - 1 );
|
||||
*int_data[ int_index ] = QString::fromRawData( ref.data(), ref.count() ).toInt();
|
||||
// find the previous "chunk"
|
||||
index_last = index;
|
||||
index = url.lastIndexOf( QLatin1Char( ':' ), index_last - 1 );
|
||||
--int_index;
|
||||
}
|
||||
// NOTE: 11 is the length of "textedit://"
|
||||
*file = url.mid( 11, index_last != -1 ? index_last - 11 : -1 );
|
||||
return true;
|
||||
}
|
||||
|
||||
QString Okular::sourceReferenceToolTip( const QString &source, int row, int col )
|
||||
{
|
||||
Q_UNUSED( row );
|
||||
Q_UNUSED( col );
|
||||
return i18nc( "'source' is a source file", "Source: %1", source );
|
||||
}
|
||||
|
|
23
core/sourcereference_p.h
Normal file
23
core/sourcereference_p.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef OKULAR_SOURCEREFERENCE_P_H
|
||||
#define OKULAR_SOURCEREFERENCE_P_H
|
||||
|
||||
class QString;
|
||||
|
||||
namespace Okular
|
||||
{
|
||||
|
||||
bool extractLilyPondSourceReference( const QString &url, QString *file, int *row, int *col );
|
||||
QString sourceReferenceToolTip( const QString &source, int row, int col );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue