kivio
kivio_icon_view.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kivio_icon_view.h"
00020
00021 #include "kivio_stencil_spawner.h"
00022 #include "kivio_stencil_spawner_set.h"
00023 #include "kivio_stencil_spawner_info.h"
00024 #include "kivio_spawner_drag.h"
00025 #include "kivio_common.h"
00026 #include "kivioglobal.h"
00027 #include "kivio_stencil.h"
00028
00029 #include <qbrush.h>
00030 #include <qcursor.h>
00031 #include <qpalette.h>
00032 #include <klocale.h>
00033 #include <kdebug.h>
00034 #include <kglobalsettings.h>
00035
00036 KivioStencilSpawner* KivioIconView::m_pCurDrag = 0L;
00037 QPtrList<KivioIconView> KivioIconView::objList;
00038
00039
00040
00041
00042
00043
00044 KivioIconViewItem::KivioIconViewItem( QIconView *parent )
00045 : QIconViewItem( parent )
00046 {
00047 m_pSpawner = NULL;
00048 setText("stencil");
00049 }
00050
00051 KivioIconViewItem::~KivioIconViewItem()
00052 {
00053 m_pSpawner = NULL;
00054 }
00055
00056 void KivioIconViewItem::setStencilSpawner( KivioStencilSpawner *pSpawn )
00057 {
00058 KivioStencilSpawnerInfo *pInfo;
00059
00060 m_pSpawner = pSpawn;
00061
00062 if( !m_pSpawner )
00063 {
00064 setText( i18n("untitled stencil", "Untitled") );
00065 }
00066 else
00067 {
00068 pInfo = m_pSpawner->info();
00069 setText( pInfo->title() );
00070 KivioStencil* stencil = m_pSpawner->newStencil();
00071 setPixmap(Kivio::generatePixmapFromStencil(32, 32, stencil));
00072 delete stencil;
00073 }
00074
00075 }
00076
00077 bool KivioIconViewItem::acceptDrop( const QMimeSource * ) const
00078 {
00079 return false;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088 KivioIconView::KivioIconView( bool _readWrite,QWidget *parent, const char *name )
00089 : QIconView( parent, name )
00090 {
00091 m_pSpawnerSet = NULL;
00092 m_pCurDrag = NULL;
00093 isReadWrite=_readWrite;
00094 objList.append(this);
00095
00096 setGridX( 64 );
00097 setGridY( 64 );
00098 setResizeMode( Adjust );
00099 setWordWrapIconText(true);
00100 setHScrollBarMode( AlwaysOff );
00101 setVScrollBarMode( Auto );
00102 setAutoArrange(true);
00103 setSorting(true);
00104
00105 setItemsMovable(false);
00106
00107 setArrangement(LeftToRight);
00108 setAcceptDrops(false);
00109 viewport()->setAcceptDrops(false);
00110 if(isReadWrite) {
00111 connect(this, SIGNAL(doubleClicked(QIconViewItem*)), this, SLOT(slotDoubleClicked(QIconViewItem*)));
00112 connect(this, SIGNAL(clicked(QIconViewItem*)), this, SLOT(slotClicked(QIconViewItem*)));
00113 }
00114 }
00115
00116 KivioIconView::~KivioIconView()
00117 {
00118 objList.remove(this);
00119 m_pCurDrag = NULL;
00120 }
00121
00122 void KivioIconView::setStencilSpawnerSet( KivioStencilSpawnerSet *pSet )
00123 {
00124 m_pSpawnerSet = pSet;
00125 m_pCurDrag = NULL;
00126
00127 KivioStencilSpawner *pSpawner;
00128 KivioIconViewItem *pItem;
00129
00130 pSpawner = pSet->spawners()->first();
00131 while( pSpawner )
00132 {
00133 pItem = new KivioIconViewItem( this );
00134 pItem->setKey(pSpawner->info()->title());
00135 pItem->setStencilSpawner(pSpawner);
00136
00137 pSpawner = pSet->spawners()->next();
00138 }
00139 }
00140
00141 QDragObject *KivioIconView::dragObject()
00142 {
00143 if( !currentItem() || !isReadWrite)
00144 return 0;
00145
00146 QPoint orig = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) );
00147 KivioSpawnerDrag *drag = new KivioSpawnerDrag( this, viewport() );
00148
00149 const char*null_pix[]={
00150 "1 1 1 1",
00151 "# c None",
00152 "#"};
00153 drag->setPixmap(null_pix);
00154
00155 KivioIconViewItem *item = (KivioIconViewItem *)currentItem();
00156
00157 QIconDragItem id;
00158 QString full;
00159 full = item->spawner()->set()->dir() + "/" + item->spawner()->info()->title();
00160 id.setData( QCString(full.ascii()));
00161
00162 drag->append( id,
00163 QRect( item->pixmapRect(FALSE).x() - orig.x(),
00164 item->pixmapRect(FALSE).y() - orig.y(),
00165 item->pixmapRect().width(),
00166 item->pixmapRect().height() ),
00167 QRect( item->textRect(FALSE).x() - orig.x(),
00168 item->textRect(FALSE).y() - orig.y(),
00169 item->textRect().width(),
00170 item->textRect().height() ),
00171 *(item->spawner()) );
00172
00173
00174
00175
00176
00177
00178
00179 m_pCurDrag = item->spawner();
00180
00181 return drag;
00182 }
00183
00184 void KivioIconView::clearCurrentDrag()
00185 {
00186 m_pCurDrag = 0;
00187 }
00188
00189
00190 void KivioIconView::slotDoubleClicked( QIconViewItem *pQtItem )
00191 {
00192 KivioIconViewItem* pItem = dynamic_cast<KivioIconViewItem *>(pQtItem);
00193
00194 if( !pItem )
00195 {
00196 kdDebug(43000) << "KivioIconView::slotDoubleClicked() - Clicked item is not a KivioIconViewItem!" << endl;
00197 return;
00198 }
00199
00200 KivioStencilSpawner* pSpawner = pItem->spawner();
00201
00202 emit createNewStencil(pSpawner);
00203 }
00204
00205 void KivioIconView::slotClicked(QIconViewItem* item)
00206 {
00207 KivioIconViewItem* stencilItem = dynamic_cast<KivioIconViewItem *>(item);
00208
00209 if(!stencilItem)
00210 {
00211 kdDebug(43000) << "KivioIconView::slotClicked() - Clicked item is not a KivioIconViewItem!" << endl;
00212 return;
00213 }
00214
00215 KivioStencilSpawner* spawner = stencilItem->spawner();
00216 emit stencilSelected(spawner);
00217 }
00218
00219 #include "kivio_icon_view.moc"
|