1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : tag filter view for the right sidebar
9
* Copyright (C) 2009 by Johannes Wienke <languitar at semipol dot de>
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)
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.
22
* ============================================================ */
24
#include "tagfiltersidebarwidget.moc"
30
#include <qcheckbox.h>
34
#include <kselectaction.h>
38
#include "albummodel.h"
39
#include "contextmenuhelper.h"
40
#include "tagcheckview.h"
45
class TagFilterViewPriv
51
restoreTagFiltersAction(0),
52
onRestoreTagFiltersAction(0),
53
offRestoreTagFiltersAction(0)
57
TagModel *tagFilterModel;
59
KSelectAction *restoreTagFiltersAction;
60
QAction *onRestoreTagFiltersAction;
61
QAction *offRestoreTagFiltersAction;
65
TagFilterView::TagFilterView(QWidget *parent, TagModel *tagFilterModel) :
66
TagCheckView(parent, tagFilterModel),
67
d(new TagFilterViewPriv)
70
d->tagFilterModel = tagFilterModel;
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"));
78
TagFilterView::~TagFilterView()
83
void TagFilterView::addCustomContextMenuActions(ContextMenuHelper &cmh, Album *album)
85
TagCheckView::addCustomContextMenuActions(cmh, album);
88
cmh.addAction(d->restoreTagFiltersAction);
90
d->onRestoreTagFiltersAction->setChecked(isRestoreCheckState());
91
d->offRestoreTagFiltersAction->setChecked(!isRestoreCheckState());
95
void TagFilterView::handleCustomContextMenuAction(QAction *action, AlbumPointer<Album> album)
97
TagCheckView::handleCustomContextMenuAction(action, album);
104
if (action == d->onRestoreTagFiltersAction) // Restore TagFilters ON.
106
setRestoreCheckState(true);
108
else if (action == d->offRestoreTagFiltersAction) // Restore TagFilters OFF.
110
setRestoreCheckState(false);
115
// -----------------------------------------------------------------------------
117
class TagFilterSideBarWidgetPriv
121
TagFilterSideBarWidgetPriv() :
122
configLastShowUntaggedEntry("Show Untagged"),
123
configMatchingConditionEntry("Matching Condition"),
125
tagFilterSearchBar(0)
129
QString configLastShowUntaggedEntry;
130
QString configMatchingConditionEntry;
132
TagFilterView *tagFilterView;
133
SearchTextBar *tagFilterSearchBar;
135
TagModel *tagFilterModel;
137
QCheckBox *withoutTagCheckBox;
138
KComboBox *matchingConditionComboBox;
142
TagFilterSideBarWidget::TagFilterSideBarWidget(QWidget *parent,
143
TagModel *tagFilterModel) :
144
QWidget(parent), StateSavingObject(this), d(new TagFilterSideBarWidgetPriv)
147
setObjectName("TagFilter Sidebar");
149
d->tagFilterModel = tagFilterModel;
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());
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."));
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));
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);
171
QVBoxLayout *layout = new QVBoxLayout(this);
173
layout->addWidget(d->tagFilterView);
174
layout->addWidget(d->tagFilterSearchBar);
175
layout->addWidget(d->withoutTagCheckBox);
176
layout->addWidget(matchingConditionLabel);
177
layout->addWidget(d->matchingConditionComboBox);
181
connect(d->tagFilterView, SIGNAL(checkedTagsChanged(const QList<TAlbum*>&)),
182
this, SLOT(slotCheckedTagsChanged(const QList<TAlbum*>&)));
184
connect(d->withoutTagCheckBox, SIGNAL(stateChanged(int)),
185
this, SLOT(slotWithoutTagChanged(int)));
187
connect(d->matchingConditionComboBox, SIGNAL(currentIndexChanged(int)),
188
this, SLOT(slotMatchingConditionChanged(int)));
192
TagFilterSideBarWidget::~TagFilterSideBarWidget()
196
void TagFilterSideBarWidget::slotResetTagFilters()
198
d->tagFilterView->slotResetCheckState();
199
d->withoutTagCheckBox->setChecked(false);
202
void TagFilterSideBarWidget::slotMatchingConditionChanged(int index)
208
void TagFilterSideBarWidget::slotCheckedTagsChanged(const QList<TAlbum*> &tags)
214
void TagFilterSideBarWidget::slotWithoutTagChanged(int newState)
220
void TagFilterSideBarWidget::filterChanged()
223
bool showUntagged = d->withoutTagCheckBox->checkState() == Qt::Checked;
228
foreach(TAlbum *tag, d->tagFilterView->getCheckedTags())
237
emit tagFilterChanged(tagIds,
238
(ImageFilterSettings::MatchingCondition)d->matchingConditionComboBox->itemData(
239
d->matchingConditionComboBox->currentIndex()).toInt(),
244
void TagFilterSideBarWidget::setConfigGroup(KConfigGroup group)
246
StateSavingObject::setConfigGroup(group);
247
d->tagFilterView->setConfigGroup(group);
250
void TagFilterSideBarWidget::doLoadState()
252
d->matchingConditionComboBox->setCurrentIndex(getConfigGroup().readEntry(
253
entryName(d->configMatchingConditionEntry), 0));
254
d->tagFilterView->loadState();
256
if (d->tagFilterView->isRestoreCheckState())
258
d->withoutTagCheckBox->setChecked(getConfigGroup().readEntry(entryName(
259
d->configLastShowUntaggedEntry), false));
265
void TagFilterSideBarWidget::doSaveState()
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();