File indexing completed on 2024-05-05 12:57:18
0001 /* 0002 * Copyright (C) 2012-2015 by Stephen Allewell 0003 * steve.allewell@gmail.com 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2 of the License, or 0008 * (at your option) any later version. 0009 */ 0010 0011 #include "ConfigurationDialogs.h" 0012 0013 #include "PaperSizes.h" 0014 #include "SchemeManager.h" 0015 #include "SymbolManager.h" 0016 0017 EditorConfigPage::EditorConfigPage(QWidget *parent, const QString &name) 0018 : QWidget(parent) 0019 { 0020 setObjectName(name); 0021 setupUi(this); 0022 } 0023 0024 PatternConfigPage::PatternConfigPage(QWidget *parent, const QString &name) 0025 : QWidget(parent) 0026 { 0027 setObjectName(name); 0028 setupUi(this); 0029 0030 m_currentDocumentUnitsIndex = Configuration::document_UnitsFormat(); 0031 m_currentClothCountUnitsIndex = Configuration::editor_ClothCountUnits(); 0032 0033 // change the Default list item for cloth count measurement to append with the users locale measurement 0034 QString localeUnits = (QLocale::system().measurementSystem() == QLocale::MetricSystem) ? i18n("Default (Centimeters)") : i18n("Default (Inches)"); 0035 kcfg_Editor_ClothCountUnits->setItemText(kcfg_Editor_ClothCountUnits->findText(i18n("Default")), localeUnits); 0036 0037 setPatternSizePrecision(); 0038 setClothCountPrecision(); 0039 } 0040 0041 void PatternConfigPage::on_kcfg_Editor_ClothCountUnits_activated(int index) 0042 { 0043 Configuration::EnumEditor_ClothCountUnits::type clothCountTypeSelected = static_cast<Configuration::EnumEditor_ClothCountUnits::type>(index); 0044 0045 if (clothCountTypeSelected == Configuration::EnumEditor_ClothCountUnits::Default) { 0046 clothCountTypeSelected = (QLocale::system().measurementSystem() == QLocale::MetricSystem) ? Configuration::EnumEditor_ClothCountUnits::Centimeters 0047 : Configuration::EnumEditor_ClothCountUnits::Inches; 0048 } 0049 0050 if (m_currentClothCountUnitsIndex != clothCountTypeSelected) { 0051 m_currentClothCountUnitsIndex = clothCountTypeSelected; 0052 0053 double horizontalClothCount = kcfg_Editor_HorizontalClothCount->value(); 0054 double verticalClothCount = kcfg_Editor_VerticalClothCount->value(); 0055 0056 if (clothCountTypeSelected == Configuration::EnumEditor_ClothCountUnits::Inches) { 0057 horizontalClothCount *= 2.54; 0058 verticalClothCount *= 2.54; 0059 } else { 0060 horizontalClothCount /= 2.54; 0061 verticalClothCount /= 2.54; 0062 } 0063 0064 setClothCountPrecision(); 0065 0066 kcfg_Editor_HorizontalClothCount->setValue(horizontalClothCount); 0067 kcfg_Editor_VerticalClothCount->setValue(verticalClothCount); 0068 } 0069 } 0070 0071 void PatternConfigPage::on_kcfg_Document_UnitsFormat_activated(int index) 0072 { 0073 Configuration::EnumDocument_UnitsFormat::type documentUnitsTypeSelected = static_cast<Configuration::EnumDocument_UnitsFormat::type>(index); 0074 0075 if (m_currentDocumentUnitsIndex != documentUnitsTypeSelected) { 0076 int originalDocumentUnitsIndex = m_currentDocumentUnitsIndex; 0077 m_currentDocumentUnitsIndex = documentUnitsTypeSelected; 0078 0079 double documentWidth = kcfg_Document_Width->value(); 0080 double documentHeight = kcfg_Document_Height->value(); 0081 0082 double horizontalClothCount = kcfg_Editor_HorizontalClothCount->value(); 0083 double verticalClothCount = kcfg_Editor_VerticalClothCount->value(); 0084 0085 switch (originalDocumentUnitsIndex) { 0086 case Configuration::EnumDocument_UnitsFormat::Stitches: 0087 documentWidth /= horizontalClothCount; 0088 documentHeight /= verticalClothCount; 0089 0090 switch (documentUnitsTypeSelected) { 0091 case Configuration::EnumDocument_UnitsFormat::Inches: 0092 if (m_currentClothCountUnitsIndex 0093 == Configuration::EnumEditor_ClothCountUnits::Centimeters) { // from stitches to inches with cloth count in centimeters 0094 documentWidth /= 2.54; 0095 documentHeight /= 2.54; 0096 } 0097 0098 break; 0099 0100 case Configuration::EnumDocument_UnitsFormat::Centimeters: 0101 if (m_currentClothCountUnitsIndex 0102 == Configuration::EnumEditor_ClothCountUnits::Inches) { // from stitches to centimeters with cloth count in inches 0103 documentWidth *= 2.54; 0104 documentHeight *= 2.54; 0105 } 0106 0107 break; 0108 0109 default: 0110 // Do not need to do anything 0111 break; 0112 } 0113 0114 break; 0115 0116 case Configuration::EnumDocument_UnitsFormat::Inches: 0117 switch (documentUnitsTypeSelected) { 0118 case Configuration::EnumDocument_UnitsFormat::Stitches: 0119 documentWidth *= horizontalClothCount; 0120 documentHeight *= verticalClothCount; 0121 0122 if (m_currentClothCountUnitsIndex 0123 == Configuration::EnumEditor_ClothCountUnits::Centimeters) { // from inches to stitches with cloth count in centimeters 0124 documentWidth *= 2.54; 0125 documentHeight *= 2.54; 0126 } 0127 0128 break; 0129 0130 case Configuration::EnumDocument_UnitsFormat::Centimeters: // from inches to centimeters with cloch count in inches 0131 documentWidth *= 2.54; 0132 documentHeight *= 2.54; 0133 break; 0134 0135 default: 0136 // do not need to do anything 0137 break; 0138 } 0139 0140 break; 0141 0142 case Configuration::EnumDocument_UnitsFormat::Centimeters: 0143 switch (documentUnitsTypeSelected) { 0144 case Configuration::EnumDocument_UnitsFormat::Stitches: 0145 documentWidth *= horizontalClothCount; 0146 documentHeight *= verticalClothCount; 0147 0148 if (m_currentClothCountUnitsIndex 0149 == Configuration::EnumEditor_ClothCountUnits::Inches) { // from centimeters to stitches with cloth count in inches 0150 documentWidth /= 2.54; 0151 documentHeight /= 2.54; 0152 } 0153 0154 break; 0155 0156 case Configuration::EnumDocument_UnitsFormat::Inches: // from centimeters to inches with cloth count in centimeters 0157 documentWidth /= 2.54; 0158 documentHeight /= 2.54; 0159 break; 0160 0161 default: 0162 // do not need to do anything 0163 break; 0164 } 0165 0166 break; 0167 } 0168 0169 setPatternSizePrecision(); 0170 0171 kcfg_Document_Width->setValue(documentWidth); 0172 kcfg_Document_Height->setValue(documentHeight); 0173 } 0174 } 0175 0176 void PatternConfigPage::on_kcfg_Editor_ClothCountLink_toggled(bool checked) 0177 { 0178 kcfg_Editor_ClothCountLink->setIcon((checked) ? QIcon::fromTheme(QStringLiteral("object-locked")) : QIcon::fromTheme(QStringLiteral("object-unlocked"))); 0179 kcfg_Editor_VerticalClothCount->setEnabled(!checked); 0180 kcfg_Editor_VerticalClothCount->setValue(kcfg_Editor_HorizontalClothCount->value()); 0181 } 0182 0183 void PatternConfigPage::on_kcfg_Editor_HorizontalClothCount_valueChanged(double value) 0184 { 0185 if (kcfg_Editor_ClothCountLink->isChecked()) { 0186 kcfg_Editor_VerticalClothCount->setValue(value); 0187 } 0188 } 0189 0190 void PatternConfigPage::setPatternSizePrecision() 0191 { 0192 switch (m_currentDocumentUnitsIndex) { 0193 case Configuration::EnumDocument_UnitsFormat::Stitches: 0194 kcfg_Document_Width->setDecimals(0); 0195 kcfg_Document_Height->setDecimals(0); 0196 kcfg_Document_Width->setSingleStep(1); 0197 kcfg_Document_Height->setSingleStep(1); 0198 break; 0199 0200 case Configuration::EnumDocument_UnitsFormat::Inches: 0201 kcfg_Document_Width->setDecimals(2); 0202 kcfg_Document_Height->setDecimals(2); 0203 kcfg_Document_Width->setSingleStep(0.01); 0204 kcfg_Document_Height->setSingleStep(0.01); 0205 break; 0206 0207 case Configuration::EnumDocument_UnitsFormat::Centimeters: 0208 kcfg_Document_Width->setDecimals(2); 0209 kcfg_Document_Height->setDecimals(2); 0210 kcfg_Document_Width->setSingleStep(0.01); 0211 kcfg_Document_Height->setSingleStep(0.01); 0212 break; 0213 0214 default: 0215 break; 0216 } 0217 0218 kcfg_Document_Width->setRange(Configuration::document_Min_Width(), Configuration::document_Max_Width()); 0219 kcfg_Document_Height->setRange(Configuration::document_Min_Height(), Configuration::document_Max_Height()); 0220 } 0221 0222 void PatternConfigPage::setClothCountPrecision() 0223 { 0224 if (m_currentClothCountUnitsIndex == Configuration::EnumEditor_ClothCountUnits::Default) { 0225 m_currentClothCountUnitsIndex = (QLocale::system().measurementSystem() == QLocale::MetricSystem) 0226 ? Configuration::EnumEditor_ClothCountUnits::Centimeters 0227 : Configuration::EnumEditor_ClothCountUnits::Inches; 0228 } 0229 0230 switch (m_currentClothCountUnitsIndex) { 0231 case Configuration::EnumEditor_ClothCountUnits::Inches: 0232 kcfg_Editor_HorizontalClothCount->setDecimals(0); 0233 kcfg_Editor_HorizontalClothCount->setSingleStep(1.0); 0234 kcfg_Editor_HorizontalClothCount->setSuffix(i18nc("Per inch measurements", "/in")); 0235 kcfg_Editor_VerticalClothCount->setDecimals(0); 0236 kcfg_Editor_VerticalClothCount->setSingleStep(1.0); 0237 kcfg_Editor_VerticalClothCount->setSuffix(i18nc("Per inch measurements", "/in")); 0238 break; 0239 0240 case Configuration::EnumEditor_ClothCountUnits::Centimeters: 0241 kcfg_Editor_HorizontalClothCount->setDecimals(1); 0242 kcfg_Editor_HorizontalClothCount->setSingleStep(0.1); 0243 kcfg_Editor_HorizontalClothCount->setSuffix(i18nc("Per centimeter measurements", "/cm")); 0244 kcfg_Editor_VerticalClothCount->setDecimals(1); 0245 kcfg_Editor_VerticalClothCount->setSingleStep(0.1); 0246 kcfg_Editor_VerticalClothCount->setSuffix(i18nc("Per centimeter measurements", "/cm")); 0247 break; 0248 0249 default: 0250 break; 0251 } 0252 } 0253 0254 PaletteConfigPage::PaletteConfigPage(QWidget *parent, const QString &name) 0255 : QWidget(parent) 0256 { 0257 setObjectName(name); 0258 setupUi(this); 0259 // KConfigXT will read the currentText through the kcfg_property 0260 kcfg_Palette_DefaultScheme->setProperty("kcfg_property", QByteArray("currentText")); 0261 kcfg_Palette_DefaultSymbolLibrary->setProperty("kcfg_property", QByteArray("currentText")); 0262 kcfg_Palette_StitchStrands->setProperty("kcfg_property", QByteArray("currentText")); 0263 kcfg_Palette_BackstitchStrands->setProperty("kcfg_property", QByteArray("currentText")); 0264 kcfg_Palette_DefaultScheme->insertItems(0, SchemeManager::schemes()); 0265 kcfg_Palette_DefaultSymbolLibrary->insertItems(0, SymbolManager::libraries()); 0266 // KConfigXT can't write the currentText, so this needs to be set manually 0267 kcfg_Palette_DefaultScheme->setCurrentItem(Configuration::palette_DefaultScheme()); 0268 kcfg_Palette_DefaultSymbolLibrary->setCurrentItem(Configuration::palette_DefaultSymbolLibrary()); 0269 kcfg_Palette_StitchStrands->setCurrentIndex(Configuration::palette_StitchStrands() - 1); 0270 kcfg_Palette_BackstitchStrands->setCurrentIndex(Configuration::palette_BackstitchStrands() - 1); 0271 } 0272 0273 void PaletteConfigPage::defaultClicked() 0274 { 0275 // Clicking Default button doesn't work with the KComboBoxes with text defaults, set them manually 0276 kcfg_Palette_DefaultScheme->setCurrentItem(Configuration::defaultPalette_DefaultSchemeValue()); 0277 kcfg_Palette_DefaultSymbolLibrary->setCurrentItem(Configuration::defaultPalette_DefaultSymbolLibraryValue()); 0278 kcfg_Palette_StitchStrands->setCurrentIndex(Configuration::defaultPalette_StitchStrandsValue() - 1); 0279 kcfg_Palette_BackstitchStrands->setCurrentIndex(Configuration::defaultPalette_BackstitchStrandsValue() - 1); 0280 } 0281 0282 ImportConfigPage::ImportConfigPage(QWidget *parent, const QString &name) 0283 : QWidget(parent) 0284 { 0285 setObjectName(name); 0286 setupUi(this); 0287 } 0288 0289 LibraryConfigPage::LibraryConfigPage(QWidget *parent, const QString &name) 0290 : QWidget(parent) 0291 { 0292 setObjectName(name); 0293 setupUi(this); 0294 } 0295 0296 PrinterConfigPage::PrinterConfigPage(QWidget *parent, const QString &name) 0297 : QWidget(parent) 0298 { 0299 setObjectName(name); 0300 setupUi(this); 0301 0302 for (QPageSize::PageSizeId id : PageSizes::sizesForPrint()) { 0303 kcfg_Page_Size->addItem(QPageSize::name(id)); 0304 } 0305 } 0306 0307 #include "moc_ConfigurationDialogs.cpp"