• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

digikam

albumicongroupitem.cpp

Go to the documentation of this file.
00001 /* ============================================================
00002  *
00003  * This file is a part of digiKam project
00004  * http://www.digikam.org
00005  *
00006  * Date        : 2005-04-25
00007  * Description : implementation to render album icons group item.
00008  *
00009  * Copyright (C) 2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
00010  *
00011  * This program is free software; you can redistribute it
00012  * and/or modify it under the terms of the GNU General
00013  * Public License as published by the Free Software Foundation;
00014  * either version 2, or (at your option)
00015  * any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * ============================================================ */
00023 
00024 #include "albumicongroupitem.h"
00025 
00026 // Qt includes
00027 
00028 #include <QPainter>
00029 #include <QPixmap>
00030 
00031 // KDE includes
00032 
00033 #include <kcalendarsystem.h>
00034 #include <kglobal.h>
00035 #include <klocale.h>
00036 #include <kstringhandler.h>
00037 
00038 // Local includes
00039 
00040 #include "album.h"
00041 #include "albumiconview.h"
00042 #include "albummanager.h"
00043 #include "albumsettings.h"
00044 #include "themeengine.h"
00045 
00046 namespace Digikam
00047 {
00048 
00049 AlbumIconGroupItem::AlbumIconGroupItem(AlbumIconView* view, int albumID)
00050                   : IconGroupItem(view), m_albumID(albumID), m_view(view)
00051 {
00052 }
00053 
00054 AlbumIconGroupItem::~AlbumIconGroupItem()
00055 {
00056 }
00057 
00058 int AlbumIconGroupItem::compare(IconGroupItem* group)
00059 {
00060     AlbumIconGroupItem* agroup = (AlbumIconGroupItem*)group;
00061 
00062     PAlbum* mine = AlbumManager::instance()->findPAlbum(m_albumID);
00063     PAlbum* his  = AlbumManager::instance()->findPAlbum(agroup->m_albumID);
00064 
00065     if (!mine || !his)
00066         return 0;
00067 
00068     const AlbumSettings *settings = m_view->settings();
00069 
00070     switch (settings->getImageSortOrder())
00071     {
00072         case(AlbumSettings::ByIName):
00073         case(AlbumSettings::ByISize):
00074         case(AlbumSettings::ByIPath):
00075         case(AlbumSettings::ByIRating):
00076         {
00077             return KStringHandler::naturalCompare(mine->albumPath(), his->albumPath());
00078         }
00079         case(AlbumSettings::ByIDate):
00080         {
00081             if (mine->date() < his->date())
00082                 return -1;
00083             else if (mine->date() > his->date())
00084                 return 1;
00085             else
00086                 return 0;
00087         }
00088     }
00089 
00090     return 0;
00091 }
00092 
00093 void AlbumIconGroupItem::paintBanner(QPainter *p)
00094 {
00095     AlbumManager* man = AlbumManager::instance();
00096     PAlbum* album     = man->findPAlbum(m_albumID);
00097 
00098     QString dateAndComments;
00099     QString prettyUrl;
00100 
00101     if (album)
00102     {
00103         QDate  date  = album->date();
00104 
00105         KLocale tmpLocale(*KGlobal::locale());
00106 
00107         tmpLocale.setDateFormat("%d"); // day of month with two digits
00108         QString day = tmpLocale.formatDate(date);
00109 
00110         tmpLocale.setDateFormat("%b"); // short form of the month
00111         QString month = tmpLocale.formatDate(date);
00112 
00113         tmpLocale.setDateFormat("%Y"); // long form of the year
00114         QString year = tmpLocale.formatDate(date);
00115 
00116         dateAndComments = i18ncp("%1: day of month with two digits, %2: short month name, %3: year",
00117                                  "Album Date: %2 %3 %4 - 1 Item", "Album Date: %2 %3 %4 - %1 Items",
00118                                  count(), day, month, year);
00119 
00120         if (!album->caption().isEmpty())
00121         {
00122             QString caption = album->caption();
00123             dateAndComments += " - " + caption.replace('\n', ' ');
00124         }
00125 
00126         prettyUrl = album->prettyUrl();
00127     }
00128 
00129     QRect r(0, 0, rect().width(), rect().height());
00130 
00131     p->drawPixmap(0, 0, m_view->bannerPixmap());
00132 
00133     QFont fn(m_view->font());
00134     fn.setBold(true);
00135     int fnSize = fn.pointSize();
00136     bool usePointSize;
00137     if (fnSize > 0)
00138     {
00139         fn.setPointSize(fnSize+2);
00140         usePointSize = true;
00141     }
00142     else
00143     {
00144         fnSize = fn.pixelSize();
00145         fn.setPixelSize(fnSize+2);
00146         usePointSize = false;
00147     }
00148 
00149     p->setPen(ThemeEngine::instance()->textSelColor());
00150     p->setFont(fn);
00151 
00152     QRect tr;
00153     p->drawText(5, 5, r.width(), r.height(),
00154                Qt::AlignLeft | Qt::AlignTop,
00155                prettyUrl.left(-1), &tr);
00156 
00157     r.setY(tr.height() + 2);
00158 
00159     if (usePointSize)
00160         fn.setPointSize(m_view->font().pointSize());
00161     else
00162         fn.setPixelSize(m_view->font().pixelSize());
00163 
00164     fn.setBold(false);
00165     p->setFont(fn);
00166 
00167     p->drawText(5, r.y(), r.width(), r.height(),
00168                Qt::AlignLeft | Qt::AlignVCenter, dateAndComments);
00169 }
00170 
00171 }  // namespace Digikam

digikam

Skip menu "digikam"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • digikam
Generated for API Reference by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal