[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdenonbeta/krecipes/src/widgets
From: Unai Garro <ugarro () telefonica ! net>
Date: 2004-03-20 19:42:47
Message-ID: 20040320194247.4506599AC () office ! kde ! org
[Download RAW message or body]
CVS commit by uga:
Add an optional filter function to the widget
M +45 -8 krelistview.cpp 1.4
M +9 -3 krelistview.h 1.2
--- kdenonbeta/krecipes/src/widgets/krelistview.cpp #1.3:1.4
@@ -12,15 +12,32 @@
#include <klocale.h>
-KreListView::KreListView(QWidget *parent,const QString &title):QVBox(parent)
+KreListView::KreListView(QWidget *parent,const QString &title,bool filter, int \
filterCol):QVBox(parent) {
-if (title!=QString::null)
+
+ filteredColumn=filterCol;
+ QWidget *header=this;
+ if (filter) header=new QHBox(this);
+
+ if (title!=QString::null)
{
- label=new QLabel(this);
- label->setText(title);
+ listLabel=new QLabel(header);
+ listLabel->setText(title);
}
-list=new KListView(this);
-list->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
-setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
-setSpacing(10);
+
+ if (filter) {
+ filterBox=new QHBox(header); \
((QHBox*)header)->setSpacing(30); + \
filterBox->setFrameShape(QFrame::Box); filterBox->setMargin(2); + \
filterLabel=new QLabel(filterBox); filterLabel->setText(i18n("Search:")); + \
filterEdit=new KLineEdit(filterBox); + }
+
+
+ list=new KListView(this);
+ list->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
+ setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
+ setSpacing(10);
+
+ //Connect Signals & Slots
+ if (filter) connect(filterEdit,SIGNAL(textChanged(const \
QString&)),this,SLOT(filter(const QString&))); }
@@ -28,2 +45,22 @@ KreListView::~KreListView()
{
}
+
+void KreListView::filter(const QString& s)
+{
+for (QListViewItem *it=list->firstChild();it;it=it->nextSibling())
+ {
+ if ( s.isNull() || s == "" ) // Don't filter if the filter text is \
empty + {
+ it->setVisible(true);
+ }
+ else // It's a category. Check the children
+ {
+
+ if (it->text(filteredColumn).contains(s,false)) \
it->setVisible(true); + else it->setVisible(false);
+
+ }
+
+
+ }
+}
\ No newline at end of file
--- kdenonbeta/krecipes/src/widgets/krelistview.h #1.1:1.2
@@ -15,5 +15,5 @@
#include <qvbox.h>
#include <klistview.h>
-
+#include <klineedit.h>
@@ -26,11 +26,17 @@ Q_OBJECT
public:
- KreListView(QWidget *parent,const QString &title=QString::null);
+ KreListView(QWidget *parent,const QString &title=QString::null, bool \
filter=false, int filterCol=0); ~KreListView();
KListView *listView(){return list;}
private:
- QLabel *label;
+ QHBox *filterBox;
+ QLabel *listLabel;
+ int filteredColumn;
+ QLabel *filterLabel;
+ KLineEdit *filterEdit;
KListView *list;
+private slots:
+ void filter(const QString& s);
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic