hydrogen 1.2.6
SongEditorPanelTagWidget.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-2025 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
23#include <QtGui>
24#include <QtWidgets>
25
26#include "UndoActions.h"
27#include "../HydrogenApp.h"
29#include "SongEditorPanel.h"
30#include "SongEditor.h"
31
32#include <core/Hydrogen.h>
33#include <core/Timeline.h>
34
35namespace H2Core
36{
37
39 : QDialog( pParent )
40 , m_nTimelinePosition( nBeat )
41{
43 setupUi( this );
44
45 setWindowTitle( tr( "Tag" ) );
47}
48
51
53{
54 auto pTimeline = Hydrogen::get_instance()->getTimeline();
55
56 m_oldTags.resize( m_nMaxRows );
57
58 for ( int ii = 0; ii < m_nMaxRows; ii++ ) {
59 tagTableWidget->insertRow( ii );
60 m_oldTags[ ii ] = "";
61 }
62
63 auto tagVector = pTimeline->getAllTags();
64
65 //read the tag vector and fill all tags into items
66 bool bExistingTagClicked = false;
67
68 for ( const auto& ttag : tagVector ){
69 if ( ttag->nColumn < m_nMaxRows ) {
70 QTableWidgetItem *newTagItem = new QTableWidgetItem();
71 newTagItem->setText( ttag->sTag );
72 tagTableWidget->setItem( ttag->nColumn, 0, newTagItem );
73 m_oldTags[ ttag->nColumn ] = ttag->sTag;
74
75 if ( ttag->nColumn == m_nTimelinePosition ) {
76 bExistingTagClicked = true;
77 tagTableWidget->setCurrentItem( newTagItem );
78 tagTableWidget->openPersistentEditor( newTagItem );
79 }
80 }
81 }
82
83 if ( ! bExistingTagClicked ) {
84 // Open an editor on a blank line
85 QTableWidgetItem *newBlankItem = new QTableWidgetItem();
86 tagTableWidget->setItem( m_nTimelinePosition , 0, newBlankItem );
87 tagTableWidget->setCurrentItem( newBlankItem );
88 tagTableWidget->openPersistentEditor( newBlankItem );
89 }
90}
91
92
97
98
100{
101 QTableWidgetItem* pCurrentItem = tagTableWidget->currentItem();
102 if ( pCurrentItem != nullptr ) {
103 tagTableWidget->closePersistentEditor( pCurrentItem );
104 }
105
106 Hydrogen* pHydrogen = Hydrogen::get_instance();
107 auto pTimeline = pHydrogen->getTimeline();
108 auto tagVector = pTimeline->getAllTags();
109
110 for ( int ii = 0; ii < m_nMaxRows; ii++ ){
111 QTableWidgetItem* pTagItem = tagTableWidget->item( ii, 0 );
112 if ( pTagItem != nullptr && m_oldTags[ ii ] != pTagItem->text() ) {
113 SE_editTagAction *action =
114 new SE_editTagAction( pTagItem->text(), m_oldTags[ ii ], ii );
115 HydrogenApp::get_instance()->m_pUndoStack->push( action );
116 }
117 }
118 accept();
119}
120
121
122void SongEditorPanelTagWidget::on_tagTableWidget_currentItemChanged(QTableWidgetItem * current, QTableWidgetItem * previous )
123{
124 tagTableWidget->closePersistentEditor(previous);
125}
126
127}
Hydrogen Audio Engine.
Definition Hydrogen.h:54
std::shared_ptr< Timeline > getTimeline() const
Definition Hydrogen.h:644
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
Definition Hydrogen.h:84
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
int getMaxBars() const
void on_tagTableWidget_currentItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous)
SongEditorPanelTagWidget(QWidget *pParent, int beat)
static HydrogenApp * get_instance()
Returns the instance of HydrogenApp class.
QUndoStack * m_pUndoStack