You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
261 lines
7.5 KiB
261 lines
7.5 KiB
14 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (c) 2003 Scott Wheeler <wheeler@kde.org>
|
||
|
Adapted to be used with KMyMoney under KDE 3.2 .. 3.4
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#ifndef KLISTVIEWSEARCHLINE_H
|
||
|
#define KLISTVIEWSEARCHLINE_H
|
||
|
|
||
|
#include <klineedit.h>
|
||
14 years ago
|
#include <tqhbox.h>
|
||
14 years ago
|
#include <kmymoney/export.h>
|
||
|
|
||
12 years ago
|
class TDEListView;
|
||
14 years ago
|
class TQListViewItem;
|
||
|
class TQToolButton;
|
||
14 years ago
|
|
||
|
/**
|
||
|
* This class makes it easy to add a search line for filtering the items in a
|
||
|
* listview based on a simple text search.
|
||
|
*
|
||
|
* No changes to the application other than instantiating this class with an
|
||
12 years ago
|
* appropriate TDEListView should be needed.
|
||
14 years ago
|
*
|
||
|
* @since 3.3
|
||
|
*/
|
||
|
|
||
12 years ago
|
class KMYMONEY_EXPORT TDEListViewSearchLine : public KLineEdit
|
||
14 years ago
|
{
|
||
|
Q_OBJECT
|
||
13 years ago
|
|
||
14 years ago
|
|
||
|
public:
|
||
|
|
||
|
/**
|
||
12 years ago
|
* Constructs a TDEListViewSearchLine with \a listView being the TDEListView to
|
||
14 years ago
|
* be filtered.
|
||
|
*
|
||
|
* If \a listView is null then the widget will be disabled until a listview
|
||
|
* is set with setListView().
|
||
|
*/
|
||
12 years ago
|
TDEListViewSearchLine(TQWidget *parent = 0, TDEListView *listView = 0, const char *name = 0);
|
||
14 years ago
|
|
||
|
/**
|
||
12 years ago
|
* Constructs a TDEListViewSearchLine without any TDEListView to filter. The
|
||
|
* TDEListView object has to be set later with setListView().
|
||
14 years ago
|
*/
|
||
12 years ago
|
TDEListViewSearchLine(TQWidget *parent, const char *name);
|
||
14 years ago
|
|
||
|
/**
|
||
12 years ago
|
* Destroys the TDEListViewSearchLine.
|
||
14 years ago
|
*/
|
||
12 years ago
|
virtual ~TDEListViewSearchLine();
|
||
14 years ago
|
|
||
|
/**
|
||
|
* Returns true if the search is case sensitive. This defaults to false.
|
||
|
*
|
||
|
* @see setCaseSensitive()
|
||
|
*/
|
||
|
bool caseSensitive() const;
|
||
|
|
||
|
/**
|
||
|
* Returns the current list of columns that will be searched. If the
|
||
|
* returned list is empty all visible columns will be searched.
|
||
|
*
|
||
|
* @see setSearchColumns
|
||
|
*/
|
||
14 years ago
|
TQValueList<int> searchColumns() const;
|
||
14 years ago
|
|
||
|
/**
|
||
14 years ago
|
* If this is true (the default) then the parents of matched items will also
|
||
14 years ago
|
* be shown.
|
||
|
*
|
||
|
* @see setKeepParentsVisible()
|
||
|
*/
|
||
|
bool keepParentsVisible() const;
|
||
|
|
||
|
/**
|
||
|
* Returns the listview that is currently filtered by the search.
|
||
|
*
|
||
|
* @see setListView()
|
||
|
*/
|
||
12 years ago
|
TDEListView *listView() const;
|
||
14 years ago
|
|
||
|
public slots:
|
||
|
/**
|
||
|
* Updates search to only make visible the items that match \a s. If
|
||
|
* \a s is null then the line edit's text will be used.
|
||
|
*/
|
||
14 years ago
|
virtual void updateSearch(const TQString &s = TQString());
|
||
14 years ago
|
|
||
|
/**
|
||
|
* Make the search case sensitive or case insensitive.
|
||
|
*
|
||
|
* @see caseSenstive()
|
||
|
*/
|
||
|
void setCaseSensitive(bool cs);
|
||
|
|
||
|
/**
|
||
|
* When a search is active on a list that's organized into a tree view if
|
||
13 years ago
|
* a parent or ancesestor of an item is does not match the search then it
|
||
13 years ago
|
* will be hidden and as such so too will any children that match.
|
||
14 years ago
|
*
|
||
14 years ago
|
* If this is set to true (the default) then the parents of matching items
|
||
14 years ago
|
* will be shown.
|
||
|
*
|
||
|
* @see keepParentsVisible
|
||
|
*/
|
||
|
void setKeepParentsVisible(bool v);
|
||
|
|
||
|
/**
|
||
|
* Sets the list of columns to be searched. The default is to search all,
|
||
|
* visible columns which can be restored by passing \a columns as an empty
|
||
|
* list.
|
||
|
*
|
||
|
* @see searchColumns
|
||
|
*/
|
||
14 years ago
|
void setSearchColumns(const TQValueList<int> &columns);
|
||
14 years ago
|
|
||
|
/**
|
||
12 years ago
|
* Sets the TDEListView that is filtered by this search line. If \a lv is null
|
||
14 years ago
|
* then the widget will be disabled.
|
||
|
*
|
||
|
* @see listView()
|
||
|
*/
|
||
12 years ago
|
void setListView(TDEListView *lv);
|
||
14 years ago
|
|
||
|
protected:
|
||
|
|
||
|
/**
|
||
|
* Returns true if \a item matches the search \a s. This will be evaluated
|
||
|
* based on the value of caseSensitive(). This can be overridden in
|
||
|
* subclasses to implement more complicated matching schemes.
|
||
|
*/
|
||
14 years ago
|
virtual bool itemMatches(const TQListViewItem *item, const TQString &s) const;
|
||
14 years ago
|
|
||
|
/**
|
||
|
* Re-implemented for internal reasons. API not affected.
|
||
|
*
|
||
14 years ago
|
* See TQLineEdit::mousePressEvent().
|
||
14 years ago
|
*/
|
||
14 years ago
|
virtual TQPopupMenu *createPopupMenu();
|
||
14 years ago
|
|
||
|
protected slots:
|
||
|
/**
|
||
|
* When keys are pressed a new search string is created and a timer is
|
||
|
* activated. The most recent search is activated when this timer runs out
|
||
|
* if another key has not yet been pressed.
|
||
|
*
|
||
|
* This method makes @param search the most recent search and starts the
|
||
|
* timer.
|
||
|
*
|
||
|
* Together with activateSearch() this makes it such that searches are not
|
||
|
* started until there is a short break in the users typing.
|
||
|
*
|
||
|
* @see activateSearch()
|
||
|
*/
|
||
14 years ago
|
void queueSearch(const TQString &search);
|
||
14 years ago
|
|
||
|
/**
|
||
|
* When the timer started with queueSearch() expires this slot is called.
|
||
|
* If there has been another timer started then this slot does nothing.
|
||
|
* However if there are no other pending searches this starts the list view
|
||
|
* search.
|
||
|
*
|
||
|
* @see queueSearch()
|
||
|
*/
|
||
|
void activateSearch();
|
||
|
|
||
|
private:
|
||
|
|
||
|
/**
|
||
13 years ago
|
* This is used in case parent items of matching items shouldn't be
|
||
14 years ago
|
* visible. It hides all items that don't match the search string.
|
||
|
*/
|
||
|
void checkItemParentsNotVisible();
|
||
|
|
||
|
/**
|
||
13 years ago
|
* This is used in case parent items of matching items should be visible.
|
||
13 years ago
|
* It makes a recursive call to all children. It returns true if at least
|
||
14 years ago
|
* one item in the subtree with the given root item is visible.
|
||
|
*/
|
||
14 years ago
|
bool checkItemParentsVisible(TQListViewItem *item, TQListViewItem *highestHiddenParent = 0);
|
||
14 years ago
|
|
||
|
private slots:
|
||
14 years ago
|
void itemAdded(TQListViewItem *item) const;
|
||
14 years ago
|
void listViewDeleted();
|
||
|
void searchColumnsMenuActivated(int);
|
||
|
|
||
|
private:
|
||
12 years ago
|
class TDEListViewSearchLinePrivate;
|
||
|
TDEListViewSearchLinePrivate *d;
|
||
14 years ago
|
};
|
||
|
|
||
|
/**
|
||
12 years ago
|
* Creates a widget featuring a TDEListViewSearchLine, a label with the text
|
||
14 years ago
|
* "Search" and a button to clear the search.
|
||
|
*
|
||
|
* @since 3.4
|
||
|
*/
|
||
12 years ago
|
class KMYMONEY_EXPORT TDEListViewSearchLineWidget : public TQHBox
|
||
14 years ago
|
{
|
||
|
Q_OBJECT
|
||
13 years ago
|
|
||
14 years ago
|
|
||
|
public:
|
||
|
/**
|
||
12 years ago
|
* Creates a TDEListViewSearchLineWidget for \a listView with \a parent as the
|
||
13 years ago
|
* parent with and \a name.
|
||
14 years ago
|
*/
|
||
12 years ago
|
TDEListViewSearchLineWidget(TDEListView *listView = 0, TQWidget *parent = 0,
|
||
14 years ago
|
const char *name = 0);
|
||
|
|
||
|
/**
|
||
12 years ago
|
* Destroys the TDEListViewSearchLineWidget
|
||
14 years ago
|
*/
|
||
12 years ago
|
~TDEListViewSearchLineWidget();
|
||
14 years ago
|
|
||
|
/**
|
||
|
* Creates the search line. This can be useful to reimplement in cases where
|
||
12 years ago
|
* a TDEListViewSearchLine subclass is used.
|
||
14 years ago
|
*/
|
||
12 years ago
|
virtual TDEListViewSearchLine *createSearchLine(TDEListView *listView);
|
||
14 years ago
|
|
||
|
/**
|
||
|
* Returns a pointer to the search line.
|
||
|
*/
|
||
12 years ago
|
TDEListViewSearchLine *searchLine() const;
|
||
14 years ago
|
|
||
|
protected slots:
|
||
|
/**
|
||
|
* Creates the widgets inside of the widget. This is called from the
|
||
|
* constructor via a single shot timer so that it it guaranteed to run
|
||
|
* after construction is complete. This makes it suitable for overriding in
|
||
|
* subclasses.
|
||
|
*/
|
||
|
virtual void createWidgets();
|
||
|
|
||
|
private slots:
|
||
|
void positionInToolBar();
|
||
|
|
||
|
private:
|
||
12 years ago
|
class TDEListViewSearchLineWidgetPrivate;
|
||
|
TDEListViewSearchLineWidgetPrivate *d;
|
||
14 years ago
|
};
|
||
|
|
||
|
#endif
|