| 1 | /* |
|---|
| 2 | * Hydrogen |
|---|
| 3 | * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net] |
|---|
| 4 | * |
|---|
| 5 | * http://www.hydrogen-music.org |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY, without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | #include "PatternPropertiesDialog.h" |
|---|
| 24 | #include "Skin.h" |
|---|
| 25 | |
|---|
| 26 | #include <hydrogen/hydrogen.h> |
|---|
| 27 | #include <hydrogen/Pattern.h> |
|---|
| 28 | #include <hydrogen/Preferences.h> |
|---|
| 29 | |
|---|
| 30 | using namespace std; |
|---|
| 31 | using namespace H2Core; |
|---|
| 32 | |
|---|
| 33 | PatternPropertiesDialog::PatternPropertiesDialog(QWidget* parent, Pattern *pattern) |
|---|
| 34 | : QDialog(parent) |
|---|
| 35 | { |
|---|
| 36 | setupUi( this ); |
|---|
| 37 | setWindowTitle( trUtf8( "Pattern properties" ) ); |
|---|
| 38 | |
|---|
| 39 | this->pattern = pattern; |
|---|
| 40 | |
|---|
| 41 | patternNameTxt->setText( pattern->get_name() ); |
|---|
| 42 | patternNameTxt->selectAll(); |
|---|
| 43 | |
|---|
| 44 | QString category = pattern->get_category(); |
|---|
| 45 | |
|---|
| 46 | if ( category == "" ){ |
|---|
| 47 | category = "not_categorized"; |
|---|
| 48 | } |
|---|
| 49 | categoryComboBox->addItem( category ); |
|---|
| 50 | |
|---|
| 51 | Preferences *pPref = H2Core::Preferences::getInstance(); |
|---|
| 52 | |
|---|
| 53 | std::list<QString>::const_iterator cur_patternCategories; |
|---|
| 54 | |
|---|
| 55 | if ( pPref->m_patternCategories.size() == 0 ) { |
|---|
| 56 | pPref->m_patternCategories.push_back( "not_categorized" ); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | //categoryComboBox->clear(); |
|---|
| 60 | |
|---|
| 61 | for( cur_patternCategories = pPref->m_patternCategories.begin(); cur_patternCategories != pPref->m_patternCategories.end(); ++cur_patternCategories ) |
|---|
| 62 | { |
|---|
| 63 | if ( categoryComboBox->currentText() != *cur_patternCategories ){ |
|---|
| 64 | categoryComboBox->addItem( *cur_patternCategories ); |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | defaultNameCheck( pattern->get_name() ); |
|---|
| 69 | okBtn->setEnabled(true); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | * Destructor |
|---|
| 75 | */ |
|---|
| 76 | PatternPropertiesDialog::~PatternPropertiesDialog() |
|---|
| 77 | { |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | void PatternPropertiesDialog::on_cancelBtn_clicked() |
|---|
| 82 | { |
|---|
| 83 | reject(); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | void PatternPropertiesDialog::on_okBtn_clicked() |
|---|
| 88 | { |
|---|
| 89 | QString pattName = patternNameTxt->text(); |
|---|
| 90 | QString pattCategory = categoryComboBox->currentText(); |
|---|
| 91 | |
|---|
| 92 | Preferences *pPref = H2Core::Preferences::getInstance(); |
|---|
| 93 | std::list<QString>::const_iterator cur_testpatternCategories; |
|---|
| 94 | |
|---|
| 95 | bool test = true; |
|---|
| 96 | for( cur_testpatternCategories = pPref->m_patternCategories.begin(); cur_testpatternCategories != pPref->m_patternCategories.end(); ++cur_testpatternCategories ) |
|---|
| 97 | { |
|---|
| 98 | if ( categoryComboBox->currentText() == *cur_testpatternCategories ){ |
|---|
| 99 | test = false; |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | if (test == true ) { |
|---|
| 104 | pPref->m_patternCategories.push_back( pattCategory ); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | pattern->set_name(pattName); |
|---|
| 108 | pattern->set_category( pattCategory ); |
|---|
| 109 | accept(); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | void PatternPropertiesDialog::defaultNameCheck( QString pattName ) |
|---|
| 113 | { |
|---|
| 114 | |
|---|
| 115 | PatternList *patternList = Hydrogen::get_instance()->getSong()->get_pattern_list(); |
|---|
| 116 | |
|---|
| 117 | for (uint i = 0; i < patternList->get_size(); i++) { |
|---|
| 118 | if ( patternList->get(i)->get_name() == pattName) { |
|---|
| 119 | patternNameTxt->setText( trUtf8( "%1#2").arg(patternList->get(i)->get_name()) ); |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | bool PatternPropertiesDialog::nameCheck( QString pattName ) |
|---|
| 126 | { |
|---|
| 127 | if (pattName == "") { |
|---|
| 128 | return false; |
|---|
| 129 | } |
|---|
| 130 | PatternList *patternList = Hydrogen::get_instance()->getSong()->get_pattern_list(); |
|---|
| 131 | |
|---|
| 132 | for (uint i = 0; i < patternList->get_size(); i++) { |
|---|
| 133 | if ( patternList->get(i)->get_name() == pattName) { |
|---|
| 134 | return false; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | return true; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | void PatternPropertiesDialog::on_categoryComboBox_editTextChanged() |
|---|
| 142 | { |
|---|
| 143 | if ( categoryComboBox->currentText() == pattern->get_category() ) { |
|---|
| 144 | okBtn->setEnabled( false ); |
|---|
| 145 | } |
|---|
| 146 | else { |
|---|
| 147 | okBtn->setEnabled(true); |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | void PatternPropertiesDialog::on_patternNameTxt_textChanged() |
|---|
| 153 | { |
|---|
| 154 | if ( nameCheck( patternNameTxt->text() ) ) { |
|---|
| 155 | okBtn->setEnabled( true ); |
|---|
| 156 | } |
|---|
| 157 | else { |
|---|
| 158 | okBtn->setEnabled( false ); |
|---|
| 159 | } |
|---|
| 160 | } |
|---|