2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-11-04 21:38:54 +01:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vapplication.h
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-11-04 21:38:54 +01:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-11-04 21:38:54 +01:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-11-04 21:38:54 +01:00
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-11-04 21:38:54 +01:00
|
|
|
|
2013-09-23 14:08:06 +02:00
|
|
|
#ifndef VAPPLICATION_H
|
|
|
|
#define VAPPLICATION_H
|
|
|
|
|
|
|
|
#include <QApplication>
|
2014-03-19 19:27:11 +01:00
|
|
|
#include "../options.h"
|
2014-09-26 19:09:20 +02:00
|
|
|
#include "../widgets/vmaingraphicsview.h"
|
2014-12-04 18:55:49 +01:00
|
|
|
#include "../../libs/qmuparser/qmutranslation.h"
|
2015-02-10 20:27:11 +01:00
|
|
|
#include "vsettings.h"
|
2014-03-19 19:27:11 +01:00
|
|
|
|
2014-07-10 11:36:46 +02:00
|
|
|
class VApplication;// used in define
|
2014-06-08 20:10:57 +02:00
|
|
|
class QUndoStack;
|
|
|
|
class VMainGraphicsView;
|
2014-07-15 15:51:15 +02:00
|
|
|
class VMainGraphicsScene;
|
2014-09-05 10:01:46 +02:00
|
|
|
class VPattern;
|
2014-11-20 13:18:43 +01:00
|
|
|
class QFile;
|
2014-11-28 14:49:06 +01:00
|
|
|
class QLockFile;
|
2014-03-19 19:27:11 +01:00
|
|
|
|
|
|
|
#if defined(qApp)
|
|
|
|
#undef qApp
|
|
|
|
#endif
|
|
|
|
#define qApp (static_cast<VApplication*>(QCoreApplication::instance()))
|
2013-09-23 14:08:06 +02:00
|
|
|
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-27 13:27:26 +01:00
|
|
|
* @brief The VApplication class reimplamentation QApplication class.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
class VApplication : public QApplication
|
|
|
|
{
|
2013-09-23 14:08:06 +02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-03-19 19:27:11 +01:00
|
|
|
VApplication(int &argc, char ** argv);
|
2014-11-20 13:18:43 +01:00
|
|
|
virtual ~VApplication();
|
2014-10-23 11:13:18 +02:00
|
|
|
static void NewValentina(const QString &fileName = QString());
|
2014-07-15 15:51:15 +02:00
|
|
|
static void CheckFactor(qreal &oldFactor, const qreal &Newfactor);
|
2014-06-13 19:02:41 +02:00
|
|
|
virtual bool notify(QObject * receiver, QEvent * event);
|
|
|
|
Unit patternUnit() const;
|
|
|
|
void setPatternUnit(const Unit &patternUnit);
|
|
|
|
MeasurementsType patternType() const;
|
|
|
|
void setPatternType(const MeasurementsType &patternType);
|
2014-07-23 12:04:23 +02:00
|
|
|
|
|
|
|
double toPixel(double val, const Unit &unit) const;
|
|
|
|
double toPixel(double val) const;
|
|
|
|
double fromPixel(double pix, const Unit &unit) const;
|
2014-06-13 19:02:41 +02:00
|
|
|
double fromPixel(double pix) const;
|
2014-07-23 12:04:23 +02:00
|
|
|
|
2015-01-26 16:02:57 +01:00
|
|
|
static bool TryLock(QLockFile *lock);
|
|
|
|
|
2014-06-13 19:02:41 +02:00
|
|
|
static const qreal PrintDPI;
|
|
|
|
QString translationsPath() const;
|
|
|
|
qreal widthMainLine() const;
|
|
|
|
qreal widthHairLine() const;
|
|
|
|
QString VarToUser(const QString &var) const;
|
|
|
|
QString VarFromUser(const QString &var) const;
|
|
|
|
QString GuiText(const QString &measurement) const;
|
|
|
|
QString Description(const QString &measurement) const;
|
|
|
|
QString PostfixOperator(const QString &name) const;
|
2015-02-10 21:09:44 +01:00
|
|
|
|
2014-06-13 19:02:41 +02:00
|
|
|
QString FormulaFromUser(const QString &formula);
|
|
|
|
QString FormulaToUser(const QString &formula);
|
2015-02-10 21:09:44 +01:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
QString LocaleToString(const T &value)
|
|
|
|
{
|
|
|
|
QLocale loc;
|
|
|
|
qApp->getSettings()->GetOsSeparator() ? loc = QLocale::system() : loc = QLocale(QLocale::C);
|
|
|
|
return loc.toString(value);
|
|
|
|
}
|
|
|
|
|
2014-06-13 19:02:41 +02:00
|
|
|
QUndoStack *getUndoStack() const;
|
|
|
|
VMainGraphicsView *getSceneView() const;
|
|
|
|
void setSceneView(VMainGraphicsView *value);
|
|
|
|
QTimer *getAutoSaveTimer() const;
|
|
|
|
void setAutoSaveTimer(QTimer *value);
|
2014-07-08 12:59:50 +02:00
|
|
|
QWidget *getMainWindow() const;
|
|
|
|
void setMainWindow(QWidget *value);
|
2014-07-08 13:26:13 +02:00
|
|
|
bool getOpeningPattern() const;
|
|
|
|
void setOpeningPattern();
|
2014-11-22 17:15:47 +01:00
|
|
|
|
2014-07-10 11:36:46 +02:00
|
|
|
void OpenSettings();
|
2014-11-22 17:15:47 +01:00
|
|
|
VSettings *getSettings();
|
|
|
|
|
2014-07-15 15:51:15 +02:00
|
|
|
VMainGraphicsScene *getCurrentScene() const;
|
|
|
|
void setCurrentScene(VMainGraphicsScene *value);
|
2014-09-05 10:01:46 +02:00
|
|
|
|
|
|
|
void setCurrentDocument(VPattern *doc);
|
|
|
|
VPattern *getCurrentDocument()const;
|
2014-09-08 13:02:14 +02:00
|
|
|
|
|
|
|
static void setOverrideCursor(const QString & pixmapPath, int hotX = -1, int hotY = -1);
|
2014-09-11 18:52:02 +02:00
|
|
|
static void restoreOverrideCursor(const QString & pixmapPath);
|
2014-09-09 15:11:50 +02:00
|
|
|
|
|
|
|
static QStringList LabelLanguages();
|
2014-09-18 11:30:33 +02:00
|
|
|
QString STDescription(const QString &id)const;
|
2014-11-29 13:12:43 +01:00
|
|
|
|
2014-11-20 13:18:43 +01:00
|
|
|
void StartLogging();
|
|
|
|
QTextStream *LogFile();
|
2014-11-15 16:52:27 +01:00
|
|
|
|
2014-11-29 13:12:43 +01:00
|
|
|
|
2014-11-15 16:52:27 +01:00
|
|
|
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
|
|
|
static void DrMingw();
|
|
|
|
void CollectReports() const;
|
2014-11-20 13:18:43 +01:00
|
|
|
#endif // defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
|
|
|
|
2014-11-15 16:52:27 +01:00
|
|
|
private slots:
|
2014-11-20 13:18:43 +01:00
|
|
|
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
2014-11-15 16:52:27 +01:00
|
|
|
void CleanGist() const;
|
2014-11-15 17:29:10 +01:00
|
|
|
#endif // defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
2014-11-20 13:18:43 +01:00
|
|
|
|
2014-03-19 19:27:11 +01:00
|
|
|
private:
|
2014-06-04 13:30:45 +02:00
|
|
|
Q_DISABLE_COPY(VApplication)
|
2014-06-13 19:02:41 +02:00
|
|
|
Unit _patternUnit;
|
|
|
|
MeasurementsType _patternType;
|
|
|
|
qreal _widthMainLine;
|
|
|
|
qreal _widthHairLine;
|
2014-12-04 18:55:49 +01:00
|
|
|
QMap<QString, qmu::QmuTranslation> measurements;
|
|
|
|
QMap<QString, qmu::QmuTranslation> guiTexts;
|
|
|
|
QMap<QString, qmu::QmuTranslation> descriptions;
|
|
|
|
QMap<QString, qmu::QmuTranslation> variables;
|
|
|
|
QMap<QString, qmu::QmuTranslation> functions;
|
|
|
|
QMap<QString, qmu::QmuTranslation> postfixOperators;
|
|
|
|
QMap<QString, qmu::QmuTranslation> stDescriptions;
|
2014-06-13 19:02:41 +02:00
|
|
|
QUndoStack *undoStack;
|
|
|
|
VMainGraphicsView *sceneView;
|
2014-07-15 15:51:15 +02:00
|
|
|
VMainGraphicsScene *currentScene;
|
2014-06-13 19:02:41 +02:00
|
|
|
QTimer *autoSaveTimer;
|
2014-07-08 12:59:50 +02:00
|
|
|
/**
|
|
|
|
* @brief mainWindow pointer to main window. Usefull if need create modal dialog. Without pointer to main window
|
|
|
|
* modality doesn't work.
|
|
|
|
*/
|
|
|
|
QWidget *mainWindow;
|
2014-07-08 13:26:13 +02:00
|
|
|
/**
|
|
|
|
* @brief openingPattern true when we opening pattern. If something will be wrong in formula this help understand if
|
|
|
|
* we can allow user use Undo option.
|
|
|
|
*/
|
|
|
|
bool openingPattern;
|
2014-07-10 11:36:46 +02:00
|
|
|
/**
|
|
|
|
* @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable.
|
|
|
|
*/
|
2014-11-22 17:15:47 +01:00
|
|
|
VSettings *settings;
|
2014-09-05 10:01:46 +02:00
|
|
|
|
|
|
|
VPattern *doc;
|
2014-11-20 13:18:43 +01:00
|
|
|
QFile *log;
|
|
|
|
QTextStream *out;
|
2014-11-28 14:49:06 +01:00
|
|
|
QLockFile *logLock;
|
2014-06-13 19:02:41 +02:00
|
|
|
void InitLineWidth();
|
|
|
|
void InitMeasurements();
|
|
|
|
void InitVariables();
|
|
|
|
void InitFunctions();
|
|
|
|
void InitPostfixOperators();
|
2014-09-18 11:30:33 +02:00
|
|
|
void InitSTDescriptions();
|
2014-06-13 19:02:41 +02:00
|
|
|
bool MeasurementsFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
|
|
|
|
bool VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
|
|
|
|
bool PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token,
|
|
|
|
int &bias) const;
|
|
|
|
bool FunctionsFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
|
|
|
|
bool VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const;
|
|
|
|
void CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens,
|
|
|
|
QMap<int, QString> &numbers);
|
|
|
|
void BiasTokens(int position, int bias, QMap<int, QString> &tokens) const;
|
2014-12-04 18:55:49 +01:00
|
|
|
void InitMeasurement(const QString &name, const qmu::QmuTranslation &m, const qmu::QmuTranslation &g,
|
|
|
|
const qmu::QmuTranslation &d);
|
2014-11-15 16:52:27 +01:00
|
|
|
|
|
|
|
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
|
|
|
static const QString GistFileName;
|
|
|
|
|
|
|
|
void CollectReport(const QString &reportName) const;
|
|
|
|
void SendReport(const QString &reportName) const;
|
2014-11-20 13:18:43 +01:00
|
|
|
QString ReadFileForSending(QFile &file)const;
|
2014-11-29 13:12:43 +01:00
|
|
|
void ClearOldReports()const;
|
2014-11-30 16:30:47 +01:00
|
|
|
void GatherLogs()const;
|
2014-11-15 17:29:10 +01:00
|
|
|
#endif // defined(Q_OS_WIN) && defined(Q_CC_GNU)
|
2014-11-20 13:18:43 +01:00
|
|
|
|
|
|
|
QString LogDirPath()const;
|
|
|
|
QString LogPath()const;
|
2014-11-28 14:49:06 +01:00
|
|
|
void CreateLogDir()const;
|
|
|
|
void BeginLogging();
|
|
|
|
void ClearOldLogs()const;
|
2013-09-23 14:08:06 +02:00
|
|
|
};
|
|
|
|
|
2014-06-08 12:59:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-12 09:22:29 +02:00
|
|
|
inline Unit VApplication::patternUnit() const
|
2014-03-19 19:27:11 +01:00
|
|
|
{
|
|
|
|
return _patternUnit;
|
|
|
|
}
|
|
|
|
|
2014-06-08 12:59:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-12 09:22:29 +02:00
|
|
|
inline MeasurementsType VApplication::patternType() const
|
2014-03-19 19:27:11 +01:00
|
|
|
{
|
|
|
|
return _patternType;
|
|
|
|
}
|
|
|
|
|
2014-06-08 12:59:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-12 09:22:29 +02:00
|
|
|
inline void VApplication::setPatternType(const MeasurementsType &patternType)
|
2014-03-19 19:27:11 +01:00
|
|
|
{
|
|
|
|
_patternType = patternType;
|
|
|
|
}
|
|
|
|
|
2014-06-08 12:59:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-26 05:39:07 +01:00
|
|
|
inline qreal VApplication::widthMainLine() const
|
|
|
|
{
|
|
|
|
return _widthMainLine;
|
|
|
|
}
|
|
|
|
|
2014-06-08 12:59:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-26 05:39:07 +01:00
|
|
|
inline qreal VApplication::widthHairLine() const
|
|
|
|
{
|
|
|
|
return _widthHairLine;
|
|
|
|
}
|
2014-03-19 19:27:11 +01:00
|
|
|
|
2014-06-08 12:59:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline QUndoStack *VApplication::getUndoStack() const
|
|
|
|
{
|
|
|
|
return undoStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline VMainGraphicsView *VApplication::getSceneView() const
|
|
|
|
{
|
|
|
|
return sceneView;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void VApplication::setSceneView(VMainGraphicsView *value)
|
|
|
|
{
|
|
|
|
sceneView = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline QTimer *VApplication::getAutoSaveTimer() const
|
|
|
|
{
|
|
|
|
return autoSaveTimer;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void VApplication::setAutoSaveTimer(QTimer *value)
|
|
|
|
{
|
|
|
|
autoSaveTimer = value;
|
|
|
|
}
|
|
|
|
|
2014-09-05 10:01:46 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void VApplication::setCurrentDocument(VPattern *doc)
|
|
|
|
{
|
|
|
|
this->doc = doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline VPattern *VApplication::getCurrentDocument() const
|
|
|
|
{
|
|
|
|
SCASSERT(doc != nullptr)
|
2014-09-08 13:02:14 +02:00
|
|
|
return doc;
|
2014-09-05 10:01:46 +02:00
|
|
|
}
|
|
|
|
|
2013-09-23 14:08:06 +02:00
|
|
|
#endif // VAPPLICATION_H
|