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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3758 - (hide annotations) (download)
Fri Mar 27 17:57:40 2020 UTC (4 years ago) by capela
File size: 9140 byte(s)
- Early fixing to build for Qt >= 5.15.0.
1 capela 1464 // qsamplerInstrumentListForm.cpp
2     //
3     /****************************************************************************
4 capela 3758 Copyright (C) 2003-2020, rncbc aka Rui Nuno Capela. All rights reserved.
5 capela 1464 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 capela 2064 #include "qsamplerInstrumentList.h"
27    
28 schoenebeck 1492 #include "qsamplerInstrumentForm.h"
29 capela 1513
30 schoenebeck 1461 #include "qsamplerOptions.h"
31     #include "qsamplerInstrument.h"
32 capela 1513 #include "qsamplerMainForm.h"
33 schoenebeck 1461
34 capela 1519 #include <QHeaderView>
35 capela 1528 #include <QMessageBox>
36 capela 2066 #include <QContextMenuEvent>
37 schoenebeck 1461
38 capela 2722 #include <QCheckBox>
39 capela 1519
40 capela 2722
41 schoenebeck 1461 namespace QSampler {
42    
43 capela 1558 //-------------------------------------------------------------------------
44     // QSampler::InstrumentListForm -- Instrument map list form implementation.
45     //
46    
47 capela 3758 InstrumentListForm::InstrumentListForm ( QWidget *pParent, Qt::WindowFlags wflags )
48 capela 1504 : QMainWindow(pParent, wflags)
49 capela 1473 {
50 capela 1509 m_ui.setupUi(this);
51 schoenebeck 1461
52 capela 2066 m_pInstrumentListView = new InstrumentListView(this);
53     QMainWindow::setCentralWidget(m_pInstrumentListView);
54    
55 capela 1509 // Setup toolbar widgets.
56 capela 2065 m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar);
57 capela 1509 m_pMapComboBox->setMinimumWidth(120);
58     m_pMapComboBox->setEnabled(false);
59     m_pMapComboBox->setToolTip(tr("Instrument Map"));
60 capela 2066
61 capela 2065 m_ui.instrumentToolbar->addWidget(m_pMapComboBox);
62     m_ui.instrumentToolbar->addSeparator();
63     m_ui.instrumentToolbar->addAction(m_ui.newInstrumentAction);
64     m_ui.instrumentToolbar->addAction(m_ui.editInstrumentAction);
65     m_ui.instrumentToolbar->addAction(m_ui.deleteInstrumentAction);
66     m_ui.instrumentToolbar->addSeparator();
67     m_ui.instrumentToolbar->addAction(m_ui.refreshInstrumentsAction);
68 schoenebeck 1461
69     QObject::connect(m_pMapComboBox,
70     SIGNAL(activated(int)),
71     SLOT(activateMap(int)));
72 capela 2066 QObject::connect(m_pInstrumentListView->selectionModel(),
73     SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)),
74 capela 1528 SLOT(stabilizeForm()));
75     QObject::connect(
76 capela 2064 m_pInstrumentListView,
77 capela 2067 SIGNAL(activated(const QModelIndex&)),
78 capela 1509 SLOT(editInstrument(const QModelIndex&)));
79 capela 1504 QObject::connect(
80 capela 1509 m_ui.newInstrumentAction,
81 schoenebeck 1492 SIGNAL(triggered()),
82 capela 1509 SLOT(newInstrument()));
83 capela 1504 QObject::connect(
84 capela 1509 m_ui.deleteInstrumentAction,
85 schoenebeck 1492 SIGNAL(triggered()),
86 capela 1509 SLOT(deleteInstrument()));
87 capela 1504 QObject::connect(
88 capela 1509 m_ui.editInstrumentAction,
89 schoenebeck 1492 SIGNAL(triggered()),
90 capela 1509 SLOT(editInstrument()));
91 capela 1528 QObject::connect(
92     m_ui.refreshInstrumentsAction,
93     SIGNAL(triggered()),
94     SLOT(refreshInstruments()));
95 capela 1509
96 capela 1528 // Things must be stable from the start.
97     stabilizeForm();
98 schoenebeck 1461 }
99    
100 capela 1504
101     InstrumentListForm::~InstrumentListForm (void)
102     {
103 capela 2066 delete m_pMapComboBox;
104 capela 2064 delete m_pInstrumentListView;
105 schoenebeck 1461 }
106    
107    
108     // Notify our parent that we're emerging.
109     void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )
110     {
111 capela 1504 MainForm* pMainForm = MainForm::getInstance();
112     if (pMainForm)
113     pMainForm->stabilizeForm();
114 schoenebeck 1461
115     QWidget::showEvent(pShowEvent);
116     }
117    
118    
119     // Notify our parent that we're closing.
120     void InstrumentListForm::hideEvent ( QHideEvent *pHideEvent )
121     {
122     QWidget::hideEvent(pHideEvent);
123    
124 capela 1504 MainForm* pMainForm = MainForm::getInstance();
125     if (pMainForm)
126     pMainForm->stabilizeForm();
127 schoenebeck 1461 }
128    
129    
130 capela 1504 // Just about to notify main-window that we're closing.
131     void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ )
132     {
133     QWidget::hide();
134    
135     MainForm *pMainForm = MainForm::getInstance();
136     if (pMainForm)
137     pMainForm->stabilizeForm();
138     }
139    
140    
141 schoenebeck 1461 // Refresh all instrument list and views.
142     void InstrumentListForm::refreshInstruments (void)
143     {
144     MainForm* pMainForm = MainForm::getInstance();
145 capela 3555 if (pMainForm == nullptr)
146 schoenebeck 1461 return;
147    
148 capela 1558 Options *pOptions = pMainForm->options();
149 capela 3555 if (pOptions == nullptr)
150 schoenebeck 1461 return;
151    
152     // Get/save current map selection...
153 capela 1499 int iMap = m_pMapComboBox->currentIndex();
154 schoenebeck 1461 if (iMap < 0 || m_pMapComboBox->count() < 2)
155     iMap = pOptions->iMidiMap + 1;
156    
157     // Populate maps list.
158     m_pMapComboBox->clear();
159 capela 1499 m_pMapComboBox->addItem(tr("(All)"));
160 capela 1558 m_pMapComboBox->insertItems(1, Instrument::getMapNames());
161 schoenebeck 1461
162     // Adjust to saved selection...
163     if (iMap < 0 || iMap >= m_pMapComboBox->count())
164     iMap = 0;
165 capela 1499 m_pMapComboBox->setCurrentIndex(iMap);
166 schoenebeck 1461 m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);
167    
168     activateMap(iMap);
169     }
170    
171    
172     // Refresh instrument maps selector.
173     void InstrumentListForm::activateMap ( int iMap )
174     {
175     MainForm* pMainForm = MainForm::getInstance();
176 capela 3555 if (pMainForm == nullptr)
177 schoenebeck 1461 return;
178    
179 capela 1558 Options *pOptions = pMainForm->options();
180 capela 3555 if (pOptions == nullptr)
181 schoenebeck 1461 return;
182    
183     int iMidiMap = iMap - 1;
184     if (iMidiMap >= 0)
185     pOptions->iMidiMap = iMidiMap;
186    
187 capela 2064 m_pInstrumentListView->setMidiMap(iMidiMap);
188     m_pInstrumentListView->refresh();
189 capela 1528
190     stabilizeForm();
191 schoenebeck 1461 }
192    
193 capela 1504
194 capela 2067 void InstrumentListForm::newInstrument (void)
195     {
196     Instrument instrument;
197    
198     InstrumentForm form(this);
199     form.setup(&instrument);
200     if (!form.exec())
201     return;
202    
203     // Commit...
204     instrument.mapInstrument();
205    
206     // add new item to the table model
207     m_pInstrumentListView->addInstrument(
208     instrument.map(),
209     instrument.bank(),
210     instrument.prog());
211    
212     stabilizeForm();
213     }
214    
215    
216 capela 1504 void InstrumentListForm::editInstrument (void)
217     {
218 capela 2064 editInstrument(m_pInstrumentListView->currentIndex());
219 schoenebeck 1492 }
220    
221 capela 1504
222     void InstrumentListForm::editInstrument ( const QModelIndex& index )
223     {
224 capela 2064 if (!index.isValid())
225 schoenebeck 1492 return;
226    
227 capela 2064 Instrument *pInstrument
228     = static_cast<Instrument *> (index.internalPointer());
229 capela 3555 if (pInstrument == nullptr)
230 capela 2064 return;
231 schoenebeck 1492
232     // Save current key values...
233 capela 2065 int iMap = pInstrument->map();
234     int iBank = pInstrument->bank();
235     int iProg = pInstrument->prog();
236 capela 2064
237 capela 2065 Instrument instrument(iMap, iBank, iProg);
238    
239 schoenebeck 1492 // Do the edit dance...
240     InstrumentForm form(this);
241 capela 2071 form.setup(pInstrument);
242 capela 1504 if (!form.exec())
243     return;
244 capela 2067
245 schoenebeck 1492 // Commit...
246 capela 2071 pInstrument->mapInstrument();
247 capela 2064
248 capela 2067 // Check whether we changed instrument key...
249 capela 2071 if (pInstrument->map() == iMap &&
250     pInstrument->bank() == iBank &&
251     pInstrument->prog() == iProg) {
252 capela 2067 // Just update tree item...
253 capela 2070 m_pInstrumentListView->updateInstrument(pInstrument);
254 capela 2067 } else {
255     // Unmap old instance...
256 capela 2071 instrument.unmapInstrument();
257 capela 2068 // Correct the position of the instrument in the model
258 capela 2070 m_pInstrumentListView->resortInstrument(pInstrument);
259 capela 2067 }
260 capela 2065
261     stabilizeForm();
262 schoenebeck 1492 }
263    
264    
265 capela 1504 void InstrumentListForm::deleteInstrument (void)
266     {
267 capela 2064 const QModelIndex& index = m_pInstrumentListView->currentIndex();
268     if (!index.isValid())
269 capela 1504 return;
270    
271 capela 2064 Instrument *pInstrument
272     = static_cast<Instrument *> (index.internalPointer());
273 capela 3555 if (pInstrument == nullptr)
274 capela 1504 return;
275 schoenebeck 1492
276 capela 1528 MainForm *pMainForm = MainForm::getInstance();
277 capela 3555 if (pMainForm == nullptr)
278 capela 1528 return;
279    
280     // Prompt user if this is for real...
281 capela 1558 Options *pOptions = pMainForm->options();
282 capela 1528 if (pOptions && pOptions->bConfirmRemove) {
283 capela 3559 const QString& sTitle = tr("Warning");
284 capela 2722 const QString& sText = tr(
285     "About to delete instrument map entry:\n\n"
286 capela 1528 "%1\n\n"
287     "Are you sure?")
288 capela 2722 .arg(pInstrument->name());
289     #if 0
290     if (QMessageBox::warning(this, sTitle, sText,
291     QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
292     return;
293     #else
294     QMessageBox mbox(this);
295     mbox.setIcon(QMessageBox::Warning);
296     mbox.setWindowTitle(sTitle);
297     mbox.setText(sText);
298     mbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
299     QCheckBox cbox(tr("Don't ask this again"));
300     cbox.setChecked(false);
301     cbox.blockSignals(true);
302     mbox.addButton(&cbox, QMessageBox::ActionRole);
303     if (mbox.exec() == QMessageBox::Cancel)
304     return;
305     if (cbox.isChecked())
306     pOptions->bConfirmRemove = false;
307     #endif
308 capela 1528 }
309    
310 schoenebeck 1492 pInstrument->unmapInstrument();
311 capela 2064
312 capela 2071 // Let the instrument vanish from the table model...
313 capela 2064 m_pInstrumentListView->removeInstrument(pInstrument);
314 capela 2065
315     stabilizeForm();
316 schoenebeck 1492 }
317    
318 capela 1528
319     // Update form actions enablement...
320     void InstrumentListForm::stabilizeForm (void)
321     {
322     MainForm *pMainForm = MainForm::getInstance();
323    
324     bool bEnabled = (pMainForm && pMainForm->client());
325     m_ui.newInstrumentAction->setEnabled(bEnabled);
326 capela 2064 const QModelIndex& index = m_pInstrumentListView->currentIndex();
327 capela 1528 bEnabled = (bEnabled && index.isValid());
328     m_ui.editInstrumentAction->setEnabled(bEnabled);
329     m_ui.deleteInstrumentAction->setEnabled(bEnabled);
330     }
331    
332    
333 capela 2066 // Context menu request.
334     void InstrumentListForm::contextMenuEvent (
335     QContextMenuEvent *pContextMenuEvent )
336 capela 1528 {
337 capela 2067 QMenu menu(this);
338    
339     menu.addAction(m_ui.newInstrumentAction);
340     menu.addSeparator();
341     menu.addAction(m_ui.editInstrumentAction);
342     menu.addAction(m_ui.deleteInstrumentAction);
343     menu.addSeparator();
344     menu.addAction(m_ui.refreshInstrumentsAction);
345    
346     menu.exec(pContextMenuEvent->globalPos());
347 capela 1528 }
348    
349    
350 schoenebeck 1461 } // namespace QSampler
351 capela 1464
352    
353     // end of qsamplerInstrumentListForm.cpp

  ViewVC Help
Powered by ViewVC