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

« back to all changes in this revision

Viewing changes to digikam/digikam/folderview.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:
7
7
 * Description : implementation of folder view.
8
8
 *
9
9
 * Copyright (C) 2005-2006 by Joern Ahrens <joern.ahrens@kdemail.net>
10
 
 * Copyright (C) 2006-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 * Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
11
 *
12
12
 * This program is free software; you can redistribute it
13
13
 * and/or modify it under the terms of the GNU General
26
26
 
27
27
#include <qpixmap.h>
28
28
#include <qvaluelist.h>
 
29
#include <qstyle.h>
29
30
 
30
31
// KDE includes.
31
32
 
60
61
        oldHighlightItem = 0;
61
62
    }
62
63
 
63
 
    bool         active;
64
 
    
65
 
    int          itemHeight;
66
 
 
67
 
    QPixmap      itemRegPix;
68
 
    QPixmap      itemSelPix;
69
 
    
70
 
    QPoint       dragStartPos;    
71
 
 
72
 
    FolderItem  *dragItem;
73
 
    FolderItem  *oldHighlightItem;
 
64
    bool           active;
 
65
 
 
66
    int            itemHeight;
 
67
 
 
68
    QPixmap        itemRegPix;
 
69
    QPixmap        itemSelPix;
 
70
 
 
71
    QPoint         dragStartPos;
 
72
 
 
73
    QListViewItem *dragItem;
 
74
    QListViewItem *oldHighlightItem;
74
75
};
75
76
 
76
77
//-----------------------------------------------------------------------------
122
123
{
123
124
    if(!item)
124
125
        return QRect();
125
 
    
 
126
 
126
127
    QRect r = QListView::itemRect(item);
127
128
    r.setLeft(r.left()+(item->depth()+(rootIsDecorated() ? 1 : 0))*treeStepSize());
128
 
    return r;    
 
129
    return r;
129
130
}
130
131
 
131
132
QPixmap FolderView::itemBasePixmapRegular() const
132
133
{
133
 
    return d->itemRegPix;    
 
134
    return d->itemRegPix;
134
135
}
135
136
 
136
137
QPixmap FolderView::itemBasePixmapSelected() const
137
138
{
138
 
    return d->itemSelPix;    
 
139
    return d->itemSelPix;
139
140
}
140
141
 
141
142
void FolderView::resizeEvent(QResizeEvent* e)
183
184
        }
184
185
        return;
185
186
    }
186
 
    
 
187
 
187
188
    if(d->dragItem && 
188
189
       (d->dragStartPos - e->pos()).manhattanLength() > QApplication::startDragDistance())
189
190
    {
190
191
        QPoint vp = contentsToViewport(e->pos());
191
 
        FolderItem *item = dynamic_cast<FolderItem*>(itemAt(vp));
 
192
        QListViewItem *item = itemAt(vp);
192
193
        if(!item)
193
194
        {
194
195
            d->dragItem = 0;
195
196
            return;
196
197
        }
197
 
    }    
 
198
    }
198
199
}
199
200
 
