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

tdeui

  • tdeui
tdelistbox.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 #include "config.h"
19 
20 #include <tqtimer.h>
21 
22 #include <tdeglobalsettings.h>
23 #include <kcursor.h>
24 #include <tdeapplication.h>
25 #include <kipc.h>
26 #include <kdebug.h>
27 
28 #include "tdelistbox.h"
29 
30 TDEListBox::TDEListBox( TQWidget *parent, const char *name, WFlags f )
31  : TQListBox( parent, name, f ), d(0)
32 {
33  connect( this, TQ_SIGNAL( onViewport() ),
34  this, TQ_SLOT( slotOnViewport() ) );
35  connect( this, TQ_SIGNAL( onItem( TQListBoxItem * ) ),
36  this, TQ_SLOT( slotOnItem( TQListBoxItem * ) ) );
37  slotSettingsChanged(TDEApplication::SETTINGS_MOUSE);
38  if (kapp)
39  {
40  connect( kapp, TQ_SIGNAL( settingsChanged(int) ), TQ_SLOT( slotSettingsChanged(int) ) );
41  kapp->addKipcEventMask( KIPC::SettingsChanged );
42  }
43 
44  m_pCurrentItem = 0L;
45 
46  m_pAutoSelect = new TQTimer( this );
47  connect( m_pAutoSelect, TQ_SIGNAL( timeout() ),
48  this, TQ_SLOT( slotAutoSelect() ) );
49 }
50 
51 void TDEListBox::slotOnItem( TQListBoxItem *item )
52 {
53  if ( item && m_bChangeCursorOverItem && m_bUseSingle )
54  viewport()->setCursor( KCursor().handCursor() );
55 
56  if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) {
57  m_pAutoSelect->start( m_autoSelectDelay, true );
58  m_pCurrentItem = item;
59  }
60 }
61 
62 void TDEListBox::slotOnViewport()
63 {
64  if ( m_bChangeCursorOverItem )
65  viewport()->unsetCursor();
66 
67  m_pAutoSelect->stop();
68  m_pCurrentItem = 0L;
69 }
70 
71 
72 void TDEListBox::slotSettingsChanged(int category)
73 {
74  if (category != TDEApplication::SETTINGS_MOUSE)
75  return;
76  m_bUseSingle = TDEGlobalSettings::singleClick();
77 
78  disconnect( this, TQ_SIGNAL( mouseButtonClicked( int, TQListBoxItem *,
79  const TQPoint & ) ),
80  this, TQ_SLOT( slotMouseButtonClicked( int, TQListBoxItem *,
81  const TQPoint & ) ) );
82 // disconnect( this, TQ_SIGNAL( doubleClicked( TQListBoxItem *,
83 // const TQPoint & ) ),
84 // this, TQ_SLOT( slotExecute( TQListBoxItem *,
85 // const TQPoint & ) ) );
86 
87  if( m_bUseSingle )
88  {
89  connect( this, TQ_SIGNAL( mouseButtonClicked( int, TQListBoxItem *,
90  const TQPoint & ) ),
91  this, TQ_SLOT( slotMouseButtonClicked( int, TQListBoxItem *,
92  const TQPoint & ) ) );
93  }
94  else
95  {
96 // connect( this, TQ_SIGNAL( doubleClicked( TQListBoxItem *,
97 // const TQPoint & ) ),
98 // this, TQ_SLOT( slotExecute( TQListBoxItem *,
99 // const TQPoint & ) ) );
100  }
101 
102  m_bChangeCursorOverItem = TDEGlobalSettings::changeCursorOverIcon();
103  m_autoSelectDelay = TDEGlobalSettings::autoSelectDelay();
104 
105  if( !m_bUseSingle || !m_bChangeCursorOverItem )
106  viewport()->unsetCursor();
107 }
108 
109 void TDEListBox::slotAutoSelect()
110 {
111  // check that the item still exists
112  if( index( m_pCurrentItem ) == -1 )
113  return;
114 
115  //Give this widget the keyboard focus.
116  if( !hasFocus() )
117  setFocus();
118 
119  ButtonState keybstate = TDEApplication::keyboardMouseState();
120 
121  TQListBoxItem* previousItem = item( currentItem() );
122  setCurrentItem( m_pCurrentItem );
123 
124  if( m_pCurrentItem ) {
125  //Shift pressed?
126  if( (keybstate & ShiftButton) ) {
127  bool block = signalsBlocked();
128  blockSignals( true );
129 
130  //No Ctrl? Then clear before!
131  if( !(keybstate & ControlButton) )
132  clearSelection();
133 
134  bool select = !m_pCurrentItem->isSelected();
135  bool update = viewport()->isUpdatesEnabled();
136  viewport()->setUpdatesEnabled( false );
137 
138  bool down = index( previousItem ) < index( m_pCurrentItem );
139  TQListBoxItem* it = down ? previousItem : m_pCurrentItem;
140  for (;it ; it = it->next() ) {
141  if ( down && it == m_pCurrentItem ) {
142  setSelected( m_pCurrentItem, select );
143  break;
144  }
145  if ( !down && it == previousItem ) {
146  setSelected( previousItem, select );
147  break;
148  }
149  setSelected( it, select );
150  }
151 
152  blockSignals( block );
153  viewport()->setUpdatesEnabled( update );
154  triggerUpdate( false );
155 
156  emit selectionChanged();
157 
158  if( selectionMode() == TQListBox::Single )
159  emit selectionChanged( m_pCurrentItem );
160  }
161  else if( (keybstate & ControlButton) )
162  setSelected( m_pCurrentItem, !m_pCurrentItem->isSelected() );
163  else {
164  bool block = signalsBlocked();
165  blockSignals( true );
166 
167  if( !m_pCurrentItem->isSelected() )
168  clearSelection();
169 
170  blockSignals( block );
171 
172  setSelected( m_pCurrentItem, true );
173  }
174  }
175  else
176  kdDebug() << "Thatīs not supposed to happen!!!!" << endl;
177 }
178 
179 void TDEListBox::emitExecute( TQListBoxItem *item, const TQPoint &pos )
180 {
181  ButtonState keybstate = TDEApplication::keyboardMouseState();
182 
183  m_pAutoSelect->stop();
184 
185  //Donīt emit executed if in SC mode and Shift or Ctrl are pressed
186  if( !( m_bUseSingle && ((keybstate & ShiftButton) || (keybstate & ControlButton)) ) ) {
187  emit executed( item );
188  emit executed( item, pos );
189  }
190 }
191 
192 //
193 // 2000-16-01 Espen Sand
194 // This widget is used in dialogs. It should ignore
195 // F1 (and combinations) and Escape since these are used
196 // to start help or close the dialog. This functionality
197 // should be done in TQListView but it is not (at least now)
198 //
199 void TDEListBox::keyPressEvent(TQKeyEvent *e)
200 {
201  if( e->key() == Key_Escape )
202  {
203  e->ignore();
204  }
205  else if( e->key() == Key_F1 )
206  {
207  e->ignore();
208  }
209  else
210  {
211  TQListBox::keyPressEvent(e);
212  }
213 }
214 
215 void TDEListBox::focusOutEvent( TQFocusEvent *fe )
216 {
217  m_pAutoSelect->stop();
218 
219  TQListBox::focusOutEvent( fe );
220 }
221 
222 void TDEListBox::leaveEvent( TQEvent *e )
223 {
224  m_pAutoSelect->stop();
225 
226  TQListBox::leaveEvent( e );
227 }
228 
229 void TDEListBox::contentsMousePressEvent( TQMouseEvent *e )
230 {
231  if( (selectionMode() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) {
232  bool block = signalsBlocked();
233  blockSignals( true );
234 
235  clearSelection();
236 
237  blockSignals( block );
238  }
239 
240  TQListBox::contentsMousePressEvent( e );
241 }
242 
243 void TDEListBox::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
244 {
245  TQListBox::contentsMouseDoubleClickEvent( e );
246 
247  TQListBoxItem* item = itemAt( contentsToViewport( e->pos() ) );
248 
249  if( item ) {
250  emit doubleClicked( item, e->globalPos() );
251 
252  if( (e->button() == TQt::LeftButton) && !m_bUseSingle )
253  emitExecute( item, e->globalPos() );
254  }
255 }
256 
257 void TDEListBox::slotMouseButtonClicked( int btn, TQListBoxItem *item, const TQPoint &pos )
258 {
259  if( (btn == TQt::LeftButton) && item )
260  emitExecute( item, pos );
261 }
262 
263 void TDEListBox::virtual_hook( int, void* )
264 { /*BASE::virtual_hook( id, data );*/ }
265 
266 #include "tdelistbox.moc"
KCursor
A TQCursor wrapper allowing "themed" cursors and auto-hiding cursors.
Definition: kcursor.h:46
TDEApplication::keyboardMouseState
static ButtonState keyboardMouseState()
TDEGlobalSettings::changeCursorOverIcon
static bool changeCursorOverIcon()
TDEGlobalSettings::autoSelectDelay
static int autoSelectDelay()
TDEGlobalSettings::singleClick
static bool singleClick()
TDEListBox::slotAutoSelect
void slotAutoSelect()
Auto selection happend.
Definition: tdelistbox.cpp:109
TDEListBox::executed
void executed(TQListBoxItem *item)
Emitted whenever the user executes an listbox item.
TDEListBox::doubleClicked
void doubleClicked(TQListBoxItem *item, const TQPoint &pos)
This signal gets emitted whenever the user double clicks into the listbox.
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
TDEStdAccel::name
TQString name(StdAccel id)

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
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.1
This website is maintained by Timothy Pearson.