Eneboo - Documentación para desarrolladores
src/qt/tools/designer/designer/pixmapcollectioneditor.ui.h
Ir a la documentación de este archivo.
00001 /**********************************************************************
00002 ** Copyright (C) 2001-2007 Trolltech ASA.  All rights reserved.
00003 **
00004 ** This file is part of Qt Designer.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00012 ** licenses may use this file in accordance with the Qt Commercial License
00013 ** Agreement provided with the Software.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00019 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00020 **   information about Qt Commercial License Agreements.
00021 **
00022 ** Contact info@trolltech.com if any conditions of this licensing are
00023 ** not clear to you.
00024 **
00025 **********************************************************************/
00026 
00027 void PixmapCollectionEditor::init()
00028 {
00029     project = 0;
00030     setChooserMode( FALSE );
00031 }
00032 
00033 void PixmapCollectionEditor::destroy()
00034 {
00035 }
00036 
00037 void PixmapCollectionEditor::addPixmap()
00038 {
00039     if ( !project )
00040         return;
00041 
00042     QString f;
00043     QStringList pixmaps = qChoosePixmaps( this );
00044     if ( pixmaps.isEmpty() )
00045         return;
00046 
00047     QString lastName;
00048     for ( QStringList::ConstIterator it = pixmaps.begin(); it != pixmaps.end(); ++it ) {
00049         QPixmap pm( *it );
00050         if ( pm.isNull() )
00051             continue;
00052         PixmapCollection::Pixmap pixmap;
00053         pixmap.pix = pm;
00054         QFileInfo fi ( *it );
00055         pixmap.name = fi.fileName();
00056         pixmap.absname = fi.filePath();
00057         if ( !project->pixmapCollection()->addPixmap( pixmap, FALSE ) )
00058             continue;
00059         lastName = pixmap.name;
00060     }
00061 
00062     updateView();
00063     QIconViewItem *item = viewPixmaps->findItem( lastName );
00064     if ( item ) {
00065         viewPixmaps->setCurrentItem( item );
00066         viewPixmaps->ensureItemVisible( item );
00067     }
00068 
00069 }
00070 
00071 void PixmapCollectionEditor::removePixmap()
00072 {
00073     if ( !project || !viewPixmaps->currentItem() )
00074         return;
00075     project->pixmapCollection()->removePixmap( viewPixmaps->currentItem()->text() );
00076     updateView();
00077 }
00078 
00079 void PixmapCollectionEditor::updateView()
00080 {
00081     if ( !project )
00082         return;
00083 
00084     viewPixmaps->clear();
00085 
00086     QValueList<PixmapCollection::Pixmap> pixmaps = project->pixmapCollection()->pixmaps();
00087     for ( QValueList<PixmapCollection::Pixmap>::Iterator it = pixmaps.begin(); it != pixmaps.end(); ++it ) {
00088         // #### might need to scale down the pixmap
00089         QIconViewItem *item = new QIconViewItem( viewPixmaps, (*it).name, scaledPixmap( (*it).pix ) );
00090         //item->setRenameEnabled( TRUE ); // this will be a bit harder to implement
00091         item->setDragEnabled( FALSE );
00092         item->setDropEnabled( FALSE );
00093     }
00094     viewPixmaps->setCurrentItem( viewPixmaps->firstItem() );
00095     currentChanged( viewPixmaps->firstItem() );
00096 }
00097 
00098 void PixmapCollectionEditor::currentChanged( QIconViewItem * i )
00099 {
00100     buttonOk->setEnabled( !!i );
00101 }
00102 
00103 void PixmapCollectionEditor::setChooserMode( bool c )
00104 {
00105     chooser = c;
00106     if ( chooser ) {
00107         buttonClose->hide();
00108         buttonOk->show();
00109         buttonCancel->show();
00110         buttonOk->setEnabled( FALSE );
00111         buttonOk->setDefault( TRUE );
00112         connect( viewPixmaps, SIGNAL( doubleClicked( QIconViewItem * ) ), buttonOk, SIGNAL( clicked() ) );
00113         connect( viewPixmaps, SIGNAL( returnPressed( QIconViewItem * ) ), buttonOk, SIGNAL( clicked() ) );
00114         setCaption( tr( "Choose an Image" ) );
00115     } else {
00116         buttonClose->show();
00117         buttonOk->hide();
00118         buttonCancel->hide();
00119         buttonClose->setDefault( TRUE );
00120     }
00121     updateView();
00122 }
00123 
00124 void PixmapCollectionEditor::setCurrentItem( const QString & name )
00125 {
00126     QIconViewItem *i = viewPixmaps->findItem( name );
00127     if ( i ) {
00128         viewPixmaps->setCurrentItem( i );
00129         currentChanged( i );
00130     }
00131 }
00132 
00133 void PixmapCollectionEditor::setProject( Project * pro )
00134 {
00135     project = pro;
00136     updateView();
00137 }
00138 
00139 QPixmap PixmapCollectionEditor::scaledPixmap( const QPixmap & p )
00140 {
00141     QPixmap pix( p );
00142     if ( pix.width() < 50 && pix.height() < 50 )
00143         return pix;
00144     QImage img;
00145     img = pix;
00146     img = img.smoothScale( 50, 50 );
00147     pix.convertFromImage( img );
00148     return pix;
00149 }
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'