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

tdeui

  • tdeui
kiconview.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Torben Weis <weis@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
19#include "config.h"
20
21#include <tqtimer.h>
22#include <tqpainter.h>
23#include <tqpixmapcache.h>
24#include <tqcleanuphandler.h>
25
26#include "kiconview.h"
27#include "kwordwrap.h"
28#include <tdeconfig.h>
29#include <kdebug.h>
30#include <tdeglobal.h>
31#include <tdeglobalsettings.h>
32#include <tdeapplication.h>
33#include <kipc.h>
34
35#include <kcursor.h>
36#include <kpixmap.h>
37#include <kpixmapeffect.h>
38
39class TDEIconView::TDEIconViewPrivate
40{
41public:
42 TDEIconViewPrivate() {
43 mode = TDEIconView::Execute;
44 fm = 0L;
45 doAutoSelect = true;
46 textHeight = 0;
47 dragHoldItem = 0L;
48 }
49 TDEIconView::Mode mode;
50 bool doAutoSelect;
51 TQFontMetrics *fm;
52 TQPixmapCache maskCache;
53 int textHeight;
54 TQIconViewItem *dragHoldItem;
55 TQTimer dragHoldTimer;
56 TQTimer doubleClickIgnoreTimer;
57};
58
59TDEIconView::TDEIconView( TQWidget *parent, const char *name, WFlags f )
60 : TQIconView( parent, name, f )
61{
62 d = new TDEIconViewPrivate;
63
64 connect( this, TQ_SIGNAL( onViewport() ),
65 this, TQ_SLOT( slotOnViewport() ) );
66 connect( this, TQ_SIGNAL( onItem( TQIconViewItem * ) ),
67 this, TQ_SLOT( slotOnItem( TQIconViewItem * ) ) );
68 slotSettingsChanged( TDEApplication::SETTINGS_MOUSE );
69 if ( tdeApp ) { // maybe null when used inside designer
70 connect( tdeApp, TQ_SIGNAL( settingsChanged(int) ), TQ_SLOT( slotSettingsChanged(int) ) );
71 tdeApp->addKipcEventMask( KIPC::SettingsChanged );
72 }
73
74 m_pCurrentItem = 0L;
75
76 m_pAutoSelect = new TQTimer( this );
77 connect( m_pAutoSelect, TQ_SIGNAL( timeout() ),
78 this, TQ_SLOT( slotAutoSelect() ) );
79
80 connect( &d->dragHoldTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(slotDragHoldTimeout()) );
81}
82
83TDEIconView::~TDEIconView()
84{
85 delete d->fm;
86 delete d;
87}
88
89
90void TDEIconView::setMode( TDEIconView::Mode mode )
91{
92 d->mode = mode;
93}
94
95TDEIconView::Mode TDEIconView::mode() const
96{
97 return d->mode;
98}
99
100void TDEIconView::slotOnItem( TQIconViewItem *item )
101{
102 if ( item ) {
103 if ( m_bUseSingle ) {
104 if ( m_bChangeCursorOverItem )
105 viewport()->setCursor( KCursor().handCursor() );
106
107 if ( (m_autoSelectDelay > -1) ) {
108 m_pAutoSelect->start( m_autoSelectDelay, true );
109 }
110 }
111 m_pCurrentItem = item;
112 }
113}
114
115void TDEIconView::slotOnViewport()
116{
117 if ( m_bUseSingle && m_bChangeCursorOverItem )
118 viewport()->unsetCursor();
119
120 m_pAutoSelect->stop();
121 m_pCurrentItem = 0L;
122}
123
124void TDEIconView::slotSettingsChanged(int category)
125{
126 if ( category != TDEApplication::SETTINGS_MOUSE )
127 return;
128 m_bUseSingle = TDEGlobalSettings::singleClick();
129 //kdDebug() << "TDEIconView::slotSettingsChanged for mouse, usesingle=" << m_bUseSingle << endl;
130
131 disconnect( this, TQ_SIGNAL( mouseButtonClicked( int, TQIconViewItem *,
132 const TQPoint & ) ),
133 this, TQ_SLOT( slotMouseButtonClicked( int, TQIconViewItem *,
134 const TQPoint & ) ) );
135// disconnect( this, TQ_SIGNAL( doubleClicked( TQIconViewItem *,
136// const TQPoint & ) ),
137// this, TQ_SLOT( slotExecute( TQIconViewItem *,
138// const TQPoint & ) ) );
139
140 if( m_bUseSingle ) {
141 connect( this, TQ_SIGNAL( mouseButtonClicked( int, TQIconViewItem *,
142 const TQPoint & ) ),
143 this, TQ_SLOT( slotMouseButtonClicked( int, TQIconViewItem *,
144 const TQPoint & ) ) );
145 }
146 else {
147// connect( this, TQ_SIGNAL( doubleClicked( TQIconViewItem *,
148// const TQPoint & ) ),
149// this, TQ_SLOT( slotExecute( TQIconViewItem *,
150// const TQPoint & ) ) );
151 }
152
153 m_bChangeCursorOverItem = TDEGlobalSettings::changeCursorOverIcon();
154 m_autoSelectDelay = m_bUseSingle ? TDEGlobalSettings::autoSelectDelay() : -1;
155
156 if( !m_bUseSingle || !m_bChangeCursorOverItem )
157 viewport()->unsetCursor();
158}
159
160void TDEIconView::slotAutoSelect()
161{
162 // check that the item still exists
163 if( index( m_pCurrentItem ) == -1 || !d->doAutoSelect )
164 return;
165
166 //Give this widget the keyboard focus.
167 if( !hasFocus() )
168 setFocus();
169
170 ButtonState keybstate = TDEApplication::keyboardMouseState();
171 TQIconViewItem* previousItem = currentItem();
172 setCurrentItem( m_pCurrentItem );
173
174 if( m_pCurrentItem ) {
175 //Shift pressed?
176 if( (keybstate & ShiftButton) ) {
177 //Temporary implementation of the selection until TQIconView supports it
178 bool block = signalsBlocked();
179 blockSignals( true );
180
181 //No Ctrl? Then clear before!
182 if( !(keybstate & ControlButton) )
183 clearSelection();
184
185 bool select = !m_pCurrentItem->isSelected();
186 bool update = viewport()->isUpdatesEnabled();
187 viewport()->setUpdatesEnabled( false );
188
189 //Calculate the smallest rectangle that contains the current Item
190 //and the one that got the autoselect event
191 TQRect r;
192 TQRect redraw;
193 if ( previousItem )
194 r = TQRect( TQMIN( previousItem->x(), m_pCurrentItem->x() ),
195 TQMIN( previousItem->y(), m_pCurrentItem->y() ),
196 0, 0 );
197 else
198 r = TQRect( 0, 0, 0, 0 );
199 if ( previousItem->x() < m_pCurrentItem->x() )
200 r.setWidth( m_pCurrentItem->x() - previousItem->x() + m_pCurrentItem->width() );
201 else
202 r.setWidth( previousItem->x() - m_pCurrentItem->x() + previousItem->width() );
203 if ( previousItem->y() < m_pCurrentItem->y() )
204 r.setHeight( m_pCurrentItem->y() - previousItem->y() + m_pCurrentItem->height() );
205 else
206 r.setHeight( previousItem->y() - m_pCurrentItem->y() + previousItem->height() );
207 r = r.normalize();
208
209 //Check for each item whether it is within the rectangle.
210 //If yes, select it
211 for( TQIconViewItem* i = firstItem(); i; i = i->nextItem() ) {
212 if( i->intersects( r ) ) {
213 redraw = redraw.unite( i->rect() );
214 setSelected( i, select, true );
215 }
216 }
217
218 blockSignals( block );
219 viewport()->setUpdatesEnabled( update );
220 repaintContents( redraw, false );
221
222 emit selectionChanged();
223
224 if( selectionMode() == TQIconView::Single )
225 emit selectionChanged( m_pCurrentItem );
226
227 //setSelected( m_pCurrentItem, true, (keybstate & ControlButton), (keybstate & ShiftButton) );
228 }
229 else if( (keybstate & ControlButton) )
230 setSelected( m_pCurrentItem, !m_pCurrentItem->isSelected(), true );
231 else
232 setSelected( m_pCurrentItem, true );
233 }
234 else
235 kdDebug() << "TDEIconView: That's not supposed to happen!!!!" << endl;
236}
237
238void TDEIconView::emitExecute( TQIconViewItem *item, const TQPoint &pos )
239{
240 if ( d->mode != Execute )
241 {
242 // kdDebug() << "TDEIconView::emitExecute : not in execute mode !" << endl;
243 return;
244 }
245
246 ButtonState keybstate = TDEApplication::keyboardMouseState();
247
248 m_pAutoSelect->stop();
249
250 //Don't emit executed if in SC mode and Shift or Ctrl are pressed
251 if( !( m_bUseSingle && ((keybstate & ShiftButton) || (keybstate & ControlButton)) ) ) {
252 setSelected( item, false );
253 viewport()->unsetCursor();
254 emit executed( item );
255 emit executed( item, pos );
256 }
257}
258
259void TDEIconView::updateDragHoldItem( TQDropEvent *e )
260{
261 TQIconViewItem *item = findItem( e->pos() );
262
263 if ( d->dragHoldItem != item)
264 {
265 d->dragHoldItem = item;
266 if( item )
267 {
268 d->dragHoldTimer.start( 1000, true );
269 }
270 else
271 {
272 d->dragHoldTimer.stop();
273 }
274 }
275}
276
277void TDEIconView::focusOutEvent( TQFocusEvent *fe )
278{
279 m_pAutoSelect->stop();
280
281 TQIconView::focusOutEvent( fe );
282}
283
284void TDEIconView::leaveEvent( TQEvent *e )
285{
286 m_pAutoSelect->stop();
287
288 TQIconView::leaveEvent( e );
289}
290
291void TDEIconView::contentsMousePressEvent( TQMouseEvent *e )
292{
293 if( (selectionMode() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) {
294 bool block = signalsBlocked();
295 blockSignals( true );
296
297 clearSelection();
298
299 blockSignals( block );
300 }
301
302 TQIconView::contentsMousePressEvent( e );
303 d->doAutoSelect = false;
304}
305
306void TDEIconView::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
307{
308 TQIconView::contentsMouseDoubleClickEvent( e );
309
310 TQIconViewItem* item = findItem( e->pos() );
311
312 if( item ) {
313 if( (e->button() == TQt::LeftButton) && !m_bUseSingle )
314 emitExecute( item, e->globalPos() );
315
316 emit doubleClicked( item, e->globalPos() );
317 }
318 d->doubleClickIgnoreTimer.start(0, true);
319}
320
321void TDEIconView::slotMouseButtonClicked( int btn, TQIconViewItem *item, const TQPoint &pos )
322{
323 //kdDebug() << " TDEIconView::slotMouseButtonClicked() item=" << item << endl;
324 if( d->doubleClickIgnoreTimer.isActive() )
325 return; // Ignore double click
326
327 if( (btn == TQt::LeftButton) && item )
328 emitExecute( item, pos );
329}
330
331void TDEIconView::contentsMouseReleaseEvent( TQMouseEvent *e )
332{
333 d->doAutoSelect = true;
334 TQIconView::contentsMouseReleaseEvent( e );
335}
336
337void TDEIconView::contentsDragEnterEvent( TQDragEnterEvent *e )
338{
339 updateDragHoldItem( e );
340 TQIconView::contentsDragEnterEvent( e );
341}
342
343void TDEIconView::contentsDragLeaveEvent( TQDragLeaveEvent *e )
344{
345 d->dragHoldTimer.stop();
346 d->dragHoldItem = 0L;
347 TQIconView::contentsDragLeaveEvent( e );
348}
349
350
351void TDEIconView::contentsDragMoveEvent( TQDragMoveEvent *e )
352{
353 updateDragHoldItem( e );
354 TQIconView::contentsDragMoveEvent( e );
355}
356
357void TDEIconView::contentsDropEvent( TQDropEvent* e )
358{
359 d->dragHoldTimer.stop();
360 TQIconView::contentsDropEvent( e );
361}
362
363void TDEIconView::slotDragHoldTimeout()
364{
365 TQIconViewItem *tmp = d->dragHoldItem;
366 d->dragHoldItem = 0L;
367
368 emit held( tmp );
369}
370
371void TDEIconView::takeItem( TQIconViewItem * item )
372{
373 if ( item == d->dragHoldItem )
374 {
375 d->dragHoldTimer.stop();
376 d->dragHoldItem = 0L;
377 }
378
379 TQIconView::takeItem( item );
380}
381
382void TDEIconView::cancelPendingHeldSignal()
383{
384 d->dragHoldTimer.stop();
385 d->dragHoldItem = 0L;
386}
387
388void TDEIconView::wheelEvent( TQWheelEvent *e )
389{
390 if (horizontalScrollBar() && (arrangement() == TQIconView::TopToBottom)) {
391 TQWheelEvent ce(e->pos(), e->delta(), e->state(), TQt::Horizontal);
392 TQApplication::sendEvent( horizontalScrollBar(), &ce);
393 if (ce.isAccepted()) {
394 e->accept();
395 return;
396 }
397 }
398 TQIconView::wheelEvent(e);
399}
400
401void TDEIconView::setFont( const TQFont &font )
402{
403 delete d->fm;
404 d->fm = 0L;
405 TQIconView::setFont( font );
406}
407
408TQFontMetrics *TDEIconView::itemFontMetrics() const
409{
410 if (!d->fm) {
411 // TQIconView creates one too, but we can't access it
412 d->fm = new TQFontMetrics( font() );
413 }
414 return d->fm;
415}
416
417TQPixmap TDEIconView::selectedIconPixmap( TQPixmap *pix, const TQColor &col ) const
418{
419 TQPixmap m;
420 if ( d->maskCache.find( TQString::number( pix->serialNumber() ), m ) )
421 return m;
422 m = KPixmapEffect::selectedPixmap( KPixmap(*pix), col );
423 d->maskCache.insert( TQString::number( pix->serialNumber() ), m );
424 return m;
425}
426
427int TDEIconView::iconTextHeight() const
428{
429 return d->textHeight > 0 ? d->textHeight : ( wordWrapIconText() ? 99 : 1 );
430}
431
432void TDEIconView::setIconTextHeight( int n )
433{
434 int oldHeight = iconTextHeight();
435 if ( n > 1 )
436 d->textHeight = n;
437 else
438 d->textHeight = 1;
439
440 // so that Qt still shows the tooltip when even a wrapped text is too long
441 setWordWrapIconText( false );
442
443 // update view if needed
444 if ( iconTextHeight() != oldHeight )
445 setFont( font() ); // hack to recalc items
446}
447
449
450class TDEIconViewItem::TDEIconViewItemPrivate
451{
452 public:
453 TDEIconViewItemPrivate() {
454 m_pixmapSize = TQSize(0,0);
455 }
456
457 public:
458 TQSize m_pixmapSize;
459 int realTextHeight;
460};
461
462void TDEIconViewItem::init()
463{
464 m_wordWrap = 0L;
465 d = 0L;
466 calcRect();
467}
468
469TDEIconViewItem::~TDEIconViewItem()
470{
471 delete m_wordWrap;
472 if (d) {
473 delete d;
474 }
475}
476
477void TDEIconViewItem::calcRect( const TQString& text_ )
478{
479 if ( !d ) {
480 d = new TDEIconViewItemPrivate;
481 }
482 d->realTextHeight = -1;
483
484 bool drawRoundedRect = TDEGlobalSettings::iconUseRoundedRect();
485
486 Q_ASSERT( iconView() );
487 if ( !iconView() )
488 return;
489 delete m_wordWrap;
490 m_wordWrap = 0L;
491#ifndef NDEBUG // be faster for the end-user, such a bug will have been fixed before hand :)
492 if ( !iconView()->inherits("TDEIconView") )
493 {
494 kdWarning() << "TDEIconViewItem used in a " << iconView()->className() << " !!" << endl;
495 return;
496 }
497#endif
498 //kdDebug() << "TDEIconViewItem::calcRect - " << text() << endl;
499 TDEIconView *view = static_cast<TDEIconView *>(iconView());
500 TQRect itemIconRect = pixmapRect();
501 TQRect itemTextRect = textRect();
502 TQRect itemRect = rect();
503
504 int pw = 0;
505 int ph = 0;
506
507#ifndef TQT_NO_PICTURE
508 if ( picture() ) {
509 TQRect br = picture()->boundingRect();
510 pw = br.width() + 2;
511 ph = br.height() + 2;
512 } else
513#endif
514 {
515 // Qt uses unknown_icon if no pixmap. Let's see if we need that - I doubt it
516 if (!pixmap())
517 return;
518 pw = pixmap()->width() + 2;
519 ph = pixmap()->height() + 2;
520 }
521 itemIconRect.setWidth( pw );
522#if 1 // FIXME
523 // There is a bug in Qt which prevents the item from being placed
524 // properly when the pixmapRect is not at the top of the itemRect, so we
525 // have to increase the height of the pixmapRect and leave it at the top
526 // of the itemRect...
527 if ( d && !d->m_pixmapSize.isNull() ) {
528 itemIconRect.setHeight( d->m_pixmapSize.height() + 2 );
529 }
530 else
531#endif
532 itemIconRect.setHeight( ph );
533
534 int tw = 0;
535 if ( d && !d->m_pixmapSize.isNull() ) {
536 tw = view->maxItemWidth() - ( view->itemTextPos() == TQIconView::Bottom ? 0 :
537 d->m_pixmapSize.width() + 2 );
538 }
539 else {
540 tw = view->maxItemWidth() - ( view->itemTextPos() == TQIconView::Bottom ? 0 :
541 itemIconRect.width() );
542 }
543
544 TQFontMetrics *fm = view->itemFontMetrics();
545 TQString t;
546 TQRect r;
547
548 // When is text_ set ? Doesn't look like it's ever set.
549 t = text_.isEmpty() ? text() : text_;
550
551 // Max text height
552 int nbLines = static_cast<TDEIconView*>( iconView() )->iconTextHeight();
553 int height = nbLines > 0 ? fm->height() * nbLines : 0xFFFFFFFF;
554
555 // Should not be higher than pixmap if text is alongside icons
556 if ( view->itemTextPos() != TQIconView::Bottom ) {
557 if ( d && !d->m_pixmapSize.isNull() )
558 height = TQMIN( d->m_pixmapSize.height() + 2, height );
559 else
560 height = TQMIN( itemIconRect.height(), height );
561 height = TQMAX( height, fm->height() );
562 }
563
564 // Calculate the word-wrap
565 TQRect outerRect( 0, 0, tw - 6, height );
566 m_wordWrap = KWordWrap::formatText( *fm, outerRect, 0, t );
567 r = m_wordWrap->boundingRect();
568
569 int realWidth = TQMAX( TQMIN( r.width() + 4, tw ), fm->width( "X" ) );
570 if (drawRoundedRect == true) {
571 itemTextRect.setWidth( realWidth + 2);
572 }
573 else {
574 itemTextRect.setWidth( realWidth );
575 }
576 itemTextRect.setHeight( r.height() );
577
578 int w = 0; int h = 0; int y = 0;
579 if ( view->itemTextPos() == TQIconView::Bottom ) {
580 // If the pixmap size has been specified, use it
581 if ( d && !d->m_pixmapSize.isNull() )
582 {
583 w = TQMAX( itemTextRect.width(), d->m_pixmapSize.width() + 2 );
584 h = itemTextRect.height() + d->m_pixmapSize.height() + 2 + 1;
585#if 0 // FIXME
586 // Waiting for the qt bug to be solved, the pixmapRect must
587 // stay on the top...
588 y = d->m_pixmapSize.height() + 2 - itemIconRect.height();
589#endif
590 }
591 else {
592 w = TQMAX( itemTextRect.width(), itemIconRect.width() );
593 h = itemTextRect.height() + itemIconRect.height() + 1;
594 }
595
596 itemRect.setWidth( w );
597 itemRect.setHeight( h );
598 int width = TQMAX( w, TQApplication::globalStrut().width() ); // see TQIconViewItem::width()
599 int height = TQMAX( h, TQApplication::globalStrut().height() ); // see TQIconViewItem::height()
600 itemTextRect = TQRect( ( width - itemTextRect.width() ) / 2, height - itemTextRect.height(),
601 itemTextRect.width(), itemTextRect.height() );
602 itemIconRect = TQRect( ( width - itemIconRect.width() ) / 2, y,
603 itemIconRect.width(), itemIconRect.height() );
604 }
605 else {
606 // If the pixmap size has been specified, use it
607 if ( d && !d->m_pixmapSize.isNull() ) {
608 h = TQMAX( itemTextRect.height(), d->m_pixmapSize.height() + 2 );
609#if 0 // FIXME
610 // Waiting for the qt bug to be solved, the pixmapRect must
611 // stay on the top...
612 y = ( d->m_pixmapSize.height() + 2 - itemIconRect.height() ) / 2;
613#endif
614 }
615 else {
616 h = TQMAX( itemTextRect.height(), itemIconRect.height() );
617 }
618 w = itemTextRect.width() + itemIconRect.width() + 1;
619
620 itemRect.setWidth( w );
621 itemRect.setHeight( h );
622 int width = TQMAX( w, TQApplication::globalStrut().width() ); // see TQIconViewItem::width()
623 int height = TQMAX( h, TQApplication::globalStrut().height() ); // see TQIconViewItem::height()
624
625 itemTextRect = TQRect( width - itemTextRect.width(), ( height - itemTextRect.height() ) / 2,
626 itemTextRect.width(), itemTextRect.height() );
627 if ( itemIconRect.height() > itemTextRect.height() ) { // icon bigger than text -> center vertically
628 itemIconRect = TQRect( 0, ( height - itemIconRect.height() ) / 2,
629 itemIconRect.width(), itemIconRect.height() );
630 }
631 else { // icon smaller than text -> place in top or center with first line
632 itemIconRect = TQRect( 0, TQMAX(( fm->height() - itemIconRect.height() ) / 2 + y, 0),
633 itemIconRect.width(), itemIconRect.height() );
634 }
635 if ( ( itemIconRect.height() <= 20 ) && ( itemTextRect.height() < itemIconRect.height() ) ) {
636 d->realTextHeight = itemTextRect.height();
637 itemTextRect.setY( itemIconRect.y() );
638 itemTextRect.setHeight( itemIconRect.height() - 2 );
639 }
640 }
641
642 if ( itemIconRect != pixmapRect() ) {
643 setPixmapRect( itemIconRect );
644 }
645 if ( itemTextRect != textRect() ) {
646 setTextRect( itemTextRect );
647 }
648 if ( itemRect != rect() ) {
649 setItemRect( itemRect );
650 }
651
652 // Done by setPixmapRect, setTextRect and setItemRect ! [and useless if no rect changed]
653 //view->updateItemContainer( this );
654
655}
656
657void TDEIconViewItem::paintItem( TQPainter *p, const TQColorGroup &cg )
658{
659 TQIconView* view = iconView();
660 Q_ASSERT( view );
661 if ( !view )
662 return;
663#ifndef NDEBUG // be faster for the end-user, such a bug will have been fixed before hand :)
664 if ( !view->inherits("TDEIconView") )
665 {
666 kdWarning() << "TDEIconViewItem used in a " << view->className() << " !!" << endl;
667 return;
668 }
669#endif
670
671 p->save();
672
673 paintPixmap(p, cg);
674 paintText(p, cg);
675
676 p->restore();
677}
678
679KWordWrap * TDEIconViewItem::wordWrap()
680{
681 return m_wordWrap;
682}
683
684void TDEIconViewItem::paintPixmap( TQPainter *p, const TQColorGroup &cg )
685{
686 TDEIconView *kview = static_cast<TDEIconView *>(iconView());
687
688#ifndef TQT_NO_PICTURE
689 if ( picture() ) {
690 TQPicture *pic = picture();
691 if ( isSelected() ) {
692 // TODO something as nice as selectedIconPixmap if possible ;)
693 p->fillRect( pixmapRect( false ), TQBrush( cg.highlight(), TQBrush::Dense4Pattern) );
694 }
695 p->drawPicture( x()-pic->boundingRect().x(), y()-pic->boundingRect().y(), *pic );
696 } else
697#endif
698 {
699 int iconX = pixmapRect( false ).x();
700 int iconY = pixmapRect( false ).y();
701
702 TQPixmap *pix = pixmap();
703 if ( !pix || pix->isNull() )
704 return;
705
706#if 1 // FIXME
707 // Move the pixmap manually because the pixmapRect is at the
708 // top of the itemRect
709 // (won't be needed anymore in future versions of qt)
710 if ( d && !d->m_pixmapSize.isNull() )
711 {
712 int offset = 0;
713 if ( kview->itemTextPos() == TQIconView::Bottom )
714 offset = d->m_pixmapSize.height() - pix->height();
715 else
716 offset = ( d->m_pixmapSize.height() - pix->height() ) / 2;
717 if ( offset > 0 )
718 iconY += offset;
719 }
720#endif
721 if ( isSelected() ) {
722 TQPixmap selectedPix = kview->selectedIconPixmap( pix, cg.highlight() );
723 p->drawPixmap( iconX, iconY, selectedPix );
724 } else {
725 p->drawPixmap( iconX, iconY, *pix );
726 }
727 }
728}
729
730void TDEIconViewItem::paintText( TQPainter *p, const TQColorGroup &cg )
731{
732 bool drawRoundedRect = TDEGlobalSettings::iconUseRoundedRect();
733 int textX;
734 if (drawRoundedRect == true) {
735 textX = textRect( false ).x() + 4;
736 }
737 else {
738 textX = textRect( false ).x() + 2;
739 }
740 int textY;
741 if ( d && (d->realTextHeight != -1) ) {
742 textY = textRect( false ).y() + ((rect().height() - d->realTextHeight) / 2);
743 }
744 else {
745 textY = textRect( false ).y();
746 }
747
748 if ( isSelected() ) {
749 if (drawRoundedRect == true) {
750 p->setBrush(TQBrush(cg.highlight()));
751 p->setPen(TQPen(cg.highlight()));
752 p->drawRoundRect( textRect( false ) ,1000/textRect(false).width(),1000/textRect(false).height() );
753 }
754 else {
755 p->fillRect( textRect( false ), cg.highlight() );
756 }
757 p->setPen( TQPen( cg.highlightedText() ) );
758 }
759 else {
760 if ( iconView()->itemTextBackground() != TQt::NoBrush ) {
761 p->fillRect( textRect( false ), iconView()->itemTextBackground() );
762 }
763 p->setPen( cg.text() );
764 }
765
766 int align = iconView()->itemTextPos() == TQIconView::Bottom ? AlignHCenter : AlignAuto;
767 m_wordWrap->drawText( p, textX, textY, align | KWordWrap::Truncate );
768}
769
770TQSize TDEIconViewItem::pixmapSize() const
771{
772 return d ? d->m_pixmapSize : TQSize( 0, 0 );
773}
774
775void TDEIconViewItem::setPixmapSize( const TQSize& size )
776{
777 if ( !d ) {
778 d = new TDEIconViewItemPrivate;
779 }
780
781 d->m_pixmapSize = size;
782}
783
784void TDEIconView::virtual_hook( int, void* )
785{ /*BASE::virtual_hook( id, data );*/ }
786
787#include "kiconview.moc"
KCursor
A TQCursor wrapper allowing "themed" cursors and auto-hiding cursors.
Definition: kcursor.h:46
KPixmapEffect::selectedPixmap
static KPixmap selectedPixmap(const KPixmap &pixmap, const TQColor &col)
KPixmap
KWordWrap
Word-wrap algorithm that takes into account beautifulness ;)
Definition: kwordwrap.h:49
KWordWrap::boundingRect
TQRect boundingRect() const
Definition: kwordwrap.h:77
KWordWrap::formatText
static KWordWrap * formatText(TQFontMetrics &fm, const TQRect &r, int flags, const TQString &str, int len=-1)
Main method for wrapping text.
Definition: kwordwrap.cpp:34
KWordWrap::drawText
void drawText(TQPainter *painter, int x, int y, int flags=TQt::AlignAuto) const
Draw the text that has been previously wrapped, at position x,y.
Definition: kwordwrap.cpp:219
TDEApplication::keyboardMouseState
static ButtonState keyboardMouseState()
TDEGlobalSettings::iconUseRoundedRect
static bool iconUseRoundedRect()
TDEGlobalSettings::changeCursorOverIcon
static bool changeCursorOverIcon()
TDEGlobalSettings::autoSelectDelay
static int autoSelectDelay()
TDEGlobalSettings::singleClick
static bool singleClick()
TDEIconViewItem::setPixmapSize
void setPixmapSize(const TQSize &size)
Using this function, you can specify a custom size for the pixmap.
Definition: kiconview.cpp:775
TDEIconViewItem::pixmapSize
TQSize pixmapSize() const
Definition: kiconview.cpp:770
TDEIconView
A variant of TQIconView that honors KDE's system-wide settings.
Definition: kiconview.h:43
TDEIconView::held
void held(TQIconViewItem *item)
This signal is emitted whenever the user hold something on an iconview during a drag'n'drop.
TDEIconView::executed
void executed(TQIconViewItem *item)
This signal is emitted whenever the user executes an iconview item.
TDEIconView::doubleClicked
void doubleClicked(TQIconViewItem *item, const TQPoint &pos)
This signal gets emitted whenever the user double clicks into the iconview.
TDEIconView::setMode
void setMode(Mode m)
Sets the mode to Execute or Select.
Definition: kiconview.cpp:90
TDEIconView::mode
Mode mode() const
Definition: kiconview.cpp:95
TDEIconView::setFont
virtual void setFont(const TQFont &)
Reimplemented for internal purposes.
Definition: kiconview.cpp:401
TDEIconView::cancelPendingHeldSignal
void cancelPendingHeldSignal()
This method allows to handle correctly cases where a subclass needs the held() signal to not be trigg...
Definition: kiconview.cpp:382
TDEIconView::takeItem
virtual void takeItem(TQIconViewItem *item)
Reimplemented for held() signal behavior internal purposes.
Definition: kiconview.cpp:371
TDEIconView::setIconTextHeight
void setIconTextHeight(int n)
Set the maximum number of lines that will be used to display icon text.
Definition: kiconview.cpp:432
TDEIconView::iconTextHeight
int iconTextHeight() const
Definition: kiconview.cpp:427
TDEIconView::Mode
Mode
TDEIconView has two different operating modes.
Definition: kiconview.h:62
TDEIconView::slotAutoSelect
void slotAutoSelect()
Auto selection happend.
Definition: kiconview.cpp:160
kdWarning
kdbgstream kdWarning(int area=0)
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.4
This website is maintained by Timothy Pearson.