| 1 | /*********************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2010-2017 Innocent De Marchi <[email protected]> |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | ***********************************************************************/ |
| 19 | //#include <QTest> |
| 20 | |
| 21 | #include "funcions.h" |
| 22 | #include "constants.h" |
| 23 | |
| 24 | |
| 25 | |
| 26 | /* |
| 27 | Directoris linux |
| 28 | 21/04/11 |
| 29 | Modificat per permetre la coexistència de l'aplicació instal·lada |
| 30 | i el codi font |
| 31 | */ |
| 32 | QString directoriLinux(){ |
| 33 | QDir dirArxiu; |
| 34 | if (dirArxiu.exists(QCoreApplication::applicationDirPath()+ QDir().separator()+ |
| 35 | "images")){ |
| 36 | return QCoreApplication::applicationDirPath(); |
| 37 | } |
| 38 | else if (dirArxiu.exists(DIRECTORIS_LINUX)){ |
| 39 | return DIRECTORIS_LINUX; |
| 40 | } |
| 41 | else return QCoreApplication::applicationDirPath(); |
| 42 | /* |
| 43 | QString dirInicial=QCoreApplication::applicationDirPath().replace(DIRECTORIS_LINUX_PROGRAMA,""); |
| 44 | dirInicial=dirInicial.append(DIRECTORIS_LINUX_AUXILIARS); |
| 45 | QDir dirArxiu; |
| 46 | if (dirArxiu.exists(DIRECTORIS_LINUX)){ |
| 47 | return DIRECTORIS_LINUX; |
| 48 | } |
| 49 | else if (dirArxiu.exists(dirInicial)){ |
| 50 | return dirInicial; |
| 51 | } |
| 52 | else return QCoreApplication::applicationDirPath(); |
| 53 | */ |
| 54 | } |
| 55 | |
| 56 | |
| 57 | /* |
| 58 | Número de fitxes de la configuració passada per parámetre |
| 59 | */ |
| 60 | int numeroConfiguracio(QString config){ |
| 61 | int numero=0; |
| 62 | for(int llista=0 ; llista<config.size();++llista){ |
| 63 | numero=numero+config.mid(llista,1).toInt(); |
| 64 | } |
| 65 | // qDebug("numero configuracio %d",numero); |
| 66 | return numero; |
| 67 | } |
| 68 | |
| 69 | QString coordenadesAMoviment(QString coordenades){ |
| 70 | QRegExp coord(".(\\d+),(\\d+). -> .(\\d+),(\\d+)."); |
| 71 | if (coord.exactMatch(coordenades)){ |
| 72 | int fitxaBotada=((coord.cap(1).toInt()+coord.cap(3).toInt())/2)*100+ |
| 73 | ((coord.cap(2).toInt()+coord.cap(4).toInt())/2); |
| 74 | return QString("%1 %2 %3").arg(coord.cap(1).toInt()*100+coord.cap(2).toInt()). |
| 75 | arg(fitxaBotada). |
| 76 | arg(coord.cap(3).toInt()*100+coord.cap(4).toInt()); |
| 77 | } |
| 78 | else { |
| 79 | return QString("");} |
| 80 | } |
| 81 | |
| 82 | /* fa una pausa en milisegons*/ |
| 83 | //void pausa(int temps){ |
| 84 | // QTest::qSleep(temps); |
| 85 | // qApp->processEvents(); |
| 86 | //} |