NinjamPanel::NinjamPanel(QWidget *parent) : QWidget(parent), ui(new Ui::NinjamPanel), hostSyncButton(nullptr) { ui->setupUi(this); // initialize combos for (int bpm = 40; bpm <= 400; bpm += 10) ui->comboBpm->addItem(QString::number(bpm), bpm); int bpis[] = {8, 16, 32, 48, 64}; for (int i = 0; i < 4; ++i) ui->comboBpi->addItem(QString::number(bpis[i]), bpis[i]); ui->comboBpm->setValidator(new QIntValidator(40, 400, ui->comboBpm)); ui->comboBpi->setValidator(new QIntValidator(3, 64, ui->comboBpi)); ui->comboBpi->setCompleter(0);// disabling completer ui->comboBpm->setCompleter(0);// disabling completer QObject::connect(ui->comboBeatsPerAccent, SIGNAL(currentIndexChanged(int)), this, SLOT(updateAccentsStatus(int))); QObject::connect(ui->comboShape, SIGNAL(currentIndexChanged(int)), this, SLOT(updateIntervalProgressShape(int))); buildShapeModel(); ui->levelSlider->installEventFilter(this); ui->panSlider->installEventFilter(this); QObject::connect(ui->comboBpi, SIGNAL(activated(QString)), this, SIGNAL(bpiComboActivated(QString))); QObject::connect(ui->comboBpm, SIGNAL(activated(QString)), this, SIGNAL(bpmComboActivated(QString))); QObject::connect(ui->comboBeatsPerAccent, SIGNAL(currentIndexChanged(int)), SIGNAL(accentsComboChanged(int))); QObject::connect(ui->levelSlider, SIGNAL(valueChanged(int)), this, SIGNAL(gainSliderChanged( int))); QObject::connect(ui->panSlider, SIGNAL(valueChanged(int)), this, SIGNAL(panSliderChanged(int))); QObject::connect(ui->muteButton, SIGNAL(clicked(bool)), this, SIGNAL(muteButtonClicked())); QObject::connect(ui->soloButton, SIGNAL(clicked(bool)), this, SIGNAL(soloButtonClicked())); ui->peakMeterLeft->setOrientation(PeakMeter::HORIZONTAL); ui->peakMeterRight->setOrientation(PeakMeter::HORIZONTAL); }
void NinjamPanel::translate() { ui->retranslateUi(this); // rebuild the accents and shape combos to show translated strings. The signals are blocked to avoid reset the combos and loose the user selections. QSignalBlocker comboShapeBlocker(ui->comboShape); QSignalBlocker comboAccentsBlocker(ui->comboAccentBeats); // save the current indexes before rebuild the combos int currentShape = ui->comboShape->currentIndex(); int currentAccent = ui->comboAccentBeats->currentIndex(); buildAccentsdModel(ui->intervalPanel->getBeatsPerInterval()); buildShapeModel(); // restore the selected indexes ui->comboShape->setCurrentIndex(currentShape); ui->comboAccentBeats->setCurrentIndex(currentAccent); // compute the max width string in combo and set the combobox list items width to match int items = ui->comboShape->count(); QFontMetrics fontMetrics = ui->comboShape->fontMetrics(); int maxComboItemWidth = 0; for (int i = 0; i < items; ++i) { int itemTextWidth = fontMetrics.width(ui->comboShape->itemText(i)); if (itemTextWidth > maxComboItemWidth) maxComboItemWidth = itemTextWidth; } ui->comboShape->view()->setMinimumWidth(qMax(ui->comboShape->width(), maxComboItemWidth + 20)); // translate sync button if (hostSyncButton) { hostSyncButton->setText(tr("Sync with %1").arg(hostName)); } }