Show meta info about cover (size, resolution, MIME-type)
This commit is contained in:
parent
1357fd1a32
commit
42004c8760
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include <qtutilities/misc/conversion.h>
|
#include <qtutilities/misc/conversion.h>
|
||||||
|
|
||||||
|
#include <c++utilities/conversion/stringconversion.h>
|
||||||
#include <c++utilities/io/catchiofailure.h>
|
#include <c++utilities/io/catchiofailure.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QStringBuilder>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -57,6 +59,7 @@ PicturePreviewSelection::PicturePreviewSelection(Tag *tag, KnownField field, QWi
|
||||||
, m_rectItem(nullptr)
|
, m_rectItem(nullptr)
|
||||||
, m_tag(tag)
|
, m_tag(tag)
|
||||||
, m_field(field)
|
, m_field(field)
|
||||||
|
, m_currentFileSize(0)
|
||||||
, m_currentTypeIndex(0)
|
, m_currentTypeIndex(0)
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
@ -213,6 +216,29 @@ void PicturePreviewSelection::setup(PreviousValueHandling previousValueHandling)
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Updates the tooltip to show the current file size and MIME-type.
|
||||||
|
*/
|
||||||
|
void PicturePreviewSelection::updateSizeAndMimeType(size_t fileSize, const QSize &resolution, const QString &mimeType)
|
||||||
|
{
|
||||||
|
QStringList info;
|
||||||
|
info.reserve(3);
|
||||||
|
if (fileSize) {
|
||||||
|
info << QString::fromStdString(ConversionUtilities::dataSizeToString(fileSize));
|
||||||
|
}
|
||||||
|
if (!resolution.isEmpty()) {
|
||||||
|
info << QString::number(resolution.width()) % QStringLiteral(" x ") % QString::number(resolution.height()) % QStringLiteral(" px");
|
||||||
|
}
|
||||||
|
if (!mimeType.isEmpty()) {
|
||||||
|
info << mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_currentFileSize = fileSize;
|
||||||
|
m_currentResolution = resolution;
|
||||||
|
m_currentMimeType = mimeType;
|
||||||
|
setToolTip(info.join(QChar('\n')));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Pushes the ID3v2 cover values to the specified \a tag.
|
* \brief Pushes the ID3v2 cover values to the specified \a tag.
|
||||||
* \param tag Specifies a tag to push the values to.
|
* \param tag Specifies a tag to push the values to.
|
||||||
|
@ -282,6 +308,7 @@ void PicturePreviewSelection::clear()
|
||||||
}
|
}
|
||||||
updatePreview(m_currentTypeIndex);
|
updatePreview(m_currentTypeIndex);
|
||||||
updateDescription(m_currentTypeIndex);
|
updateDescription(m_currentTypeIndex);
|
||||||
|
updateSizeAndMimeType(0, QSize(), QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -388,15 +415,22 @@ void PicturePreviewSelection::extractSelected()
|
||||||
void PicturePreviewSelection::displaySelected()
|
void PicturePreviewSelection::displaySelected()
|
||||||
{
|
{
|
||||||
assert(m_currentTypeIndex < m_values.size());
|
assert(m_currentTypeIndex < m_values.size());
|
||||||
TagValue &value = m_values[m_currentTypeIndex];
|
const auto &value = m_values[m_currentTypeIndex];
|
||||||
if (!value.isEmpty()) {
|
if (value.isEmpty()) {
|
||||||
|
QMessageBox::warning(this, QCoreApplication::applicationName(), tr("There is no image attached."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// load image
|
||||||
QImage img;
|
QImage img;
|
||||||
if (value.mimeType() == "-->") {
|
if (value.mimeType() == "-->") {
|
||||||
QFile file(Utility::stringToQString(value.toString(), value.dataEncoding()));
|
const auto fileName(Utility::stringToQString(value.toString(), value.dataEncoding()));
|
||||||
|
QFile file(fileName);
|
||||||
if (file.open(QFile::ReadOnly)) {
|
if (file.open(QFile::ReadOnly)) {
|
||||||
img = QImage::fromData(file.readAll());
|
img = QImage::fromData(file.readAll());
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::warning(this, QCoreApplication::applicationName(), tr("The attached image can't be found."));
|
QMessageBox::warning(this, QCoreApplication::applicationName(),
|
||||||
|
tr("The attached image can't be found. It is supposed to be stored as external file \"%1\".").arg(fileName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -404,10 +438,16 @@ void PicturePreviewSelection::displaySelected()
|
||||||
}
|
}
|
||||||
if (img.isNull()) {
|
if (img.isNull()) {
|
||||||
QMessageBox::warning(this, QCoreApplication::applicationName(), tr("The attached image can't be displayed."));
|
QMessageBox::warning(this, QCoreApplication::applicationName(), tr("The attached image can't be displayed."));
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// show dialog
|
||||||
QDialog dlg;
|
QDialog dlg;
|
||||||
dlg.setWindowFlags(Qt::Tool);
|
dlg.setWindowFlags(Qt::Tool);
|
||||||
dlg.setWindowTitle(tr("Cover - %1").arg(QCoreApplication::applicationName()));
|
const auto additionalInfo = toolTip().replace(QLatin1String("\n"), QLatin1String(", "));
|
||||||
|
const auto title = !additionalInfo.isEmpty() ? tr("Cover - %1 - %2").arg(additionalInfo, QCoreApplication::applicationName())
|
||||||
|
: tr("Cover - %1").arg(QCoreApplication::applicationName());
|
||||||
|
dlg.setWindowTitle(title);
|
||||||
QBoxLayout layout(QBoxLayout::Up);
|
QBoxLayout layout(QBoxLayout::Up);
|
||||||
layout.setMargin(0);
|
layout.setMargin(0);
|
||||||
QGraphicsView view(&dlg);
|
QGraphicsView view(&dlg);
|
||||||
|
@ -419,10 +459,6 @@ void PicturePreviewSelection::displaySelected()
|
||||||
dlg.setLayout(&layout);
|
dlg.setLayout(&layout);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
QMessageBox::warning(this, QCoreApplication::applicationName(), tr("There is no image attached."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Asks the user to alter the MIME-type of the selected cover.
|
* \brief Asks the user to alter the MIME-type of the selected cover.
|
||||||
|
@ -430,14 +466,16 @@ void PicturePreviewSelection::displaySelected()
|
||||||
void PicturePreviewSelection::changeMimeTypeOfSelected()
|
void PicturePreviewSelection::changeMimeTypeOfSelected()
|
||||||
{
|
{
|
||||||
assert(m_currentTypeIndex < m_values.size());
|
assert(m_currentTypeIndex < m_values.size());
|
||||||
TagValue &selectedCover = m_values[m_currentTypeIndex];
|
auto &selectedCover = m_values[m_currentTypeIndex];
|
||||||
auto mimeType = QString::fromUtf8(selectedCover.mimeType().data());
|
auto mimeType = QString::fromUtf8(selectedCover.mimeType().data());
|
||||||
bool ok;
|
bool ok;
|
||||||
mimeType = QInputDialog::getText(
|
mimeType = QInputDialog::getText(
|
||||||
this, tr("Enter/confirm mime type"), tr("Confirm or enter the mime type of the selected file."), QLineEdit::Normal, mimeType, &ok);
|
this, tr("Enter/confirm mime type"), tr("Confirm or enter the mime type of the selected file."), QLineEdit::Normal, mimeType, &ok);
|
||||||
if (ok) {
|
if (!ok) {
|
||||||
selectedCover.setMimeType(mimeType.toUtf8().data());
|
return;
|
||||||
}
|
}
|
||||||
|
selectedCover.setMimeType(mimeType.toUtf8().data());
|
||||||
|
updateSizeAndMimeType(m_currentFileSize, m_currentResolution, mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -591,9 +629,10 @@ void PicturePreviewSelection::updatePreview(int index)
|
||||||
QImage img;
|
QImage img;
|
||||||
if (value.mimeType() == "-->") {
|
if (value.mimeType() == "-->") {
|
||||||
QFile file(Utility::stringToQString(value.toString(), value.dataEncoding()));
|
QFile file(Utility::stringToQString(value.toString(), value.dataEncoding()));
|
||||||
if (file.open(QFile::ReadOnly))
|
if (file.open(QFile::ReadOnly)) {
|
||||||
img = QImage::fromData(file.readAll());
|
img = QImage::fromData(file.readAll());
|
||||||
else {
|
updateSizeAndMimeType(static_cast<std::size_t>(file.size()), img.size(), QString());
|
||||||
|
} else {
|
||||||
m_textItem->setPlainText(tr("The attached image can't be found."));
|
m_textItem->setPlainText(tr("The attached image can't be found."));
|
||||||
m_textItem->setVisible(true);
|
m_textItem->setVisible(true);
|
||||||
m_pixmapItem->setVisible(false);
|
m_pixmapItem->setVisible(false);
|
||||||
|
@ -601,6 +640,7 @@ void PicturePreviewSelection::updatePreview(int index)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
img = QImage::fromData(reinterpret_cast<const uchar *>(value.dataPointer()), value.dataSize());
|
img = QImage::fromData(reinterpret_cast<const uchar *>(value.dataPointer()), value.dataSize());
|
||||||
|
updateSizeAndMimeType(value.dataSize(), img.size(), QString::fromStdString(value.mimeType()));
|
||||||
}
|
}
|
||||||
if (img.isNull()) {
|
if (img.isNull()) {
|
||||||
m_pixmap = QPixmap();
|
m_pixmap = QPixmap();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <tagparser/tag.h>
|
#include <tagparser/tag.h>
|
||||||
|
|
||||||
|
#include <QSize>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -72,6 +73,7 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setup(PreviousValueHandling previousValueHandling = PreviousValueHandling::Clear);
|
void setup(PreviousValueHandling previousValueHandling = PreviousValueHandling::Clear);
|
||||||
|
void updateSizeAndMimeType(std::size_t fileSize, const QSize &resolution, const QString &mimeType);
|
||||||
|
|
||||||
std::unique_ptr<Ui::PicturePreviewSelection> m_ui;
|
std::unique_ptr<Ui::PicturePreviewSelection> m_ui;
|
||||||
QGraphicsScene *m_scene;
|
QGraphicsScene *m_scene;
|
||||||
|
@ -82,6 +84,9 @@ private:
|
||||||
TagParser::Tag *m_tag;
|
TagParser::Tag *m_tag;
|
||||||
TagParser::KnownField m_field;
|
TagParser::KnownField m_field;
|
||||||
QList<TagParser::TagValue> m_values;
|
QList<TagParser::TagValue> m_values;
|
||||||
|
std::size_t m_currentFileSize;
|
||||||
|
QSize m_currentResolution;
|
||||||
|
QString m_currentMimeType;
|
||||||
int m_currentTypeIndex;
|
int m_currentTypeIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue