~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to digikam/tagfiltersidebarwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2010-04-09 21:30:01 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100409213001-4bfyibrd359rn7o3
Tags: 2:1.2.0-0ubuntu1
* New upstream release (LP: #560576)
* Remove all patches, fixed upstream
  - Remove quilt build-depend

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2000-12-05
 
7
 * Description : tag filter view for the right sidebar
 
8
 *
 
9
 * Copyright (C) 2009 by Johannes Wienke <languitar at semipol dot de>
 
10
 *
 
11
 * This program is free software; you can redistribute it
 
12
 * and/or modify it under the terms of the GNU General
 
13
 * Public License as published by the Free Software Foundation;
 
14
 * either version 2, or (at your option)
 
15
 * any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * ============================================================ */
 
23
 
 
24
#include "tagfiltersidebarwidget.moc"
 
25
 
 
26
// Qt includes
 
27
 
 
28
#include <qlabel.h>
 
29
#include <qlayout.h>
 
30
#include <qcheckbox.h>
 
31
 
 
32
// KDE includes
 
33
 
 
34
#include <kselectaction.h>
 
35
 
 
36
// Local includes
 
37
 
 
38
#include "albummodel.h"
 
39
#include "contextmenuhelper.h"
 
40
#include "tagcheckview.h"
 
41
 
 
42
namespace Digikam
 
43
{
 
44
 
 
45
class TagFilterViewPriv
 
46
{
 
47
public:
 
48
 
 
49
    TagFilterViewPriv() :
 
50
        tagFilterModel(0),
 
51
        restoreTagFiltersAction(0),
 
52
        onRestoreTagFiltersAction(0),
 
53
        offRestoreTagFiltersAction(0)
 
54
    {
 
55
    }
 
56
 
 
57
    TagModel *tagFilterModel;
 
58
 
 
59
    KSelectAction *restoreTagFiltersAction;
 
60
    QAction *onRestoreTagFiltersAction;
 
61
    QAction *offRestoreTagFiltersAction;
 
62
 
 
63
};
 
64
 
 
65
TagFilterView::TagFilterView(QWidget *parent, TagModel *tagFilterModel) :
 
66
    TagCheckView(parent, tagFilterModel),
 
67
    d(new TagFilterViewPriv)
 
68
{
 
69
 
 
70
    d->tagFilterModel = tagFilterModel;
 
71
 
 
72
    d->restoreTagFiltersAction = new KSelectAction(i18n("Restore Tag Filters"), this);
 
73
    d->onRestoreTagFiltersAction = d->restoreTagFiltersAction->addAction(i18n("On"));
 
74
    d->offRestoreTagFiltersAction = d->restoreTagFiltersAction->addAction(i18n("Off"));
 
75
 
 
76
}
 
77
 
 
78
TagFilterView::~TagFilterView()
 
79
{
 
80
    delete d;
 
81
}
 
82
 
 
83
void TagFilterView::addCustomContextMenuActions(ContextMenuHelper &cmh, Album *album)
 
84
{
 
85
    TagCheckView::addCustomContextMenuActions(cmh, album);
 
86
 
 
87
    // restoring
 
88
    cmh.addAction(d->restoreTagFiltersAction);
 
89
 
 
90
    d->onRestoreTagFiltersAction->setChecked(isRestoreCheckState());
 
91
    d->offRestoreTagFiltersAction->setChecked(!isRestoreCheckState());
 
92
 
 
93
}
 
94
 
 
95
void TagFilterView::handleCustomContextMenuAction(QAction *action, AlbumPointer<Album> album)
 
96
{
 
97
    TagCheckView::handleCustomContextMenuAction(action, album);
 
98
 
 
99
    if (!action)
 
100
    {
 
101
        return;
 
102
    }
 
103
 
 
104
    if (action == d->onRestoreTagFiltersAction)        // Restore TagFilters ON.
 
105
    {
 
106
        setRestoreCheckState(true);
 
107
    }
 
108
    else if (action == d->offRestoreTagFiltersAction)        // Restore TagFilters OFF.
 
109
    {
 
110
        setRestoreCheckState(false);
 
111
    }
 
112
 
 
113
}
 
114
 
 
115
// -----------------------------------------------------------------------------
 
116
 
 
117
class TagFilterSideBarWidgetPriv
 
118
{
 
119
public:
 
120
 
 
121
    TagFilterSideBarWidgetPriv() :
 
122
        configLastShowUntaggedEntry("Show Untagged"),
 
123
        configMatchingConditionEntry("Matching Condition"),
 
124
        tagFilterView(0),
 
125
        tagFilterSearchBar(0)
 
126
    {
 
127
    }
 
128
 
 
129
    QString configLastShowUntaggedEntry;
 
130
    QString configMatchingConditionEntry;
 
131
 
 
132
    TagFilterView    *tagFilterView;
 
133
    SearchTextBar    *tagFilterSearchBar;
 
134
 
 
135
    TagModel *tagFilterModel;
 
136
 
 
137
    QCheckBox *withoutTagCheckBox;
 
138
    KComboBox *matchingConditionComboBox;
 
139
 
 
140
};
 
141
 
 
142
TagFilterSideBarWidget::TagFilterSideBarWidget(QWidget *parent,
 
143
                TagModel *tagFilterModel) :
 
144
    QWidget(parent), StateSavingObject(this), d(new TagFilterSideBarWidgetPriv)
 
145
{
 
146
 
 
147
    setObjectName("TagFilter Sidebar");
 
148
 
 
149
    d->tagFilterModel = tagFilterModel;
 
150
 
 
151
    d->tagFilterView      = new TagFilterView(this, tagFilterModel);
 
152
    d->tagFilterView->setObjectName("DigikamViewTagFilterView");
 
153
    d->tagFilterSearchBar = new SearchTextBar(this, "DigikamViewTagFilterSearchBar");
 
154
    d->tagFilterSearchBar->setModel(tagFilterModel, AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole);
 
155
    d->tagFilterSearchBar->setFilterModel(d->tagFilterView->albumFilterModel());
 
156
 
 
157
    const QString notTaggedTitle = i18n("Images Without Tag");
 
158
    d->withoutTagCheckBox = new QCheckBox(notTaggedTitle, this);
 
159
    d->withoutTagCheckBox->setWhatsThis(i18n("Show images without a tag."));
 
160
 
 
161
    QLabel *matchingConditionLabel = new QLabel(i18n("Matching Condition:"), this);
 
162
    matchingConditionLabel->setWhatsThis(i18n(
 
163
                    "Defines in which way the selected tags are combined to filter the images. "
 
164
                    "This also includes the '%1' check box.", notTaggedTitle));
 
165
 
 
166
    d->matchingConditionComboBox = new KComboBox(this);
 
167
    d->matchingConditionComboBox->setWhatsThis(matchingConditionLabel->whatsThis());
 
168
    d->matchingConditionComboBox->addItem(i18n("AND"), ImageFilterSettings::AndCondition);
 
169
    d->matchingConditionComboBox->addItem(i18n("OR"), ImageFilterSettings::OrCondition);
 
170
 
 
171
    QVBoxLayout *layout = new QVBoxLayout(this);
 
172
 
 
173
    layout->addWidget(d->tagFilterView);
 
174
    layout->addWidget(d->tagFilterSearchBar);
 
175
    layout->addWidget(d->withoutTagCheckBox);
 
176
    layout->addWidget(matchingConditionLabel);
 
177
    layout->addWidget(d->matchingConditionComboBox);
 
178
 
 
179
    // connection
 
180
 
 
181
    connect(d->tagFilterView, SIGNAL(checkedTagsChanged(const QList<TAlbum*>&)),
 
182
            this, SLOT(slotCheckedTagsChanged(const QList<TAlbum*>&)));
 
183
 
 
184
    connect(d->withoutTagCheckBox, SIGNAL(stateChanged(int)),
 
185
            this, SLOT(slotWithoutTagChanged(int)));
 
186
 
 
187
    connect(d->matchingConditionComboBox, SIGNAL(currentIndexChanged(int)),
 
188
            this, SLOT(slotMatchingConditionChanged(int)));
 
189
 
 
190
}
 
191
 
 
192
TagFilterSideBarWidget::~TagFilterSideBarWidget()
 
193
{
 
194
}
 
195
 
 
196
void TagFilterSideBarWidget::slotResetTagFilters()
 
197
{
 
198
    d->tagFilterView->slotResetCheckState();
 
199
    d->withoutTagCheckBox->setChecked(false);
 
200
}
 
201
 
 
202
void TagFilterSideBarWidget::slotMatchingConditionChanged(int index)
 
203
{
 
204
    Q_UNUSED(index);
 
205
    filterChanged();
 
206
}
 
207
 
 
208
void TagFilterSideBarWidget::slotCheckedTagsChanged(const QList<TAlbum*> &tags)
 
209
{
 
210
    Q_UNUSED(tags);
 
211
    filterChanged();
 
212
}
 
213
 
 
214
void TagFilterSideBarWidget::slotWithoutTagChanged(int newState)
 
215
{
 
216
    Q_UNUSED(newState);
 
217
    filterChanged();
 
218
}
 
219
 
 
220
void TagFilterSideBarWidget::filterChanged()
 
221
{
 
222
 
 
223
    bool showUntagged = d->withoutTagCheckBox->checkState() == Qt::Checked;
 
224
 
 
225
    QList<int> tagIds;
 
226
    if (!showUntagged)
 
227
    {
 
228
        foreach(TAlbum *tag, d->tagFilterView->getCheckedTags())
 
229
        {
 
230
            if (tag)
 
231
            {
 
232
                tagIds << tag->id();
 
233
            }
 
234
        }
 
235
    }
 
236
 
 
237
    emit tagFilterChanged(tagIds,
 
238
                          (ImageFilterSettings::MatchingCondition)d->matchingConditionComboBox->itemData(
 
239
                                          d->matchingConditionComboBox->currentIndex()).toInt(),
 
240
                          showUntagged);
 
241
 
 
242
}
 
243
 
 
244
void TagFilterSideBarWidget::setConfigGroup(KConfigGroup group)
 
245
{
 
246
    StateSavingObject::setConfigGroup(group);
 
247
    d->tagFilterView->setConfigGroup(group);
 
248
}
 
249
 
 
250
void TagFilterSideBarWidget::doLoadState()
 
251
{
 
252
    d->matchingConditionComboBox->setCurrentIndex(getConfigGroup().readEntry(
 
253
                    entryName(d->configMatchingConditionEntry), 0));
 
254
    d->tagFilterView->loadState();
 
255
 
 
256
    if (d->tagFilterView->isRestoreCheckState())
 
257
    {
 
258
        d->withoutTagCheckBox->setChecked(getConfigGroup().readEntry(entryName(
 
259
                        d->configLastShowUntaggedEntry), false));
 
260
    }
 
261
 
 
262
    filterChanged();
 
263
}
 
264
 
 
265
void TagFilterSideBarWidget::doSaveState()
 
266
{
 
267
    getConfigGroup().writeEntry(entryName(d->configMatchingConditionEntry),
 
268
                    d->matchingConditionComboBox->currentIndex());
 
269
    d->tagFilterView->saveState();
 
270
    getConfigGroup().writeEntry(entryName(d->configLastShowUntaggedEntry),
 
271
                        d->withoutTagCheckBox->isChecked());
 
272
    getConfigGroup().sync();
 
273
}
 
274
 
 
275
}