aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayer-desktop
diff options
context:
space:
mode:
Diffstat (limited to 'qmidiplayer-desktop')
-rw-r--r--qmidiplayer-desktop/qmpchannelswindow.cpp39
-rw-r--r--qmidiplayer-desktop/qmpchannelswindow.hpp4
-rw-r--r--qmidiplayer-desktop/qmpdeviceprioritydialog.cpp2
-rw-r--r--qmidiplayer-desktop/qmpdevpropdialog.cpp51
-rw-r--r--qmidiplayer-desktop/qmpdevpropdialog.ui6
-rw-r--r--qmidiplayer-desktop/qmpsettingswindow.cpp13
-rw-r--r--qmidiplayer-desktop/qmpsettingswindow.ui6
7 files changed, 75 insertions, 46 deletions
diff --git a/qmidiplayer-desktop/qmpchannelswindow.cpp b/qmidiplayer-desktop/qmpchannelswindow.cpp
index 029daff..fe0eeff 100644
--- a/qmidiplayer-desktop/qmpchannelswindow.cpp
+++ b/qmidiplayer-desktop/qmpchannelswindow.cpp
@@ -95,6 +95,20 @@ QVariant qmpChannelsModel::data(const QModelIndex&index,int role)const
}
return QVariant();
}
+bool qmpChannelsModel::setData(const QModelIndex&index,const QVariant&value,int role)
+{
+ if(index.column()==3)
+ {
+ if(role!=Qt::ItemDataRole::DisplayRole)return false;
+ std::vector<std::string> dsv=CMidiPlayer::getInstance()->getMidiOutDevices();
+ int idx=std::find(dsv.begin(),dsv.end(),value.toString().toStdString())-dsv.begin();
+ if(idx==CMidiPlayer::getInstance()->getChannelOutput(index.row()))return false;
+ CMidiPlayer::getInstance()->setChannelOutput(index.row(),idx);
+ emit dataChanged(index,index,{Qt::DisplayRole});
+ return true;
+ }
+ return false;
+}
QVariant qmpChannelsModel::headerData(int section,Qt::Orientation orientation,int role)const
{
if(role!=Qt::ItemDataRole::DisplayRole)return QVariant();
@@ -152,8 +166,8 @@ void qmpChannelsModel::channelMSClearAll(int type)
}
}
-qmpDeviceItemDelegate::qmpDeviceItemDelegate(QWidget*parent):QStyledItemDelegate(parent),par(parent)
-{}
+qmpDeviceItemDelegate::qmpDeviceItemDelegate(bool ignoreInternal,QWidget*parent):
+ QStyledItemDelegate(parent),par(parent),nofs(ignoreInternal){}
void qmpDeviceItemDelegate::paint(QPainter*painter,const QStyleOptionViewItem&option,const QModelIndex&index)const
{
QStyleOptionViewItem opt;
@@ -162,6 +176,7 @@ void qmpDeviceItemDelegate::paint(QPainter*painter,const QStyleOptionViewItem&op
socb.currentText=opt.text;
socb.editable=false;
socb.rect=option.rect;
+ socb.state=opt.state;
par->style()->drawComplexControl(QStyle::ComplexControl::CC_ComboBox,&socb,painter);
par->style()->drawControl(QStyle::CE_ComboBoxLabel,&socb,painter);
}
@@ -182,6 +197,10 @@ QWidget* qmpDeviceItemDelegate::createEditor(QWidget*parent,const QStyleOptionVi
Q_UNUSED(index)
QComboBox *cb=new QComboBox(parent);
cb->setEditable(false);
+ connect(cb,static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),this,[index,cb](int){
+ const_cast<QAbstractItemModel*>(index.model())->setData(index,cb->currentText(),Qt::ItemDataRole::DisplayRole);
+ cb->hidePopup();
+ });
return cb;
}
void qmpDeviceItemDelegate::setEditorData(QWidget*widget,const QModelIndex&index)const
@@ -196,21 +215,15 @@ void qmpDeviceItemDelegate::setEditorData(QWidget*widget,const QModelIndex&index
cb->clear();
std::vector<std::string> devs=qmpMainWindow::getInstance()->getPlayer()->getMidiOutDevices();
for(auto s:devs)
- cb->addItem(QString::fromStdString(s));
- cb->setCurrentIndex(qmpMainWindow::getInstance()->getPlayer()->getChannelOutput(index.row()));
+ if(!nofs||(nofs&&s!="Internal FluidSynth"))
+ cb->addItem(QString::fromStdString(s));
+ cb->setCurrentText(index.data().toString());
cb->showPopup();
- connect(cb,static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),[this,index,cb](int id){
- QTableView*pv=qobject_cast<QTableView*>(this->parent());
- qmpMainWindow::getInstance()->getPlayer()->setChannelOutput(index.row(),id);
- emit pv->model()->dataChanged(index,index,{Qt::DisplayRole});
- cb->hidePopup();
- });
}
void qmpDeviceItemDelegate::setModelData(QWidget*editor,QAbstractItemModel*model,const QModelIndex&index)const
{
QComboBox *cb=qobject_cast<QComboBox*>(editor);
- qmpMainWindow::getInstance()->getPlayer()->setChannelOutput(index.row(),cb->currentIndex());
- emit model->dataChanged(index,index,{Qt::DisplayRole});
+ model->setData(index,cb->currentText(),Qt::ItemDataRole::DisplayRole);
}
void qmpDeviceItemDelegate::updateEditorGeometry(QWidget*editor,const QStyleOptionViewItem&option,const QModelIndex&index)const
{
@@ -225,7 +238,7 @@ qmpChannelsWindow::qmpChannelsWindow(QWidget *parent) :
ui->setupUi(this);
ui->tvChannels->setHorizontalHeader(new QHeaderView(Qt::Orientation::Horizontal));
ui->tvChannels->setModel(chmodel=new qmpChannelsModel);
- ui->tvChannels->setItemDelegateForColumn(3,new qmpDeviceItemDelegate(ui->tvChannels));
+ ui->tvChannels->setItemDelegateForColumn(3,new qmpDeviceItemDelegate(false,ui->tvChannels));
ui->tvChannels->setAlternatingRowColors(true);
ui->tvChannels->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
ui->tvChannels->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
diff --git a/qmidiplayer-desktop/qmpchannelswindow.hpp b/qmidiplayer-desktop/qmpchannelswindow.hpp
index 93742a2..072f9d3 100644
--- a/qmidiplayer-desktop/qmpchannelswindow.hpp
+++ b/qmidiplayer-desktop/qmpchannelswindow.hpp
@@ -40,6 +40,7 @@ class qmpChannelsModel:public QAbstractTableModel
int rowCount(const QModelIndex&parent=QModelIndex())const override;
QModelIndex parent(const QModelIndex&child)const override;
QVariant data(const QModelIndex&index,int role=Qt::ItemDataRole::DisplayRole)const override;
+ bool setData(const QModelIndex &index,const QVariant &value,int role=Qt::EditRole)override;
QVariant headerData(int section,Qt::Orientation orientation,int role=Qt::ItemDataRole::DisplayRole)const override;
Qt::ItemFlags flags(const QModelIndex&idx)const override;
public slots:
@@ -56,7 +57,7 @@ class qmpDeviceItemDelegate:public QStyledItemDelegate
{
Q_OBJECT
public:
- explicit qmpDeviceItemDelegate(QWidget*parent=nullptr);
+ explicit qmpDeviceItemDelegate(bool ignoreInternal=false,QWidget*parent=nullptr);
void paint(QPainter*painter,const QStyleOptionViewItem&option,const QModelIndex&index)const override;
QSize sizeHint(const QStyleOptionViewItem&option,const QModelIndex&index)const override;
QWidget* createEditor(QWidget*parent,const QStyleOptionViewItem&option,const QModelIndex&index)const override;
@@ -65,6 +66,7 @@ class qmpDeviceItemDelegate:public QStyledItemDelegate
void updateEditorGeometry(QWidget*editor,const QStyleOptionViewItem&option,const QModelIndex&index)const override;
private:
QWidget *par;
+ bool nofs;
};
class qmpChannelsWindow:public QWidget
diff --git a/qmidiplayer-desktop/qmpdeviceprioritydialog.cpp b/qmidiplayer-desktop/qmpdeviceprioritydialog.cpp
index a319fd1..d26fb45 100644
--- a/qmidiplayer-desktop/qmpdeviceprioritydialog.cpp
+++ b/qmidiplayer-desktop/qmpdeviceprioritydialog.cpp
@@ -37,7 +37,6 @@ void qmpDevicePriorityDialog::setupRegisteredDevices()
e->setEditable(false);
e->setCheckState(Qt::CheckState::Checked);
QStandardItem *a=new QStandardItem;
- a->setEnabled(false);
a->setText(sconn.find(dev.toString().toStdString())!=sconn.end()?"Connected":"Disconnected");
a->setEditable(false);
QStandardItem *devn=new QStandardItem(dev.toString());
@@ -53,7 +52,6 @@ void qmpDevicePriorityDialog::setupRegisteredDevices()
e->setEditable(false);
e->setCheckState(Qt::CheckState::Unchecked);
QStandardItem *a=new QStandardItem;
- a->setEnabled(false);
a->setText("Connected");
a->setEditable(false);
QStandardItem *devn=new QStandardItem(QString::fromStdString(dev));
diff --git a/qmidiplayer-desktop/qmpdevpropdialog.cpp b/qmidiplayer-desktop/qmpdevpropdialog.cpp
index 150f54b..30f1568 100644
--- a/qmidiplayer-desktop/qmpdevpropdialog.cpp
+++ b/qmidiplayer-desktop/qmpdevpropdialog.cpp
@@ -3,10 +3,10 @@
#include <QLabel>
#include <QFileDialog>
#include <QTableWidgetItem>
-#include <QCheckBox>
#include "qmpdevpropdialog.hpp"
#include "qmpmainwindow.hpp"
#include "qmpsettingswindow.hpp"
+#include "qmpchannelswindow.hpp"
#include "ui_qmpdevpropdialog.h"
qmpDevPropDialog::qmpDevPropDialog(QWidget *parent) :
@@ -14,6 +14,19 @@ qmpDevPropDialog::qmpDevPropDialog(QWidget *parent) :
ui(new Ui::qmpDevPropDialog)
{
ui->setupUi(this);
+ ui->twProps->setItemDelegateForColumn(0,new qmpDeviceItemDelegate(true,ui->twProps));
+ ui->twProps->setEditTriggers(QAbstractItemView::EditTrigger::NoEditTriggers);
+ connect(ui->twProps,&QTableWidget::cellClicked,[this](int r,int c){
+ if(c!=0)return;
+ this->ui->twProps->edit(ui->twProps->model()->index(r,c));
+ });
+ connect(ui->twProps,&QTableWidget::cellChanged,this,[this](int r,int c){
+ if(c!=0)return;
+ QString connst("Disconnected");
+ for(auto&ds:qmpMainWindow::getInstance()->getPlayer()->getMidiOutDevices())
+ if(ui->twProps->item(r,c)->text()==QString::fromStdString(ds)){connst="Connected";break;}
+ ui->twProps->item(r,1)->setText(connst);
+ });
}
qmpDevPropDialog::~qmpDevPropDialog()
@@ -48,10 +61,10 @@ void qmpDevPropDialog::setupRow(const QString&dn,const QString&din)
int r;
ui->twProps->insertRow(r=ui->twProps->rowCount());
ui->twProps->setRowHeight(r,32);
- QComboBox *cb;
- ui->twProps->setCellWidget(r,0,cb=new QComboBox);
- for(auto&s:qmpMainWindow::getInstance()->getPlayer()->getMidiOutDevices())
- if(s!="Internal FluidSynth")cb->addItem(QString::fromStdString(s));
+ QTableWidgetItem *cbx=new QTableWidgetItem;
+ ui->twProps->setItem(r,1,cbx);
+ QTableWidgetItem *cb;
+ ui->twProps->setItem(r,0,cb=new QTableWidgetItem);
QWidget *fw=new QWidget;
QLabel *lb;QPushButton *pb;
fw->setLayout(new QHBoxLayout);
@@ -61,29 +74,19 @@ void qmpDevPropDialog::setupRow(const QString&dn,const QString&din)
fw->layout()->addWidget(pb=new QPushButton);
pb->setText("...");
pb->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
- QCheckBox *cbx;
- ui->twProps->setCellWidget(r,1,cbx=new QCheckBox);
- cbx->setEnabled(false);
- cbx->setChecked(false);
+ cbx->setFlags(Qt::ItemFlag::ItemIsEnabled|Qt::ItemFlag::ItemIsSelectable);
+ cbx->setText("Disconnected");
ui->twProps->setCellWidget(r,2,fw);
ui->twProps->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
- connect(cb,&QComboBox::currentTextChanged,this,[this,r](const QString&s){
- bool conn=false;
- for(auto&ds:qmpMainWindow::getInstance()->getPlayer()->getMidiOutDevices())
- if(s==QString::fromStdString(ds)){conn=true;break;}
- ((QCheckBox*)ui->twProps->cellWidget(r,1))->setChecked(conn);
- });
if(dn.length())
{
- cb->setCurrentText(dn);
- if(cb->currentText()!=dn)
- {
- cb->setEditable(true);
- cb->setCurrentText(dn);
- cb->setEnabled(false);
- }
+ cb->setText(dn);
+ cb->setFlags(cb->flags()|Qt::ItemFlag::ItemIsEditable);
+ std::vector<std::string> dsv=CMidiPlayer::getInstance()->getMidiOutDevices();
+ if(std::find(dsv.begin(),dsv.end(),dn.toStdString())==dsv.end())
+ cb->setFlags(cb->flags()&(~Qt::ItemFlag::ItemIsEnabled));
+ else cb->setFlags(cb->flags()|Qt::ItemFlag::ItemIsEnabled);
}
- emit cb->currentTextChanged(cb->currentText());
connect(pb,&QPushButton::clicked,this,[this,lb,fw]{
lb->setText(QFileDialog::getOpenFileUrl(this,"Select Device Initialization File",QUrl()).path());
fw->setProperty("fn",lb->text());
@@ -97,7 +100,7 @@ void qmpDevPropDialog::on_buttonBox_accepted()
s->remove("");
for(int i=0;i<ui->twProps->rowCount();++i)
{
- s->setValue(((QComboBox*)ui->twProps->cellWidget(i,0))->currentText(),
+ s->setValue(ui->twProps->item(i,0)->text(),
ui->twProps->cellWidget(i,2)->property("fn").toString());
}
s->endGroup();
diff --git a/qmidiplayer-desktop/qmpdevpropdialog.ui b/qmidiplayer-desktop/qmpdevpropdialog.ui
index 6cea5c0..641a511 100644
--- a/qmidiplayer-desktop/qmpdevpropdialog.ui
+++ b/qmidiplayer-desktop/qmpdevpropdialog.ui
@@ -16,6 +16,12 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="twProps">
+ <property name="selectionMode">
+ <enum>QAbstractItemView::SingleSelection</enum>
+ </property>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectRows</enum>
+ </property>
<column>
<property name="text">
<string>Device</string>
diff --git a/qmidiplayer-desktop/qmpsettingswindow.cpp b/qmidiplayer-desktop/qmpsettingswindow.cpp
index 3aef529..ee08fb9 100644
--- a/qmidiplayer-desktop/qmpsettingswindow.cpp
+++ b/qmidiplayer-desktop/qmpsettingswindow.cpp
@@ -288,7 +288,7 @@ void qmpSettingsWindow::settingsUpdate()
for(int i=0;i<ui->twPluginList->rowCount();++i)
settings->setValue(
QString("PluginSwitch/")+ui->twPluginList->item(i,1)->text(),
- ((QCheckBox*)ui->twPluginList->cellWidget(i,0))->isChecked()?1:0);
+ ui->twPluginList->item(i,0)->checkState()==Qt::CheckState::Checked?1:0);
updateCustomOptions();
settings->sync();
}
@@ -360,11 +360,12 @@ void qmpSettingsWindow::updatePluginList(qmpPluginManager *pmgr)
for(unsigned i=0;i<plugins->size();++i)
{
ui->twPluginList->insertRow(i);
- ui->twPluginList->setCellWidget(i,0,new QCheckBox(""));
- if(settings->value(QString("PluginSwitch/")+QString(plugins->at(i).name.c_str()),1).toInt())
- {((QCheckBox*)ui->twPluginList->cellWidget(i,0))->setChecked(true);plugins->at(i).enabled=true;}
- else
- {((QCheckBox*)ui->twPluginList->cellWidget(i,0))->setChecked(false);plugins->at(i).enabled=false;}
+ QTableWidgetItem *icb;
+ ui->twPluginList->setItem(i,0,icb=new QTableWidgetItem());
+ bool enabled=settings->value(QString("PluginSwitch/")+QString(plugins->at(i).name.c_str()),1).toInt();
+ icb->setCheckState(enabled?Qt::CheckState::Checked:Qt::CheckState::Unchecked);
+ icb->setFlags(Qt::ItemFlag::ItemIsEnabled|Qt::ItemFlag::ItemIsSelectable|Qt::ItemFlag::ItemIsUserCheckable);
+ plugins->at(i).enabled=enabled;
ui->twPluginList->setItem(i,1,new QTableWidgetItem(plugins->at(i).name.c_str()));
ui->twPluginList->setItem(i,2,new QTableWidgetItem(plugins->at(i).version.c_str()));
ui->twPluginList->setItem(i,3,new QTableWidgetItem(plugins->at(i).path.c_str()));
diff --git a/qmidiplayer-desktop/qmpsettingswindow.ui b/qmidiplayer-desktop/qmpsettingswindow.ui
index c773958..6cdd665 100644
--- a/qmidiplayer-desktop/qmpsettingswindow.ui
+++ b/qmidiplayer-desktop/qmpsettingswindow.ui
@@ -730,6 +730,12 @@
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QTableWidget" name="twPluginList">
+ <property name="selectionMode">
+ <enum>QAbstractItemView::SingleSelection</enum>
+ </property>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectRows</enum>
+ </property>
<column>
<property name="text">
<string>E</string>