00001
00002
00003
00004
00005
00006
00007
00008 #include "TCanvas.h"
00009 #include "TClass.h"
00010 #include "TFile.h"
00011
00012 #if QT_VERSION >= 0x40000
00013
00014 #include <QPixmap>
00015 #include <QMimeSource>
00016 #include <Q3MimeSourceFactory>
00017 #include <Q3ImageDrag>
00018 #include <Q3ListViewItem>
00019 typedef Q3ListViewItem QListViewItem;
00020 typedef Q3DragObject QDragObject;
00021 typedef Q3TextDrag QTextDrag;
00022 typedef Q3ImageDrag QImageDrag;
00023 typedef Q3MimeSourceFactory QMimeSourceFactory;
00024 #endif
00025
00026 static QPixmap uic_load_pixmap( const QString &name )
00027 {
00028 const QMimeSource *m = QMimeSourceFactory::defaultFactory()->data( name );
00029 if ( !m )
00030 return QPixmap();
00031 QPixmap pix;
00032 QImageDrag::decode( m, pix );
00033 return pix;
00034 }
00035
00036 void qtrootexample1::init()
00037 {
00038 TKey *key;
00039 TFile *fxDiskFile;
00040
00041 (TQRootCanvas1->GetCanvas())->Divide(2,2);
00042 fxDiskFile = new TFile("test.root");
00043 TIter next(fxDiskFile->GetListOfKeys());
00044 while ((key = (TKey*) next())) {
00045 AddItemToListView1(key->ReadObj());
00046 }
00047 }
00048
00049 void qtrootexample1::destroy()
00050 {
00051
00052 }
00053
00054 void qtrootexample1::ListView1_mouseButtonPressed( int, QListViewItem *SelectedItem, const QPoint &, int )
00055 {
00056 if (SelectedItem!=0) {
00057 QDragObject *d = new QTextDrag(SelectedItem->text(0),ListView1);
00058 d->dragCopy();
00059 }
00060 }
00061
00062 void qtrootexample1::AddItemToListView1(TObject *Key)
00063 {
00064 if( Key->IsA()->InheritsFrom("TH2") ) {
00065 QListViewItem * item1 = new QListViewItem(ListView1, Key->GetName() ,"TH2");
00066 item1->setPixmap( 0, uic_load_pixmap( "h2_t.png" ) );
00067 }
00068 else if (Key->IsA()->InheritsFrom("TH1")) {
00069 QListViewItem * item1 = new QListViewItem(ListView1, Key->GetName(),"TH1");
00070 item1->setPixmap( 0, uic_load_pixmap( "h1_t.png" ) );
00071 }
00072 }
00073