28 #include <tqdatetime.h>
30 #include <tqpainter.h>
33 #include <tqtooltip.h>
36 #include <tdeglobalsettings.h>
40 #define MIN_ITEM_WIDTH 80
42 class CardViewTip :
public TQLabel
45 CardViewTip( TQWidget *parent = 0,
const char *name = 0 )
46 : TQLabel( parent, name )
48 setPalette( TQToolTip::palette() );
49 setFrameStyle( Panel | Plain );
57 void leaveEvent( TQEvent* )
67 class CardViewItemList :
public TQPtrList<CardViewItem>
70 virtual int compareItems( TQPtrCollection::Item item1,
71 TQPtrCollection::Item item2 )
76 if ( cItem1 == cItem2 )
79 if ( (cItem1 == 0) || (cItem2 == 0) )
80 return cItem1 ? -1 : 1;
91 class CardViewSeparator
102 ~CardViewSeparator() {}
104 void paintSeparator( TQPainter *p, TQColorGroup &cg )
106 p->fillRect( 0, 0, mRect.width(), mRect.height(),
107 cg.brush(TQColorGroup::Button) );
110 void repaintSeparator()
112 mView->repaintContents( mRect );
120 class CardViewPrivate
124 : mSelectionMode(
CardView::Multi ),
125 mDrawCardBorder( true ),
126 mDrawFieldLabels( true ),
127 mDrawSeparators( true),
129 mShowEmptyFields( false ),
130 mLayoutDirty( true ),
131 mLastClickOnItem( false ),
135 mMaxFieldLines( INT_MAX ),
137 mLastClickPos( TQPoint(0, 0) ),
138 mRubberBandAnchor( 0 ),
139 mCompText( TQString() )
142 CardViewItemList mItemList;
143 TQPtrList<CardViewSeparator> mSeparatorList;
147 CardView::SelectionMode mSelectionMode;
148 bool mDrawCardBorder;
149 bool mDrawFieldLabels;
150 bool mDrawSeparators;
152 bool mShowEmptyFields;
154 bool mLastClickOnItem;
160 TQPoint mLastClickPos;
166 int mRubberBandAnchor;
177 TQDateTime mCompUpdated;
180 class CardViewItemPrivate
183 CardViewItemPrivate() {}
186 TQPtrList< CardViewItem::Field > mFieldList;
196 : d( new CardViewItemPrivate() ), mView( parent )
203 CardViewItem::~CardViewItem()
213 void CardViewItem::initialize()
215 d->mSelected =
false;
216 d->mFieldList.setAutoDelete(
true );
217 d->maxLabelWidth = 0;
232 TQFontMetrics fm = *(mView->d->mFm);
233 TQFontMetrics bFm = *(mView->d->mBFm);
234 bool drawLabels = mView->d->mDrawFieldLabels;
235 bool drawBorder = mView->d->mDrawCardBorder;
238 int h =
height() - ( mg * 2 );
239 const int colonWidth( fm.width(
":" ) );
240 int labelXPos = 2 + mg;
241 int labelWidth = TQMIN( w / 2 - 4 - mg, d->maxLabelWidth + colonWidth + 4 );
242 int valueXPos = labelWidth + 4 + mg;
243 int valueWidth = w - labelWidth - 4 - mg;
245 p->setFont( mView->font() );
246 labelWidth -= colonWidth;
249 valueXPos = labelXPos;
255 pen = TQPen( cg.highlight(), 1 );
257 pen = TQPen( cg.button(), 1 );
262 p->drawRect( mg, mg, w, h );
266 brush = cg.brush( TQColorGroup::Highlight );
268 brush = cg.brush( TQColorGroup::Button );
270 p->fillRect( mg, mg, w, 4 + bFm.height(), brush );
277 p->setPen( cg.highlightedText() );
279 p->setPen( cg.buttonText() );
281 p->drawText( 2 + mg, 2 + mg + bFm.ascent(), trimString( d->mCaption, w - 4, bFm ) );
285 TQPtrListIterator<CardViewItem::Field> iter( d->mFieldList );
286 TQString label, value;
287 int yPos = mg + 4 + bFm.height() + fm.height();
288 p->setPen( cg.text() );
290 int fh = fm.height();
294 for ( iter.toFirst(); iter.current(); ++iter ) {
295 value = (*iter)->second;
296 if ( value.isEmpty() && ! mView->d->mShowEmptyFields )
300 label = trimString( (*iter)->first, labelWidth, fm );
301 p->drawText( labelXPos, yPos, label +
":" );
304 for ( cln = 0; cln <= maxLines; cln++ ) {
305 tmp = value.section(
'\n', cln, cln );
306 if ( !tmp.isEmpty() )
307 p->drawText( valueXPos, yPos + cln * fh, trimString( tmp, valueWidth, fm ) );
314 yPos += cln * fh + 2;
318 if ( mView->
currentItem() ==
this && mView->hasFocus() ) {
319 mView->style().drawPrimitive( TQStyle::PE_FocusRect, p,
320 TQRect( 0, 0, mView->
itemWidth(), h + (2 * mg) ), cg,
321 TQStyle::Style_FocusAtBorder,
322 TQStyleOption(
isSelected() ? cg.highlight() : cg.base() ) );
335 if ( allowCache && d->hcache )
344 int baseHeight = 8 + ( 2 * mView->
itemMargin() );
350 int fh = mView->d->mFm->height();
354 TQPtrListIterator<CardViewItem::Field> iter( d->mFieldList );
355 for ( iter.toFirst(); iter.current(); ++iter ) {
356 if ( !sef && (*iter)->second.isEmpty() )
358 lines = TQMIN( (*iter)->second.contains(
'\n' ) + 1, maxLines );
359 fieldHeight += ( lines * fh ) + 2;
363 fieldHeight += mView->d->mBFm->height();
364 d->hcache = baseHeight + fieldHeight;
375 d->mSelected = selected;
381 d->mFieldList.append( f );
386 d->maxLabelWidth = TQMAX( mView->d->mFm->width( label ), d->maxLabelWidth );
394 TQPtrListIterator<CardViewItem::Field> iter( d->mFieldList );
395 for ( iter.toFirst(); iter.current(); ++iter ) {
397 if ( f->first == label )
402 d->mFieldList.remove( *iter );
411 d->mFieldList.clear();
418 TQString CardViewItem::trimString(
const TQString &text,
int width,
419 TQFontMetrics &fm )
const
421 if ( fm.width( text ) <= width )
424 TQString dots =
"...";
425 int dotWidth = fm.width( dots );
429 while ( fm.width( trimmed ) + dotWidth < width ) {
430 trimmed += text[ charNum ];
435 trimmed = trimmed.left( trimmed.length() - 1 );
465 TQPtrListIterator<CardViewItem::Field> iter( d->mFieldList );
466 for ( iter.toFirst(); iter.current(); ++iter )
467 if ( (*iter)->first == label )
468 return (*iter)->second;
476 bool trimmed(
false );
479 int y = mView->d->mBFm->height() + 6 + mrg;
483 bool isLabel = drawLabels && itempos.x() < w / 2 ? true :
false;
485 if ( itempos.y() < y ) {
486 if ( itempos.y() < 8 + mrg || itempos.y() > y - 4 )
490 trimmed = mView->d->mBFm->width( s ) > w - 4;
505 int fh = mView->d->mFm->height();
508 for ( _f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next() )
509 if ( se || ! _f->second.isEmpty() )
510 y += ( TQMIN( _f->second.contains(
'\n' ) + 1, maxLines ) * fh ) + 2;
512 if ( isLabel && itempos.y() > y + fh )
515 s = isLabel ? f->first : f->second;
517 int colonWidth = mView->d->mFm->width(
":");
518 lw = drawLabels ? TQMIN( w / 2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) : 0;
519 int mw = isLabel ? lw - colonWidth : w - lw - ( mrg * 2 );
521 trimmed = mView->d->mFm->width( s ) > mw - colonWidth;
523 TQRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, TQt::AlignTop|TQt::AlignLeft, s ) );
524 trimmed = r.width() > mw || r.height() / fh > TQMIN( s.contains(
'\n' ) + 1, maxLines );
529 tip->setFont( (isLabel && !lw) ? mView->
headerFont() : mView->font() );
534 lx = isLabel || !drawLabels ? mrg : lw + mrg + 2;
535 TQPoint pnt( mView->contentsToViewport( TQPoint( d->x, d->y ) ) );
536 pnt += TQPoint( lx, y );
539 if ( pnt.x() + tip->width() > mView->visibleWidth() )
540 pnt.setX( mView->visibleWidth() - tip->width() );
541 if ( pnt.y() + tip->height() > mView->visibleHeight() )
542 pnt.setY( TQMAX( 0, mView->visibleHeight() - tip->height() ) );
551 int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin;
552 int iy = itempos.y();
558 int fh = mView->d->mFm->height();
561 for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) {
562 if ( showEmpty || !f->second.isEmpty() )
563 ypos += (TQMIN( f->second.contains(
'\n' )+1, maxLines ) * fh) + 2;
573 : TQScrollView( parent, name ),
574 d( new CardViewPrivate() )
576 d->mItemList.setAutoDelete(
true );
577 d->mSeparatorList.setAutoDelete(
true );
580 d->mFm =
new TQFontMetrics( f );
583 d->mBFm =
new TQFontMetrics( f );
584 d->mTip =
new CardViewTip( viewport() );
586 d->mTimer =
new TQTimer(
this,
"mouseTimer" );
588 viewport()->setMouseTracking(
true );
589 viewport()->setFocusProxy(
this );
590 viewport()->setFocusPolicy(TQWidget::WheelFocus );
591 viewport()->setBackgroundMode( PaletteBase );
593 connect( d->mTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( tryShowFullText() ) );
595 setBackgroundMode( PaletteBackground, PaletteBase );
598 setVScrollBarMode( AlwaysOff );
601 CardView::~CardView()
611 d->mItemList.inSort( item );
617 if ( d->mCurrentItem == item )
619 d->mItemList.take( d->mItemList.findRef( item ) );
626 d->mItemList.clear();
633 if ( !d->mCurrentItem && d->mItemList.count() )
634 d->mCurrentItem = d->mItemList.first();
636 return d->mCurrentItem;
643 else if ( item->cardView() !=
this ) {
644 kdDebug(5720)<<
"CardView::setCurrentItem: Item ("<<item<<
") not owned! Backing out.."<<endl;
650 if ( d->mSelectionMode == Single ) {
654 d->mCurrentItem = item;
661 if ( ! d->mOnSeparator )
670 TQPtrListIterator<CardViewItem> iter( d->mItemList );
672 for ( iter.toFirst(); iter.current() && !found; ++iter ) {
674 if ( TQRect( item->d->x, item->d->y, d->mItemWidth, item->
height() ).contains( viewPos ) )
686 return TQRect( item->d->x, item->d->y, d->mItemWidth, item->
height() );
691 ensureVisible( item->d->x, item->d->y, d->mItemSpacing, 0 );
692 ensureVisible( item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0 );
697 repaintContents( TQRect( item->d->x, item->d->y, d->mItemWidth, item->
height() ) );
704 d->mSelectionMode = mode;
709 return d->mSelectionMode;
714 TQPtrListIterator<CardViewItem> iter( d->mItemList );
716 for ( iter.toFirst(); iter.current(); ++iter ) {
717 if ( (*iter)->isSelected() ) {
718 (*iter)->setSelected(
false );
719 (*iter)->repaintCard();
724 }
else if ( d->mSelectionMode != CardView::Single ) {
725 for ( iter.toFirst(); iter.current(); ++iter ) {
726 (*iter)->setSelected(
true );
729 if ( d->mItemList.count() > 0 ) {
732 viewport()->update();
739 if ( (item == 0) || (item->
isSelected() == selected) )
742 if ( selected && d->mCurrentItem != item ) {
744 d->mCurrentItem = item;
749 if ( d->mSelectionMode == CardView::Single ) {
750 bool b = signalsBlocked();
751 blockSignals(
true );
764 }
else if ( d->mSelectionMode == CardView::Multi ) {
768 }
else if ( d->mSelectionMode == CardView::Extended ) {
769 bool b = signalsBlocked();
770 blockSignals(
true );
788 TQPtrListIterator<CardViewItem> iter( d->mItemList );
789 for ( iter.toFirst(); iter.current(); ++iter ) {
790 if ( (*iter)->isSelected() )
799 return d->mItemList.first();
804 return d->mItemList.count();
808 TQt::StringComparisonMode compare )
const
812 if ( text.isEmpty() )
815 TQPtrListIterator<CardViewItem> iter( d->mItemList );
816 if ( compare & TQt::BeginsWith ) {
818 for ( iter.toFirst(); iter.current(); ++iter ) {
819 value = (*iter)->fieldValue( label ).upper();
820 if ( value.startsWith( text.upper() ) )
824 kdDebug(5720) <<
"CardView::findItem: search method not implemented" << endl;
832 return d->mDrawSeparators ?
833 d->mItemWidth + ( 2 * d->mItemSpacing ) + d->mSepWidth :
834 d->mItemWidth + d->mItemSpacing;
838 int clipw,
int cliph )
840 TQScrollView::drawContents( p, clipx, clipy, clipw, cliph );
842 if ( d->mLayoutDirty )
846 TQColorGroup cg = viewport()->palette().active();
848 TQRect clipRect( clipx, clipy, clipw, cliph );
852 CardViewSeparator *sep;
855 viewport()->erase( clipRect );
858 TQPtrListIterator<CardViewItem> iter( d->mItemList );
859 for ( iter.toFirst(); iter.current(); ++iter) {
861 cardRect.setRect( item->d->x, item->d->y, d->mItemWidth, item->
height() );
863 if ( clipRect.intersects( cardRect ) || clipRect.contains( cardRect ) ) {
866 p->translate( cardRect.x(), cardRect.y() );
873 TQPtrListIterator<CardViewSeparator> sepIter( d->mSeparatorList );
874 for ( sepIter.toFirst(); sepIter.current(); ++sepIter ) {
876 sepRect = sep->mRect;
878 if ( clipRect.intersects( sepRect ) || clipRect.contains( sepRect ) ) {
880 p->translate( sepRect.x(), sepRect.y() );
881 sep->paintSeparator( p, cg );
889 TQScrollView::resizeEvent( event );
902 int cardSpacing = d->mItemSpacing;
905 d->mSeparatorList.clear();
907 TQPtrListIterator<CardViewItem> iter( d->mItemList );
909 CardViewSeparator *sep = 0;
912 for ( iter.toFirst(); iter.current(); ++iter ) {
917 if ( yPos + item->
height() + cardSpacing >= height() - horizontalScrollBar()->height() ) {
918 maxHeight = TQMAX( maxHeight, yPos );
923 xPos += cardSpacing + maxWidth;
924 if ( d->mDrawSeparators ) {
926 sep =
new CardViewSeparator(
this );
927 sep->mRect.moveTopLeft( TQPoint( xPos, yPos + d->mItemMargin ) );
928 xPos += d->mSepWidth + cardSpacing;
929 d->mSeparatorList.append( sep );
939 maxWidth = TQMAX( maxWidth, d->mItemWidth );
943 resizeContents( xPos + cardSpacing, maxHeight );
947 TQPtrListIterator<CardViewSeparator> sepIter( d->mSeparatorList );
948 for ( sepIter.toFirst(); sepIter.current(); ++sepIter )
949 (*sepIter)->mRect.setHeight( maxHeight - 2 * cardSpacing - 2 * d->mItemMargin );
951 d->mLayoutDirty =
false;
956 d->mItemList.findRef( item );
957 return d->mItemList.next();
962 return d->mItemMargin;
967 if ( margin == d->mItemMargin )
970 d->mItemMargin = margin;
976 return d->mItemSpacing;
981 if ( spacing == d->mItemSpacing )
984 d->mItemSpacing = spacing;
988 void CardView::contentsMousePressEvent( TQMouseEvent *e )
990 TQScrollView::contentsMousePressEvent( e );
992 TQPoint pos = contentsToViewport( e->pos() );
993 d->mLastClickPos = e->pos();
998 d->mLastClickOnItem =
false;
999 if ( d->mOnSeparator) {
1000 d->mResizeAnchor = e->x() + contentsX();
1001 d->mColspace = (2 * d->mItemSpacing);
1002 int ccw = d->mItemWidth + d->mColspace + d->mSepWidth;
1003 d->mFirst = (contentsX() + d->mSepWidth) / ccw;
1004 d->mPressed = (d->mResizeAnchor + d->mSepWidth) / ccw;
1005 d->mSpan = d->mPressed - d->mFirst;
1006 d->mFirstX = d->mFirst * ccw;
1008 d->mFirstX -= d->mSepWidth;
1016 d->mLastClickOnItem =
true;
1025 if ( e->button() & TQt::RightButton ) {
1027 bool blocked = signalsBlocked();
1028 blockSignals(
true );
1030 blockSignals( blocked );
1040 if ( d->mSelectionMode == CardView::Single ) {
1045 bool b = signalsBlocked();
1046 blockSignals(
true );
1053 }
else if ( d->mSelectionMode == CardView::Multi ) {
1058 }
else if ( d->mSelectionMode == CardView::Extended ) {
1059 if ( (e->button() & TQt::LeftButton) && (e->state() & TQt::ShiftButton) ) {
1060 if ( item == other )
1065 if ( s && !(e->state() & ControlButton) ) {
1066 bool b = signalsBlocked();
1067 blockSignals(
true );
1073 a = d->mItemList.findRef( item );
1074 b = d->mItemList.findRef( other );
1075 from = a < b ? a : b;
1079 for ( ; from <= to; from++ ) {
1080 aItem = d->mItemList.at( from );
1086 }
else if ( (e->button() & TQt::LeftButton) && (e->state() & TQt::ControlButton) ) {
1090 }
else if ( e->button() & TQt::LeftButton ) {
1091 bool b = signalsBlocked();
1092 blockSignals(
true );
1103 void CardView::contentsMouseReleaseEvent( TQMouseEvent *e )
1105 TQScrollView::contentsMouseReleaseEvent( e );
1107 if ( d->mResizeAnchor && d->mSpan ) {
1110 int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor) / d->mSpan);
1111 drawRubberBands( 0 );
1113 if ( contentsX() ) {
1114 int newX = TQMAX( 0, ( d->mPressed * ( newiw + d->mColspace + d->mSepWidth ) ) - e->x() );
1115 setContentsPos( newX, contentsY() );
1120 d->mResizeAnchor = 0;
1121 d->mRubberBandAnchor = 0;
1126 if ( (e->state() & TQt::ShiftButton) || (e->state() & TQt::ControlButton) )
1132 if ( item && TDEGlobalSettings::singleClick() )
1136 void CardView::contentsMouseDoubleClickEvent( TQMouseEvent *e )
1138 TQScrollView::contentsMouseDoubleClickEvent( e );
1143 d->mCurrentItem = item;
1145 if ( item && !TDEGlobalSettings::singleClick() )
1151 void CardView::contentsMouseMoveEvent( TQMouseEvent *e )
1154 if ( d->mResizeAnchor ) {
1156 if ( x != d->mRubberBandAnchor )
1157 drawRubberBands( x );
1161 if ( d->mLastClickOnItem && (e->state() & TQt::LeftButton) &&
1162 ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) {
1168 d->mTimer->start( 500 );
1172 if ( d->mDrawSeparators ) {
1173 int colcontentw = d->mItemWidth + (2 * d->mItemSpacing);
1174 int colw = colcontentw + d->mSepWidth;
1175 int m = e->x() % colw;
1176 if ( m >= colcontentw && m > 0 ) {
1177 setCursor( SplitHCursor );
1178 d->mOnSeparator =
true;
1180 setCursor( ArrowCursor );
1181 d->mOnSeparator =
false;
1186 void CardView::enterEvent( TQEvent* )
1188 d->mTimer->start( 500 );
1191 void CardView::leaveEvent( TQEvent* )
1194 if ( d->mOnSeparator ) {
1195 d->mOnSeparator =
false;
1196 setCursor( ArrowCursor );
1200 void CardView::focusInEvent( TQFocusEvent* )
1202 if ( !d->mCurrentItem && d->mItemList.count() )
1204 else if ( d->mCurrentItem )
1205 d->mCurrentItem->repaintCard();
1208 void CardView::focusOutEvent( TQFocusEvent* )
1210 if ( d->mCurrentItem )
1211 d->mCurrentItem->repaintCard();
1214 void CardView::keyPressEvent( TQKeyEvent *e )
1221 uint pos = d->mItemList.findRef( d->mCurrentItem );
1225 switch ( e->key() ) {
1228 aItem = d->mItemList.at( pos - 1 );
1233 if ( pos < d->mItemList.count() - 1 ) {
1234 aItem = d->mItemList.at( pos + 1 );
1243 TQPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y );
1244 aPoint -= TQPoint( 30, -(d->mCurrentItem->height() / 2) );
1245 aItem =
itemAt( aPoint );
1247 while ( !aItem && aPoint.y() > 27 ) {
1248 aPoint -= TQPoint( 0, 16 );
1249 aItem =
itemAt( aPoint );
1259 TQPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y );
1260 aPoint += TQPoint( 30, (d->mCurrentItem->height() / 2) );
1261 aItem =
itemAt( aPoint );
1262 while ( !aItem && aPoint.y() > 27 ) {
1263 aPoint -= TQPoint( 0, 16 );
1264 aItem =
itemAt( aPoint );
1272 aItem = d->mItemList.first();
1276 aItem = d->mItemList.last();
1283 if ( contentsX() <= 0 )
1286 int theCol = ( TQMAX( 0, ( contentsX() / cw) * cw ) ) + d->mItemSpacing;
1287 aItem =
itemAt( TQPoint( theCol + 1, d->mItemSpacing + 1 ) );
1300 int theCol = ( (( contentsX() + visibleWidth() ) / cw) * cw ) + d->mItemSpacing + 1;
1302 if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() ) % cw) <= int( d->mItemSpacing + d->mSepWidth ) )
1306 while ( theCol > contentsWidth() )
1309 aItem =
itemAt( TQPoint( theCol, d->mItemSpacing + 1 ) );
1317 setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() );
1327 itemRect(d->mCurrentItem).center() ) );
1330 if ( (e->state() & ControlButton) && e->key() == Key_A ) {
1334 }
else if ( !e->text().isEmpty() && e->text()[ 0 ].isPrint() ) {
1342 if ( d->mSelectionMode == CardView::Extended ) {
1343 if ( e->state() & ShiftButton ) {
1350 a = d->mItemList.findRef( aItem );
1351 b = d->mItemList.findRef( old );
1352 from = a < b ? a : b;
1355 if ( to - from > 1 ) {
1356 bool b = signalsBlocked();
1357 blockSignals(
true );
1363 for ( ; from <= to; from++ ) {
1364 item = d->mItemList.at( from );
1370 }
else if ( e->state() & ControlButton ) {
1374 bool b = signalsBlocked();
1375 blockSignals(
true );
1388 scrollBy( 2 * e->delta() / -3, 0 );
1393 if ( d->mLayoutDirty != dirty ) {
1394 d->mLayoutDirty = dirty;
1401 if ( enabled != d->mDrawCardBorder ) {
1402 d->mDrawCardBorder = enabled;
1409 return d->mDrawCardBorder;
1414 if ( enabled != d->mDrawSeparators ) {
1415 d->mDrawSeparators = enabled;
1422 return d->mDrawSeparators;
1427 if ( enabled != d->mDrawFieldLabels ) {
1428 d->mDrawFieldLabels = enabled;
1435 return d->mDrawFieldLabels;
1440 if ( show != d->mShowEmptyFields ) {
1441 d->mShowEmptyFields = show;
1448 return d->mShowEmptyFields;
1457 void CardView::tryShowFullText()
1461 TQPoint cpos = viewportToContents( viewport()->mapFromGlobal( TQCursor::pos() ) );
1465 TQPoint ipos = cpos -
itemRect( item ).topLeft();
1470 void CardView::drawRubberBands(
int pos )
1473 (!d->mSpan || ((pos - d->mFirstX) / d->mSpan) - d->mColspace - d->mSepWidth < MIN_ITEM_WIDTH) )
1476 int tmpcw = (d->mRubberBandAnchor - d->mFirstX) / d->mSpan;
1477 int x = d->mFirstX + tmpcw - d->mSepWidth - contentsX();
1478 int h = visibleHeight();
1480 TQPainter p( viewport() );
1481 p.setRasterOp( XorROP );
1486 if ( d->mRubberBandAnchor )
1488 p.drawRect( x, 0, 2, h );
1491 }
while ( x < visibleWidth() && n < d->mSeparatorList.count() );
1495 tmpcw = (pos - d->mFirstX) / d->mSpan;
1497 x = d->mFirstX + tmpcw - d->mSepWidth - contentsX();
1499 p.drawRect( x, 0, 2, h );
1502 }
while ( x < visibleWidth() && n < d->mSeparatorList.count() );
1503 d->mRubberBandAnchor = pos;
1508 return d->mItemWidth;
1513 if ( w == d->mItemWidth )
1515 if ( w < MIN_ITEM_WIDTH )
1524 d->mHeaderFont = fnt;
1526 d->mBFm =
new TQFontMetrics( fnt );
1531 return d->mHeaderFont;
1536 TQScrollView::setFont( fnt );
1538 d->mFm =
new TQFontMetrics( fnt );
1543 return d->mSepWidth;
1548 d->mSepWidth = width;
1554 return d->mMaxFieldLines;
1559 d->mMaxFieldLines = howmany ? howmany : INT_MAX;
1563 #include "cardview.moc"
Represents a single card (item) in the card view.
void removeField(const TQString &label)
Removes the field with label label from the card.
const TQString & caption() const
virtual void paintCard(TQPainter *p, TQColorGroup &cg)
Paints the card using the given painter and color group.
CardViewItem * nextItem() const
void clearFields()
Removes all the fields from this card.
void setSelected(bool selected)
Sets the card as selected.
void setCaption(const TQString &caption)
Sets the caption of the card.
void showFullString(const TQPoint &pos, CardViewTip *tip)
Called by the parent card view when the mouse has been resting for a certain amount of time.
virtual void repaintCard()
Repaints the card.
CardViewItem(CardView *parent, const TQString &caption=TQString())
Constructor.
TQPair< TQString, TQString > Field
A single field in the card view.
int height(bool allowCache=true) const
TQString fieldValue(const TQString &label) const
void insertField(const TQString &label, const TQString &value)
Adds a field to the card.
Field * fieldAt(const TQPoint &itempos) const
The CardView is a method of displaying data in cards.
void returnPressed(CardViewItem *)
Emitted when the return key is pressed in an item.
void setDrawColSeparators(bool enabled)
Sets if the column separator should be drawn.
CardViewItem * itemAt(const TQPoint &viewPos) const
void setDrawCardBorder(bool enabled)
Sets if the border around a card should be draw.
int separatorWidth() const
void setShowEmptyFields(bool show)
Sets if fields with no value should be drawn (of cause the label only, but it allows for embedded edi...
CardViewItem * itemAfter(const CardViewItem *item) const
void setItemSpacing(uint spacing)
Sets the item spacing.
void currentChanged(CardViewItem *)
Emitted when the current item changes.
bool drawColSeparators() const
void clear()
Clears the view and deletes all card view items.
void setMaxFieldLines(int howmany)
Sets the maximum number of lines to display pr field.
void ensureItemVisible(const CardViewItem *item)
Ensures that the given item is in the viewable area of the widget.
void contextMenuRequested(CardViewItem *, const TQPoint &)
Emitted when the context menu is requested in some way.
void setSelectionMode(SelectionMode mode)
Sets the selection mode.
CardViewItem * firstItem() const
CardViewItem * currentItem() const
CardViewItem * findItem(const TQString &text, const TQString &label, TQt::StringComparisonMode compare=TQt::BeginsWith) const
Attempts to find the first item matching the params.
void setFont(const TQFont &fnt)
Reimplementation from TQWidget.
TQFont headerFont() const
CardViewItem * selectedItem() const
TQRect itemRect(const CardViewItem *item) const
void setCurrentItem(CardViewItem *item)
Sets the CardViewItem item to the current item in the view.
bool isSelected(CardViewItem *item) const
void doubleClicked(CardViewItem *)
Emitted whenever the user double clicks on an item.
void executed(CardViewItem *)
Emitted whenever the user 'executes' an item.
void drawContents(TQPainter *p, int clipx, int clipy, int clipw, int cliph)
Determines which cards intersect that region and tells them to paint themselves.
uint columnWidth() const
Returns the amounts of pixels required for one column.
void calcLayout()
Does the math based on the bounding rect of the cards to properly lay the cards out on the screen.
void contentsWheelEvent(TQWheelEvent *)
Changes the direction the canvas scolls.
void setHeaderFont(const TQFont &fnt)
Sets the header font.
void setSeparatorWidth(int width)
Sets the column separator width.
int maxFieldLines() const
void takeItem(CardViewItem *item)
Takes the item from the view.
void setItemMargin(uint margin)
Sets the internal item margin.
void setDrawFieldLabels(bool enabled)
Sets if the field labels should be drawn.
void selectAll(bool state)
Selects or deselects all items.
bool drawCardBorder() const
void setLayoutDirty(bool dirty)
Sets the layout to dirty and calls for a repaint.
void insertItem(CardViewItem *item)
Inserts the item into the card view.
void selectionChanged()
Emitted whenever the selection changes.
void clicked(CardViewItem *)
This method is emitted whenever an item is clicked.
void repaintItem(const CardViewItem *item)
Repaints the given item.
void setItemWidth(int width)
Sets the width made available to card items.
void resizeEvent(TQResizeEvent *)
Sets the layout to dirty and repaints.
bool drawFieldLabels() const
SelectionMode selectionMode() const
bool showEmptyFields() const
void setSelected(CardViewItem *item, bool selected)
Selects or deselects the given item.
CardView(TQWidget *parent, const char *name)
Constructor.
virtual void startDrag()
Overload this method to be told when a drag should be started.