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

digikam

albumiconviewfilter.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        : 2007-11-27
00007  * Description : a bar to filter album contents
00008  *
00009  * Copyright (C) 2007-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
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 "albumiconviewfilter.moc"
00025 
00026 // KDE includes
00027 
00028 
00029 #include <klocale.h>
00030 #include <kdeversion.h>
00031 #include <kdialog.h>
00032 
00033 // Local includes
00034 
00035 #include "albumsettings.h"
00036 #include "ratingfilter.h"
00037 #include "mimefilter.h"
00038 #include "statusled.h"
00039 
00040 namespace Digikam
00041 {
00042 
00043 class AlbumIconViewFilterPriv
00044 {
00045 public:
00046 
00047     AlbumIconViewFilterPriv()
00048     {
00049         textFilter   = 0;
00050         mimeFilter   = 0;
00051         ratingFilter = 0;
00052         led          = 0;
00053     }
00054 
00055 /* NOTE: There is a problem with Qt4.3 and KDE < 4.1.0 if statusbar host a KLineEdit:
00056          digiKam crash. Text Filter bar is replaced by a simple QLineEdit in this case.
00057  */
00058 #if KDE_IS_VERSION(4,1,0)
00059     SearchTextBar*       textFilter;
00060 #else
00061     QLineEdit*           textFilter;
00062 #endif
00063 
00064     StatusLed*           led;
00065     MimeFilter*          mimeFilter;
00066     RatingFilter*        ratingFilter;
00067     ImageFilterSettings  settings;
00068 };
00069 
00070 AlbumIconViewFilter::AlbumIconViewFilter(QWidget* parent)
00071                    : KHBox(parent), d(new AlbumIconViewFilterPriv)
00072 {
00073     d->led = new StatusLed(this);
00074     d->led->installEventFilter(this);
00075     d->led->setLedColor(StatusLed::Gray);
00076     d->led->setWhatsThis(i18n("This LED indicates the global image filter status, "
00077                               "encompassing all status-bar filters and all tag filters "
00078                               "from the right sidebar.\n\n"
00079                               "GRAY: no filter is active, all items are visible.\n"
00080                               "RED: filtering is on, but no items match.\n"
00081                               "GREEN: filter(s) match(es) at least one item.\n\n"
00082                               "Any mouse button click will reset all filters."));
00083 
00084 #if KDE_IS_VERSION(4,1,0)
00085     d->textFilter = new SearchTextBar(this, "AlbumIconViewFilterSearchTextBar");
00086     d->textFilter->setTextQueryCompletion(true);
00087 #else
00088     d->textFilter = new QLineEdit(this);
00089 #endif
00090 
00091     d->textFilter->setToolTip(i18n("Text quick filter (search)"));
00092     d->textFilter->setWhatsThis(i18n("Enter search patterns to quickly filter this view on "
00093                                      "file names, captions (comments), and tags"));
00094 
00095     d->mimeFilter   = new MimeFilter(this);
00096     d->ratingFilter = new RatingFilter(this);
00097 
00098     layout()->setAlignment(d->ratingFilter, Qt::AlignCenter);
00099     setSpacing(KDialog::spacingHint());
00100     setMargin(0);
00101 
00102     connect(d->ratingFilter, SIGNAL(signalRatingFilterChanged(int, ImageFilterSettings::RatingCondition)),
00103             this, SIGNAL(ratingFilterChanged(int, ImageFilterSettings::RatingCondition)));
00104 
00105     connect(d->mimeFilter, SIGNAL(activated(int)),
00106             this, SIGNAL(mimeTypeFilterChanged(int)));
00107 
00108     connect(d->textFilter, SIGNAL(signalSearchTextSettings(const SearchTextSettings&)),
00109             this, SIGNAL(textFilterChanged(const SearchTextSettings&)));
00110 }
00111 
00112 AlbumIconViewFilter::~AlbumIconViewFilter()
00113 {
00114     delete d;
00115 }
00116 
00117 void AlbumIconViewFilter::readSettings()
00118 {
00119     AlbumSettings *settings = AlbumSettings::instance();
00120     d->ratingFilter->setRatingFilterCondition((Digikam::ImageFilterSettings::RatingCondition)
00121                                               (settings->getRatingFilterCond()));
00122     /*
00123     Bug 181705: always enable filters
00124     d->ratingFilter->setEnabled(settings->getIconShowRating());
00125     d->textFilter->setEnabled(settings->getIconShowName()     ||
00126                               settings->getIconShowComments() ||
00127                               settings->getIconShowTags());
00128     */
00129 }
00130 
00131 void AlbumIconViewFilter::saveSettings()
00132 {
00133     AlbumSettings::instance()->setRatingFilterCond(d->ratingFilter->ratingFilterCondition());
00134 }
00135 
00136 void AlbumIconViewFilter::slotFilterMatches(bool match)
00137 {
00138     QStringList filtersList;
00139     QString     message;
00140 
00141     if (!d->textFilter->text().isEmpty())
00142         filtersList.append(i18n("<br/><nobr><i>Text</i></nobr>"));
00143 
00144     if (d->mimeFilter->mimeFilter() != MimeFilter::AllFiles)
00145         filtersList.append(i18n("<br/><nobr><i>Mime Type</i></nobr>"));
00146 
00147     if (d->ratingFilter->rating() != 0 || d->ratingFilter->ratingFilterCondition() != ImageFilterSettings::GreaterEqualCondition)
00148         filtersList.append(i18n("<br/><nobr><i>Rating</i></nobr>"));
00149 
00150     if (d->settings.isFilteringByTags())
00151         filtersList.append(i18n("<br/><nobr><i>Tags</i></nobr>"));
00152 
00153     if (filtersList.count() > 1)
00154         message = i18n("<nobr><b>Active filters:</b></nobr>");
00155     else
00156         message = i18n("<nobr><b>Active filter:</b></nobr>");
00157 
00158     message.append(filtersList.join(QString()));
00159 
00160     if (filtersList.isEmpty())
00161     {
00162         d->led->setToolTip(i18n("No active filter"));
00163         d->led->setLedColor(StatusLed::Gray);
00164     }
00165     else
00166     {
00167         d->led->setToolTip(message);
00168         d->led->setLedColor(match ? StatusLed::Green : StatusLed::Red);
00169     }
00170 }
00171 
00172 void AlbumIconViewFilter::slotFilterMatchesForText(bool match)
00173 {
00174 #if KDE_IS_VERSION(4,1,0)
00175     d->textFilter->slotSearchResult(match);
00176 #endif
00177 }
00178 
00179 void AlbumIconViewFilter::slotFilterSettingsChanged(const ImageFilterSettings &settings)
00180 {
00181     d->settings = settings;
00182 }
00183 
00184 bool AlbumIconViewFilter::eventFilter(QObject *object, QEvent *e)
00185 {
00186     QWidget *widget = static_cast<QWidget*>(object);
00187 
00188     if (e->type() == QEvent::MouseButtonRelease)
00189     {
00190         QMouseEvent* event = static_cast<QMouseEvent*>(e);
00191         if ( widget->rect().contains(event->pos()) && d->led->ledColor() != StatusLed::Gray)
00192         {
00193             // Reset all filters settings.
00194             d->textFilter->setText(QString());
00195             d->ratingFilter->setRating(0);
00196             d->ratingFilter->setRatingFilterCondition(ImageFilterSettings::GreaterEqualCondition);
00197             d->mimeFilter->setMimeFilter(MimeFilter::AllFiles);
00198             emit resetTagFilters();
00199         }
00200     }
00201 
00202     return false;
00203 }
00204 
00205 }  // 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