AlbumShaper 1.0a3
items.cpp
Go to the documentation of this file.
1//==============================================
2// copyright : (C) 2003-2005 by Will Stokes
3//==============================================
4// This program is free software; you can redistribute it
5// and/or modify it under the terms of the GNU General
6// Public License as published by the Free Software
7// Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//==============================================
10
11//Systemwide includes
12#include <q3iconview.h>
13//Added by qt3to4:
14#include <QKeyEvent>
15#include <QEvent>
16
17//Projectwide includes
18#include "items.h"
19#include "item.h"
20
21//==============================================
23 const char* name ) : Q3IconView( parent, name)
24{
26// setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum);
27
28 //connect mouse over events to paint pseudo selection in ligher blue
29 connect( this, SIGNAL(onItem(Q3IconViewItem*)),
30 this, SLOT(repaintGroup(Q3IconViewItem*)) );
31
32 //clear any pseudo selection when mouse moves off icons
33 connect( this, SIGNAL(onViewport()),
34 this, SLOT(clearPseudoSelection()) );
35}
36//==============================================
37void Items::keyPressEvent( QKeyEvent* e )
38{
39 //change key left/right presses to up/down events
40 int key = e->key();
41 if( key == Qt::Key_Left) key = Qt::Key_Up;
42 if( key == Qt::Key_Right) key = Qt::Key_Down;
43
44 Q3IconView::keyPressEvent(
45 new QKeyEvent(QEvent::KeyPress,
46 key,
47 e->ascii(),
48 e->state(),
49 e->text(),
50 e->isAutoRepeat(),
51 e->count() ) );
52}
53//==============================================
54QSize Items::sizeHint() const
55{
56 QSize s = Q3IconView::sizeHint();
57
58 //find max item width
59 s.setWidth(0);
60 Q3IconViewItem *item;
61 for( item = firstItem(); item != NULL; item = item->nextItem() )
62 {
63 if(item->width() + 2 > s.width() )
64 s.setWidth( item->width() );
65 }
66 s.setWidth( s.width() + 2*spacing() );
67 return s;
68}
69//==============================================
70void Items::repaintGroup( Q3IconViewItem* pseudoSelection)
71{
72 //if old pseudo selection unselect it
74
75 //paint new selection
76 currentPseudoSelection = (Item*)pseudoSelection;
78 repaintItem(currentPseudoSelection);
79}
80//==============================================
82{
83 //if old pseudo selection unselect it
84 if(currentPseudoSelection != NULL)
85 {
87 repaintItem(currentPseudoSelection);
89 }
90}
91//==============================================
Definition item.h:28
void setMousedOver(bool val)
Definition item.cpp:60
Item * currentPseudoSelection
Definition items.h:40
void clearPseudoSelection()
Definition items.cpp:81
Items(QWidget *parent=0, const char *name=0)
Definition items.cpp:22
void keyPressEvent(QKeyEvent *e)
Definition items.cpp:37
QSize sizeHint() const
Definition items.cpp:54
void repaintGroup(Q3IconViewItem *pseudoSelection)
Definition items.cpp:70