• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDE3Support

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

KDE's Doxygen guidelines are available online.

KDE3Support

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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