File indexing completed on 2025-01-19 03:56:06
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-03-22 0007 * Description : Qt Model for Albums 0008 * 0009 * SPDX-FileCopyrightText: 2008-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "albummodel_p.h" 0016 0017 namespace Digikam 0018 { 0019 0020 AlbumModel::AlbumModel(RootAlbumBehavior rootBehavior, QObject* const parent) 0021 : AbstractCheckableAlbumModel(Album::PHYSICAL, 0022 AlbumManager::instance()->findPAlbum(0), 0023 rootBehavior, parent) 0024 { 0025 m_columnHeader = i18n("Albums"); 0026 setupThumbnailLoading(); 0027 0028 connect(DIO::instance(), SIGNAL(signalTrashCounters()), 0029 this, SLOT(slotUpdateTrashCounters())); 0030 0031 connect(AlbumManager::instance(), SIGNAL(signalPAlbumsDirty(QHash<int,int>)), 0032 this, SLOT(setCountHash(QHash<int,int>))); 0033 0034 setCountHash(AlbumManager::instance()->getPAlbumsCount()); 0035 } 0036 0037 AlbumModel::~AlbumModel() 0038 { 0039 } 0040 0041 PAlbum* AlbumModel::albumForIndex(const QModelIndex& index) const 0042 { 0043 return static_cast<PAlbum*>(AbstractCheckableAlbumModel::albumForIndex(index)); 0044 } 0045 0046 QVariant AlbumModel::decorationRoleData(Album* album) const 0047 { 0048 // asynchronous signals are handled by parent class 0049 0050 QPixmap thumb = AlbumThumbnailLoader::instance()->getAlbumThumbnailDirectly(static_cast<PAlbum*>(album)); 0051 int size = ApplicationSettings::instance()->getTreeViewIconSize(); 0052 0053 double ratio = thumb.devicePixelRatio(); 0054 int rsize = qRound((double)size * ratio); 0055 thumb = thumb.scaled(rsize, rsize, Qt::KeepAspectRatio, 0056 Qt::SmoothTransformation); 0057 0058 QPixmap pix(rsize, rsize); 0059 pix.fill(Qt::transparent); 0060 pix.setDevicePixelRatio(ratio); 0061 0062 QPainter p(&pix); 0063 p.drawPixmap((rsize - thumb.width()) / 2, 0064 (rsize - thumb.height()) / 2, thumb); 0065 p.end(); 0066 0067 prepareAddExcludeDecoration(album, pix); 0068 0069 return pix; 0070 } 0071 0072 Album* AlbumModel::albumForId(int id) const 0073 { 0074 return AlbumManager::instance()->findPAlbum(id); 0075 } 0076 0077 QVariant AlbumModel::albumData(Album* a, int role) const 0078 { 0079 if ((role == Qt::DisplayRole) && 0080 showCount() && 0081 a->isTrashAlbum()) 0082 { 0083 PAlbum* const palbum = static_cast<PAlbum*>(a->parent()); 0084 0085 if (palbum) 0086 { 0087 int counter = DIO::getTrashCounter(palbum->folderPath()); 0088 0089 return QString::fromUtf8("%1 (%2)").arg(albumName(a)).arg(counter); 0090 } 0091 } 0092 0093 return AbstractCheckableAlbumModel::albumData(a, role); 0094 } 0095 0096 void AlbumModel::slotUpdateTrashCounters() 0097 { 0098 Q_FOREACH (Album* const album, AlbumManager::instance()->allPAlbums()) 0099 { 0100 if (album->isTrashAlbum()) 0101 { 0102 QModelIndex index = indexForAlbum(album); 0103 0104 if (index.isValid()) 0105 { 0106 Q_EMIT dataChanged(index, index); 0107 } 0108 } 0109 } 0110 } 0111 0112 } // namespace Digikam 0113 0114 #include "moc_albummodel.cpp"