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
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
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
00063
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
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 };