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

« back to all changes in this revision

Viewing changes to digikam/libs/widgets/metadata/metadatalistview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.3.2 upstream) (37 hardy)
  • mto: This revision was merged to the branch mainline in revision 39.
  • Revision ID: james.westby@ubuntu.com-20080717202539-1bw3w3nrsso7yj4z
* 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:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2006-02-21
 
7
 * Description : a generic list view widget to 
 
8
 *               display metadata
 
9
 * 
 
10
 * Copyright (c) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
11
 *
 
12
 * This program is free software; you can redistribute it
 
13
 * and/or modify it under the terms of the GNU General
 
14
 * Public License as published by the Free Software Foundation;
 
15
 * either version 2, or (at your option)
 
16
 * any later version.
 
17
 * 
 
18
 * This program is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
 * GNU General Public License for more details.
 
22
 * 
 
23
 * ============================================================ */
 
24
 
 
25
// Qt includes.
 
26
 
 
27
#include <qtimer.h>
 
28
#include <qptrlist.h>
 
29
#include <qpalette.h>
 
30
#include <qheader.h>
 
31
#include <qwhatsthis.h>
 
32
 
 
33
// KDE includes.
 
34
 
 
35
#include <klocale.h>
 
36
 
 
37
// Local includes.
 
38
 
 
39
#include "mdkeylistviewitem.h"
 
40
#include "metadatalistviewitem.h"
 
41
#include "metadatalistview.h"
 
42
#include "metadatalistview.moc"
 
43
 
 
44
namespace Digikam
 
