1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Dialog_MetaInfo.h"
25 #include "Model_MetaInfo.h"
28 #include <QMessageBox>
30 #include <QFileDialog>
33 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
35 ////////////////////////////////////////////////////////////
36 // Constructor & Destructor
37 ////////////////////////////////////////////////////////////
39 MetaInfoDialog::MetaInfoDialog(QWidget
*parent
)
43 //Init the dialog, from the .ui file
50 setMinimumSize(this->size());
51 setMaximumHeight(this->height());
54 tableView
->verticalHeader()->setVisible(false);
55 tableView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
56 tableView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
57 tableView
->horizontalHeader()->setStretchLastSection(true);
59 //Enable up/down button
60 connect(upButton
, SIGNAL(clicked()), this, SLOT(upButtonClicked()));
61 connect(downButton
, SIGNAL(clicked()), this, SLOT(downButtonClicked()));
62 connect(editButton
, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
65 m_contextMenuInfo
= new QMenu();
66 m_contextMenuArtwork
= new QMenu();
67 QAction
*editMetaInfoAction
= m_contextMenuInfo
->addAction(QIcon(":/icons/table_edit.png"), tr("Edit this Information"));
68 QAction
*copyMetaInfoAction
= m_contextMenuInfo
->addAction(QIcon(":/icons/page_white_copy.png"), tr("Copy everything to Meta Info tab"));
69 QAction
*clearMetaInfoAction
= m_contextMenuInfo
->addAction(QIcon(":/icons/bin.png"), tr("Clear all Meta Info"));
70 QAction
*loadArtworkAction
= m_contextMenuArtwork
->addAction(QIcon(":/icons/folder_image.png"), tr("Load Artwork From File"));
71 QAction
*clearArtworkAction
= m_contextMenuArtwork
->addAction(QIcon(":/icons/bin.png"), tr("Clear Artwork"));
72 SET_FONT_BOLD(editMetaInfoAction
, true);
73 SET_FONT_BOLD(loadArtworkAction
, true);
74 connect(tableView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(infoContextMenuRequested(QPoint
)));
75 connect(labelArtwork
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(artworkContextMenuRequested(QPoint
)));
76 connect(frameArtwork
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(artworkContextMenuRequested(QPoint
)));
77 connect(editMetaInfoAction
, SIGNAL(triggered(bool)), this, SLOT(editButtonClicked()));
78 connect(copyMetaInfoAction
, SIGNAL(triggered(bool)), this, SLOT(copyMetaInfoActionTriggered()));
79 connect(clearMetaInfoAction
, SIGNAL(triggered(bool)), this, SLOT(clearMetaInfoActionTriggered()));
80 connect(loadArtworkAction
, SIGNAL(triggered(bool)), this, SLOT(editButtonClicked()));
81 connect(clearArtworkAction
, SIGNAL(triggered(bool)), this, SLOT(clearArtworkActionTriggered()));
83 //Install event filter
84 labelArtwork
->installEventFilter(this);
87 labelHeaderText
->setText(QString("<b>%1</b><br>%2").arg(tr("Meta Information"), tr("The following meta information have been extracted from the original file.")));
90 MetaInfoDialog::~MetaInfoDialog(void)
92 LAMEXP_DELETE(m_contextMenuInfo
);
93 LAMEXP_DELETE(m_contextMenuArtwork
);
96 ////////////////////////////////////////////////////////////
98 ////////////////////////////////////////////////////////////
100 int MetaInfoDialog::exec(AudioFileModel
&audioFile
, bool allowUp
, bool allowDown
)
102 MetaInfoModel
*model
= new MetaInfoModel(&audioFile
);
103 tableView
->setModel(model
);
105 frameArtwork
->hide();
106 setWindowTitle(tr("Meta Information: %1").arg(QFileInfo(audioFile
.filePath()).fileName()));
107 editButton
->setEnabled(true);
108 upButton
->setEnabled(allowUp
);
109 downButton
->setEnabled(allowDown
);
110 buttonArtwork
->setChecked(false);
112 if(!audioFile
.fileCover().isEmpty())
115 if(artwork
.load(audioFile
.fileCover()))
117 if((artwork
.width() > 256) || (artwork
.height() > 256))
119 artwork
= artwork
.scaled(256, 256, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
121 labelArtwork
->setPixmap(QPixmap::fromImage(artwork
));
125 qWarning("Error: Failed to load cover art!");
126 labelArtwork
->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png")));
131 labelArtwork
->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png")));
134 int iResult
= QDialog::exec();
136 tableView
->setModel(NULL
);
137 LAMEXP_DELETE(model
);
142 void MetaInfoDialog::upButtonClicked(void)
147 void MetaInfoDialog::downButtonClicked(void)
152 void MetaInfoDialog::editButtonClicked(void)
154 if(!buttonArtwork
->isChecked())
156 dynamic_cast<MetaInfoModel
*>(tableView
->model())->editItem(tableView
->currentIndex(), this);
160 QString fileName
= QFileDialog::getOpenFileName(this, tr("Load Artwork"), QString(), QString::fromLatin1("JPEG (*.jpg);;PNG (*.png);;GIF (*.gif)"));
161 if(!fileName
.isEmpty())
164 if(artwork
.load(fileName
))
166 if((artwork
.width() > 256) || (artwork
.height() > 256))
168 artwork
= artwork
.scaled(256, 256, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
170 dynamic_cast<MetaInfoModel
*>(tableView
->model())->editArtwork(fileName
);
171 labelArtwork
->setPixmap(QPixmap::fromImage(artwork
));
175 qWarning("Error: Failed to load cover art!");
176 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
)));
181 void MetaInfoDialog::infoContextMenuRequested(const QPoint
&pos
)
183 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
184 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
188 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
190 m_contextMenuInfo
->popup(sender
->mapToGlobal(pos
));
195 void MetaInfoDialog::artworkContextMenuRequested(const QPoint
&pos
)
197 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
198 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
202 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
204 m_contextMenuArtwork
->popup(sender
->mapToGlobal(pos
));
209 void MetaInfoDialog::copyMetaInfoActionTriggered(void)
214 void MetaInfoDialog::clearMetaInfoActionTriggered(void)
216 if(MetaInfoModel
*model
= dynamic_cast<MetaInfoModel
*>(tableView
->model()))
218 model
->clearData(true);
222 void MetaInfoDialog::clearArtworkActionTriggered(void)
224 labelArtwork
->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png")));
225 dynamic_cast<MetaInfoModel
*>(tableView
->model())->editArtwork(QString());
228 bool MetaInfoDialog::eventFilter(QObject
*obj
, QEvent
*event
)
230 if((obj
== labelArtwork
) && (event
->type() == QEvent::MouseButtonDblClick
))
236 return QDialog::eventFilter(obj
, event
);