• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kiconviewsearchline.cpp
1 /* This file is part of the KDE libraries
2  Copyright (c) 2010 Timothy Pearson <kb9vqf@pearsoncomputing.net>
3  Copyright (c) 2004 Gustavo Sverzut Barbieri <gsbarbieri@users.sourceforge.net>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
27 #include "kiconviewsearchline.h"
28 
29 #include <tqiconview.h>
30 #include <tdelocale.h>
31 #include <tqtimer.h>
32 #include <kdebug.h>
33 
34 #define DEFAULT_CASESENSITIVE false
35 
36 typedef TQValueList <TQIconViewItem *> QIconViewItemList;
37 
38 class TDEIconViewSearchLine::TDEIconViewSearchLinePrivate
39 {
40 public:
41  TDEIconViewSearchLinePrivate() :
42  iconView( 0 ),
43  caseSensitive( DEFAULT_CASESENSITIVE ),
44  activeSearch( false ),
45  queuedSearches( 0 ) {}
46 
47  TQIconView *iconView;
48  bool caseSensitive;
49  bool activeSearch;
50  TQString search;
51  int queuedSearches;
52 };
53 
54 /******************************************************************************
55  * Public Methods *
56  *****************************************************************************/
57 TDEIconViewSearchLine::TDEIconViewSearchLine( TQWidget *parent,
58  TQIconView *iconView,
59  const char *name ) :
60  KLineEdit( parent, name )
61 {
62  d = NULL;
63  init( iconView );
64 }
65 
66 TDEIconViewSearchLine::TDEIconViewSearchLine( TQWidget *parent, const char *name ) :
67  KLineEdit( parent, name )
68 {
69  d = NULL;
70  init( NULL );
71 }
72 
73 TDEIconViewSearchLine::~TDEIconViewSearchLine()
74 {
75  clear(); // empty hiddenItems, returning items back to iconView
76  delete d;
77 }
78 
79 bool TDEIconViewSearchLine::caseSensitive() const
80 {
81  return d->caseSensitive;
82 }
83 
84 TQIconView *TDEIconViewSearchLine::iconView() const
85 {
86  return d->iconView;
87 }
88 
89 /******************************************************************************
90  * Public Slots *
91  *****************************************************************************/
92 void TDEIconViewSearchLine::updateSearch( const TQString &s )
93 {
94  long original_count;
95  int original_hiddenListChanged;
96 
97  if( ! d->iconView )
98  return; // disabled
99 
100  TQString search = d->search = s.isNull() ? text() : s;
101  TQIconViewItem *currentItem = d->iconView->currentItem();
102 
103  TQIconViewItem *item = NULL;
104 
105  // Remove Non-Matching items, add them them to hidden list
106  TQIconViewItem *i = d->iconView->firstItem();
107  while ( i != NULL ) {
108  item = i;
109  i = i->nextItem(); // Point to next, otherwise will loose it.
110  if ( ! itemMatches( item, search ) ) {
111  hideItem( item );
112 
113  if ( item == currentItem )
114  currentItem = NULL; // It's not in iconView anymore.
115  }
116  else {
117  showItem( item );
118  }
119  }
120 
121  d->iconView->sort();
122  d->iconView->arrangeItemsInGrid(true);
123 
124  if ( currentItem != NULL )
125  d->iconView->ensureItemVisible( currentItem );
126 }
127 
128 void TDEIconViewSearchLine::clear()
129 {
130  // Clear hidden list, give items back to TQIconView, if it still exists
131  TQIconViewItem *item = NULL;
132 
133  TQIconViewItem *i = d->iconView->firstItem();
134  while ( i != NULL ) {
135  item = i;
136  i = i->nextItem(); // Point to next, otherwise will loose it.
137  showItem( item );
138  }
139 
140  d->search = "";
141  d->queuedSearches = 0;
142  KLineEdit::clear();
143 }
144 
145 void TDEIconViewSearchLine::iconDeleted(const TQString &filename) {
146  // Do nothing...
147 }
148 
149 void TDEIconViewSearchLine::setCaseSensitive( bool cs )
150 {
151  d->caseSensitive = cs;
152 }
153 
154 void TDEIconViewSearchLine::setIconView( TQIconView *iv )
155 {
156  if ( d->iconView != NULL )
157  disconnect( d->iconView, TQT_SIGNAL( destroyed() ),
158  this, TQT_SLOT( iconViewDeleted() ) );
159 
160  d->iconView = iv;
161 
162  if ( iv != NULL )
163  {
164  connect( d->iconView, TQT_SIGNAL( destroyed() ),
165  this, TQT_SLOT( iconViewDeleted() ) );
166  setEnabled( true );
167  }
168  else
169  setEnabled( false );
170 }
171 
172 /******************************************************************************
173  * Protected Methods *
174  *****************************************************************************/
175 bool TDEIconViewSearchLine::itemMatches( const TQIconViewItem *item,
176  const TQString &s ) const
177 {
178  if ( s.isEmpty() )
179  return true;
180 
181  if ( item == NULL )
182  return false;
183 
184  TQString itemtext = item->text();
185  return ( itemtext.find( s, 0, caseSensitive() ) >= 0 );
186 }
187 
188 void TDEIconViewSearchLine::init( TQIconView *iconView )
189 {
190  delete d;
191  d = new TDEIconViewSearchLinePrivate;
192 
193  d->iconView = iconView;
194 
195  connect( this, TQT_SIGNAL( textChanged( const TQString & ) ),
196  this, TQT_SLOT( queueSearch( const TQString & ) ) );
197 
198  if ( iconView != NULL )
199  {
200  connect( iconView, TQT_SIGNAL( destroyed() ),
201  this, TQT_SLOT( iconViewDeleted() ) );
202  setEnabled( true );
203  }
204  else
205  setEnabled( false );
206 }
207 
208 void TDEIconViewSearchLine::hideItem( TQIconViewItem *item )
209 {
210  if ( ( item == NULL ) || ( d->iconView == NULL ) )
211  return;
212 
213  item->setVisible(false);
214 }
215 
216 void TDEIconViewSearchLine::showItem( TQIconViewItem *item )
217 {
218  if ( d->iconView == NULL )
219  {
220  kdDebug() << __FILE__ << ":" << __LINE__ <<
221  "showItem() could not be called while there's no iconView set." <<
222  endl;
223  return;
224  }
225 
226  item->setVisible(true);
227 }
228 
229 /******************************************************************************
230  * Protected Slots *
231  *****************************************************************************/
232 void TDEIconViewSearchLine::queueSearch( const TQString &s )
233 {
234  d->queuedSearches++;
235  d->search = s;
236  TQTimer::singleShot( 200, this, TQT_SLOT( activateSearch() ) );
237 }
238 
239 void TDEIconViewSearchLine::activateSearch()
240 {
241  d->queuedSearches--;
242 
243  if ( d->queuedSearches <= 0 )
244  {
245  updateSearch( d->search );
246  d->queuedSearches = 0;
247  }
248  else {
249  TQTimer::singleShot( 200, this, TQT_SLOT( activateSearch() ) );
250  }
251 }
252 
253 /******************************************************************************
254  * Private Slots *
255  *****************************************************************************/
256 void TDEIconViewSearchLine::iconViewDeleted()
257 {
258  d->iconView = NULL;
259  setEnabled( false );
260 }
261 
262 #include "kiconviewsearchline.moc"

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • knewstuff
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.