200
201
void FolderView::contentsMousePressEvent(QMouseEvent *e)
201
202
{
 
203
    QPoint vp           = contentsToViewport(e->pos());
 
204
    QListViewItem *item = itemAt(vp);
 
205
 
 
206
    // With Check Box item, we will toggle on/off item using middle mouse button.
 
207
    // See B.K.O #130906
 
208
    FolderCheckListItem *citem = dynamic_cast<FolderCheckListItem*>(item);
 
209
    if(citem && e->button() == MidButton && mouseInItemRect(item, e->pos().x()))
 
210
    {
 
211
        QListView::contentsMousePressEvent(e);
 
212
        citem->setOn(!citem->isOn());
 
213
        return;
 
214
    }
 
215
 
202
216
    QListView::contentsMousePressEvent(e);
203
217
 
204
 
    QPoint vp        = contentsToViewport(e->pos());
205
 
    FolderItem *item = dynamic_cast<FolderItem*>(itemAt(vp));
206
218
    if(item && e->button() == LeftButton) 
207
219
    {
 
220
        // Prepare D&D if necessary
208
221
        d->dragStartPos = e->pos();
209
222
        d->dragItem     = item;
210
223
        return;
213
226
 
214
227
void FolderView::contentsMouseReleaseEvent(QMouseEvent *e)
215
228
{
 
229
    QPoint vp           = contentsToViewport(e->pos());
 
230
    QListViewItem *item = itemAt(vp);
 
231
 
216
232
    QListView::contentsMouseReleaseEvent(e);
217
233
 
 
234
    if(item && e->button() == LeftButton)
 
235
    {
 
236
        // See B.K.O #126871: collapse/expand treeview using left mouse button single click.
 
237
        if (mouseInItemRect(item, e->pos().x()))
 
238
            item->setOpen(!item->isOpen());
 
239
    }
 
240
 
218
241
    d->dragItem = 0;
219
242
}
220
243
 
222
245
{
223
246
    QDragObject *o = dragObject();
224
247
    if(o)
225
 
        o->drag();        
 
248
        o->drag();
226
249
}
227
250
 
228
 
FolderItem* FolderView::dragItem() const
 
251
QListViewItem* FolderView::dragItem() const
229
252
{
230
253
    return d->dragItem;
231
254
}
233
256
void FolderView::contentsDragEnterEvent(QDragEnterEvent *e)
234
257
{
235
258
    QListView::contentsDragEnterEvent(e);
236
 
    
 
259
 
237
260
    e->accept(acceptDrop(e));
238
261
}
239
262
 
240
263
void FolderView::contentsDragLeaveEvent(QDragLeaveEvent * e)
241
264
{
242
265
    QListView::contentsDragLeaveEvent(e);
243
 
    
 
266
 
244
267
    if(d->oldHighlightItem)
245
268
    {
246
 
        d->oldHighlightItem->setFocus(false);
 
269
        FolderItem *fitem = dynamic_cast<FolderItem*>(d->oldHighlightItem);
 
270
        if (fitem)
 
271
            fitem->setFocus(false);
 
272
        else
 
273
        {
 
274
            FolderCheckListItem *citem = dynamic_cast<FolderCheckListItem*>(d->oldHighlightItem);
 
275
            if (citem)
 
276
                citem->setFocus(false);
 
277
        }
247
278
        d->oldHighlightItem->repaint();
248
 
        d->oldHighlightItem = 0;        
 
279
        d->oldHighlightItem = 0;
249
280
    }
250
281
}
251
282
 
252
283
void FolderView::contentsDragMoveEvent(QDragMoveEvent *e)
253
284
{
254
285
    QListView::contentsDragMoveEvent(e);
255
 
    
256
 
    QPoint vp        = contentsToViewport(e->pos());
257
 
    FolderItem *item = dynamic_cast<FolderItem*>(itemAt(vp));
 
286
 
 
287
    QPoint vp           = contentsToViewport(e->pos());
 
288
    QListViewItem *item = itemAt(vp);
258
289
    if(item)
259
290
    {
260
291
        if(d->oldHighlightItem)
261
292
        {
262
 
            d->oldHighlightItem->setFocus(false);
 
293
            FolderItem *fitem = dynamic_cast<FolderItem*>(d->oldHighlightItem);
 
294
            if (fitem)
 
295
                fitem->setFocus(false);
 
296
            else
 
297
            {
 
298
                FolderCheckListItem *citem = dynamic_cast<FolderCheckListItem*>(d->oldHighlightItem);
 
299
                if (citem)
 
300
                    citem->setFocus(false);
 
301
            }
263
302
            d->oldHighlightItem->repaint();
264
303
        }
265
 
        item->setFocus(true);
 
304
 
 
305
        FolderItem *fitem = dynamic_cast<FolderItem*>(item);
 
306
        if (fitem)
 
307
            fitem->setFocus(true);
 
308
        else
 
309
        {
 
310
            FolderCheckListItem *citem = dynamic_cast<FolderCheckListItem*>(item);
 
311
            if (citem)
 
312
                citem->setFocus(true);
 
313
        }
266
314
        d->oldHighlightItem = item;
267
315
        item->repaint();
268
316
    }
272
320
void FolderView::contentsDropEvent(QDropEvent *e)
273
321
{
274
322
    QListView::contentsDropEvent(e);
275
 
    
 
323
 
276
324
    if(d->oldHighlightItem)
277
325
    {
278
 
        d->oldHighlightItem->setFocus(false);
 
326
        FolderItem *fitem = dynamic_cast<FolderItem*>(d->oldHighlightItem);
 
327
        if (fitem)
 
328
            fitem->setFocus(false);
 
329
        else
 
330
        {
 
331
            FolderCheckListItem *citem = dynamic_cast<FolderCheckListItem*>(d->oldHighlightItem);
 
332
            if (citem)
 
333
                citem->setFocus(false);
 
334
        }
279
335
        d->oldHighlightItem->repaint();
280
336
        d->oldHighlightItem = 0;
281
337
    }
290
346
{
291
347
    if (!item)
292
348
        return false;
293
 
    
 
349
 
294
350
    x += contentsX();
295
351
 
296
352
    int offset = treeStepSize()*(item->depth() + (rootIsDecorated() ? 1 : 0));
297
353
    offset    += itemMargin();
298
354
    int width  = item->width(fontMetrics(), this, 0);
299
 
    
300
 
    return (x > offset && x < (offset + width));
 
355
 
 
356
    int boxsize = 0;
 
357
    FolderCheckListItem* citem = dynamic_cast<FolderCheckListItem*>(item);
 
358
    if (citem && 
 
359
        ((citem->type() == QCheckListItem::CheckBox) || (citem->type() == QCheckListItem::CheckBoxController)))
 
360
        boxsize = style().pixelMetric(QStyle::PM_CheckListButtonSize, this);
 
361
 
 
362
    return (x > (offset + boxsize) && x < (offset + boxsize + width));
301
363
}
302
364
 
303
365
void FolderView::slotThemeChanged()
308
370
    d->itemRegPix = ThemeEngine::instance()->listRegPixmap(w, h);
309
371
    d->itemSelPix = ThemeEngine::instance()->listSelPixmap(w, h);
310
372
 
311
 
    QPalette plt(palette());
312
 
    QColorGroup cg(plt.active());
313
 
    cg.setColor(QColorGroup::Base, ThemeEngine::instance()->baseColor());
314
 
    cg.setColor(QColorGroup::Text, ThemeEngine::instance()->textRegColor());
315
 
    cg.setColor(QColorGroup::HighlightedText, ThemeEngine::instance()->textSelColor());
316
 
    cg.setColor(QColorGroup::Link, ThemeEngine::instance()->textSpecialRegColor());
317
 
    cg.setColor(QColorGroup::LinkVisited, ThemeEngine::instance()->textSpecialSelColor());
318
 
    plt.setActive(cg);
319
 
    plt.setInactive(cg);
320
 
    setPalette(plt);
321
 
 
322
373
    viewport()->update();
323
374
}
324
375
 
325
376
void FolderView::slotAllAlbumsLoaded()
326
377
{
327
378
    disconnect(AlbumManager::instance(), SIGNAL(signalAllAlbumsLoaded()),
328
 
               this, SLOT(slotAllAlbumsLoaded()));    
 
379
               this, SLOT(slotAllAlbumsLoaded()));
329
380
    loadViewState();
330
381
}
331
382
 
333
384
{
334
385
    KConfig *config = kapp->config();
335
386
    config->setGroup(name());
336
 
    
 
387
 
337
388
    int selectedItem = config->readNumEntry("LastSelectedItem", 0);
338
 
    
 
389
 
339
390
    QValueList<int> openFolders;
340
391
    if(config->hasKey("OpenFolders"))
341
392
    {
342
393
        openFolders = config->readIntListEntry("OpenFolders");
343
394
    }
344
 
    
345
 
    FolderItem *item      = 0;    
346
 
    FolderItem *foundItem = 0;    
 
395
 
 
396
    FolderItem *item      = 0;
 
397
    FolderItem *foundItem = 0;
347
398
    QListViewItemIterator it(this->lastItem());
348
 
    
 
399
 
349
400
    for( ; it.current(); --it)
350
401
    {
351
402
        item = dynamic_cast<FolderItem*>(it.current());
352
403
        if(!item)
353
404
            continue;
354
 
    
 
405
 
355
406
        // Start the album root always open
356
407
        if(openFolders.contains(item->id()) || item->id() == 0)
357
408
            setOpen(item, true);
358
409
        else
359
410
            setOpen(item, false);
360
 
    
 
411
 
361
412
        if(item->id() == selectedItem)
362
413
        {
363
414
            // Save the found selected item so that it can be made visible.
380
431
{
381
432
    KConfig *config = kapp->config();
382
433
    config->setGroup(name());
383
 
   
 
434
 
384
435
    FolderItem *item = dynamic_cast<FolderItem*>(selectedItem());
385
436
    if(item)
386
437
        config->writeEntry("LastSelectedItem", item->id());
387
438
    else
388
439
        config->writeEntry("LastSelectedItem", 0);
389
 
    
 
440
 
390
441
    QValueList<int> openFolders;
391
442
    QListViewItemIterator it(this);
392
443
    for( ; it.current(); ++it)
400
451
 
401
452
void FolderView::slotSelectionChanged()
402
453
{
403
 
    QListView::selectionChanged();    
 
454
    QListView::selectionChanged();
404
455
}
405
456
 
406
457
void FolderView::selectItem(int)
408
459
}
409
460
 
410
461
}  // namespace Digikam
411