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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC