• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/libkopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • libkopete
  • ui
kopetelistviewsearchline.cpp
Go to the documentation of this file.
1 /*
2  kopetelistviewsearchline.cpp - a widget for performing quick searches on Kopete::ListViews
3  Based on code from KMail, copyright (c) 2004 Till Adam <adam@kde.org>
4 
5  Copyright (c) 2004 by Richard Smith <kde@metafoo.co.uk>
6 
7  Kopete (c) 2004 by the Kopete developers <kopete-devel@kde.org>
8 
9  *************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  *************************************************************************
17 */
18 
19 #include "kopetelistviewsearchline.h"
20 #include "kopetelistviewitem.h"
21 #include "kopetelistview.h"
22 
23 namespace Kopete {
24 namespace UI {
25 namespace ListView {
26 
27 SearchLine::SearchLine( QWidget *parent, ListView *listView )
28  : K3ListViewSearchLine( parent, listView ), searchEmpty(true)
29 {
30 }
31 
32 SearchLine::~SearchLine()
33 {
34 }
35 
36 
37 void SearchLine::updateSearch( const QString &s )
38 {
39  // we copy a huge chunk of code here simply in order to override
40  // the way items are shown/hidden. KSearchLine rudely
41  // calls setVisible() on items with no way to customize this behaviour.
42 
43  //BEGIN code from KSearchLine::updateSearch
44  if( !listView() )
45  return;
46 
47  search = s.isNull() ? text() : s;
48  searchEmpty = search.isEmpty();
49 
50  // If there's a selected item that is visible, make sure that it's visible
51  // when the search changes too (assuming that it still matches).
52 
53  Q3ListViewItem *currentItem = 0;
54 
55  switch( listView()->selectionMode() )
56  {
57  case K3ListView::NoSelection:
58  break;
59  case K3ListView::Single:
60  currentItem = listView()->selectedItem();
61  break;
62  default:
63  for( Q3ListViewItemIterator it(listView(), Q3ListViewItemIterator::Selected | Q3ListViewItemIterator::Visible);
64  it.current() && !currentItem; ++it )
65  {
66  if( listView()->itemRect( it.current() ).isValid() )
67  currentItem = it.current();
68  }
69  }
70 
71  if( keepParentsVisible() )
72  checkItemParentsVisible( listView()->firstChild() );
73  else
74  checkItemParentsNotVisible();
75 
76  if( currentItem )
77  listView()->ensureItemVisible( currentItem );
78  //END code from KSearchLine::updateSearch
79 }
80 
81 void SearchLine::checkItemParentsNotVisible()
82 {
83  //BEGIN code from KSearchLine::checkItemParentsNotVisible
84  Q3ListViewItemIterator it( listView() );
85  for( ; it.current(); ++it )
86  {
87  Q3ListViewItem *item = it.current();
88  if( itemMatches( item, search ) )
89  setItemVisible( item, true );
90  else
91  setItemVisible( item, false );
92  }
93  //END code from KSearchLine::checkItemParentsNotVisible
94 }
95 
96 bool SearchLine::checkItemParentsVisible( Q3ListViewItem *item )
97 {
98  //BEGIN code from KSearchLine::checkItemParentsVisible
99  bool visible = false;
100  for( ; item; item = item->nextSibling() ) {
101  if( ( item->firstChild() && checkItemParentsVisible( item->firstChild() ) ) ||
102  itemMatches( item, search ) )
103  {
104  setItemVisible( item, true );
105  // OUCH! this operation just became exponential-time.
106  // however, setting an item visible sets all its descendents
107  // visible too, which we definitely don't want.
108  // plus, in Kopete the nesting is never more than 2 deep,
109  // so this really just doubles the runtime, if that.
110  // this still can be done in O(n) time by a mark-set process,
111  // but that's overkill in our case.
112  checkItemParentsVisible( item->firstChild() );
113  visible = true;
114  }
115  else
116  setItemVisible( item, false );
117  }
118  return visible;
119  //END code from KSearchLine::checkItemParentsVisible
120 }
121 
122 void SearchLine::setItemVisible( Q3ListViewItem *it, bool b )
123 {
124  if( Item *item = dynamic_cast<Item*>( it ) )
125  item->setSearchMatch( b, !searchEmpty );
126  else
127  it->setVisible( b );
128 }
129 
130 } // namespace ListView
131 } // namespace UI
132 } // namespace Kopete
133 
134 #include "kopetelistviewsearchline.moc"
Kopete::UI::ListView::SearchLine::SearchLine
SearchLine(QWidget *parent=0, ListView *listView=0)
Constructs a SearchLine with listView being the ListView to be filtered.
Definition: kopetelistviewsearchline.cpp:27
QWidget
Q3ListViewItem::nextSibling
Q3ListViewItem * nextSibling() const
kopetelistview.h
Kopete::UI::ListView::SearchLine::setItemVisible
virtual void setItemVisible(Q3ListViewItem *it, bool visible)
Definition: kopetelistviewsearchline.cpp:122
Kopete::UI::ListView::ListView
Definition: kopetelistview.h:37
Q3ListViewItemIterator
QString::isNull
bool isNull() const
Q3ListViewItemIterator::current
Q3ListViewItem * current() const
Kopete::UI::ListView::SearchLine::~SearchLine
~SearchLine()
Destroys the SearchLine.
Definition: kopetelistviewsearchline.cpp:32
Q3ListViewItem
kopetelistviewsearchline.h
QString::isEmpty
bool isEmpty() const
Kopete::UI::ListView::SearchLine::checkItemParentsVisible
virtual bool checkItemParentsVisible(Q3ListViewItem *it)
Definition: kopetelistviewsearchline.cpp:96
QString
K3ListViewSearchLine
Q3ListViewItem::setVisible
void setVisible(bool b)
Kopete::UI::ListView::SearchLine::checkItemParentsNotVisible
virtual void checkItemParentsNotVisible()
Definition: kopetelistviewsearchline.cpp:81
kopetelistviewitem.h
Kopete::UI::ListView::Item
List-view item composed of Component items.
Definition: kopetelistviewitem.h:396
Kopete::UI::ListView::SearchLine::updateSearch
void updateSearch(const QString &s)
Definition: kopetelistviewsearchline.cpp:37
Q3ListViewItem::firstChild
Q3ListViewItem * firstChild() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal