42 , m_pDrumkit( pDrumkit )
43 , m_bDrumkitNameLocked( bDrumkitNameLocked )
44 , m_sNewImagePath(
"" )
46 setObjectName(
"SoundLibraryPropertiesDialog" );
53 setWindowTitle( tr(
"SoundLibrary Properties" ) );
55 setMinimumSize( width(), height() );
58 connect( licenseComboBox, SIGNAL( currentIndexChanged(
int ) ),
61 connect( imageLicenseComboBox, SIGNAL( currentIndexChanged(
int ) ),
64 bool bDrumkitWritable =
false;
66 if ( pDrumkit !=
nullptr ){
69 pDrumkit->get_path() );
72 bDrumkitWritable =
true;
75 nameTxt->setText( pDrumkit->get_name() );
77 if ( bDrumkitNameLocked ) {
78 nameTxt->setIsActive(
false );
79 nameTxt->setToolTip( tr(
"Altering the name of a drumkit would result in the creation of a new one. To do so, you need to load the drumkit (if you haven't done so already) using right click > load and select Drumkits > Save As in the main menu" ) );
82 authorTxt->setText( QString( pDrumkit->get_author() ) );
83 infoTxt->append( QString( pDrumkit->get_info() ) );
85 License license = pDrumkit->get_license();
86 licenseComboBox->setCurrentIndex(
static_cast<int>( license.
getType() ) );
89 imageText->setText( QString( pDrumkit->get_image() ) );
91 License imageLicense = pDrumkit->get_image_license();
92 imageLicenseComboBox->setCurrentIndex(
static_cast<int>( imageLicense.
getType() ) );
97 licenseStringLbl->hide();
98 licenseStringTxt->hide();
101 imageLicenseStringLbl->hide();
102 imageLicenseStringTxt->hide();
105 licenseComboBox->setToolTip( pCommonStrings->getLicenseComboToolTip() );
106 licenseStringLbl->setText( pCommonStrings->getLicenseStringLbl() );
107 licenseStringTxt->setToolTip( pCommonStrings->getLicenseStringToolTip() );
108 imageLicenseComboBox->setToolTip( pCommonStrings->getLicenseComboToolTip() );
109 imageLicenseStringLbl->setText( pCommonStrings->getLicenseStringLbl() );
110 imageLicenseStringTxt->setToolTip( pCommonStrings->getLicenseStringToolTip() );
114 if ( ! bDrumkitWritable && bDrumkitNameLocked ) {
115 QString sToolTip = tr(
"The current drumkit is read-only. Please use Drumkits > Save As in the main menu to create a new one first." );
119 authorTxt->setIsActive(
false );
120 authorTxt->setToolTip( sToolTip );
121 infoTxt->setEnabled(
false );
122 infoTxt->setReadOnly(
true );
123 infoTxt->setToolTip( sToolTip );
124 licenseComboBox->setIsActive(
false );
125 licenseComboBox->setToolTip( sToolTip );
126 licenseStringTxt->setIsActive(
false );
127 licenseStringTxt->setToolTip( sToolTip );
128 imageText->setIsActive(
false );
129 imageText->setToolTip( sToolTip );
130 imageLicenseComboBox->setIsActive(
false );
131 imageLicenseComboBox->setToolTip( sToolTip );
132 imageLicenseStringTxt->setIsActive(
false );
133 imageLicenseStringTxt->setToolTip( sToolTip );
134 saveBtn->setIsActive(
false );
135 saveBtn->setToolTip( sToolTip );
136 imageBrowsePushButton->setIsActive(
false );
137 imageBrowsePushButton->setToolTip( sToolTip );
141 infoTxt->setStyleSheet( QString(
"\
144 background-color: %2; \
146 .arg( pPref->getColorTheme()->m_windowTextColor.name() )
147 .arg( pPref->getColorTheme()->m_windowColor.name() ) );
151 saveBtn->setFixedFontSize( 12 );
152 saveBtn->setSize( QSize( 70, 23 ) );
153 saveBtn->setBorderRadius( 3 );
154 m_cancelBtn->setFixedFontSize( 12 );
155 m_cancelBtn->setSize( QSize( 70, 23 ) );
156 m_cancelBtn->setBorderRadius( 3 );
157 imageBrowsePushButton->setFixedFontSize( 12 );
158 imageBrowsePushButton->setBorderRadius( 3 );
159 imageBrowsePushButton->setSize( QSize( 70, 23 ) );
161 contentTable->setColumnCount( 4 );
162 contentTable->setHorizontalHeaderLabels( QStringList() <<
163 tr(
"Instrument" ) <<
167 contentTable->verticalHeader()->hide();
168 contentTable->horizontalHeader()->setStretchLastSection(
true );
170 contentTable->setColumnWidth( 0, 160 );
171 contentTable->setColumnWidth( 1, 80 );
172 contentTable->setColumnWidth( 2, 210 );
206 auto contentVector =
m_pDrumkit->summarizeContent();
208 if ( contentVector.size() > 0 ) {
209 contentTable->show();
210 contentLabel->show();
211 contentTable->setRowCount( contentVector.size() );
213 int nFirstMismatchRow = -1;
215 for (
int ii = 0; ii < contentVector.size(); ++ ii ) {
216 const auto ccontent = contentVector[ ii ];
218 QLineEdit* pInstrumentItem =
new QLineEdit( ccontent->m_sInstrumentName );
219 pInstrumentItem->setEnabled(
false );
220 pInstrumentItem->setToolTip( ccontent->m_sInstrumentName );
221 QLineEdit* pComponentItem =
new QLineEdit( ccontent->m_sComponentName );
222 pComponentItem->setEnabled(
false );
223 pComponentItem->setToolTip( ccontent->m_sComponentName );
224 QLineEdit* pSampleItem =
new QLineEdit( ccontent->m_sSampleName );
225 pSampleItem->setEnabled(
false );
226 pSampleItem->setToolTip( ccontent->m_sSampleName );
227 QLineEdit* pLicenseItem =
228 new QLineEdit( ccontent->m_license.getLicenseString() );
229 pLicenseItem->setEnabled(
false );
230 pLicenseItem->setToolTip( ccontent->m_license.getLicenseString() );
233 if ( ccontent->m_license !=
m_pDrumkit->get_license() ) {
234 QString sRed = QString(
"color: %1; background-color: %2" )
235 .arg( pPref->getColorTheme()->m_buttonRedColor.name() )
236 .arg( pPref->getColorTheme()->m_windowColor.name() );
237 pInstrumentItem->setStyleSheet( sRed );
238 pComponentItem->setStyleSheet( sRed );
239 pSampleItem->setStyleSheet( sRed );
240 pLicenseItem->setStyleSheet( sRed );
242 if ( nFirstMismatchRow == -1 ) {
243 nFirstMismatchRow = ii;
247 contentTable->setCellWidget( ii, 0, pInstrumentItem );
248 contentTable->setCellWidget( ii, 1, pComponentItem );
249 contentTable->setCellWidget( ii, 2, pSampleItem );
250 contentTable->setCellWidget( ii, 3, pLicenseItem );
254 if ( nFirstMismatchRow != -1 ) {
255 contentTable->showRow( nFirstMismatchRow );
259 contentTable->hide();
260 contentLabel->hide();
298 QPixmap *pPixmap =
new QPixmap ( filename );
301 if ( pPixmap->isNull() ) {
302 ERRORLOG( QString(
"Unable to load pixmap from [%1]" ).arg( filename ) );
303 drumkitImageLabel->hide();
308 int x = (int) drumkitImageLabel->size().width();
309 int y = drumkitImageLabel->size().height();
310 float labelAspect = (float) x / y;
311 float imageAspect = (float) pPixmap->width() / pPixmap->height();
313 if ( ( x < pPixmap->width() ) || ( y < pPixmap->height() ) )
315 if ( labelAspect >= imageAspect )
318 *pPixmap = pPixmap->scaledToHeight( y );
323 *pPixmap = pPixmap->scaledToWidth( x );
326 drumkitImageLabel->setPixmap(*pPixmap);
327 drumkitImageLabel->show();
363 auto pSong = pHydrogen->getSong();
370 License licenseCheck( licenseStringTxt->text() );
371 if (
static_cast<int>(licenseCheck.
getType()) != licenseComboBox->currentIndex() ) {
372 if ( QMessageBox::warning(
this,
"Hydrogen",
373 tr(
"Specified drumkit License String does not comply with the license selected in the combo box." ),
374 QMessageBox::Ok | QMessageBox::Cancel,
375 QMessageBox::Cancel )
376 == QMessageBox::Cancel ) {
377 WARNINGLOG( QString(
"Abort, since drumkit License String [%1] does not comply to selected License Type [%2]" )
378 .arg( licenseStringTxt->text() )
384 License imageLicenseCheck( imageLicenseStringTxt->text() );
385 if (
static_cast<int>(imageLicenseCheck.
getType()) !=
386 imageLicenseComboBox->currentIndex() ) {
387 if ( QMessageBox::warning(
this,
"Hydrogen",
388 tr(
"Specified image License String does not comply with the license selected in the combo box." ),
389 QMessageBox::Ok | QMessageBox::Cancel,
390 QMessageBox::Cancel )
391 == QMessageBox::Cancel ) {
392 WARNINGLOG( QString(
"Abort, since drumkit image License String [%1] does not comply to selected License Type [%2]" )
393 .arg( imageLicenseStringTxt->text() )
401 if ( nameTxt->text().isEmpty() ){
402 QMessageBox::warning(
this,
"Hydrogen", tr(
"The name of the drumkit must not be left empty" ) );
406 QString sNewLicenseString( licenseStringTxt->text() );
407 if ( licenseComboBox->currentIndex() ==
409 sNewLicenseString =
"";
411 License newLicense( sNewLicenseString );
414 QString sNewImageLicenseString( imageLicenseStringTxt->text() );
415 if ( imageLicenseComboBox->currentIndex() ==
417 sNewImageLicenseString =
"";
419 License newImageLicense( sNewImageLicenseString );
422 const QString sOldPath =
m_pDrumkit->get_path();
423 if (
m_pDrumkit->get_name() != nameTxt->text() ) {
433 if (
m_pDrumkit->get_license() != newLicense ) {
438 ERRORLOG(
"User cancelled dialog due to licensing issues." );
444 QString sOldImagePath;
445 if ( imageText->text() !=
m_pDrumkit->get_image() ) {
446 int nRes = QMessageBox::information(
this,
"Hydrogen",
447 tr(
"Delete previous drumkit image" )
448 .append( QString(
" [%1]" ).arg(
m_pDrumkit->get_image() ) ),
449 QMessageBox::Yes | QMessageBox::No );
450 if ( nRes == QMessageBox::Yes ) {
451 sOldImagePath = QString(
"%1/%2" ).arg( sOldPath )
457 if (
m_pDrumkit->get_image_license() != newImageLicense ) {
458 m_pDrumkit->set_image_license( newImageLicense );
461 QApplication::setOverrideCursor(Qt::WaitCursor);
465 QApplication::restoreOverrideCursor();
466 QMessageBox::information(
this,
"Hydrogen", tr (
"Saving of this drumkit failed."));
467 ERRORLOG(
"Saving of this drumkit failed." );
476 if ( fileInfo.dir().absolutePath() !=
m_pDrumkit->get_path() ) {
479 const QString sTargetPath =
480 QString(
"%1/%2" ).arg(
m_pDrumkit->get_path() )
481 .arg( fileInfo.fileName() );
487 if ( ! sOldImagePath.isEmpty() ) {
491 pHydrogen->getSoundLibraryDatabase()->updateDrumkits();
493 QApplication::restoreOverrideCursor();