From dfdd98ae185a46949b668d01fcce3f5f2646970a Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Mon, 7 Oct 2019 00:19:16 +0800 Subject: A less stupid way to save the soundfont list. Old soundfont list will be ignored. Stop using widgets in the soundfont table. The soundfont table is no longer exposed. --- qmidiplayer-desktop/qmpmainwindow.cpp | 10 +++--- qmidiplayer-desktop/qmpsettingswindow.cpp | 56 +++++++++++++++++-------------- qmidiplayer-desktop/qmpsettingswindow.hpp | 3 +- qmidiplayer-desktop/qmpsettingswindow.ui | 6 ++++ 4 files changed, 43 insertions(+), 32 deletions(-) (limited to 'qmidiplayer-desktop') diff --git a/qmidiplayer-desktop/qmpmainwindow.cpp b/qmidiplayer-desktop/qmpmainwindow.cpp index 0bcf070..78230be 100644 --- a/qmidiplayer-desktop/qmpmainwindow.cpp +++ b/qmidiplayer-desktop/qmpmainwindow.cpp @@ -325,15 +325,17 @@ void qmpMainWindow::playerSetup(IFluidSettings* fs) } void qmpMainWindow::loadSoundFont(IFluidSettings *fs) { - for(int i=settingsw->getSFWidget()->rowCount()-1;i>=0;--i) + QList sflist=settingsw->getSettingsIntf()->value("Audio/SoundFonts",QList{}).toList(); + for(auto i=sflist.rbegin();i!=sflist.rend();++i) { - if(!((QCheckBox*)settingsw->getSFWidget()->cellWidget(i,0))->isChecked())continue; + if(i->toString().startsWith('#'))continue; + QString sf=i->toString(); #ifdef _WIN32 - char* c=wcsto8bit(settingsw->getSFWidget()->item(i,1)->text().toStdWString().c_str()); + char* c=wcsto8bit(sf.toStdWString().c_str()); fs->loadSFont(c); free(c); #else - fs->loadSFont(settingsw->getSFWidget()->item(i,1)->text().toStdString().c_str()); + fs->loadSFont(sf.toStdString().c_str()); #endif } } diff --git a/qmidiplayer-desktop/qmpsettingswindow.cpp b/qmidiplayer-desktop/qmpsettingswindow.cpp index 409b087..3aef529 100644 --- a/qmidiplayer-desktop/qmpsettingswindow.cpp +++ b/qmidiplayer-desktop/qmpsettingswindow.cpp @@ -56,9 +56,6 @@ void qmpSettingsWindow::hideEvent(QHideEvent *event) event->accept(); } - -QTableWidget* qmpSettingsWindow::getSFWidget(){return ui->twSoundfont;} - void qmpSettingsWindow::on_buttonBox_accepted() { settingsUpdate(); @@ -166,19 +163,24 @@ void qmpSettingsWindow::settingsInit() settings->setValue("Audio/BankSelect",ui->cbBSMode->currentText()); settings->setValue("Audio/Gain",settings->value("Audio/Gain",50)); - int sfc=settings->value("SoundFonts/SFCount",0).toInt(); - ui->twSoundfont->clear();for(int i=1;i<=sfc;++i) + QList sflist=settings->value("Audio/SoundFonts",QList{}).toList(); + ui->twSoundfont->clear(); + for(int i=0;itwSoundfont->insertRow(i-1); - ui->twSoundfont->setItem(i-1,1,new QTableWidgetItem(settings->value("SoundFonts/SF"+QString::number(i),"").toString())); - ui->twSoundfont->setCellWidget(i-1,0,new QCheckBox("")); - ((QCheckBox*)ui->twSoundfont->cellWidget(i-1,0))->setChecked(settings->value("SoundFonts/SF"+QString::number(i)+"Enabled",1).toInt()); + ui->twSoundfont->insertRow(i); + QTableWidgetItem *sfn,*sfe; + QString sf=sflist[i].toString(); + bool enabled=!sf.startsWith('#'); + if(!enabled)sf=sf.mid(1); + ui->twSoundfont->setItem(i,1,sfn=new QTableWidgetItem(sf)); + ui->twSoundfont->setItem(i,0,sfe=new QTableWidgetItem()); + sfn->setFlags(Qt::ItemFlag::ItemIsEnabled|Qt::ItemFlag::ItemIsSelectable); + sfe->setFlags(Qt::ItemFlag::ItemIsEnabled|Qt::ItemFlag::ItemIsSelectable|Qt::ItemFlag::ItemIsUserCheckable); + sfe->setCheckState(enabled?Qt::CheckState::Checked:Qt::CheckState::Unchecked); } - ui->twSoundfont->setColumnWidth(0,22); - ui->twSoundfont->setColumnWidth(1,400); - QStringList qs;qs.push_back("E");qs.push_back("Path"); + ui->twSoundfont->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents); + QStringList qs{"E","Path"}; ui->twSoundfont->setHorizontalHeaderLabels(qs); - settings->setValue("SoundFonts/SFCount",sfc); settings->setValue("Behavior/RestorePlaylist",settings->value("Behavior/RestorePlaylist",0)); ui->cbRestorePlaylist->setChecked(settings->value("Behavior/RestorePlaylist",0).toInt()); @@ -233,13 +235,14 @@ void qmpSettingsWindow::settingsUpdate() settings->setValue("Audio/BankSelect",ui->cbBSMode->currentText()); - settings->setValue("SoundFonts/SFCount",ui->twSoundfont->rowCount()); - + QList sflist; for(int i=0;itwSoundfont->rowCount();++i) { - settings->setValue("SoundFonts/SF"+QString::number(i+1),ui->twSoundfont->item(i,1)->text()); - settings->setValue("SoundFonts/SF"+QString::number(i+1)+"Enabled",int(((QCheckBox*)ui->twSoundfont->cellWidget(i,0))->isChecked())); + QString sfs=ui->twSoundfont->item(i,1)->text(); + if(ui->twSoundfont->item(i,0)->checkState()==Qt::CheckState::Unchecked)sfs="#"+sfs; + sflist.push_back(sfs); } + settings->setValue("Audio/SoundFonts",sflist); settings->setValue("Behavior/RestorePlaylist",ui->cbRestorePlaylist->isChecked()?1:0); @@ -305,8 +308,11 @@ void qmpSettingsWindow::on_pbAdd_clicked() QStringList sl=QFileDialog::getOpenFileNames(this,"Add File","","SoundFont files (*.sf2)"); for(int i=0;itwSoundfont->insertRow(ui->twSoundfont->rowCount()); - ui->twSoundfont->setItem(ui->twSoundfont->rowCount()-1,1,new QTableWidgetItem(sl.at(i))); - ui->twSoundfont->setCellWidget(ui->twSoundfont->rowCount()-1,0,new QCheckBox("")); + QTableWidgetItem *sfn,*sfe; + ui->twSoundfont->setItem(ui->twSoundfont->rowCount()-1,1,sfn=new QTableWidgetItem(sl[i])); + ui->twSoundfont->setItem(ui->twSoundfont->rowCount()-1,0,sfe=new QTableWidgetItem()); + sfn->setFlags(Qt::ItemFlag::ItemIsEnabled|Qt::ItemFlag::ItemIsSelectable); + sfe->setFlags(Qt::ItemFlag::ItemIsEnabled|Qt::ItemFlag::ItemIsSelectable|Qt::ItemFlag::ItemIsUserCheckable); } } @@ -323,11 +329,10 @@ void qmpSettingsWindow::on_pbUp_clicked() { int cid=ui->twSoundfont->currentRow();if(!cid)return; QTableWidgetItem *ci=ui->twSoundfont->takeItem(cid,1); - bool e=((QCheckBox*)ui->twSoundfont->cellWidget(cid,0))->isChecked(); + QTableWidgetItem *ce=ui->twSoundfont->takeItem(cid,0); ui->twSoundfont->removeRow(cid); ui->twSoundfont->insertRow(cid-1); - ui->twSoundfont->setCellWidget(cid-1,0,new QCheckBox("")); - ((QCheckBox*)ui->twSoundfont->cellWidget(cid-1,0))->setChecked(e); + ui->twSoundfont->setItem(cid-1,0,ce); ui->twSoundfont->setItem(cid-1,1,ci); ui->twSoundfont->setCurrentCell(cid-1,1); } @@ -336,11 +341,10 @@ void qmpSettingsWindow::on_pbDown_clicked() { int cid=ui->twSoundfont->currentRow();if(cid==ui->twSoundfont->rowCount()-1)return; QTableWidgetItem *ci=ui->twSoundfont->takeItem(cid,1); - bool e=((QCheckBox*)ui->twSoundfont->cellWidget(cid,0))->isChecked(); + QTableWidgetItem *ce=ui->twSoundfont->takeItem(cid,0); ui->twSoundfont->removeRow(cid); ui->twSoundfont->insertRow(cid+1); - ui->twSoundfont->setCellWidget(cid+1,0,new QCheckBox("")); - ((QCheckBox*)ui->twSoundfont->cellWidget(cid+1,0))->setChecked(e); + ui->twSoundfont->setItem(cid+1,0,ce); ui->twSoundfont->setItem(cid+1,1,ci); ui->twSoundfont->setCurrentCell(cid+1,1); } @@ -377,7 +381,7 @@ void qmpSettingsWindow::postInit() { int sf=0; for(int i=0;itwSoundfont->rowCount();++i) - if(((QCheckBox*)ui->twSoundfont->cellWidget(i,0))->isChecked())++sf; + if(ui->twSoundfont->item(i,0)->checkState()==Qt::CheckState::Checked)++sf; std::string selecteddev; std::vector devs=qmpMainWindow::getInstance()->getPlayer()->getMidiOutDevices(); std::set devset; diff --git a/qmidiplayer-desktop/qmpsettingswindow.hpp b/qmidiplayer-desktop/qmpsettingswindow.hpp index 0e208ca..c1ae410 100644 --- a/qmidiplayer-desktop/qmpsettingswindow.hpp +++ b/qmidiplayer-desktop/qmpsettingswindow.hpp @@ -86,12 +86,11 @@ class qmpSettingsWindow:public QDialog Q_OBJECT public: - explicit qmpSettingsWindow(QWidget *parent=0); + explicit qmpSettingsWindow(QWidget *parent=nullptr); ~qmpSettingsWindow(); void closeEvent(QCloseEvent *event); void hideEvent(QHideEvent *event); void settingsInit(); - QTableWidget *getSFWidget(); void updatePluginList(qmpPluginManager *pmgr); void registerOptionInt(std::string tab,std::string desc,std::string key,int min,int max,int defaultval); int getOptionInt(std::string key); diff --git a/qmidiplayer-desktop/qmpsettingswindow.ui b/qmidiplayer-desktop/qmpsettingswindow.ui index 3619943..c773958 100644 --- a/qmidiplayer-desktop/qmpsettingswindow.ui +++ b/qmidiplayer-desktop/qmpsettingswindow.ui @@ -474,6 +474,12 @@ QAbstractItemView::InternalMove + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + E -- cgit v1.2.3