From 012d7dab72fdcac72381db2493882eace82f8095 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Thu, 9 Mar 2017 19:36:12 +0000 Subject: added cover tab to the track details dialog git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@7083 90c681e8-e032-0410-971d-27865f9a5e38 --- src/qmmpui/coverviewer.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ src/qmmpui/coverviewer_p.h | 53 ++++++++++++++++++++++++++++++++++++++ src/qmmpui/detailsdialog.cpp | 11 +++++++- src/qmmpui/qmmpui.pro | 6 +++-- 4 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 src/qmmpui/coverviewer.cpp create mode 100644 src/qmmpui/coverviewer_p.h (limited to 'src/qmmpui') diff --git a/src/qmmpui/coverviewer.cpp b/src/qmmpui/coverviewer.cpp new file mode 100644 index 000000000..0a9bb731b --- /dev/null +++ b/src/qmmpui/coverviewer.cpp @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2017 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include +#include +#include +#include +#include +#include "coverviewer_p.h" + +CoverViewer::CoverViewer(QWidget *parent) + : QWidget(parent) +{ + QAction *saveAsAction = new QAction(tr("&Save As..."), this); + connect(saveAsAction, SIGNAL(triggered()), SLOT(saveAs())); + addAction(saveAsAction); + setContextMenuPolicy(Qt::ActionsContextMenu); +} + +CoverViewer::~CoverViewer() +{} + +void CoverViewer::setPixmap(const QPixmap &pixmap) +{ + m_pixmap = pixmap; + update(); +} + +void CoverViewer::paintEvent(QPaintEvent *p) +{ + QPainter paint(this); + if(!m_pixmap.isNull()) + paint.drawPixmap(0,0, m_pixmap.scaled(p->rect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} + +void CoverViewer::saveAs() +{ + QString path = FileDialog::getSaveFileName(this, tr("Save Cover As"), + QDir::homePath() + "/cover.jpg", + tr("Images") +" (*.png *.jpg)"); + + if (!path.isEmpty()) + m_pixmap.save(path); +} diff --git a/src/qmmpui/coverviewer_p.h b/src/qmmpui/coverviewer_p.h new file mode 100644 index 000000000..d4a1b7bff --- /dev/null +++ b/src/qmmpui/coverviewer_p.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2017 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef COVERVIEWER_H +#define COVERVIEWER_H + +#include +#include + +class QMouseEvent; + +/** + @internal + @author Ilya Kotov +*/ + +class CoverViewer : public QWidget +{ +Q_OBJECT +public: + CoverViewer(QWidget *parent = 0); + + ~CoverViewer(); + + void setPixmap(const QPixmap&); + +protected: + void paintEvent(QPaintEvent *event); + +private slots: + void saveAs(); + +private: + QPixmap m_pixmap; +}; + +#endif diff --git a/src/qmmpui/detailsdialog.cpp b/src/qmmpui/detailsdialog.cpp index f3633898e..64a42906b 100644 --- a/src/qmmpui/detailsdialog.cpp +++ b/src/qmmpui/detailsdialog.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009-2016 by Ilya Kotov * + * Copyright (C) 2009-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -31,6 +31,7 @@ #include "ui_detailsdialog.h" #include "playlisttrack.h" #include "tageditor_p.h" +#include "coverviewer_p.h" #include "detailsdialog.h" DetailsDialog::DetailsDialog(QList tracks, QWidget *parent) @@ -143,6 +144,14 @@ void DetailsDialog::updatePage() m_metaData = *m_track; qDeleteAll(flist); + QPixmap cover = MetaDataManager::instance()->getCover(m_path); + if(!cover.isNull()) + { + CoverViewer *coverViewer = new CoverViewer(this); + coverViewer->setPixmap(cover); + m_ui->tabWidget->addTab(coverViewer, tr("Cover")); + } + m_metaDataModel = MetaDataManager::instance()->createMetaDataModel(m_path, this); if(m_metaDataModel) diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro index 2c91c593c..91b78321c 100644 --- a/src/qmmpui/qmmpui.pro +++ b/src/qmmpui/qmmpui.pro @@ -70,7 +70,8 @@ HEADERS += general.h \ metadataformatter.h \ columneditor_p.h \ playlistheadermodel.h \ - metadatahelper_p.h + metadatahelper_p.h \ + coverviewer_p.h SOURCES += general.cpp \ playlistparser.cpp \ @@ -107,7 +108,8 @@ SOURCES += general.cpp \ metadataformatter.cpp \ columneditor.cpp \ playlistheadermodel.cpp \ - metadatahelper.cpp + metadatahelper.cpp \ + coverviewer.cpp FORMS += forms/detailsdialog.ui \ forms/tageditor.ui \ -- cgit v1.2.3-13-gbd6f