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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3758 - (show 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 // qsamplerInstrumentListForm.cpp
2 //
3 /****************************************************************************
4 Copyright (C) 2003-2020, 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 #include "qsamplerAbout.h"
24 #include "qsamplerInstrumentListForm.h"
25
26 #include "qsamplerInstrumentList.h"
27
28 #include "qsamplerInstrumentForm.h"
29
30 #include "qsamplerOptions.h"
31 #include "qsamplerInstrument.h"
32 #include "qsamplerMainForm.h"
33
34 #include <QHeaderView>
35 #include <QMessageBox>
36 #include <QContextMenuEvent>
37
38 #include <QCheckBox>
39
40
41 namespace QSampler {
42
43 //-------------------------------------------------------------------------
44 // QSampler::InstrumentListForm -- Instrument map list form implementation.
45 //
46
47 InstrumentListForm::InstrumentListForm ( QWidget *pParent, Qt::WindowFlags wflags )
48 : QMainWindow(pParent, wflags)
49 {
50 m_ui.setupUi(this);
51
52 m_pInstrumentListView = new InstrumentListView(this);
53 QMainWindow::setCentralWidget(m_pInstrumentListView);
54
55 // Setup toolbar widgets.
56 m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar);
57 m_pMapComboBox->setMinimumWidth(120);
58 m_pMapComboBox->setEnabled(false);
59 m_pMapComboBox->setToolTip(tr("Instrument Map"));
60
61 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
69 QObject::connect(m_pMapComboBox,
70 SIGNAL(activated(int)),
71 SLOT(activateMap(int)));
72 QObject::connect(m_pInstrumentListView->selectionModel(),
73 SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)),
74 SLOT(stabilizeForm()));
75 QObject::connect(
76 m_pInstrumentListView,
77 SIGNAL(activated(const QModelIndex&)),
78 SLOT(editInstrument(const QModelIndex&)));
79 QObject::connect(
80 m_ui.newInstrumentAction,
81 SIGNAL(triggered()),
82 SLOT(newInstrument()));
83 QObject::connect(
84 m_ui.deleteInstrumentAction,
85 SIGNAL(triggered()),
86 SLOT(deleteInstrument()));
87 QObject::connect(
88 m_ui.editInstrumentAction,
89 SIGNAL(triggered()),
90 SLOT(editInstrument()));
91 QObject::connect(
92 m_ui.refreshInstrumentsAction,
93 SIGNAL(triggered()),
94 SLOT(refreshInstruments()));
95
96 // Things must be stable from the start.
97 stabilizeForm();
98 }
99
100
101 InstrumentListForm::~InstrumentListForm (void)
102 {
103 delete m_pMapComboBox;
104 delete m_pInstrumentListView;
105 }
106
107
108 // Notify our parent that we're emerging.
109 void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )
110 {
111 MainForm* pMainForm = MainForm::getInstance();
112 if (pMainForm)
113 pMainForm->stabilizeForm();
114
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 MainForm* pMainForm = MainForm::getInstance();
125 if (pMainForm)
126 pMainForm->stabilizeForm();
127 }
128
129
130 // 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 // Refresh all instrument list and views.
142 void InstrumentListForm::refreshInstruments (void)
143 {
144 MainForm* pMainForm = MainForm::getInstance();
145 if (pMainForm == nullptr)
146 return;
147
148 Options *pOptions = pMainForm->options();
149 if (pOptions == nullptr)
150 return;
151
152 // Get/save current map selection...
153 int iMap = m_pMapComboBox->currentIndex();
154 if (iMap < 0 || m_pMapComboBox->count() < 2)
155 iMap = pOptions->iMidiMap + 1;
156
157 // Populate maps list.
158 m_pMapComboBox->clear();
159 m_pMapComboBox->addItem(tr("(All)"));
160 m_pMapComboBox->insertItems(1, Instrument::getMapNames());
161
162 // Adjust to saved selection...
163 if (iMap < 0 || iMap >= m_pMapComboBox->count())
164 iMap = 0;
165 m_pMapComboBox->setCurrentIndex(iMap);
166 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 if (pMainForm == nullptr)
177 return;
178
179 Options *pOptions = pMainForm->options();
180 if (pOptions == nullptr)
181 return;
182
183 int iMidiMap = iMap - 1;
184 if (iMidiMap >= 0)
185 pOptions->iMidiMap = iMidiMap;
186
187 m_pInstrumentListView->setMidiMap(iMidiMap);
188 m_pInstrumentListView->refresh();
189
190 stabilizeForm();
191 }
192
193
194 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 void InstrumentListForm::editInstrument (void)
217 {
218 editInstrument(m_pInstrumentListView->currentIndex());
219 }
220
221
222 void InstrumentListForm::editInstrument ( const QModelIndex& index )
223 {
224 if (!index.isValid())
225 return;
226
227 Instrument *pInstrument
228 = static_cast<Instrument *> (index.internalPointer());
229 if (pInstrument == nullptr)
230 return;
231
232 // Save current key values...
233 int iMap = pInstrument->map();
234 int iBank = pInstrument->bank();
235 int iProg = pInstrument->prog();
236
237 Instrument instrument(iMap, iBank, iProg);
238
239 // Do the edit dance...
240 InstrumentForm form(this);
241 form.setup(pInstrument);
242 if (!form.exec())
243 return;
244
245 // Commit...
246 pInstrument->mapInstrument();
247
248 // Check whether we changed instrument key...
249 if (pInstrument->map() == iMap &&
250 pInstrument->bank() == iBank &&
251 pInstrument->prog() == iProg) {
252 // Just update tree item...
253 m_pInstrumentListView->updateInstrument(pInstrument);
254 } else {
255 // Unmap old instance...
256 instrument.unmapInstrument();
257 // Correct the position of the instrument in the model
258 m_pInstrumentListView->resortInstrument(pInstrument);
259 }
260
261 stabilizeForm();
262 }
263
264
265 void InstrumentListForm::deleteInstrument (void)
266 {
267 const QModelIndex& index = m_pInstrumentListView->currentIndex();
268 if (!index.isValid())
269 return;
270
271 Instrument *pInstrument
272 = static_cast<Instrument *> (index.internalPointer());
273 if (pInstrument == nullptr)
274 return;
275
276 MainForm *pMainForm = MainForm::getInstance();
277 if (pMainForm == nullptr)
278 return;
279
280 // Prompt user if this is for real...
281 Options *pOptions = pMainForm->options();
282 if (pOptions && pOptions->bConfirmRemove) {
283 const QString& sTitle = tr("Warning");
284 const QString& sText = tr(
285 "About to delete instrument map entry:\n\n"
286 "%1\n\n"
287 "Are you sure?")
288 .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 }
309
310 pInstrument->unmapInstrument();
311
312 // Let the instrument vanish from the table model...
313 m_pInstrumentListView->removeInstrument(pInstrument);
314
315 stabilizeForm();
316 }
317
318
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 const QModelIndex& index = m_pInstrumentListView->currentIndex();
327 bEnabled = (bEnabled && index.isValid());
328 m_ui.editInstrumentAction->setEnabled(bEnabled);
329 m_ui.deleteInstrumentAction->setEnabled(bEnabled);
330 }
331
332
333 // Context menu request.
334 void InstrumentListForm::contextMenuEvent (
335 QContextMenuEvent *pContextMenuEvent )
336 {
337 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 }
348
349
350 } // namespace QSampler
351
352
353 // end of qsamplerInstrumentListForm.cpp

  ViewVC Help
Powered by ViewVC