~ubuntu-branches/ubuntu/intrepid/digikam/intrepid

« back to all changes in this revision

Viewing changes to digikam/digikam/albumiconviewfilter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.2.15 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080717202539-6n7dtirbkoo7qvhd
Tags: 2:0.9.4-1
* New upstream release
  - digiKam 0.9.4 Release Plan (KDE3) ~ 13 July 08 (Closes: #490144)
* DEB_CONFIGURE_EXTRA_FLAGS := --without-included-sqlite3
* Debhelper compatibility level V7
* Install pixmaps in debian/*.install
* Add debian/digikam.lintian-overrides

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * Date        : 2007-11-27
7
7
 * Description : a bar to filter album contents
8
 
 * 
9
 
 * Copyright (C) 2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
8
 *
 
9
 * Copyright (C) 2007-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
10
10
 *
11
11
 * This program is free software; you can redistribute it
12
12
 * and/or modify it under the terms of the GNU General
13
13
 * Public License as published by the Free Software Foundation;
14
14
 * either version 2, or (at your option)
15
15
 * any later version.
16
 
 * 
 
16
 *
17
17
 * This program is distributed in the hope that it will be useful,
18
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34
34
// Local includes.
35
35
 
36
36
#include "ddebug.h"
 
37
#include "statusled.h"
37
38
#include "albumsettings.h"
38
39
#include "searchtextbar.h"
39
40
#include "ratingfilter.h"
50
51
 
51
52
    AlbumIconViewFilterPriv()
52
53
    {
53
 
        textFilter   = 0;
54
 
        mimeFilter   = 0;
55
 
        ratingFilter = 0;
 
54
        textFilter       = 0;
 
55
        mimeFilter       = 0;
 
56
        ratingFilter     = 0;
 
57
        led              = 0;
56
58
    }
57
 
    
 
59
 
 
60
    StatusLed     *led;
 
61
 
58
62
    SearchTextBar *textFilter;
59
 
    
 
63
 
60
64
    MimeFilter    *mimeFilter;
61
 
    
 
65
 
62
66
    RatingFilter  *ratingFilter;
63
67
};
64
68
 
66
70
                   : QHBox(parent)
67
71
{
68
72
    d = new AlbumIconViewFilterPriv;
69
 
    
70
 
    d->textFilter = new SearchTextBar(this);
 
73
 
 
74
    d->led = new StatusLed(this);
 
75
    d->led->installEventFilter(this);
 
76
    d->led->setLedColor(StatusLed::Gray);
 
77
    QWhatsThis::add(d->led, i18n("This LED indicates the global image filter status, "
 
78
                                 "encompassing all status-bar filters and all tag filters from the right sidebar.\n\n"
 
79
                                 "GRAY: no filter is active, all items are visible.\n"
 
80
                                 "RED: filtering is on, but no items match.\n"
 
81
                                 "GREEN: filter(s) matches at least one item.\n\n"
 
82
                                 "Any mouse button click will reset all filters."));
 
83
 
 
84
    d->textFilter = new SearchTextBar(this, "AlbumIconViewFilterTextFilter");
 
85
    d->textFilter->setEnableTextQueryCompletion(true);
71
86
    QToolTip::add(d->textFilter, i18n("Text quick filter (search)"));
72
 
    QWhatsThis::add(d->textFilter, i18n("Here you can enter search patterns to quickly "
73
 
                                        "filter this view on file names, captions "
74
 
                                        "(comments), and tags"));
 
87
    QWhatsThis::add(d->textFilter, i18n("Enter search patterns to quickly filter this view on file names, "
 
88
                                        "captions (comments), and tags"));
75
89
 
76
90
    d->mimeFilter   = new MimeFilter(this);
77
91
    d->ratingFilter = new RatingFilter(this);
78
 
    
 
92
 
79
93
    setSpacing(KDialog::spacingHint());
80
94
    setMargin(0);
81
95
 
90
104
 
91
105
    connect(AlbumLister::instance(), SIGNAL(signalItemsTextFilterMatch(bool)),
92
106
            d->textFilter, SLOT(slotSearchResult(bool)));
 
107
 
 
108
    connect(AlbumLister::instance(), SIGNAL(signalItemsFilterMatch(bool)),
 
109
            this, SLOT(slotItemsFilterMatch(bool)));
93
110
}
94
111
 
95
112
AlbumIconViewFilter::~AlbumIconViewFilter()
96
 
{    
 
113
{
97
114
    delete d;
98
115
}
99
116
 
129
146
    AlbumLister::instance()->setTextFilter(text);
130
147
}
131
148
 
 
149
void AlbumIconViewFilter::slotItemsFilterMatch(bool match)
 
150
{
 
151
    QStringList filtersList;
 
152
    QString     message;
 
153
 
 
154
    if (!d->textFilter->text().isEmpty())
 
155
        filtersList.append(i18n("<br><nobr><i>Text</i></nobr>"));
 
156
 
 
157
    if (d->mimeFilter->mimeFilter() != MimeFilter::AllFiles)
 
158
        filtersList.append(i18n("<br><nobr><i>Mime Type</i></nobr>"));
 
159
 
 
160
    if (d->ratingFilter->rating() != 0)
 
161
        filtersList.append(i18n("<br><nobr><i>Rating</i></nobr>"));
 
162
 
 
163
    if (AlbumLister::instance()->tagFiltersIsActive())
 
164
        filtersList.append(i18n("<br><nobr><i>Tags</i></nobr>"));
 
165
 
 
166
    if (filtersList.count() > 1)
 
167
        message = i18n("<nobr><b>Active filters:</b></nobr>");
 
168
    else
 
169
        message = i18n("<nobr><b>Active filter:</b></nobr>");
 
170
 
 
171
    message.append(filtersList.join(QString()));
 
172
 
 
173
    if (filtersList.isEmpty())
 
174
    {
 
175
        QToolTip::add(d->led, i18n("No active filter"));
 
176
        d->led->setLedColor(StatusLed::Gray);
 
177
    }
 
178
    else
 
179
    {
 
180
        QToolTip::add(d->led, message);
 
181
        d->led->setLedColor(match ? StatusLed::Green : StatusLed::Red);
 
182
    }
 
183
}
 
184
 
 
185
bool AlbumIconViewFilter::eventFilter(QObject *object, QEvent *e)
 
186
{
 
187
    QWidget *widget = static_cast<QWidget*>(object);
 
188
 
 
189
    if (e->type() == QEvent::MouseButtonRelease)
 
190
    {
 
191
        QMouseEvent* event = static_cast<QMouseEvent*>(e);
 
192
        if ( widget->rect().contains(event->pos()) && d->led->ledColor() != StatusLed::Gray)
 
193
        {
 
194
            // Reset all filters settings.
 
195
            d->textFilter->setText(QString());
 
196
            d->ratingFilter->setRating(0);
 
197
            d->ratingFilter->setRatingFilterCondition(AlbumLister::GreaterEqualCondition);
 
198
            d->mimeFilter->setMimeFilter(MimeFilter::AllFiles);
 
199
            emit signalResetTagFilters();
 
200
        }
 
201
    }
 
202
 
 
203
    return false;
 
204
}
 
205
 
132
206
}  // namespace Digikam