1.7.6 New features for floatimages and fixes
authorinsilmaril
Tue Jan 03 09:44:41 2006 +0000 (2006-01-03)
changeset 176f75489896084
parent 175 728f51b71e71
child 177 494e8f40f0f7
1.7.6 New features for floatimages and fixes
misc.cpp
misc.h
     1.1 --- a/misc.cpp	Tue Jan 03 09:44:41 2006 +0000
     1.2 +++ b/misc.cpp	Tue Jan 03 09:44:41 2006 +0000
     1.3 @@ -70,127 +70,6 @@
     1.4  	return QPoint ((int) (x),(int) (y));
     1.5  }
     1.6  
     1.7 -QString maskPath(QString p)
     1.8 -{
     1.9 -	// Change " " to "\ " to enable blanks in filenames
    1.10 -	p=p.replace(QChar('&'),"\\&");
    1.11 -	return p.replace(QChar(' '),"\\ ");
    1.12 -}
    1.13 -
    1.14 -QString convertToRel (const QString &src, const QString &dst)
    1.15 -{
    1.16 -	QString s=src;
    1.17 -	QString d=dst;
    1.18 -	int i;
    1.19 -
    1.20 -	if (s==d) 
    1.21 -	{
    1.22 -		// Special case, we just need the name of the file,
    1.23 -		// not the complete path
    1.24 -		i=d.findRev ("/");
    1.25 -		d=d.right (d.length()-i-1);
    1.26 -	} else
    1.27 -	{
    1.28 -		// Find relative path from src to dst
    1.29 -
    1.30 -		// Remove the first "/"
    1.31 -		if (s.section ("/",0,0).isEmpty()) 
    1.32 -		{
    1.33 -			s=s.right (s.length()-1);
    1.34 -			d=d.right (d.length()-1);
    1.35 -		}
    1.36 -		
    1.37 -		// remove identical left parts
    1.38 -		while (s.section("/",0,0) == d.section("/",0,0) ) 
    1.39 -		{
    1.40 -			i=s.find ("/");
    1.41 -			s=s.right (s.length()-i-1);
    1.42 -			d=d.right (d.length()-i-1);
    1.43 -		}
    1.44 -
    1.45 -		int srcsep=s.contains("/");
    1.46 -		int dstsep=d.contains("/");
    1.47 -		if (srcsep >=  dstsep )
    1.48 -		{
    1.49 -			// find path to go up first and then back to dst
    1.50 -			i=1;
    1.51 -			while (i<=srcsep) 
    1.52 -			{
    1.53 -				d="../"+d;
    1.54 -				i++;
    1.55 -			}	
    1.56 -		}
    1.57 -	}	
    1.58 -	return d;
    1.59 -}
    1.60 -
    1.61 -QString makeUniqueDir (QString s)
    1.62 -{
    1.63 -	char *p;
    1.64 -	int bytes=s.length();
    1.65 -	p=(char*) malloc (bytes+1);
    1.66 -	int i;
    1.67 -	for (i=0;i<bytes;i++)
    1.68 -		p[i]=s.at(i).latin1();
    1.69 -	p[bytes]=0;	
    1.70 -	QString r=mkdtemp (p);
    1.71 -	free (p);
    1.72 -	return r;
    1.73 -}
    1.74 -
    1.75 -void removeDir(QDir d)
    1.76 -{
    1.77 -	if (d.path().left(4)!="/tmp")
    1.78 -	{
    1.79 -		// FIXME testing
    1.80 -		qWarning ("misc.cpp::removeDir should remove "+d.path()+" - aborted.");
    1.81 -		return;
    1.82 -	}
    1.83 -
    1.84 -	// Traverse directories
    1.85 -	d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
    1.86 -	const QFileInfoList *dirlist = d.entryInfoList();
    1.87 -	QFileInfoListIterator itdir( *dirlist );
    1.88 -	QFileInfo *fi;
    1.89 -
    1.90 -	while ( (fi = itdir.current()) != 0 ) 
    1.91 -	{
    1.92 -		if (fi->fileName() != "." && fi->fileName() != ".." )
    1.93 -		{
    1.94 -			if ( !d.cd(fi->fileName()) ) 
    1.95 -				qWarning ("removeDir() cannot find the directory "+fi->fileName());
    1.96 -			else 
    1.97 -			{
    1.98 -				// Recursively remove subdirs
    1.99 -				removeDir (d);
   1.100 -				d.cdUp();
   1.101 -			}
   1.102 -		}	
   1.103 -		++itdir;
   1.104 -	}		
   1.105 -	// Traverse files
   1.106 -	d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
   1.107 -	const QFileInfoList *filelist = d.entryInfoList();
   1.108 -	QFileInfoListIterator itfile( *filelist );
   1.109 -
   1.110 -	while ( (fi = itfile.current()) != 0 ) 
   1.111 -	{
   1.112 -		QFile (fi->filePath()).remove();
   1.113 -		
   1.114 -		++itfile;
   1.115 -	}	
   1.116 -
   1.117 -	if (!d.rmdir(d.path()))
   1.118 -		qWarning ("removeDir("+d.path()+") failed!");
   1.119 -}		
   1.120 -
   1.121 -void makeSubDirs (const QString &s)
   1.122 -{
   1.123 -	QDir d(s);
   1.124 -	d.mkdir(s);
   1.125 -	d.mkdir ("images");	
   1.126 -	d.mkdir ("flags");	
   1.127 -}
   1.128  
   1.129  // returns masked "<" ">" "&"
   1.130  QString quotemeta(const QString &s)
   1.131 @@ -286,36 +165,3 @@
   1.132      return s;
   1.133  }	
   1.134  
   1.135 -
   1.136 -
   1.137 -ImagePreview::ImagePreview (QWidget *parent=0): QLabel (parent)
   1.138 -{
   1.139 -}
   1.140 -
   1.141 -void ImagePreview::previewUrl( const QUrl &u )
   1.142 -{
   1.143 -    QString path = u.path();
   1.144 -    QPixmap pix( path );
   1.145 -    if ( pix.isNull() )
   1.146 -        setText( QObject::tr("This is not an image.") );
   1.147 -    else
   1.148 -	{
   1.149 -		float max_w=300;
   1.150 -		float max_h=300;
   1.151 -		float r;
   1.152 -		if (pix.width()>max_w)
   1.153 -		{
   1.154 -			r=max_w / pix.width();
   1.155 -			pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
   1.156 -			// TODO not a resize, but a shrink/enlarge is needed here...
   1.157 -		}
   1.158 -		if (pix.height()>max_h)
   1.159 -		{
   1.160 -			r=max_h / pix.height();
   1.161 -			pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
   1.162 -			// TODO not a resize, but a shrink/enlarge is needed here...
   1.163 -		}
   1.164 -        setPixmap( pix );
   1.165 -	}	
   1.166 -}
   1.167 -
     2.1 --- a/misc.h	Tue Jan 03 09:44:41 2006 +0000
     2.2 +++ b/misc.h	Tue Jan 03 09:44:41 2006 +0000
     2.3 @@ -7,19 +7,12 @@
     2.4  
     2.5  using namespace std;
     2.6  
     2.7 -enum LoadMode {NewMap,ImportAdd,ImportReplace};
     2.8 -enum SaveMode {PartOfMap,CompleteMap,UndoCommand};
     2.9  
    2.10  /////////////////////////////////////////////////////////////////////////////
    2.11  QString qpointToString (const QPoint &p);
    2.12  extern ostream &operator<< (ostream &stream, QPoint const &p);
    2.13  float getAngle(const QPoint &);
    2.14  QPoint normalise (const QPoint &);
    2.15 -QString maskPath (QString );
    2.16 -QString convertToRel (const QString &,const QString &);
    2.17 -QString makeUniqueDir (QString);
    2.18 -void removeDir(QDir);
    2.19 -void makeSubDirs (const QString &);
    2.20  QString quotemeta(const QString&);	
    2.21  int max (int,int);
    2.22  class BranchObj;
    2.23 @@ -46,17 +39,4 @@
    2.24      int indentwidth;
    2.25  };
    2.26  
    2.27 -/////////////////////////////////////////////////////////////////////////////
    2.28 -
    2.29 -#include <qlabel.h>
    2.30 -#include <qfiledialog.h>
    2.31 -#include <qpixmap.h>
    2.32 -
    2.33 -class ImagePreview : public QLabel, public QFilePreview
    2.34 -{
    2.35 -public:
    2.36 -    ImagePreview( QWidget * );
    2.37 -    void previewUrl( const QUrl & );
    2.38 -};
    2.39 -
    2.40  #endif