diff -Naur original/filechooser.cpp new/filechooser.cpp --- original/filechooser.cpp 2007-06-05 20:44:16.000000000 +0200 +++ new/filechooser.cpp 2008-01-26 11:38:48.000000000 +0100 @@ -10,7 +10,8 @@ ***************************************************************************/ #include "filechooser.h" -#include +#include +#include FileChooser::FileChooser( QWidget *parent, QString name) : QDialog( parent) @@ -48,3 +49,45 @@ } } +QString FileChooser::relativePath(const QString basepath, const QString & file) +{ + + QFileInfo fi(file); + QString filename = fi.fileName(); + QString path = fi.path(); + QStringList basedirs = basepath.split("/"); + QStringList dirs = path.split("/"); + //QStringList basedirs = QStringList::split("/", basepath, false); + //QStringList dirs = QStringList::split("/", path, false); + + uint nDirs = dirs.count(); + + while ( dirs.count() > 0 && basedirs.count() > 0 && dirs[0] == basedirs[0] ) + { + dirs.pop_front(); + basedirs.pop_front(); + } + + if (nDirs != dirs.count() ) + { + path = dirs.join("/"); + + if (basedirs.count() > 0) + { + for (uint j=0; j < basedirs.count(); ++j) + { + path = "../" + path; + } + } + + if ( path.length()>0 && path.right(1) != "/" ) path = path + "/"; + } + else + { + path = fi.path(); + } + + return path; +} + + diff -Naur original/filechooser.h new/filechooser.h --- original/filechooser.h 2007-06-05 20:44:24.000000000 +0200 +++ new/filechooser.h 2008-01-26 11:31:19.000000000 +0100 @@ -23,6 +23,7 @@ Ui::FileChooser ui; QString fileName() const; QString filter,dir; + QString relativePath(const QString basepath, const QString & file); public slots: void setDir( const QString &di ); diff -Naur original/texmaker.cpp new/texmaker.cpp --- original/texmaker.cpp 2007-06-05 20:51:01.000000000 +0200 +++ new/texmaker.cpp 2008-01-26 11:49:52.000000000 +0100 @@ -2743,7 +2743,7 @@ { QString fn=sfDlg->fileName(); QFileInfo fi(fn); - InsertTag("\\includegraphics[scale=1]{"+fi.baseName()+"."+fi.completeSuffix()+"} ",26,0); + InsertTag("\\includegraphics[scale=1]{"+sfDlg->relativePath(currentDir, fn)+fi.baseName()+"."+fi.completeSuffix()+"} ",26,0); } } @@ -2763,7 +2763,7 @@ { QString fn=sfDlg->fileName(); QFileInfo fi(fn); -InsertTag("\\include{"+fi.baseName()+"}",9,0); +InsertTag("\\include{"+sfDlg->relativePath(currentDir, fn)+fi.baseName()+"}",9,0); } UpdateStructure(); } @@ -2784,7 +2784,7 @@ { QString fn=sfDlg->fileName(); QFileInfo fi(fn); -InsertTag("\\input{"+fi.baseName()+"}",7,0); +InsertTag("\\input{"+sfDlg->relativePath(currentDir, fn)+fi.baseName()+"}",7,0); } UpdateStructure(); }