Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / XGUI / XGUI_Tools.cpp
1 #include "XGUI_Tools.h"
2
3 #include <QDir>
4
5 //******************************************************************
6 QString dir(const QString& path, bool isAbs)
7 {
8   QDir aDir = QFileInfo(path).dir();
9   QString dirPath = isAbs ? aDir.absolutePath() : aDir.path();
10   if (dirPath == QString("."))
11     dirPath = QString();
12   return dirPath;
13 }
14
15 //******************************************************************
16 QString file(const QString& path, bool withExt)
17 {
18   QString fPath = path;
19   while(!fPath.isEmpty() && (fPath[fPath.length() - 1] == '\\' || fPath[fPath.length() - 1] == '/'))
20     fPath.remove(fPath.length() - 1, 1);
21
22   if (withExt)
23     return QFileInfo(fPath).fileName();
24   else
25     return QFileInfo(fPath).completeBaseName();
26 }
27
28 //******************************************************************
29 QString extension(const QString& path, bool full)
30 {
31   return full ? QFileInfo(path).completeSuffix() : QFileInfo(path).suffix();
32 }
33
34 //******************************************************************
35 QString addSlash(const QString& path)
36 {
37   QString res = path;
38   if (!res.isEmpty() && res.at(res.length() - 1) != QChar('/')
39       && res.at(res.length() - 1) != QChar('\\'))
40     res += QDir::separator();
41   return res;
42 }
43
44 //******************************************************************
45 QRect makeRect(const int x1, const int y1, const int x2, const int y2)
46 {
47   return QRect(qMin(x1, x2), qMin(y1, y2), qAbs(x2 - x1), qAbs(y2 - y1));
48 }