/[svn]/qsampler/trunk/src/qsamplerInstrumentListForm.cpp
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerInstrumentListForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1519 - (hide annotations) (download)
Sat Nov 24 13:06:19 2007 UTC (16 years, 4 months ago) by capela
File size: 7305 byte(s)
* Narrower QTableView row heights and header section left-alignment.
* Smoothed the old shinny display effect bitmap.

1 capela 1464 // qsamplerInstrumentListForm.cpp
2     //
3     /****************************************************************************
4     Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (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 capela 1513 #include "qsamplerAbout.h"
24 schoenebeck 1461 #include "qsamplerInstrumentListForm.h"
25    
26 schoenebeck 1492 #include "qsamplerInstrumentForm.h"
27 capela 1513
28 schoenebeck 1461 #include "qsamplerOptions.h"
29     #include "qsamplerInstrument.h"
30 capela 1513 #include "qsamplerMainForm.h"
31 schoenebeck 1461
32 capela 1519 #include <QHeaderView>
33 schoenebeck 1461
34 capela 1519
35 schoenebeck 1461 namespace QSampler {
36    
37 capela 1504 InstrumentListForm::InstrumentListForm (
38     QWidget* pParent, Qt::WindowFlags wflags )
39     : QMainWindow(pParent, wflags)
40 capela 1473 {
41 capela 1509 m_ui.setupUi(this);
42 schoenebeck 1461
43 capela 1509 // Setup toolbar widgets.
44     m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar);
45     m_pMapComboBox->setMinimumWidth(120);
46     m_pMapComboBox->setEnabled(false);
47     m_pMapComboBox->setToolTip(tr("Instrument Map"));
48     m_ui.InstrumentToolbar->addWidget(m_pMapComboBox);
49 schoenebeck 1461
50 capela 1509 m_ui.InstrumentToolbar->addSeparator();
51     m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction);
52     m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction);
53     m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction);
54     m_ui.InstrumentToolbar->addSeparator();
55     m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction);
56 schoenebeck 1461
57 capela 1519 int iRowHeight = m_ui.InstrumentTable->fontMetrics().height() + 4;
58     m_ui.InstrumentTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
59     m_ui.InstrumentTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
60    
61 capela 1509 m_ui.InstrumentTable->setModel(&m_model);
62     m_ui.InstrumentTable->setItemDelegate(&m_delegate);
63 capela 1519 m_ui.InstrumentTable->verticalHeader()->hide();
64 schoenebeck 1461
65     QObject::connect(m_pMapComboBox,
66     SIGNAL(activated(int)),
67     SLOT(activateMap(int)));
68 capela 1466 QObject::connect(
69 capela 1509 m_ui.refreshInstrumentsAction,
70 capela 1466 SIGNAL(triggered()),
71 capela 1509 SLOT(refreshInstruments(void)));
72 capela 1504 QObject::connect(
73 capela 1509 m_ui.InstrumentTable,
74 schoenebeck 1492 SIGNAL(activated(const QModelIndex&)),
75 capela 1509 SLOT(editInstrument(const QModelIndex&)));
76 capela 1504 QObject::connect(
77 capela 1509 m_ui.newInstrumentAction,
78 schoenebeck 1492 SIGNAL(triggered()),
79 capela 1509 SLOT(newInstrument()));
80 capela 1504 QObject::connect(
81 capela 1509 m_ui.deleteInstrumentAction,
82 schoenebeck 1492 SIGNAL(triggered()),
83 capela 1509 SLOT(deleteInstrument()));
84 capela 1504 QObject::connect(
85 capela 1509 m_ui.editInstrumentAction,
86 schoenebeck 1492 SIGNAL(triggered()),
87 capela 1509 SLOT(editInstrument()));
88    
89     MainForm *pMainForm = MainForm::getInstance();
90     if (pMainForm) {
91     QObject::connect(&m_model,
92     SIGNAL(instrumentsChanged()),
93     pMainForm, SLOT(sessionDirty()));
94     }
95 schoenebeck 1461 }
96    
97 capela 1504
98     InstrumentListForm::~InstrumentListForm (void)
99     {
100 schoenebeck 1461 delete m_pMapComboBox;
101     }
102    
103    
104     // Notify our parent that we're emerging.
105     void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )
106     {
107 capela 1504 MainForm* pMainForm = MainForm::getInstance();
108     if (pMainForm)
109     pMainForm->stabilizeForm();
110 schoenebeck 1461
111     QWidget::showEvent(pShowEvent);
112     }
113    
114    
115     // Notify our parent that we're closing.
116     void InstrumentListForm::hideEvent ( QHideEvent *pHideEvent )
117     {
118     QWidget::hideEvent(pHideEvent);
119    
120 capela 1504 MainForm* pMainForm = MainForm::getInstance();
121     if (pMainForm)
122     pMainForm->stabilizeForm();
123 schoenebeck 1461 }
124    
125    
126 capela 1504 // Just about to notify main-window that we're closing.
127     void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ )
128     {
129     QWidget::hide();
130    
131     MainForm *pMainForm = MainForm::getInstance();
132     if (pMainForm)
133     pMainForm->stabilizeForm();
134     }
135    
136    
137 schoenebeck 1461 // Refresh all instrument list and views.
138     void InstrumentListForm::refreshInstruments (void)
139     {
140     MainForm* pMainForm = MainForm::getInstance();
141     if (pMainForm == NULL)
142     return;
143    
144     qsamplerOptions *pOptions = pMainForm->options();
145     if (pOptions == NULL)
146     return;
147    
148     // Get/save current map selection...
149 capela 1499 int iMap = m_pMapComboBox->currentIndex();
150 schoenebeck 1461 if (iMap < 0 || m_pMapComboBox->count() < 2)
151     iMap = pOptions->iMidiMap + 1;
152    
153     // Populate maps list.
154     m_pMapComboBox->clear();
155 capela 1499 m_pMapComboBox->addItem(tr("(All)"));
156     m_pMapComboBox->insertItems(1, qsamplerInstrument::getMapNames());
157 schoenebeck 1461
158     // Adjust to saved selection...
159     if (iMap < 0 || iMap >= m_pMapComboBox->count())
160     iMap = 0;
161 capela 1499 m_pMapComboBox->setCurrentIndex(iMap);
162 schoenebeck 1461 m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);
163    
164     activateMap(iMap);
165     }
166    
167    
168     // Refresh instrument maps selector.
169     void InstrumentListForm::activateMap ( int iMap )
170     {
171     MainForm* pMainForm = MainForm::getInstance();
172     if (pMainForm == NULL)
173     return;
174    
175     qsamplerOptions *pOptions = pMainForm->options();
176     if (pOptions == NULL)
177     return;
178    
179     int iMidiMap = iMap - 1;
180     if (iMidiMap >= 0)
181     pOptions->iMidiMap = iMidiMap;
182    
183 capela 1509 m_model.setMidiMap(iMidiMap);
184     m_model.refresh();
185 schoenebeck 1461 }
186    
187 capela 1504
188     void InstrumentListForm::editInstrument (void)
189     {
190 capela 1509 editInstrument(m_ui.InstrumentTable->currentIndex());
191 schoenebeck 1492 }
192    
193 capela 1504
194     void InstrumentListForm::editInstrument ( const QModelIndex& index )
195     {
196 schoenebeck 1492 if (!index.isValid() || !index.data(Qt::UserRole).isValid())
197     return;
198    
199 capela 1504 qsamplerInstrument* pInstrument
200     = static_cast<qsamplerInstrument *> (
201     index.data(Qt::UserRole).value<void *> ());
202 schoenebeck 1492
203 capela 1504 if (pInstrument == NULL)
204     return;
205 schoenebeck 1492
206     // Save current key values...
207     qsamplerInstrument oldInstrument(*pInstrument);
208     // Do the edit dance...
209     InstrumentForm form(this);
210     form.setup(pInstrument);
211     if (form.exec()) {
212     // Commit...
213     pInstrument->mapInstrument();
214     // Check whether we changed instrument key...
215     if (oldInstrument.map() == pInstrument->map() &&
216     oldInstrument.bank() == pInstrument->bank() &&
217     oldInstrument.prog() == pInstrument->prog()) {
218     // just update tree item...
219     //pItem->update();
220     } else {
221     // Unmap old instance...
222     oldInstrument.unmapInstrument();
223     // correct the position of the instrument in the model
224 capela 1509 m_model.resort(*pInstrument);
225 schoenebeck 1492 }
226     // Notify we've changes...
227 capela 1509 emit m_model.reset();
228 schoenebeck 1492 }
229     }
230    
231 capela 1504
232     void InstrumentListForm::newInstrument (void)
233     {
234 schoenebeck 1492 qsamplerInstrument instrument;
235    
236     InstrumentForm form(this);
237     form.setup(&instrument);
238 capela 1504 if (!form.exec())
239     return;
240 schoenebeck 1492
241     // Commit...
242     instrument.mapInstrument();
243     // add new item to the table model
244 capela 1509 m_model.resort(instrument);
245 schoenebeck 1492 // Notify we've changes...
246     //emit model.reset();
247     //FIXME: call above didnt really refresh, so we use this for now ...
248     refreshInstruments();
249     }
250    
251    
252 capela 1504 void InstrumentListForm::deleteInstrument (void)
253     {
254 capela 1509 const QModelIndex& index = m_ui.InstrumentTable->currentIndex();
255 capela 1504 if (!index.isValid() || !index.data(Qt::UserRole).isValid())
256     return;
257    
258 schoenebeck 1492 qsamplerInstrument* pInstrument =
259 capela 1504 static_cast<qsamplerInstrument*> (
260     index.data(Qt::UserRole).value<void *> ());
261 schoenebeck 1492
262 capela 1504 if (pInstrument == NULL)
263     return;
264 schoenebeck 1492
265     pInstrument->unmapInstrument();
266     // let the instrument vanish from the table model
267 capela 1509 m_model.removeInstrument(*pInstrument);
268 schoenebeck 1492 // Notify we've changes...
269 capela 1509 emit m_model.reset();
270 schoenebeck 1492 }
271    
272 schoenebeck 1461 } // namespace QSampler
273 capela 1464
274    
275     // end of qsamplerInstrumentListForm.cpp

  ViewVC Help
Powered by ViewVC