hydrogen 1.2.3
PatternPropertiesDialog.cpp
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
24#include "HydrogenApp.h"
25#include "UndoActions.h"
26
27#include <core/Hydrogen.h>
28#include <core/Basics/Pattern.h>
31
32using namespace H2Core;
33
34PatternPropertiesDialog::PatternPropertiesDialog(QWidget* parent, Pattern *pattern, int nselectedPattern, bool savepattern)
35 : QDialog(parent)
36{
37 setupUi( this );
38 setWindowTitle( tr( "Pattern properties" ) );
39
40 this->pattern = pattern;
41
42 patternNameTxt->setText( pattern->get_name() );
43 patternNameTxt->selectAll();
44
45 patternDescTxt->setText( pattern->get_info() );
46
47 QString category = pattern->get_category();
48 __nselectedPattern = nselectedPattern;
49 __savepattern = savepattern;
50
51 if ( category == "" ){
52 category = "not_categorized";
53 }
54 categoryComboBox->addItem( category );
55
57
58 std::list<QString>::const_iterator cur_patternCategories;
59
60 if ( pPref->m_patternCategories.size() == 0 ) {
61 pPref->m_patternCategories.push_back( "not_categorized" );
62 }
63
64 //categoryComboBox->clear();
65
66 for( cur_patternCategories = pPref->m_patternCategories.begin(); cur_patternCategories != pPref->m_patternCategories.end(); ++cur_patternCategories )
67 {
68 if ( categoryComboBox->currentText() != *cur_patternCategories ){
69 categoryComboBox->addItem( *cur_patternCategories );
70 }
71 }
72
73 defaultNameCheck( pattern->get_name(), savepattern );
74 okBtn->setEnabled(true);
75}
76
77
84
85
90
91
93{
94 QString pattName = patternNameTxt->text();
95 QString pattCategory = categoryComboBox->currentText();
96 QString pattInfo = patternDescTxt->toPlainText();
97
98 // Ensure the pattern name is unique
99 PatternList *pPatternList = Hydrogen::get_instance()->getSong()->getPatternList();
100 pattName = pPatternList->find_unused_pattern_name(pattName, pattern);
101
103 std::list<QString>::const_iterator cur_testpatternCategories;
104
105 bool test = true;
106 for( cur_testpatternCategories = pPref->m_patternCategories.begin(); cur_testpatternCategories != pPref->m_patternCategories.end(); ++cur_testpatternCategories )
107 {
108 if ( categoryComboBox->currentText() == *cur_testpatternCategories ){
109 test = false;
110 }
111 }
112
113 if (test == true ) {
114 pPref->m_patternCategories.push_back( pattCategory );
115 }
116
117 if( __savepattern ){
118 pattern->set_name( pattName );
119 pattern->set_info( pattInfo );
120 pattern->set_category( pattCategory );
121 } else if ( pattern->get_name() != pattName || pattern->get_info() != pattInfo || pattern->get_category() != pattCategory) {
123 pattName, pattInfo, pattCategory, __nselectedPattern );
124 HydrogenApp::get_instance()->m_pUndoStack->push( action );
125 }
126 accept();
127}
128
129void PatternPropertiesDialog::defaultNameCheck( QString pattName, bool savepattern)
130{
131 PatternList *pPatternList = Hydrogen::get_instance()->getSong()->getPatternList();
132 if ( savepattern && !pPatternList->check_name(pattName, pattern) ) {
133 pattName = pPatternList->find_unused_pattern_name(pattName, pattern);
134 }
135
136 patternNameTxt->setText(pattName);
137}
std::shared_ptr< Song > getSong() const
Get the current song.
Definition Hydrogen.h:122
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
Definition Hydrogen.h:83
PatternList is a collection of patterns.
Definition PatternList.h:43
bool check_name(QString patternName, Pattern *ignore=NULL)
check if a pattern with name patternName already exists in this list
QString find_unused_pattern_name(QString sourceName, Pattern *ignore=NULL)
find unused patternName
Pattern class is a Note container.
Definition Pattern.h:46
const QString & get_info() const
get the category of the pattern
Definition Pattern.h:320
void set_name(const QString &name)
get the name of the pattern
Definition Pattern.h:305
const QString & get_name() const
set the category of the pattern
Definition Pattern.h:310
const QString & get_category() const
set the length of the pattern
Definition Pattern.h:330
void set_info(const QString &info)
get the info of the pattern
Definition Pattern.h:315
void set_category(const QString &category)
set the info of the pattern
Definition Pattern.h:325
Manager for User Preferences File (singleton)
Definition Preferences.h:78
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
std::list< QString > m_patternCategories
static HydrogenApp * get_instance()
Returns the instance of HydrogenApp class.
QUndoStack * m_pUndoStack
PatternPropertiesDialog(QWidget *parent, H2Core::Pattern *pattern, int nselectedPattern, bool save)
void defaultNameCheck(QString, bool)
Does some name check.