Commit 31edb4dc authored by luyikei's avatar luyikei

Implement updating thumbnails

parent 253457a6
......@@ -3,7 +3,6 @@
#include <QFileDialog>
#include <QMessageBox>
#include <QStatusBar>
#include <QDebug>
#include "MediaLibrary.h"
......@@ -16,6 +15,7 @@ MainWindow::MainWindow(QWidget *parent) :
{
ui->setupUi(this);
connect( this, &MainWindow::statusChanged, this, &MainWindow::updateStatusBar );
connect( ui->mediaListWidget, &MediaTreeWidget::thumbnailChanged, this, &MainWindow::updateThumbnail );
QMessageBox::information(this, tr( "Setup Please!" ), tr( "Please setup your database from the toolbar.") );
}
......@@ -29,8 +29,8 @@ void MainWindow::onDiscoveryCompleted(const std::string &)
{
m_ml->reload();
ui->mediListWidget->addTracks( m_ml->audioFiles( medialibrary::SortingCriteria::Default, false ) );
ui->mediListWidget->addTracks( m_ml->videoFiles( medialibrary::SortingCriteria::Default, false ) );
ui->mediaListWidget->addTracks( m_ml->audioFiles( medialibrary::SortingCriteria::Default, false ) );
ui->mediaListWidget->addTracks( m_ml->videoFiles( medialibrary::SortingCriteria::Default, false ) );
}
void MainWindow::onArtistsAdded(std::vector<ArtistPtr> artist)
......@@ -40,7 +40,7 @@ void MainWindow::onArtistsAdded(std::vector<ArtistPtr> artist)
void MainWindow::onParsingStatsUpdated(uint32_t percent)
{
ui->mediListWidget->updateThumbnails();
ui->mediaListWidget->updateThumbnails();
if ( percent < 100 ) {
emit statusChanged( QString("Parsed %1%..." ).arg( QString::number( percent ) ) );
} else {
......@@ -63,6 +63,11 @@ void MainWindow::on_actionAdd_Folder_triggered()
{
QString folderPath = QFileDialog::getExistingDirectory( this, tr( "Specify your folder to discover audio tracks" ) );
m_ml->discover( folderPath.toStdString() );
ui->mediaListWidget->clear();
ui->mediaListWidget->addTracks( m_ml->audioFiles( medialibrary::SortingCriteria::Default, false) );
ui->mediaListWidget->addTracks( m_ml->videoFiles( medialibrary::SortingCriteria::Default, false) );
ui->artistListWidget->setArtists( m_ml->artists( medialibrary::SortingCriteria::Default, false ) );
}
void MainWindow::on_actionLoad_Database_triggered()
......@@ -70,12 +75,12 @@ void MainWindow::on_actionLoad_Database_triggered()
m_dbPath = QFileDialog::getOpenFileName( this, tr( "Specify your path for database" ), QString(), tr( "SQLite database (*.db)" ) );
if ( m_dbPath.isEmpty() )
return;
m_dbPath.replace( ".db", "" ).append( ".db" );
qDebug() << m_ml->initialize( m_dbPath.toStdString(), m_thumbPath.toStdString(), static_cast<IMediaLibraryCb*>(this) );
ui->mediListWidget->addTracks( m_ml->audioFiles( medialibrary::SortingCriteria::Default, false) );
ui->mediListWidget->addTracks( m_ml->videoFiles( medialibrary::SortingCriteria::Default, false) );
ui->mediaListWidget->clear();
ui->mediaListWidget->addTracks( m_ml->audioFiles( medialibrary::SortingCriteria::Default, false) );
ui->mediaListWidget->addTracks( m_ml->videoFiles( medialibrary::SortingCriteria::Default, false) );
ui->artistListWidget->setArtists( m_ml->artists( medialibrary::SortingCriteria::Default, false ) );
}
......@@ -83,3 +88,8 @@ void MainWindow::updateStatusBar(const QString &message)
{
ui->statusBar->showMessage( message, 3000 );
}
void MainWindow::updateThumbnail(const QImage &thumb)
{
ui->thumbnail->setPixmap( QPixmap::fromImage( thumb ) );
}
......@@ -30,6 +30,7 @@ private slots:
void on_actionLoad_Database_triggered();
void updateStatusBar( const QString& message );
void updateThumbnail( const QImage& thumb );
private:
void onMediaAdded( std::vector<MediaPtr> ) override {}
......
......@@ -41,7 +41,7 @@
</widget>
</item>
<item row="0" column="0">
<widget class="MediaTreeWidget" name="mediListWidget">
<widget class="MediaTreeWidget" name="mediaListWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
......
......@@ -10,12 +10,21 @@
MediaTreeWidget::MediaTreeWidget( QWidget *parent ):
QTreeWidget( parent )
{
connect( this, &MediaTreeWidget::itemClicked, this, &MediaTreeWidget::onItemClicked);
}
MediaTreeWidget::~MediaTreeWidget()
{
}
QImage MediaTreeWidget::getThumbnailFromItem(QTreeWidgetItem *wItem)
{
return QImage( QString::fromStdString(
wItem->data( 1, Qt::UserRole ).value<std::shared_ptr<IMedia> >()->thumbnail()
)
);
}
void MediaTreeWidget::setArtists( std::vector<std::shared_ptr<IArtist> > artists)
{
clear();
......@@ -79,12 +88,17 @@ void MediaTreeWidget::addTracks(std::vector<std::shared_ptr<IMedia> > medias, QT
void MediaTreeWidget::updateThumbnails()
{
for ( QTreeWidgetItem *mItem: m_mediaItems ) {
QImage thumb( QString::fromStdString(
mItem->data( 1, Qt::UserRole ).value<std::shared_ptr<IMedia> >()->thumbnail()
)
);
for ( QTreeWidgetItem *wItem: m_mediaItems ) {
QImage thumb = MediaTreeWidget::getThumbnailFromItem( wItem );
if ( !thumb.isNull() )
mItem->setIcon( 0, QIcon( QPixmap::fromImage( thumb ) ) );
wItem->setIcon( 0, QIcon( QPixmap::fromImage( thumb ) ) );
}
}
void MediaTreeWidget::onItemClicked(QTreeWidgetItem *wItem, int column)
{
Q_UNUSED( column )
QImage thumb = MediaTreeWidget::getThumbnailFromItem( wItem );
if ( !thumb.isNull() )
emit thumbnailChanged( thumb );
}
......@@ -17,6 +17,8 @@ public:
explicit MediaTreeWidget( QWidget *parent = 0 );
~MediaTreeWidget();
static QImage getThumbnailFromItem( QTreeWidgetItem *wItem );
void setArtists( std::vector<std::shared_ptr<IArtist> > artists);
void addArtist( std::shared_ptr<IArtist> artist );
......@@ -28,6 +30,12 @@ public:
void updateThumbnails();
signals:
void thumbnailChanged( const QImage &thumb );
private slots:
void onItemClicked( QTreeWidgetItem *wItem, int column );
private:
QList<QTreeWidgetItem*> m_mediaItems;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment