/************************************************************************ ** ** @file vsettings.cpp ** @author Roman Telezhynskyi ** @date 22 11, 2014 ** ** @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-2015 Valentina project ** All Rights Reserved. ** ** 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 . ** *************************************************************************/ #include "vsettings.h" #include #include #include #include #include "../xml/vabstractmeasurements.h" #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../../utils/vmath.h" #else # include #endif const QString VSettings::SettingConfigurationOsSeparator = QStringLiteral("configuration/osSeparator"); const QString VSettings::SettingConfigurationAutosaveState = QStringLiteral("configuration/autosave/state"); const QString VSettings::SettingConfigurationAutosaveTime = QStringLiteral("configuration/autosave/time"); const QString VSettings::SettingConfigurationSendReportState = QStringLiteral("configuration/send_report/state"); const QString VSettings::SettingConfigurationLocale = QStringLiteral("configuration/locale"); const QString VSettings::SettingConfigurationUnit = QStringLiteral("configuration/unit"); const QString VSettings::SettingConfigurationLabelLanguage = QStringLiteral("configuration/label_language"); const QString VSettings::SettingConfigurationConfirmItemDeletion = QStringLiteral("configuration/confirm_item_deletion"); const QString VSettings::SettingConfigurationToolBarStyle = QStringLiteral("configuration/tool_bar_style"); const QString VSettings::SettingPathsIndividualMeasurements = QStringLiteral("paths/individual_measurements"); const QString VSettings::SettingPathsStandardMeasurements = QStringLiteral("paths/standard_measurements"); const QString VSettings::SettingPathsPattern = QStringLiteral("paths/pattern"); const QString VSettings::SettingPathsLayout = QStringLiteral("paths/layout"); const QString VSettings::SettingPatternUser = QStringLiteral("pattern/user"); const QString VSettings::SettingPatternGraphicalOutput = QStringLiteral("pattern/graphicalOutput"); const QString VSettings::SettingPatternUndo = QStringLiteral("pattern/undo"); const QString VSettings::SettingGeneralRecentFileList = QStringLiteral("recentFileList"); const QString VSettings::SettingGeneralRestoreFileList = QStringLiteral("restoreFileList"); const QString VSettings::SettingGeneralGeometry = QStringLiteral("geometry"); const QString VSettings::SettingGeneralWindowState = QStringLiteral("windowState"); const QString VSettings::SettingGeneralToolbarsState = QStringLiteral("toolbarsState"); const QString VSettings::SettingCommunityServer = QStringLiteral("community/server"); const QString VSettings::SettingCommunityServerSecure = QStringLiteral("community/serverSecure"); const QString VSettings::SettingCommunityUseProxy = QStringLiteral("community/useProxy"); const QString VSettings::SettingCommunityProxyAddress = QStringLiteral("community/proxyAddress"); const QString VSettings::SettingCommunityProxyPort = QStringLiteral("community/proxyPort"); const QString VSettings::SettingCommunityProxyUser = QStringLiteral("community/proxyUser"); const QString VSettings::SettingCommunityProxyPass = QStringLiteral("community/proxyPass"); const QString VSettings::SettingCommunityUsername = QStringLiteral("community/username"); const QString VSettings::SettingCommunitySavePassword = QStringLiteral("community/savePassword"); const QString VSettings::SettingCommunityUserPassword = QStringLiteral("community/userpassword"); const QString VSettings::SettingLayoutWidth = QStringLiteral("layout/width"); const QString VSettings::SettingLayoutSorting = QStringLiteral("layout/sorting"); const QString VSettings::SettingLayoutPaperHeight = QStringLiteral("layout/paperHeight"); const QString VSettings::SettingLayoutPaperWidth = QStringLiteral("layout/paperWidth"); const QString VSettings::SettingLayoutShift = QStringLiteral("layout/shift"); const QString VSettings::SettingLayoutRotate = QStringLiteral("layout/Rotate"); const QString VSettings::SettingLayoutRotationIncrease = QStringLiteral("layout/rotationIncrease"); const QString VSettings::SettingLayoutAutoCrop = QStringLiteral("layout/autoCrop"); const QString VSettings::SettingLayoutSaveLength = QStringLiteral("layout/saveLength"); //--------------------------------------------------------------------------------------------------------------------- VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application, QObject *parent) :QSettings(format, scope, organization, application, parent) {} //--------------------------------------------------------------------------------------------------------------------- bool VSettings::GetOsSeparator() const { return value(SettingConfigurationOsSeparator, 1).toBool(); } //--------------------------------------------------------------------------------------------------------------------- void VSettings::SetOsSeparator(const bool &value) { setValue(SettingConfigurationOsSeparator, value); } //--------------------------------------------------------------------------------------------------------------------- bool VSettings::GetAutosaveState() const { return value(SettingConfigurationAutosaveState, 1).toBool(); } //--------------------------------------------------------------------------------------------------------------------- void VSettings::SetAutosaveState(const bool &value) { setValue(SettingConfigurationAutosaveState, value); } //--------------------------------------------------------------------------------------------------------------------- int VSettings::GetAutosaveTime() const { bool ok = false; int val = value(SettingConfigurationAutosaveTime, 1).toInt(&ok); if (ok == false) { qDebug()<<"Could not convert value"<(VAbstractMeasurements::UnitConvertor(50, Unit::Mm, Unit::Px)); } //--------------------------------------------------------------------------------------------------------------------- void VSettings::SetLayoutShift(unsigned int value) { setValue(SettingLayoutShift, value); } //--------------------------------------------------------------------------------------------------------------------- unsigned int VSettings::GetLayoutWidth() const { const unsigned int def = GetDefLayoutWidth(); bool ok = false; const unsigned int lWidth = value(SettingLayoutWidth, def).toUInt(&ok); if (ok) { return lWidth; } else { return def; } } //--------------------------------------------------------------------------------------------------------------------- unsigned int VSettings::GetDefLayoutWidth() { return static_cast(VAbstractMeasurements::UnitConvertor(2.5, Unit::Mm, Unit::Px)); } //--------------------------------------------------------------------------------------------------------------------- void VSettings::SetLayoutWidth(unsigned int value) { setValue(SettingLayoutWidth, value); } //--------------------------------------------------------------------------------------------------------------------- Cases VSettings::GetLayoutGroup() const { const Cases def = GetDefLayoutGroup(); bool ok = false; const int g = value(SettingLayoutSorting, static_cast(def)).toInt(&ok); if (ok) { if (g >= static_cast(Cases::UnknownCase)) { return def; } else { return static_cast(g); } } else { return def; } } //--------------------------------------------------------------------------------------------------------------------- Cases VSettings::GetDefLayoutGroup() { return Cases::CaseDesc; } //--------------------------------------------------------------------------------------------------------------------- void VSettings::SetLayoutGroup(const Cases &value) { setValue(SettingLayoutSorting, static_cast(value)); } //--------------------------------------------------------------------------------------------------------------------- bool VSettings::GetLayoutRotate() const { return value(SettingLayoutRotate, GetDefLayoutRotate()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- bool VSettings::GetDefLayoutRotate() { return true; } //--------------------------------------------------------------------------------------------------------------------- void VSettings::SetLayoutRotate(bool value) { setValue(SettingLayoutRotate, value); } //--------------------------------------------------------------------------------------------------------------------- int VSettings::GetLayoutRotationIncrease() const { const int def = GetDefLayoutRotationIncrease(); bool ok = false; const int r = value(SettingLayoutRotationIncrease, def).toInt(&ok); if (ok) { if (not (r >= 1 && r <= 180 && 360 % r == 0)) { return def; } else { return r; } } else { return def; } } //--------------------------------------------------------------------------------------------------------------------- int VSettings::GetDefLayoutRotationIncrease() { return 180;/*degree*/ } //--------------------------------------------------------------------------------------------------------------------- void VSettings::SetLayoutRotationIncrease(int value) { setValue(SettingLayoutRotationIncrease, value); } //--------------------------------------------------------------------------------------------------------------------- bool VSettings::GetLayoutAutoCrop() const { return value(SettingLayoutAutoCrop, false).toBool(); } //--------------------------------------------------------------------------------------------------------------------- void VSettings::SetLayoutAutoCrop(bool value) { setValue(SettingLayoutAutoCrop, value); } //--------------------------------------------------------------------------------------------------------------------- bool VSettings::GetLayoutSaveLength() const { return value(SettingLayoutSaveLength, false).toBool(); } //--------------------------------------------------------------------------------------------------------------------- void VSettings::SetLayoutSaveLength(bool value) { setValue(SettingLayoutSaveLength, value); } //--------------------------------------------------------------------------------------------------------------------- QString VSettings::StandardTablesPath() { const QString stPath = QStringLiteral("/tables/standard"); #ifdef Q_OS_WIN return QApplication::applicationDirPath() + stPath; #elif defined(Q_OS_MAC) QDir dirBundle(QApplication::applicationDirPath() + QStringLiteral("/../Resources") + stPath); if (dirBundle.exists()) { return dirBundle.absolutePath(); } else { QDir dir(QApplication::applicationDirPath() + stPath); if (dir.exists()) { return dir.absolutePath(); } else { return QStringLiteral("/usr/share/valentina/tables/standard"); } } #else // Unix #ifdef QT_DEBUG return QApplication::applicationDirPath() + stPath; #else QDir dir(QApplication::applicationDirPath() + stPath); if (dir.exists()) { return dir.absolutePath(); } else { return QStringLiteral("/usr/share/valentina/tables/standard"); } #endif #endif }