1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 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"
26 #include "Model_MetaInfo.h"
29 #include <QMessageBox>
31 #include <QFileDialog>
34 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
36 ////////////////////////////////////////////////////////////
37 // Constructor & Destructor
38 ////////////////////////////////////////////////////////////
40 MetaInfoDialog::MetaInfoDialog(QWidget
*parent
)
44 //Init the dialog, from the .ui file
51 setMinimumSize(this->size());
52 setMaximumHeight(this->height());
55 tableView
->verticalHeader()->setVisible(false);
56 tableView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
57 tableView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
58 tableView
->horizontalHeader()->setStretchLastSection(true);
60 //Enable up/down button
61 connect(upButton
, SIGNAL(clicked()), this, SLOT(upButtonClicked()));
62 connect(downButton
, SIGNAL(clicked()), this, SLOT(downButtonClicked()));
63 connect(editButton
, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
66 m_contextMenuInfo
= new QMenu();
67 m_contextMenuArtwork
= new QMenu();
68 QAction
*editMetaInfoAction
= m_contextMenuInfo
->addAction(QIcon(":/icons/table_edit.png"), tr("Edit this Information"));
69 QAction
*copyMetaInfoAction
= m_contextMenuInfo
->addAction(QIcon(":/icons/page_white_copy.png"), tr("Copy everything to Meta Info tab"));
70 QAction
*clearMetaInfoAction
= m_contextMenuInfo
->addAction(QIcon(":/icons/bin.png"), tr("Clear all Meta Info"));
71 QAction
*loadArtworkAction
= m_contextMenuArtwork
->addAction(QIcon(":/icons/folder_image.png"), tr("Load Artwork From File"));
72 QAction
*clearArtworkAction
= m_contextMenuArtwork
->addAction(QIcon(":/icons/bin.png"), tr("Clear Artwork"));
73 SET_FONT_BOLD(editMetaInfoAction
, true);
74 SET_FONT_BOLD(loadArtworkAction
, true);
75 connect(tableView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(infoContextMenuRequested(QPoint
)));
76 connect(labelArtwork
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(artworkContextMenuRequested(QPoint
)));
77 connect(frameArtwork
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(artworkContextMenuRequested(QPoint
)));
78 connect(editMetaInfoAction
, SIGNAL(triggered(bool)), this, SLOT(editButtonClicked()));
79 connect(copyMetaInfoAction
, SIGNAL(triggered(bool)), this, SLOT(copyMetaInfoActionTriggered()));
80 connect(clearMetaInfoAction
, SIGNAL(triggered(bool)), this, SLOT(clearMetaInfoActionTriggered()));
81 connect(loadArtworkAction
, SIGNAL(triggered(bool)), this, SLOT(editButtonClicked()));
82 connect(clearArtworkAction
, SIGNAL(triggered(bool)), this, SLOT(clearArtworkActionTriggered()));
84 //Install event filter
85 labelArtwork
->installEventFilter(this);
88 labelHeaderText
->setText(QString("<b>%1</b><br>%2").arg(tr("Meta Information"), tr("The following meta information have been extracted from the original file.")));
91 MetaInfoDialog::~MetaInfoDialog(void)
93 LAMEXP_DELETE(m_contextMenuInfo
);
94 LAMEXP_DELETE(m_contextMenuArtwork
);
97 ////////////////////////////////////////////////////////////
99 ////////////////////////////////////////////////////////////
101 int MetaInfoDialog::exec(AudioFileModel
&audioFile
, bool allowUp
, bool allowDown
)
103 MetaInfoModel
*model
= new MetaInfoModel(&audioFile
);
104 tableView
->setModel(model
);
106 frameArtwork
->hide();
107 setWindowTitle(tr("Meta Information: %1").arg(QFileInfo(audioFile
.filePath()).fileName()));
108 editButton
->setEnabled(true);
109 upButton
->setEnabled(allowUp
);
110 downButton
->setEnabled(allowDown
);
111 buttonArtwork
->setChecked(false);
113 if(!audioFile
.metaInfo().cover().isEmpty())
116 if(artwork
.load(audioFile
.metaInfo().cover()))
118 if((artwork
.width() > 256) || (artwork
.height() > 256))
120 artwork
= artwork
.scaled(256, 256, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
122 labelArtwork
->setPixmap(QPixmap::fromImage(artwork
));
126 qWarning("Error: Failed to load cover art!");
127 labelArtwork
->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png")));
132 labelArtwork
->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png")));
135 int iResult
= QDialog::exec();
137 tableView
->setModel(NULL
);
138 LAMEXP_DELETE(model
);
143 void MetaInfoDialog::upButtonClicked(void)
148 void MetaInfoDialog::downButtonClicked(void)
153 void MetaInfoDialog::editButtonClicked(void)
155 if(!buttonArtwork
->isChecked())
157 dynamic_cast<MetaInfoModel
*>(tableView
->model())->editItem(tableView
->currentIndex(), this);
161 QString fileName
= QFileDialog::getOpenFileName(this, tr("Load Artwork"), QString(), QString::fromLatin1("JPEG (*.jpg);;PNG (*.png);;GIF (*.gif)"));
162 if(!fileName
.isEmpty())
165 if(artwork
.load(fileName
))
167 if((artwork
.width() > 256) || (artwork
.height() > 256))
169 artwork
= artwork
.scaled(256, 256, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
171 dynamic_cast<MetaInfoModel
*>(tableView
->model())->editArtwork(fileName
);
172 labelArtwork
->setPixmap(QPixmap::fromImage(artwork
));
176 qWarning("Error: Failed to load cover art!");
177 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
)));
182 void MetaInfoDialog::infoContextMenuRequested(const QPoint
&pos
)
184 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
185 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
189 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
191 m_contextMenuInfo
->popup(sender
->mapToGlobal(pos
));
196 void MetaInfoDialog::artworkContextMenuRequested(const QPoint
&pos
)
198 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
199 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
203 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
205 m_contextMenuArtwork
->popup(sender
->mapToGlobal(pos
));
210 void MetaInfoDialog::copyMetaInfoActionTriggered(void)
215 void MetaInfoDialog::clearMetaInfoActionTriggered(void)
217 if(MetaInfoModel
*model
= dynamic_cast<MetaInfoModel
*>(tableView
->model()))
219 model
->clearData(true);
223 void MetaInfoDialog::clearArtworkActionTriggered(void)
225 labelArtwork
->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png")));
226 dynamic_cast<MetaInfoModel
*>(tableView
->model())->editArtwork(QString());
229 bool MetaInfoDialog::eventFilter(QObject
*obj
, QEvent
*event
)
231 if((obj
== labelArtwork
) && (event
->type() == QEvent::MouseButtonDblClick
))
237 return QDialog::eventFilter(obj
, event
);