AlbumShaper  1.0a3
items.cpp
Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003-2005 by Will Stokes
00003 //==============================================
00004 //  This program is free software; you can redistribute it
00005 //  and/or modify it under the terms of the GNU General
00006 //  Public License as published by the Free Software
00007 //  Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //==============================================
00010 
00011 //Systemwide includes
00012 #include <qiconview.h>
00013 
00014 //Projectwide includes
00015 #include "items.h"
00016 #include "item.h"
00017 
00018 //==============================================
00019 Items::Items( QWidget* parent,
00020                       const char* name ) : QIconView( parent, name)
00021 {
00022   currentPseudoSelection = NULL;
00023 //  setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum);
00024 
00025   //connect mouse over events to paint pseudo selection in ligher blue
00026   connect( this, SIGNAL(onItem(QIconViewItem*)),
00027                 this, SLOT(repaintGroup(QIconViewItem*)) );
00028 
00029   //clear any pseudo selection when mouse moves off icons
00030   connect( this, SIGNAL(onViewport()),
00031                 this, SLOT(clearPseudoSelection()) );
00032 }
00033 //==============================================
00034 void Items::keyPressEvent( QKeyEvent* e )
00035 {
00036   //change key left/right presses to up/down events
00037   int key = e->key();
00038   if( key == Key_Left) key = Key_Up;
00039   if( key == Key_Right) key = Key_Down;
00040 
00041   QIconView::keyPressEvent(
00042     new QKeyEvent(QEvent::KeyPress,
00043               key,
00044               e->ascii(),
00045               e->state(),
00046               e->text(),
00047               e->isAutoRepeat(),
00048               e->count() ) );
00049 }
00050 //==============================================
00051 QSize Items::sizeHint() const
00052 {
00053   QSize s = QIconView::sizeHint();
00054 
00055   //find max item width
00056   s.setWidth(0);
00057   QIconViewItem *item;
00058   for( item = firstItem(); item != NULL; item = item->nextItem() )
00059   {
00060     if(item->width() + 2 > s.width() )
00061       s.setWidth( item->width() );
00062   }
00063   s.setWidth( s.width() + 2*spacing() );
00064   return s;
00065 }
00066 //==============================================
00067 void Items::repaintGroup( QIconViewItem* pseudoSelection)
00068 {
00069   //if old pseudo selection unselect it
00070   clearPseudoSelection();
00071 
00072   //paint new selection
00073   currentPseudoSelection = (Item*)pseudoSelection;
00074   currentPseudoSelection->setMousedOver(true);
00075   repaintItem(currentPseudoSelection);
00076 }
00077 //==============================================
00078 void Items::clearPseudoSelection()
00079 {
00080   //if old pseudo selection unselect it
00081   if(currentPseudoSelection != NULL)
00082   {
00083     currentPseudoSelection->setMousedOver(false);
00084     repaintItem(currentPseudoSelection);
00085     currentPseudoSelection = NULL;
00086   }
00087 }
00088 //==============================================