2015-06-18 10:45:38 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vabstractapplication.h
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 18 6, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-06-18 10:45:38 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-06-18 10:45:38 +02:00
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef VABSTRACTAPPLICATION_H
|
|
|
|
#define VABSTRACTAPPLICATION_H
|
|
|
|
|
|
|
|
#include <QApplication>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QCoreApplication>
|
2023-06-27 13:15:21 +02:00
|
|
|
#include <QElapsedTimer>
|
2023-06-08 12:20:20 +02:00
|
|
|
#include <QFileDialog>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QLocale>
|
|
|
|
#include <QMetaObject>
|
|
|
|
#include <QObject>
|
2015-09-19 21:58:32 +02:00
|
|
|
#include <QPointer>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QString>
|
2020-10-15 17:05:21 +02:00
|
|
|
#include <QTranslator>
|
2023-06-08 12:20:20 +02:00
|
|
|
#include <QtGlobal>
|
2015-09-19 21:58:32 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/def.h"
|
|
|
|
#include "../vpatterndb/vtranslatevars.h"
|
|
|
|
#include "vcommonsettings.h"
|
2015-06-18 10:45:38 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
class QUndoStack;
|
2023-06-08 12:20:20 +02:00
|
|
|
class VAbstractApplication; // use in define
|
2020-10-15 17:05:21 +02:00
|
|
|
class VCommonSettings;
|
2023-06-08 12:20:20 +02:00
|
|
|
class VSvgFontDatabase;
|
|
|
|
class QFileSystemWatcher;
|
2023-10-23 15:57:22 +02:00
|
|
|
class VAbstractShortcutManager;
|
2023-10-31 08:42:09 +01:00
|
|
|
class VKnownMeasurementsDatabase;
|
2015-06-18 10:45:38 +02:00
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
class VTextCodec;
|
2023-11-09 16:46:34 +01:00
|
|
|
#else
|
|
|
|
class QTextCodec;
|
|
|
|
using VTextCodec = QTextCodec;
|
2023-02-11 15:14:15 +01:00
|
|
|
#endif
|
|
|
|
|
2021-09-25 10:43:05 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wsuggest-final-types")
|
2021-09-25 16:18:33 +02:00
|
|
|
QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods")
|
2021-09-25 10:43:05 +02:00
|
|
|
|
2015-06-18 10:45:38 +02:00
|
|
|
class VAbstractApplication : public QApplication
|
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_OBJECT // NOLINT
|
2023-06-08 12:20:20 +02:00
|
|
|
|
2015-06-18 10:45:38 +02:00
|
|
|
public:
|
2023-06-08 12:20:20 +02:00
|
|
|
VAbstractApplication(int &argc, char **argv);
|
|
|
|
~VAbstractApplication() override;
|
2015-06-18 10:45:38 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
virtual auto TrVars() -> const VTranslateVars * = 0;
|
2015-11-18 13:42:25 +01:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto translationsPath(const QString &locale = QString()) -> QString;
|
2015-09-19 21:58:32 +02:00
|
|
|
|
2022-09-29 10:59:00 +02:00
|
|
|
void LoadTranslation(QString locale);
|
2017-09-19 15:07:48 +02:00
|
|
|
|
2023-06-08 12:20:20 +02:00
|
|
|
virtual void OpenSettings() = 0;
|
2023-05-03 13:07:02 +02:00
|
|
|
auto Settings() -> VCommonSettings *;
|
2015-06-18 10:45:38 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
template <typename T> auto LocaleToString(const T &value) -> QString;
|
2015-06-18 19:23:24 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
auto getUndoStack() const -> QUndoStack *;
|
2015-06-18 19:23:24 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
virtual auto IsAppInGUIMode() const -> bool = 0;
|
|
|
|
virtual auto IsPedantic() const -> bool;
|
2017-08-14 14:11:14 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto ClearMessage(QString msg) -> QString;
|
2020-11-20 12:18:38 +01:00
|
|
|
|
|
|
|
static const QString warningMessageSignature;
|
2023-05-03 13:07:02 +02:00
|
|
|
auto IsWarningMessage(const QString &message) const -> bool;
|
2020-11-20 12:18:38 +01:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
auto NativeFileDialog(QFileDialog::Options options = QFileDialog::Options()) const -> QFileDialog::Options;
|
2020-12-17 17:43:15 +01:00
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2023-05-03 13:07:02 +02:00
|
|
|
auto TextCodecCache(QStringConverter::Encoding encoding) const -> VTextCodec *;
|
2023-02-11 15:14:15 +01:00
|
|
|
void CacheTextCodec(QStringConverter::Encoding encoding, VTextCodec *codec);
|
|
|
|
#endif
|
|
|
|
|
2017-12-10 12:17:04 +01:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
static void WinAttachConsole();
|
|
|
|
#endif
|
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto VApp() -> VAbstractApplication *;
|
2021-02-06 14:52:21 +01:00
|
|
|
|
2023-06-22 17:30:43 +02:00
|
|
|
auto SVGFontDatabase() -> VSvgFontDatabase *;
|
2023-10-31 08:42:09 +01:00
|
|
|
|
|
|
|
virtual auto KnownMeasurementsDatabase() -> VKnownMeasurementsDatabase *;
|
2023-06-22 17:30:43 +02:00
|
|
|
|
2023-06-27 13:15:21 +02:00
|
|
|
auto AppUptime() const -> qint64;
|
|
|
|
|
2023-10-23 15:57:22 +02:00
|
|
|
auto GetShortcutManager() const -> VAbstractShortcutManager *;
|
|
|
|
|
2023-07-24 12:41:42 +02:00
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays, modernize-avoid-c-arrays)
|
|
|
|
static auto IsOptionSet(int argc, char *argv[], const char *option) -> bool;
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays, modernize-avoid-c-arrays)
|
|
|
|
static void InitHighDpiScaling(int argc, char *argv[]);
|
|
|
|
|
2015-06-18 19:23:24 +02:00
|
|
|
protected:
|
2020-10-15 17:05:21 +02:00
|
|
|
QUndoStack *undoStack;
|
2015-06-18 10:45:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable.
|
|
|
|
*/
|
2020-10-15 17:05:21 +02:00
|
|
|
VCommonSettings *settings{nullptr};
|
2015-06-18 19:23:24 +02:00
|
|
|
|
2020-10-15 17:05:21 +02:00
|
|
|
QPointer<QTranslator> qtTranslator{nullptr};
|
2023-01-18 13:57:38 +01:00
|
|
|
#if defined(Q_OS_WIN) && !defined(QBS_BUILD)
|
2020-10-15 17:05:21 +02:00
|
|
|
QPointer<QTranslator> qtxmlTranslator{nullptr};
|
|
|
|
QPointer<QTranslator> qtBaseTranslator{nullptr};
|
2023-01-18 13:57:38 +01:00
|
|
|
#endif // defined(Q_OS_WIN) && !defined(QBS_BUILD)
|
2020-10-15 17:05:21 +02:00
|
|
|
QPointer<QTranslator> appTranslator{nullptr};
|
2015-09-19 21:58:32 +02:00
|
|
|
|
2023-06-27 13:15:21 +02:00
|
|
|
QElapsedTimer m_uptimeTimer{};
|
|
|
|
|
2023-10-23 15:57:22 +02:00
|
|
|
VAbstractShortcutManager *m_shortcutManager{nullptr};
|
|
|
|
|
2023-06-08 12:20:20 +02:00
|
|
|
virtual void InitTrVars() = 0;
|
2015-09-19 21:58:32 +02:00
|
|
|
|
2022-08-03 11:17:04 +02:00
|
|
|
static void CheckSystemLocale();
|
|
|
|
|
2019-07-01 11:47:06 +02:00
|
|
|
protected slots:
|
2023-06-08 12:20:20 +02:00
|
|
|
virtual void AboutToQuit() = 0;
|
2023-06-22 17:30:43 +02:00
|
|
|
void SVGFontsPathChanged(const QString &oldPath, const QString &newPath);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void RepopulateFontDatabase(const QString &path);
|
2019-07-01 11:47:06 +02:00
|
|
|
|
2015-06-25 12:42:49 +02:00
|
|
|
private:
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_DISABLE_COPY_MOVE(VAbstractApplication) // NOLINT
|
2018-07-25 10:26:09 +02:00
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
QHash<QStringConverter::Encoding, VTextCodec *> m_codecs{};
|
|
|
|
#endif
|
|
|
|
|
2023-06-22 17:30:43 +02:00
|
|
|
VSvgFontDatabase *m_svgFontDatabase{nullptr};
|
|
|
|
QFileSystemWatcher *m_svgFontDatabaseWatcher{nullptr};
|
|
|
|
|
2015-09-19 21:58:32 +02:00
|
|
|
void ClearTranslation();
|
2023-10-31 08:42:09 +01:00
|
|
|
|
|
|
|
void RestartSVGFontDatabaseWatcher();
|
2015-06-18 10:45:38 +02:00
|
|
|
};
|
|
|
|
|
2021-09-25 10:43:05 +02:00
|
|
|
QT_WARNING_POP
|
|
|
|
|
2015-06-18 10:45:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
template <typename T> inline auto VAbstractApplication::LocaleToString(const T &value) -> QString
|
2015-06-18 10:45:38 +02:00
|
|
|
{
|
|
|
|
QLocale loc;
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->Settings()->GetOsSeparator() ? loc = QLocale() : loc = QLocale::c();
|
2015-06-18 10:45:38 +02:00
|
|
|
return loc.toString(value);
|
|
|
|
}
|
|
|
|
|
2021-06-23 14:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline auto VAbstractApplication::VApp() -> VAbstractApplication *
|
|
|
|
{
|
2023-06-08 12:20:20 +02:00
|
|
|
return qobject_cast<VAbstractApplication *>(QCoreApplication::instance());
|
2021-06-23 14:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief getSettings hide settings constructor.
|
|
|
|
* @return pointer to class for acssesing to settings in ini file.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
inline auto VAbstractApplication::Settings() -> VCommonSettings *
|
2021-06-23 14:58:43 +02:00
|
|
|
{
|
|
|
|
SCASSERT(settings != nullptr)
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2015-06-18 10:45:38 +02:00
|
|
|
#endif // VABSTRACTAPPLICATION_H
|