Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cbkmkselector.h

Go to the documentation of this file.
00001 #include <qwidget.h>
00002 #include <qlistbox.h>
00003 #include <qpushbutton.h>
00004 #include <qlayout.h>
00005 
00006 class CBkmkSelectorItem : public QListBoxText
00007 {
00008   int m_ref;
00009  public:
00010   CBkmkSelectorItem(const QString& _t, int ref) : QListBoxText(_t), m_ref(ref)
00011     {
00012     }
00013   int reference() { return m_ref; }
00014 };
00015 
00016 class CBkmkSelector : public QWidget
00017 {
00018 
00019   Q_OBJECT
00020 
00021   QListBox* bkmkselector;
00022   QPushButton* exitButton;
00023   /*
00024   void keyPressEvent ( QKeyEvent * e )
00025     {
00026       if ((e->key() == Key_Return) || (e->key() == Key_Space))
00027         {
00028           emit selected(reinterpret_cast<CBkmkSelectorItem*>(bkmkselector->item(bkmkselector->currentItem()))->reference());
00029           e->accept();
00030         }
00031       else
00032         {
00033           e->ignore();
00034         }
00035     }
00036   */
00037 signals:
00038   void selected(int i);
00039   void cancelled();
00040 private slots:
00041   void slotSelected(QListBoxItem* t)
00042   {
00043     if (t != NULL)
00044       {
00045         emit selected(reinterpret_cast<CBkmkSelectorItem*>(t)->reference());
00046       }
00047   }
00048 //void slotSelected(int t) { emit selected(t); }
00049   void slotCancel() { emit cancelled(); }
00050   void slotSort()
00051     {
00052       bkmkselector->sort();
00053 #ifdef USEQPE
00054       setCurrentItem(bkmkselector->currentItem());
00055 #endif
00056     }
00057 public:
00058   CBkmkSelector( QWidget *parent=0, const char *name=0, WFlags f = 0) :
00059         QWidget(parent, name, f)
00060   {
00061 
00062 //      QFont f("unifont", 16);
00063 //      setFont( f );
00064 
00065     QVBoxLayout* grid = new QVBoxLayout(this);
00066     QHBoxLayout* hgrid = new QHBoxLayout();
00067     bkmkselector = new QListBox(this, tr("Bookmarks"));
00068     QPushButton* _sort = new QPushButton(tr("Sort"), this);
00069     connect(_sort, SIGNAL(clicked()), this, SLOT( slotSort() ) );
00070     exitButton = new QPushButton(tr("Cancel"), this);
00071     //    connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( slotSelected(int) ) );
00072     connect(bkmkselector, SIGNAL( clicked(QListBoxItem*) ), this, SLOT( slotSelected(QListBoxItem*) ) );
00073     connect(bkmkselector, SIGNAL( returnPressed(QListBoxItem*) ), this, SLOT( slotSelected(QListBoxItem*) ) );
00074     connect(exitButton, SIGNAL( clicked() ), this, SLOT( slotCancel() ) );
00075     grid->addWidget(bkmkselector,1);
00076     grid->addLayout(hgrid);
00077     hgrid->addWidget(_sort);
00078     hgrid->addWidget(exitButton);
00079   }
00080   void clear() { bkmkselector->clear(); }
00081   void insertItem(const QString& _item, int ref)
00082     {
00083       CBkmkSelectorItem* item = new CBkmkSelectorItem(_item, ref);
00084       bkmkselector->insertItem(item); 
00085     }
00086   QString text(int index) const { return bkmkselector->text(index); }
00087   void setText(const QString& _l) { exitButton->setText(_l); }
00088   void setCurrentItem(int _i) { bkmkselector->setCurrentItem(_i); }
00089 };

Generated on Sat Nov 5 16:16:53 2005 for OPIE by  doxygen 1.4.2