45
{
 
46
 
 
47
MetadataListView::MetadataListView(QWidget* parent)
 
48
                : QListView(parent)
 
49
{
 
50
    header()->hide();
 
51
    addColumn("Name");    // No need i18n here.
 
52
    addColumn("Value");   // No need i18n here.
 
53
    setItemMargin(0);
 
54
    setAllColumnsShowFocus(true);
 
55
    setResizeMode(QListView::AllColumns);
 
56
    // Vertical scroll bar is always disable to give more 
 
57
    // free space to metadata content
 
58
    setVScrollBarMode(QScrollView::AlwaysOff);
 
59
 
 
60
    m_parent = dynamic_cast<MetadataWidget *>(parent);
 
61
 
 
62
    connect(this, SIGNAL(selectionChanged(QListViewItem*)),
 
63
            this, SLOT(slotSelectionChanged(QListViewItem*)));
 
64
}
 
65
 
 
66
MetadataListView::~MetadataListView()
 
67
{
 
68
}
 
69
 
 
70
QString MetadataListView::getCurrentItemKey()
 
71
{
 
72
    if (currentItem())
 
73
    {
 
74
        if (currentItem()->isSelectable())
 
75
        {
 
76
            MetadataListViewItem *item = static_cast<MetadataListViewItem *>(currentItem());
 
77
            return item->getKey();
 
78
        }
 
79
    }
 
80
 
 
81
    return QString();
 
82
}
 
83
 
 
84
void MetadataListView::setCurrentItemByKey(QString itemKey)
 
85
{
 
86
    if (itemKey.isNull())
 
87
        return;
 
88
 
 
89
    QListViewItemIterator it(this);
 
90
    while ( it.current() )
 
91
    {
 
92
        if ( it.current()->isSelectable() )
 
93
        {
 
94
            MetadataListViewItem *item = dynamic_cast<MetadataListViewItem *>(it.current());
 
95
 
 
96
            if (item->getKey() == itemKey)
 
97
            {
 
98
                setSelected(item, true);
 
99
                ensureItemVisible(item);
 
100
                m_selectedItemKey = itemKey;
 
101
                return;
 
102
            }
 
103
        }
 
104
 
 
105
        ++it;
 
106
    }
 
107
}
 
108
 
 
109
void MetadataListView::slotSelectionChanged(QListViewItem *item)
 
110
{
 
111
    if (!item)
 
112
        return;
 
113
 
 
114
    MetadataListViewItem* viewItem = static_cast<MetadataListViewItem *>(item);
 
115
    m_selectedItemKey = viewItem->getKey();
 
116
    QString tagValue  = viewItem->getValue().simplifyWhiteSpace();
 
117
    QString tagTitle  = m_parent->getTagTitle(m_selectedItemKey);
 
118
    QString tagDesc   = m_parent->getTagDescription(m_selectedItemKey);
 
119
    if (tagValue.length() > 128)
 
120
    {
 
121
        tagValue.truncate(128);
 
122
        tagValue.append("...");
 
123
    }
 
124
 
 
125
    QWhatsThis::add(this, i18n("<b>Title: </b><p>%1<p>"
 
126
                               "<b>Value: </b><p>%2<p>"
 
127
                               "<b>Description: </b><p>%3")
 
128
                          .arg(tagTitle)
 
129
                          .arg(tagValue)
 
130
                          .arg(tagDesc));
 
131
}
 
132
 
 
133
void MetadataListView::setIfdList(const DMetadata::MetaDataMap& ifds, const QStringList& tagsfilter)
 
134
{
 
135
    clear();
 
136
 
 
137
    uint               subItems = 0;
 
138
    QString            ifDItemName;
 
139
    MdKeyListViewItem *parentifDItem = 0;
 
140
 
 
141
    for (DMetadata::MetaDataMap::const_iterator it = ifds.begin(); it != ifds.end(); ++it)
 
142
    {
 
143
        // We checking if we have changed of ifDName
 
144
        QString currentIfDName = it.key().section('.', 1, 1);
 
145
 
 
146
        if ( currentIfDName != ifDItemName )
 
147
        {
 
148
            ifDItemName = currentIfDName;
 
149
 
 
150
            // Check if the current IfD have any items. If no remove it before to toggle to the next IfD.
 
151
            if ( subItems == 0 && parentifDItem)
 
152
                delete parentifDItem;
 
153
 
 
154
            parentifDItem = new MdKeyListViewItem(this, currentIfDName);
 
155
            subItems = 0;
 
156
        }
 
157
 
 
158
        // We ignore all unknown tags if necessary.
 
159
        if (!it.key().section('.', 2, 2).startsWith("0x"))
 
160
        {
 
161
            if (!tagsfilter.isEmpty())
 
162
            {
 
163
                // We using the filter to make a more user friendly output (Simple Mode)
 
164
 
 
165
                if (tagsfilter.contains(it.key().section('.', 2, 2)))
 
166
                {
 
167
                    QString tagTitle = m_parent->getTagTitle(it.key());
 
168
                    new MetadataListViewItem(parentifDItem, it.key(), tagTitle, it.data());
 
169
                    subItems++;
 
170
                }
 
171
            }
 
172
            else
 
173
            {
 
174
                // We don't filter the output (Complete Mode)
 
175
 
 
176
                QString tagTitle = m_parent->getTagTitle(it.key());
 
177
                new MetadataListViewItem(parentifDItem, it.key(), tagTitle, it.data());
 
178
                subItems++;
 
179
            }
 
180
        }
 
181
    }
 
182
 
 
183
    // To check if the last IfD have any items...
 
184
    if ( subItems == 0 && parentifDItem)
 
185
        delete parentifDItem;
 
186
 
 
187
    setCurrentItemByKey(m_selectedItemKey);
 
188
    QTimer::singleShot( 0, this, SLOT( triggerUpdate() ) );
 
189
}
 
190
 
 
191
void MetadataListView::setIfdList(const DMetadata::MetaDataMap& ifds, const QStringList& keysFilter,
 
192
                                  const QStringList& tagsFilter)
 
193
{
 
194
    clear();
 
195
 
 
196
    uint               subItems = 0;
 
197
    MdKeyListViewItem *parentifDItem = 0;
 
198
 
 
199
    for (QStringList::const_iterator itKeysFilter = keysFilter.begin();
 
200
         itKeysFilter != keysFilter.end();
 
201
         ++itKeysFilter)
 
202
    {
 
203
        subItems = 0;
 
204
        parentifDItem = new MdKeyListViewItem(this, *itKeysFilter);
 
205
 
 
206
        DMetadata::MetaDataMap::const_iterator it = ifds.end(); 
 
207
 
 
208
        while(1)   
 
209
        {
 
210
            if ( *itKeysFilter == it.key().section('.', 1, 1) )
 
211
            {
 
212
                // We ignore all unknown tags if necessary.
 
213
                if (!it.key().section('.', 2, 2).startsWith("0x"))
 
214
                {
 
215
                    if (!tagsFilter.isEmpty())
 
216
                    {
 
217
                        // We using the filter to make a more user friendly output (Simple Mode)
 
218
 
 
219
                        if (tagsFilter.contains(it.key().section('.', 2, 2)))
 
220
                        {
 
221
                            QString tagTitle = m_parent->getTagTitle(it.key());
 
222
                            new MetadataListViewItem(parentifDItem, it.key(), tagTitle, it.data());
 
223
                            subItems++;
 
224
                        }
 
225
                    }
 
226
                    else
 
227
                    {
 
228
                        // We don't filter the output (Complete Mode)
 
229
 
 
230
                        QString tagTitle = m_parent->getTagTitle(it.key());
 
231
                        new MetadataListViewItem(parentifDItem, it.key(), tagTitle, it.data());
 
232
                        subItems++;
 
233
                    }
 
234
                }
 
235
            }
 
236
 
 
237
            if (it == ifds.begin()) break;
 
238
            --it;
 
239
        }
 
240
 
 
241
        // We checking if the last IfD have any items. If no, we remove it.
 
242
        if ( subItems == 0 && parentifDItem)
 
243
            delete parentifDItem;
 
244
    }
 
245
 
 
246
    setCurrentItemByKey(m_selectedItemKey);
 
247
    QTimer::singleShot( 0, this, SLOT( triggerUpdate() ) );
 
248
}
 
249
 
 
250
void MetadataListView::viewportResizeEvent(QResizeEvent* e)
 
251
{
 
252
    QListView::viewportResizeEvent(e);
 
253
    QTimer::singleShot( 0, this, SLOT( triggerUpdate() ) );
 
254
}
 
255
 
 
256
void MetadataListView::slotSearchTextChanged(const QString& filter)
 
257
{
 
258
    bool query     = false;
 
259
    QString search = filter.lower();
 
260
 
 
261
    QListViewItemIterator it(this);
 
262
    for ( ; it.current(); ++it ) 
 
263
    {
 
264
        MetadataListViewItem *item = dynamic_cast<MetadataListViewItem*>(it.current());
 
265
        if (item)
 
266
       {
 
267
            if (item->text(0).lower().contains(search) ||
 
268
                item->text(1).lower().contains(search))
 
269
            {
 
270
                query = true;
 
271
                item->setVisible(true);
 
272
            }
 
273
            else
 
274
            {
 
275
                item->setVisible(false);
 
276
            }
 
277
        }
 
278
    }
 
279
 
 
280
    emit signalTextFilterMatch(query);
 
281
}
 
282
 
 
283
}  // namespace Digikam