File indexing completed on 2025-02-23 04:34:23
0001 /** 0002 * \file formatbox.cpp 0003 * Group box containing format options. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 17 Sep 2003 0008 * 0009 * Copyright (C) 2003-2018 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #include "formatbox.h" 0028 #include <QLabel> 0029 #include <QComboBox> 0030 #include <QCheckBox> 0031 #include <QString> 0032 #include <QVBoxLayout> 0033 #include <QFormLayout> 0034 #include <QLocale> 0035 #include "formatconfig.h" 0036 #include "configtable.h" 0037 #include "configtablemodel.h" 0038 0039 /** 0040 * Constructor. 0041 * 0042 * @param title title 0043 * @param parent parent widget 0044 */ 0045 FormatBox::FormatBox(const QString& title, QWidget* parent) 0046 : QGroupBox(title, parent) 0047 { 0048 m_formatEditingCheckBox = new QCheckBox(tr("Automatically apply format"), 0049 this); 0050 0051 m_caseConvComboBox = new QComboBox(this); 0052 m_caseConvComboBox->addItems(FormatConfig::getCaseConversionNames()); 0053 0054 m_localeComboBox = new QComboBox(this); 0055 m_localeComboBox->addItems(FormatConfig::getLocaleNames()); 0056 m_strRepCheckBox = new QCheckBox(tr("String replacement:"), this); 0057 m_strReplTableModel = new ConfigTableModel(this); 0058 m_strReplTableModel->setLabels({tr("From"), tr("To")}); 0059 m_strReplTable = new ConfigTable(m_strReplTableModel, this); 0060 m_strReplTable->setHorizontalResizeModes( 0061 m_strReplTableModel->getHorizontalResizeModes()); 0062 auto hlayout = new QHBoxLayout(this); 0063 m_formLayout = new QFormLayout; 0064 m_formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); 0065 m_formLayout->addRow(m_formatEditingCheckBox); 0066 m_formLayout->addRow(tr("Case conversion:"), m_caseConvComboBox); 0067 m_formLayout->addRow(tr("Locale:"), m_localeComboBox); 0068 hlayout->addLayout(m_formLayout); 0069 auto vlayout = new QVBoxLayout; 0070 vlayout->addWidget(m_strRepCheckBox); 0071 vlayout->addWidget(m_strReplTable); 0072 hlayout->addLayout(vlayout); 0073 } 0074 0075 /** 0076 * Set the values from a format configuration. 0077 * 0078 * @param cfg format configuration 0079 */ 0080 void FormatBox::fromFormatConfig(const FormatConfig& cfg) 0081 { 0082 m_formatEditingCheckBox->setChecked(cfg.formatWhileEditing()); 0083 m_caseConvComboBox->setCurrentIndex(cfg.caseConversion()); 0084 int localeIndex = m_localeComboBox->findText(cfg.localeName()); 0085 if (localeIndex == -1) { 0086 localeIndex = 0; 0087 } 0088 m_localeComboBox->setCurrentIndex(localeIndex); 0089 m_strRepCheckBox->setChecked(cfg.strRepEnabled()); 0090 m_strReplTableModel->setMap(cfg.strRepMap()); 0091 } 0092 0093 /** 0094 * Store the values in a format configuration. 0095 * 0096 * @param cfg format configuration 0097 */ 0098 void FormatBox::toFormatConfig(FormatConfig& cfg) const 0099 { 0100 cfg.setFormatWhileEditing(m_formatEditingCheckBox->isChecked()); 0101 cfg.setCaseConversion( 0102 static_cast<FormatConfig::CaseConversion>(m_caseConvComboBox->currentIndex())); 0103 if (cfg.caseConversion() >= FormatConfig::NumCaseConversions) { 0104 cfg.setCaseConversion(FormatConfig::NoChanges); 0105 } 0106 cfg.setLocaleName(m_localeComboBox->currentIndex() > 0 0107 ? m_localeComboBox->currentText() : QString()); 0108 cfg.setStrRepEnabled(m_strRepCheckBox->isChecked()); 0109 cfg.setStrRepMap(m_strReplTableModel->getMap()); 0110 }