1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Dialog_MetaInfo.h"
27 #include "Model_MetaInfo.h"
30 #include <MUtils/Global.h>
34 #include <QMessageBox>
36 #include <QFileDialog>
39 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
41 ////////////////////////////////////////////////////////////
42 // Constructor & Destructor
43 ////////////////////////////////////////////////////////////
45 MetaInfoDialog::MetaInfoDialog(QWidget
*parent
)
49 //Init the dialog, from the .ui file
56 setMinimumSize(this->size());
57 setMaximumHeight(this->height());
60 tableView
->verticalHeader()->setVisible(false);
61 tableView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
62 tableView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
63 tableView
->horizontalHeader()->setStretchLastSection(true);
65 //Enable up/down button
66 connect(upButton
, SIGNAL(clicked()), this, SLOT(upButtonClicked()));
67 connect(downButton
, SIGNAL(clicked()), this, SLOT(downButtonClicked()));
68 connect(editButton
, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
71 m_contextMenuInfo
= new QMenu();
72 m_contextMenuArtwork
= new QMenu();
73 QAction
*editMetaInfoAction
= m_contextMenuInfo
->addAction(QIcon(":/icons/table_edit.png"), tr("Edit this Information"));
74 QAction
*copyMetaInfoAction
= m_contextMenuInfo
->addAction(QIcon(":/icons/page_white_copy.png"), tr("Copy everything to Meta Info tab"));
75 QAction
*clearMetaInfoAction
= m_contextMenuInfo
->addAction(QIcon(":/icons/bin.png"), tr("Clear all Meta Info"));
76 QAction
*loadArtworkAction
= m_contextMenuArtwork
->addAction(QIcon(":/icons/folder_image.png"), tr("Load Artwork From File"));
77 QAction
*clearArtworkAction
= m_contextMenuArtwork
->addAction(QIcon(":/icons/bin.png"), tr("Clear Artwork"));
78 SET_FONT_BOLD(editMetaInfoAction
, true);
79 SET_FONT_BOLD(loadArtworkAction
, true);
80 connect(tableView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(infoContextMenuRequested(QPoint
)));
81 connect(labelArtwork
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(artworkContextMenuRequested(QPoint
)));
82 connect(frameArtwork
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(artworkContextMenuRequested(QPoint
)));
83 connect(editMetaInfoAction
, SIGNAL(triggered(bool)), this, SLOT(editButtonClicked()));
84 connect(copyMetaInfoAction
, SIGNAL(triggered(bool)), this, SLOT(copyMetaInfoActionTriggered()));
85 connect(clearMetaInfoAction
, SIGNAL(triggered(bool)), this, SLOT(clearMetaInfoActionTriggered()));
86 connect(loadArtworkAction
, SIGNAL(triggered(bool)), this, SLOT(editButtonClicked()));
87 connect(clearArtworkAction
, SIGNAL(triggered(bool)), this, SLOT(clearArtworkActionTriggered()));
89 //Install event filter
90 labelArtwork
->installEventFilter(this);
93 labelHeaderText
->setText(QString("<b>%1</b><br>%2").arg(tr("Meta Information"), tr("The following meta information have been extracted from the original file.")));
96 MetaInfoDialog::~MetaInfoDialog(void)
98 MUTILS_DELETE(m_contextMenuInfo
);
99 MUTILS_DELETE(m_contextMenuArtwork
);
102 ////////////////////////////////////////////////////////////
104 ////////////////////////////////////////////////////////////
106 int MetaInfoDialog::exec(AudioFileModel
&audioFile
, bool allowUp
, bool allowDown
)
108 MetaInfoModel
*model
= new MetaInfoModel(&audioFile
);
109 tableView
->setModel(model
);
111 frameArtwork
->hide();
112 setWindowTitle(tr("Meta Information: %1").arg(QFileInfo(audioFile
.filePath()).fileName()));
113 editButton
->setEnabled(true);
114 upButton
->setEnabled(allowUp
);
115 downButton
->setEnabled(allowDown
);
116 buttonArtwork
->setChecked(false);
118 if(!audioFile
.metaInfo().cover().isEmpty())
121 if(artwork
.load(audioFile
.metaInfo().cover()))
123 if((artwork
.width() > 256) || (artwork
.height() > 256))
125 artwork
= artwork
.scaled(256, 256, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
127 labelArtwork
->setPixmap(QPixmap::fromImage(artwork
));
131 qWarning("Error: Failed to load cover art!");
132 labelArtwork
->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png")));
137 labelArtwork
->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png")));
140 int iResult
= QDialog::exec();
142 tableView
->setModel(NULL
);
143 MUTILS_DELETE(model
);
148 void MetaInfoDialog::upButtonClicked(void)
153 void MetaInfoDialog::downButtonClicked(void)
158 void MetaInfoDialog::editButtonClicked(void)
160 if(!buttonArtwork
->isChecked())
162 dynamic_cast<MetaInfoModel
*>(tableView
->model())->editItem(tableView
->currentIndex(), this);
166 QString fileName
= QFileDialog::getOpenFileName(this, tr("Load Artwork"), QString(), QString::fromLatin1("JPEG (*.jpg);;PNG (*.png);;GIF (*.gif)"));
167 if(!fileName
.isEmpty())
170 if(artwork
.load(fileName
))
172 if((artwork
.width() > 256) || (artwork
.height() > 256))
174 artwork
= artwork
.scaled(256, 256, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
176 dynamic_cast<MetaInfoModel
*>(tableView
->model())->editArtwork(fileName
);
177 labelArtwork
->setPixmap(QPixmap::fromImage(artwork
));
181 qWarning("Error: Failed to load cover art!");
182 QMessageBox::warning(this, tr("Artwork Error"), QString("<nobr>%1</nobr><br><br><nobr>%2</nobr>").arg(tr("Sorry, failed to load artwork from selected file!"), QDir::toNativeSeparators(fileName
)));
187 void MetaInfoDialog::infoContextMenuRequested(const QPoint
&pos
)
189 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
190 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
194 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
196 m_contextMenuInfo
->popup(sender
->mapToGlobal(pos
));
201 void MetaInfoDialog::artworkContextMenuRequested(const QPoint
&pos
)
203 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
204 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
208 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
210 m_contextMenuArtwork
->popup(sender
->mapToGlobal(pos
));
215 void MetaInfoDialog::copyMetaInfoActionTriggered(void)
220 void MetaInfoDialog::clearMetaInfoActionTriggered(void)
222 if(MetaInfoModel
*model
= dynamic_cast<MetaInfoModel
*>(tableView
->model()))
224 model
->clearData(true);
228 void MetaInfoDialog::clearArtworkActionTriggered(void)
230 labelArtwork
->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png")));
231 dynamic_cast<MetaInfoModel
*>(tableView
->model())->editArtwork(QString());
234 bool MetaInfoDialog::eventFilter(QObject
*obj
, QEvent
*event
)
236 if((obj
== labelArtwork
) && (event
->type() == QEvent::MouseButtonDblClick
))
242 return QDialog::eventFilter(obj
, event
);