compile
[kdegraphics.git] / okular / core / sourcereference.cpp
blob7090b83fe59644fc60934ef882c3a9f6f79454a5
1 /***************************************************************************
2 * Copyright (C) 2007,2008 by Pino Toscano <pino@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #include "sourcereference.h"
11 #include "sourcereference_p.h"
13 #include <QtCore/QString>
14 #include <klocale.h>
16 using namespace Okular;
18 class SourceReference::Private
20 public:
21 Private()
22 : row( 0 ), column( 0 )
26 QString filename;
27 int row;
28 int column;
31 SourceReference::SourceReference( const QString &fileName, int row, int column )
32 : d( new Private )
34 d->filename = fileName;
35 d->row = row;
36 d->column = column;
39 SourceReference::~SourceReference()
41 delete d;
44 QString SourceReference::fileName() const
46 return d->filename;
49 int SourceReference::row() const
51 return d->row;
54 int SourceReference::column() const
56 return d->column;
59 bool Okular::extractLilyPondSourceReference( const QString &url, QString *file, int *row, int *col )
61 if ( !url.startsWith( QLatin1String( "textedit://" ) ) )
62 return false;
64 *row = 0;
65 *col = 0;
66 int lilyChar = 0;
67 typedef int *IntPtr;
68 const IntPtr int_data[] = { row, &lilyChar, col };
69 int int_index = sizeof( int_data ) / sizeof( int* ) - 1;
70 int index_last = -1;
71 int index = url.lastIndexOf( QLatin1Char( ':' ), index_last );
72 while ( index != -1 && int_index >= 0 )
74 // read the current "chunk"
75 const QStringRef ref = url.midRef( index + 1, index_last - index - 1 );
76 *int_data[ int_index ] = QString::fromRawData( ref.data(), ref.count() ).toInt();
77 // find the previous "chunk"
78 index_last = index;
79 index = url.lastIndexOf( QLatin1Char( ':' ), index_last - 1 );
80 --int_index;
82 // NOTE: 11 is the length of "textedit://"
83 *file = url.mid( 11, index_last != -1 ? index_last - 11 : -1 );
84 return true;
87 QString Okular::sourceReferenceToolTip( const QString &source, int row, int col )
89 Q_UNUSED( row );
90 Q_UNUSED( col );
91 return i18nc( "'source' is a source file", "Source: %1", source );