-rw-r--r-- | kaddressbook/views/cardview.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/kaddressbook/views/cardview.cpp b/kaddressbook/views/cardview.cpp index 65f793c..6351c11 100644 --- a/kaddressbook/views/cardview.cpp +++ b/kaddressbook/views/cardview.cpp | |||
@@ -563,192 +563,193 @@ void CardViewItem::showFullString( const QPoint &itempos, CardViewTip *tip ) | |||
563 | int maxLines = mView->maxFieldLines(); | 563 | int maxLines = mView->maxFieldLines(); |
564 | bool se = mView->showEmptyFields(); | 564 | bool se = mView->showEmptyFields(); |
565 | int fh = mView->d->mFm->height(); | 565 | int fh = mView->d->mFm->height(); |
566 | // { | 566 | // { |
567 | Field *_f; | 567 | Field *_f; |
568 | for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next()) | 568 | for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next()) |
569 | if ( se || ! _f->second.isEmpty() ) | 569 | if ( se || ! _f->second.isEmpty() ) |
570 | y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2; | 570 | y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2; |
571 | // } | 571 | // } |
572 | if ( isLabel && itempos.y() > y + fh ) | 572 | if ( isLabel && itempos.y() > y + fh ) |
573 | return; | 573 | return; |
574 | // label or data? | 574 | // label or data? |
575 | s = isLabel ? f->first : f->second; | 575 | s = isLabel ? f->first : f->second; |
576 | // trimmed? | 576 | // trimmed? |
577 | int colonWidth = mView->d->mFm->width(":"); | 577 | int colonWidth = mView->d->mFm->width(":"); |
578 | lw = drawLabels ? // label width | 578 | lw = drawLabels ? // label width |
579 | QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) : | 579 | QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) : |
580 | 0; | 580 | 0; |
581 | int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string | 581 | int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string |
582 | if ( isLabel ) | 582 | if ( isLabel ) |
583 | { | 583 | { |
584 | trimmed = mView->d->mFm->width( s ) > mw - colonWidth; | 584 | trimmed = mView->d->mFm->width( s ) > mw - colonWidth; |
585 | } else { | 585 | } else { |
586 | QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) ); | 586 | QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) ); |
587 | trimmed = r.width() > mw || r.height()/fh > QMIN(s.contains('\n') + 1, maxLines); | 587 | trimmed = r.width() > mw || r.height()/fh > QMIN(s.contains('\n') + 1, maxLines); |
588 | } | 588 | } |
589 | } | 589 | } |
590 | if ( trimmed ) | 590 | if ( trimmed ) |
591 | { | 591 | { |
592 | tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header | 592 | tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header |
593 | tip->setText( s ); | 593 | tip->setText( s ); |
594 | tip->adjustSize(); | 594 | tip->adjustSize(); |
595 | // find a proper position | 595 | // find a proper position |
596 | int lx; | 596 | int lx; |
597 | lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/; | 597 | lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/; |
598 | QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) )); | 598 | QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) )); |
599 | pnt += QPoint(lx, y); | 599 | pnt += QPoint(lx, y); |
600 | if ( pnt.x() < 0 ) | 600 | if ( pnt.x() < 0 ) |
601 | pnt.setX( 0 ); | 601 | pnt.setX( 0 ); |
602 | if ( pnt.x() + tip->width() > mView->visibleWidth() ) | 602 | if ( pnt.x() + tip->width() > mView->visibleWidth() ) |
603 | pnt.setX( mView->visibleWidth() - tip->width() ); | 603 | pnt.setX( mView->visibleWidth() - tip->width() ); |
604 | if ( pnt.y() + tip->height() > mView->visibleHeight() ) | 604 | if ( pnt.y() + tip->height() > mView->visibleHeight() ) |
605 | pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) ); | 605 | pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) ); |
606 | // show | 606 | // show |
607 | tip->move( pnt ); | 607 | tip->move( pnt ); |
608 | tip->show(); | 608 | tip->show(); |
609 | } | 609 | } |
610 | } | 610 | } |
611 | 611 | ||
612 | CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const | 612 | CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const |
613 | { | 613 | { |
614 | int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin; | 614 | int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin; |
615 | int iy = itempos.y(); | 615 | int iy = itempos.y(); |
616 | // skip below caption | 616 | // skip below caption |
617 | if ( iy <= ypos ) | 617 | if ( iy <= ypos ) |
618 | return 0; | 618 | return 0; |
619 | // try find a field | 619 | // try find a field |
620 | bool showEmpty = mView->showEmptyFields(); | 620 | bool showEmpty = mView->showEmptyFields(); |
621 | int fh = mView->d->mFm->height(); | 621 | int fh = mView->d->mFm->height(); |
622 | int maxLines = mView->maxFieldLines(); | 622 | int maxLines = mView->maxFieldLines(); |
623 | Field *f; | 623 | Field *f; |
624 | for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) | 624 | for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) |
625 | { | 625 | { |
626 | if ( showEmpty || !f->second.isEmpty() ) | 626 | if ( showEmpty || !f->second.isEmpty() ) |
627 | ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2; | 627 | ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2; |
628 | if ( iy <= ypos ) | 628 | if ( iy <= ypos ) |
629 | break; | 629 | break; |
630 | } | 630 | } |
631 | return f ? f : 0; | 631 | return f ? f : 0; |
632 | } | 632 | } |
633 | //END CardViewItem | 633 | //END CardViewItem |
634 | 634 | ||
635 | //BEGIN CardView | 635 | //BEGIN CardView |
636 | 636 | ||
637 | CardView::CardView(QWidget *parent, const char *name) | 637 | CardView::CardView(QWidget *parent, const char *name) |
638 | : QScrollView(parent, name), | 638 | : QScrollView(parent, name), |
639 | d(new CardViewPrivate()) | 639 | d(new CardViewPrivate()) |
640 | { | 640 | { |
641 | d->mItemList.setAutoDelete(true); | 641 | d->mItemList.setAutoDelete(true); |
642 | d->mSeparatorList.setAutoDelete(true); | 642 | d->mSeparatorList.setAutoDelete(true); |
643 | 643 | ||
644 | QFont f = font(); | 644 | QFont f = font(); |
645 | d->mFm = new QFontMetrics(f); | 645 | d->mFm = new QFontMetrics(f); |
646 | f.setBold(true); | 646 | f.setBold(true); |
647 | d->mHeaderFont = f; | 647 | d->mHeaderFont = f; |
648 | d->mBFm = new QFontMetrics(f); | 648 | d->mBFm = new QFontMetrics(f); |
649 | d->mTip = ( new CardViewTip( viewport() ) ), | 649 | d->mTip = ( new CardViewTip( viewport() ) ), |
650 | d->mTip->hide(); | 650 | d->mTip->hide(); |
651 | d->mTimer = ( new QTimer(this, "mouseTimer") ), | 651 | d->mTimer = ( new QTimer(this, "mouseTimer") ), |
652 | 652 | ||
653 | viewport()->setMouseTracking( true ); | 653 | viewport()->setMouseTracking( true ); |
654 | viewport()->setFocusProxy(this); | 654 | viewport()->setFocusProxy(this); |
655 | viewport()->setFocusPolicy(WheelFocus); | 655 | viewport()->setFocusPolicy(WheelFocus); |
656 | viewport()->setBackgroundMode(PaletteBase); | 656 | viewport()->setBackgroundMode(PaletteBase); |
657 | 657 | ||
658 | connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); | 658 | connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); |
659 | connect( this, SIGNAL(executed(CardViewItem *)), this, SIGNAL( doubleClicked(CardViewItem *)) ); | ||
659 | 660 | ||
660 | //US setBackgroundMode(PaletteBackground, PaletteBase); | 661 | //US setBackgroundMode(PaletteBackground, PaletteBase); |
661 | setBackgroundMode(PaletteBackground); | 662 | setBackgroundMode(PaletteBackground); |
662 | 663 | ||
663 | // no reason for a vertical scrollbar | 664 | // no reason for a vertical scrollbar |
664 | setVScrollBarMode(AlwaysOff); | 665 | setVScrollBarMode(AlwaysOff); |
665 | } | 666 | } |
666 | 667 | ||
667 | CardView::~CardView() | 668 | CardView::~CardView() |
668 | { | 669 | { |
669 | delete d->mFm; | 670 | delete d->mFm; |
670 | delete d->mBFm; | 671 | delete d->mBFm; |
671 | delete d; | 672 | delete d; |
672 | d = 0; | 673 | d = 0; |
673 | } | 674 | } |
674 | 675 | ||
675 | void CardView::insertItem(CardViewItem *item) | 676 | void CardView::insertItem(CardViewItem *item) |
676 | { | 677 | { |
677 | d->mItemList.inSort(item); | 678 | d->mItemList.inSort(item); |
678 | setLayoutDirty(true); | 679 | setLayoutDirty(true); |
679 | } | 680 | } |
680 | 681 | ||
681 | void CardView::takeItem(CardViewItem *item) | 682 | void CardView::takeItem(CardViewItem *item) |
682 | { | 683 | { |
683 | if ( d->mCurrentItem == item ) | 684 | if ( d->mCurrentItem == item ) |
684 | d->mCurrentItem = item->nextItem(); | 685 | d->mCurrentItem = item->nextItem(); |
685 | d->mItemList.take(d->mItemList.findRef(item)); | 686 | d->mItemList.take(d->mItemList.findRef(item)); |
686 | 687 | ||
687 | setLayoutDirty(true); | 688 | setLayoutDirty(true); |
688 | } | 689 | } |
689 | 690 | ||
690 | void CardView::clear() | 691 | void CardView::clear() |
691 | { | 692 | { |
692 | d->mItemList.clear(); | 693 | d->mItemList.clear(); |
693 | 694 | ||
694 | setLayoutDirty(true); | 695 | setLayoutDirty(true); |
695 | } | 696 | } |
696 | 697 | ||
697 | CardViewItem *CardView::currentItem() | 698 | CardViewItem *CardView::currentItem() |
698 | { | 699 | { |
699 | if ( ! d->mCurrentItem && d->mItemList.count() ) | 700 | if ( ! d->mCurrentItem && d->mItemList.count() ) |
700 | d->mCurrentItem = d->mItemList.first(); | 701 | d->mCurrentItem = d->mItemList.first(); |
701 | return d->mCurrentItem; | 702 | return d->mCurrentItem; |
702 | } | 703 | } |
703 | 704 | ||
704 | void CardView::setCurrentItem( CardViewItem *item ) | 705 | void CardView::setCurrentItem( CardViewItem *item ) |
705 | { | 706 | { |
706 | if ( !item ) | 707 | if ( !item ) |
707 | return; | 708 | return; |
708 | else if ( item->cardView() != this ) | 709 | else if ( item->cardView() != this ) |
709 | { | 710 | { |
710 | kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl; | 711 | kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl; |
711 | return; | 712 | return; |
712 | } | 713 | } |
713 | else if ( item == currentItem() ) | 714 | else if ( item == currentItem() ) |
714 | { | 715 | { |
715 | return; | 716 | return; |
716 | } | 717 | } |
717 | 718 | ||
718 | if ( d->mSelectionMode == Single ) | 719 | if ( d->mSelectionMode == Single ) |
719 | { | 720 | { |
720 | setSelected( item, true ); | 721 | setSelected( item, true ); |
721 | } | 722 | } |
722 | else | 723 | else |
723 | { | 724 | { |
724 | CardViewItem *it = d->mCurrentItem; | 725 | CardViewItem *it = d->mCurrentItem; |
725 | d->mCurrentItem = item; | 726 | d->mCurrentItem = item; |
726 | if ( it ) | 727 | if ( it ) |
727 | it->repaintCard(); | 728 | it->repaintCard(); |
728 | item->repaintCard(); | 729 | item->repaintCard(); |
729 | } | 730 | } |
730 | if ( ! d->mOnSeparator ) | 731 | if ( ! d->mOnSeparator ) |
731 | ensureItemVisible( item ); | 732 | ensureItemVisible( item ); |
732 | emit currentChanged( item ); | 733 | emit currentChanged( item ); |
733 | } | 734 | } |
734 | 735 | ||
735 | CardViewItem *CardView::itemAt(const QPoint &viewPos) | 736 | CardViewItem *CardView::itemAt(const QPoint &viewPos) |
736 | { | 737 | { |
737 | CardViewItem *item = 0; | 738 | CardViewItem *item = 0; |
738 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 739 | QPtrListIterator<CardViewItem> iter(d->mItemList); |
739 | bool found = false; | 740 | bool found = false; |
740 | for (iter.toFirst(); iter.current() && !found; ++iter) | 741 | for (iter.toFirst(); iter.current() && !found; ++iter) |
741 | { | 742 | { |
742 | item = *iter; | 743 | item = *iter; |
743 | //if (item->d->mRect.contains(viewPos)) | 744 | //if (item->d->mRect.contains(viewPos)) |
744 | if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos)) | 745 | if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos)) |
745 | found = true; | 746 | found = true; |
746 | } | 747 | } |
747 | 748 | ||
748 | if (found) | 749 | if (found) |
749 | return item; | 750 | return item; |
750 | 751 | ||
751 | return 0; | 752 | return 0; |
752 | } | 753 | } |
753 | 754 | ||
754 | QRect CardView::itemRect(const CardViewItem *item) | 755 | QRect CardView::itemRect(const CardViewItem *item) |
@@ -1173,381 +1174,383 @@ void CardView::contentsMousePressEvent(QMouseEvent *e) | |||
1173 | bool b = signalsBlocked(); | 1174 | bool b = signalsBlocked(); |
1174 | blockSignals(true); | 1175 | blockSignals(true); |
1175 | selectAll(false); | 1176 | selectAll(false); |
1176 | blockSignals(b); | 1177 | blockSignals(b); |
1177 | } | 1178 | } |
1178 | 1179 | ||
1179 | int from, to, a, b; | 1180 | int from, to, a, b; |
1180 | a = d->mItemList.findRef( item ); | 1181 | a = d->mItemList.findRef( item ); |
1181 | b = d->mItemList.findRef( other ); | 1182 | b = d->mItemList.findRef( other ); |
1182 | from = a < b ? a : b; | 1183 | from = a < b ? a : b; |
1183 | to = a > b ? a : b; | 1184 | to = a > b ? a : b; |
1184 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; | 1185 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; |
1185 | CardViewItem *aItem; | 1186 | CardViewItem *aItem; |
1186 | for ( ; from <= to; from++ ) | 1187 | for ( ; from <= to; from++ ) |
1187 | { | 1188 | { |
1188 | aItem = d->mItemList.at( from ); | 1189 | aItem = d->mItemList.at( from ); |
1189 | aItem->setSelected( s ); | 1190 | aItem->setSelected( s ); |
1190 | repaintItem( aItem ); | 1191 | repaintItem( aItem ); |
1191 | } | 1192 | } |
1192 | emit selectionChanged(); | 1193 | emit selectionChanged(); |
1193 | } | 1194 | } |
1194 | else if ((e->button() & Qt::LeftButton) && | 1195 | else if ((e->button() & Qt::LeftButton) && |
1195 | (e->state() & Qt::ControlButton)) | 1196 | (e->state() & Qt::ControlButton)) |
1196 | { | 1197 | { |
1197 | item->setSelected(!item->isSelected()); | 1198 | item->setSelected(!item->isSelected()); |
1198 | item->repaintCard(); | 1199 | item->repaintCard(); |
1199 | emit selectionChanged(); | 1200 | emit selectionChanged(); |
1200 | } | 1201 | } |
1201 | 1202 | ||
1202 | else if (e->button() & Qt::LeftButton) | 1203 | else if (e->button() & Qt::LeftButton) |
1203 | { | 1204 | { |
1204 | bool b = signalsBlocked(); | 1205 | bool b = signalsBlocked(); |
1205 | blockSignals(true); | 1206 | blockSignals(true); |
1206 | selectAll(false); | 1207 | selectAll(false); |
1207 | blockSignals(b); | 1208 | blockSignals(b); |
1208 | 1209 | ||
1209 | item->setSelected(true); | 1210 | item->setSelected(true); |
1210 | item->repaintCard(); | 1211 | item->repaintCard(); |
1211 | emit selectionChanged(); | 1212 | emit selectionChanged(); |
1212 | } | 1213 | } |
1213 | } | 1214 | } |
1214 | 1215 | ||
1215 | } | 1216 | } |
1216 | 1217 | ||
1217 | void CardView::contentsMouseReleaseEvent(QMouseEvent *e) | 1218 | void CardView::contentsMouseReleaseEvent(QMouseEvent *e) |
1218 | { | 1219 | { |
1219 | QScrollView::contentsMouseReleaseEvent(e); | 1220 | QScrollView::contentsMouseReleaseEvent(e); |
1220 | 1221 | ||
1221 | if ( d->mResizeAnchor ) | 1222 | if ( d->mResizeAnchor ) |
1222 | { | 1223 | { |
1223 | // finish the resizing: | 1224 | // finish the resizing: |
1224 | unsetCursor(); | 1225 | unsetCursor(); |
1225 | // hide rubber bands | 1226 | // hide rubber bands |
1226 | int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span); | 1227 | int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span); |
1227 | drawRubberBands( 0 ); | 1228 | drawRubberBands( 0 ); |
1228 | // we should move to reflect the new position if we are scrolled. | 1229 | // we should move to reflect the new position if we are scrolled. |
1229 | if ( contentsX() ) | 1230 | if ( contentsX() ) |
1230 | { | 1231 | { |
1231 | int newX = QMAX( 0, ( d->pressed * ( newiw + d->colspace + d->mSepWidth ) ) - e->x() ); | 1232 | int newX = QMAX( 0, ( d->pressed * ( newiw + d->colspace + d->mSepWidth ) ) - e->x() ); |
1232 | setContentsPos( newX, contentsY() ); | 1233 | setContentsPos( newX, contentsY() ); |
1233 | } | 1234 | } |
1234 | // set new item width | 1235 | // set new item width |
1235 | setItemWidth( newiw ); | 1236 | setItemWidth( newiw ); |
1236 | // reset anchors | 1237 | // reset anchors |
1237 | d->mResizeAnchor = 0; | 1238 | d->mResizeAnchor = 0; |
1238 | d->mRubberBandAnchor = 0; | 1239 | d->mRubberBandAnchor = 0; |
1239 | return; | 1240 | return; |
1240 | } | 1241 | } |
1241 | 1242 | ||
1242 | // If there are accel keys, we will not emit signals | 1243 | // If there are accel keys, we will not emit signals |
1243 | if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton)) | 1244 | if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton)) |
1244 | return; | 1245 | return; |
1245 | 1246 | ||
1246 | // Get the item at this position | 1247 | // Get the item at this position |
1247 | CardViewItem *item = itemAt(e->pos()); | 1248 | CardViewItem *item = itemAt(e->pos()); |
1248 | 1249 | ||
1249 | if (item && KGlobalSettings::singleClick()) | 1250 | if (item && KGlobalSettings::singleClick()) |
1250 | { | 1251 | { |
1251 | emit executed(item); | 1252 | emit executed(item); |
1252 | } | 1253 | } |
1253 | } | 1254 | } |
1254 | 1255 | ||
1255 | void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e) | 1256 | void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e) |
1256 | { | 1257 | { |
1257 | QScrollView::contentsMouseDoubleClickEvent(e); | 1258 | QScrollView::contentsMouseDoubleClickEvent(e); |
1258 | 1259 | ||
1259 | CardViewItem *item = itemAt(e->pos()); | 1260 | CardViewItem *item = itemAt(e->pos()); |
1260 | 1261 | ||
1261 | if (item) | 1262 | if (item) |
1262 | { | 1263 | { |
1263 | d->mCurrentItem = item; | 1264 | d->mCurrentItem = item; |
1264 | } | 1265 | } |
1265 | 1266 | ||
1266 | if (item && !KGlobalSettings::singleClick()) | 1267 | if (item && !KGlobalSettings::singleClick()) |
1267 | { | 1268 | { |
1268 | emit executed(item); | 1269 | emit executed(item); |
1269 | } | 1270 | } else |
1270 | emit doubleClicked(item); | 1271 | emit doubleClicked(item); |
1271 | } | 1272 | } |
1272 | 1273 | ||
1273 | void CardView::contentsMouseMoveEvent( QMouseEvent *e ) | 1274 | void CardView::contentsMouseMoveEvent( QMouseEvent *e ) |
1274 | { | 1275 | { |
1275 | // resizing | 1276 | // resizing |
1276 | if ( d->mResizeAnchor ) | 1277 | if ( d->mResizeAnchor ) |
1277 | { | 1278 | { |
1278 | int x = e->x(); | 1279 | int x = e->x(); |
1279 | if ( x != d->mRubberBandAnchor ) | 1280 | if ( x != d->mRubberBandAnchor ) |
1280 | drawRubberBands( x ); | 1281 | drawRubberBands( x ); |
1281 | return; | 1282 | return; |
1282 | } | 1283 | } |
1283 | 1284 | ||
1284 | if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) && | 1285 | if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) && |
1285 | ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) { | 1286 | ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) { |
1286 | 1287 | ||
1287 | startDrag(); | 1288 | startDrag(); |
1288 | return; | 1289 | return; |
1289 | } | 1290 | } |
1290 | 1291 | ||
1291 | d->mTimer->start( 500 ); | 1292 | d->mTimer->start( 500 ); |
1292 | 1293 | ||
1293 | // see if we are over a separator | 1294 | // see if we are over a separator |
1294 | // only if we actually have them painted? | 1295 | // only if we actually have them painted? |
1295 | if ( d->mDrawSeparators ) | 1296 | if ( d->mDrawSeparators ) |
1296 | { | 1297 | { |
1297 | int colcontentw = d->mItemWidth + (2*d->mItemSpacing); | 1298 | int colcontentw = d->mItemWidth + (2*d->mItemSpacing); |
1298 | int colw = colcontentw + d->mSepWidth; | 1299 | int colw = colcontentw + d->mSepWidth; |
1299 | int m = e->x()%colw; | 1300 | int m = e->x()%colw; |
1300 | if ( m >= colcontentw && m > 0 ) | 1301 | if ( m >= colcontentw && m > 0 ) |
1301 | { | 1302 | { |
1302 | setCursor( SplitVCursor ); // Why does this fail sometimes? | 1303 | setCursor( SplitVCursor ); // Why does this fail sometimes? |
1303 | d->mOnSeparator = true; | 1304 | d->mOnSeparator = true; |
1304 | } | 1305 | } |
1305 | else | 1306 | else |
1306 | { | 1307 | { |
1307 | setCursor( ArrowCursor ); | 1308 | setCursor( ArrowCursor ); |
1308 | d->mOnSeparator = false; | 1309 | d->mOnSeparator = false; |
1309 | } | 1310 | } |
1310 | } | 1311 | } |
1311 | } | 1312 | } |
1312 | 1313 | ||
1313 | void CardView::enterEvent( QEvent * ) | 1314 | void CardView::enterEvent( QEvent * ) |
1314 | { | 1315 | { |
1315 | d->mTimer->start( 500 ); | 1316 | d->mTimer->start( 500 ); |
1316 | } | 1317 | } |
1317 | 1318 | ||
1318 | void CardView::leaveEvent( QEvent * ) | 1319 | void CardView::leaveEvent( QEvent * ) |
1319 | { | 1320 | { |
1320 | d->mTimer->stop(); | 1321 | d->mTimer->stop(); |
1321 | if (d->mOnSeparator) | 1322 | if (d->mOnSeparator) |
1322 | { | 1323 | { |
1323 | d->mOnSeparator = false; | 1324 | d->mOnSeparator = false; |
1324 | setCursor( ArrowCursor ); | 1325 | setCursor( ArrowCursor ); |
1325 | } | 1326 | } |
1326 | } | 1327 | } |
1327 | 1328 | ||
1328 | void CardView::focusInEvent( QFocusEvent * ) | 1329 | void CardView::focusInEvent( QFocusEvent * ) |
1329 | { | 1330 | { |
1330 | if (!d->mCurrentItem && d->mItemList.count() ) | 1331 | if (!d->mCurrentItem && d->mItemList.count() ) |
1331 | { | 1332 | { |
1332 | setCurrentItem( d->mItemList.first() ); | 1333 | setCurrentItem( d->mItemList.first() ); |
1333 | } | 1334 | } |
1334 | else if ( d->mCurrentItem ) | 1335 | else if ( d->mCurrentItem ) |
1335 | { | 1336 | { |
1336 | d->mCurrentItem->repaintCard(); | 1337 | d->mCurrentItem->repaintCard(); |
1337 | } | 1338 | } |
1338 | } | 1339 | } |
1339 | 1340 | ||
1340 | void CardView::focusOutEvent( QFocusEvent * ) | 1341 | void CardView::focusOutEvent( QFocusEvent * ) |
1341 | { | 1342 | { |
1342 | if (d->mCurrentItem) | 1343 | if (d->mCurrentItem) |
1343 | d->mCurrentItem->repaintCard(); | 1344 | d->mCurrentItem->repaintCard(); |
1344 | } | 1345 | } |
1345 | 1346 | ||
1346 | void CardView::keyPressEvent( QKeyEvent *e ) | 1347 | void CardView::keyPressEvent( QKeyEvent *e ) |
1347 | { | 1348 | { |
1348 | if ( ! ( childCount() && d->mCurrentItem ) ) | 1349 | if ( ! ( childCount() && d->mCurrentItem ) ) |
1349 | { | 1350 | { |
1350 | e->ignore(); | 1351 | e->ignore(); |
1351 | return; | 1352 | return; |
1352 | } | 1353 | } |
1353 | 1354 | ||
1354 | uint pos = d->mItemList.findRef( d->mCurrentItem ); | 1355 | uint pos = d->mItemList.findRef( d->mCurrentItem ); |
1355 | CardViewItem *aItem = 0L; // item that gets the focus | 1356 | CardViewItem *aItem = 0L; // item that gets the focus |
1356 | CardViewItem *old = d->mCurrentItem; | 1357 | CardViewItem *old = d->mCurrentItem; |
1357 | 1358 | ||
1358 | switch ( e->key() ) | 1359 | switch ( e->key() ) |
1359 | { | 1360 | { |
1360 | case Key_Up: | 1361 | case Key_Up: |
1361 | if ( pos > 0 ) | 1362 | if ( pos > 0 ) |
1362 | { | 1363 | { |
1363 | aItem = d->mItemList.at( pos - 1 ); | 1364 | aItem = d->mItemList.at( pos - 1 ); |
1364 | setCurrentItem( aItem ); | 1365 | setCurrentItem( aItem ); |
1365 | } | 1366 | } |
1366 | break; | 1367 | break; |
1367 | case Key_Down: | 1368 | case Key_Down: |
1368 | if ( pos < d->mItemList.count() - 1 ) | 1369 | if ( pos < d->mItemList.count() - 1 ) |
1369 | { | 1370 | { |
1370 | aItem = d->mItemList.at( pos + 1 ); | 1371 | aItem = d->mItemList.at( pos + 1 ); |
1371 | setCurrentItem( aItem ); | 1372 | setCurrentItem( aItem ); |
1372 | } | 1373 | } |
1373 | break; | 1374 | break; |
1374 | case Key_Left: | 1375 | case Key_Left: |
1375 | { | 1376 | { |
1376 | // look for an item in the previous/next column, starting from | 1377 | // look for an item in the previous/next column, starting from |
1377 | // the vertical middle of the current item. | 1378 | // the vertical middle of the current item. |
1378 | // FIXME use nice calculatd measures!!! | 1379 | // FIXME use nice calculatd measures!!! |
1379 | QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y ); | 1380 | QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y ); |
1380 | aPoint -= QPoint( 30,-(d->mCurrentItem->height()/2) ); | 1381 | aPoint -= QPoint( 30,-(d->mCurrentItem->height()/2) ); |
1381 | aItem = itemAt( aPoint ); | 1382 | aItem = itemAt( aPoint ); |
1382 | // maybe we hit some space below an item | 1383 | // maybe we hit some space below an item |
1383 | while ( !aItem && aPoint.y() > 27 ) | 1384 | while ( !aItem && aPoint.y() > 27 ) |
1384 | { | 1385 | { |
1385 | aPoint -= QPoint( 0, 16 ); | 1386 | aPoint -= QPoint( 0, 16 ); |
1386 | aItem = itemAt( aPoint ); | 1387 | aItem = itemAt( aPoint ); |
1387 | } | 1388 | } |
1388 | if ( aItem ) | 1389 | if ( aItem ) |
1389 | setCurrentItem( aItem ); | 1390 | setCurrentItem( aItem ); |
1390 | } | 1391 | } |
1391 | break; | 1392 | break; |
1392 | case Key_Right: | 1393 | case Key_Right: |
1393 | { | 1394 | { |
1394 | // FIXME use nice calculated measures!!! | 1395 | // FIXME use nice calculated measures!!! |
1395 | QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y ); | 1396 | QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y ); |
1396 | aPoint += QPoint( 30,(d->mCurrentItem->height()/2) ); | 1397 | aPoint += QPoint( 30,(d->mCurrentItem->height()/2) ); |
1397 | aItem = itemAt( aPoint ); | 1398 | aItem = itemAt( aPoint ); |
1398 | while ( !aItem && aPoint.y() > 27 ) | 1399 | while ( !aItem && aPoint.y() > 27 ) |
1399 | { | 1400 | { |
1400 | aPoint -= QPoint( 0, 16 ); | 1401 | aPoint -= QPoint( 0, 16 ); |
1401 | aItem = itemAt( aPoint ); | 1402 | aItem = itemAt( aPoint ); |
1402 | } | 1403 | } |
1403 | if ( aItem ) | 1404 | if ( aItem ) |
1404 | setCurrentItem( aItem ); | 1405 | setCurrentItem( aItem ); |
1405 | } | 1406 | } |
1406 | break; | 1407 | break; |
1407 | case Key_Home: | 1408 | case Key_Home: |
1408 | aItem = d->mItemList.first(); | 1409 | aItem = d->mItemList.first(); |
1409 | setCurrentItem( aItem ); | 1410 | setCurrentItem( aItem ); |
1410 | break; | 1411 | break; |
1411 | case Key_End: | 1412 | case Key_End: |
1412 | aItem = d->mItemList.last(); | 1413 | aItem = d->mItemList.last(); |
1413 | setCurrentItem( aItem ); | 1414 | setCurrentItem( aItem ); |
1414 | break; | 1415 | break; |
1415 | case Key_Prior: // PageUp | 1416 | case Key_Prior: // PageUp |
1416 | { | 1417 | { |
1417 | // QListView: "Make the item above the top visible and current" | 1418 | // QListView: "Make the item above the top visible and current" |
1418 | // TODO if contentsY(), pick the top item of the leftmost visible column | 1419 | // TODO if contentsY(), pick the top item of the leftmost visible column |
1419 | if ( contentsX() <= 0 ) | 1420 | if ( contentsX() <= 0 ) |
1420 | return; | 1421 | return; |
1421 | int cw = columnWidth(); | 1422 | int cw = columnWidth(); |
1422 | int theCol = ( QMAX( 0, ( contentsX()/cw) * cw ) ) + d->mItemSpacing; | 1423 | int theCol = ( QMAX( 0, ( contentsX()/cw) * cw ) ) + d->mItemSpacing; |
1423 | aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) ); | 1424 | aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) ); |
1424 | if ( aItem ) | 1425 | if ( aItem ) |
1425 | setCurrentItem( aItem ); | 1426 | setCurrentItem( aItem ); |
1426 | } | 1427 | } |
1427 | break; | 1428 | break; |
1428 | case Key_Next: // PageDown | 1429 | case Key_Next: // PageDown |
1429 | { | 1430 | { |
1430 | // QListView: "Make the item below the bottom visible and current" | 1431 | // QListView: "Make the item below the bottom visible and current" |
1431 | // find the first not fully visible column. | 1432 | // find the first not fully visible column. |
1432 | // TODO: consider if a partly visible (or even hidden) item at the | 1433 | // TODO: consider if a partly visible (or even hidden) item at the |
1433 | // bottom of the rightmost column exists | 1434 | // bottom of the rightmost column exists |
1434 | int cw = columnWidth(); | 1435 | int cw = columnWidth(); |
1435 | int theCol = ( (( contentsX() + visibleWidth() )/cw) * cw ) + d->mItemSpacing + 1; | 1436 | int theCol = ( (( contentsX() + visibleWidth() )/cw) * cw ) + d->mItemSpacing + 1; |
1436 | // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden | 1437 | // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden |
1437 | if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() )%cw) <= int( d->mItemSpacing + d->mSepWidth ) ) | 1438 | if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() )%cw) <= int( d->mItemSpacing + d->mSepWidth ) ) |
1438 | theCol += cw; | 1439 | theCol += cw; |
1439 | 1440 | ||
1440 | // make sure this is not too far right | 1441 | // make sure this is not too far right |
1441 | while ( theCol > contentsWidth() ) | 1442 | while ( theCol > contentsWidth() ) |
1442 | theCol -= columnWidth(); | 1443 | theCol -= columnWidth(); |
1443 | 1444 | ||
1444 | aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) ); | 1445 | aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) ); |
1445 | 1446 | ||
1446 | if ( aItem ) | 1447 | if ( aItem ) |
1447 | setCurrentItem( aItem ); | 1448 | setCurrentItem( aItem ); |
1448 | } | 1449 | } |
1449 | break; | 1450 | break; |
1450 | case Key_Space: | 1451 | case Key_Space: |
1451 | setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() ); | 1452 | setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() ); |
1452 | emit selectionChanged(); | 1453 | emit selectionChanged(); |
1453 | break; | 1454 | break; |
1454 | case Key_Return: | 1455 | case Key_Return: |
1455 | case Key_Enter: | 1456 | case Key_Enter: |
1456 | emit returnPressed( d->mCurrentItem ); | 1457 | { |
1457 | emit executed( d->mCurrentItem ); | 1458 | emit returnPressed( d->mCurrentItem ); |
1459 | emit executed( d->mCurrentItem ); | ||
1460 | } | ||
1458 | break; | 1461 | break; |
1459 | default: | 1462 | default: |
1460 | if ( (e->state() & ControlButton) && e->key() == Key_A ) | 1463 | if ( (e->state() & ControlButton) && e->key() == Key_A ) |
1461 | { | 1464 | { |
1462 | // select all | 1465 | // select all |
1463 | selectAll( true ); | 1466 | selectAll( true ); |
1464 | break; | 1467 | break; |
1465 | } | 1468 | } |
1466 | // if we have a string, do autosearch | 1469 | // if we have a string, do autosearch |
1467 | else if ( ! e->text().isEmpty() && e->text()[0].isPrint() ) | 1470 | else if ( ! e->text().isEmpty() && e->text()[0].isPrint() ) |
1468 | { | 1471 | { |
1469 | 1472 | ||
1470 | } | 1473 | } |
1471 | break; | 1474 | break; |
1472 | } | 1475 | } |
1473 | // handle selection | 1476 | // handle selection |
1474 | if ( aItem ) | 1477 | if ( aItem ) |
1475 | { | 1478 | { |
1476 | if ( d->mSelectionMode == CardView::Extended ) | 1479 | if ( d->mSelectionMode == CardView::Extended ) |
1477 | { | 1480 | { |
1478 | if ( (e->state() & ShiftButton) ) | 1481 | if ( (e->state() & ShiftButton) ) |
1479 | { | 1482 | { |
1480 | // shift button: toggle range | 1483 | // shift button: toggle range |
1481 | // if control button is pressed, leave all items | 1484 | // if control button is pressed, leave all items |
1482 | // and toggle selection current->old current | 1485 | // and toggle selection current->old current |
1483 | // otherwise, ?????? | 1486 | // otherwise, ?????? |
1484 | bool s = ! aItem->isSelected(); | 1487 | bool s = ! aItem->isSelected(); |
1485 | int from, to, a, b; | 1488 | int from, to, a, b; |
1486 | a = d->mItemList.findRef( aItem ); | 1489 | a = d->mItemList.findRef( aItem ); |
1487 | b = d->mItemList.findRef( old ); | 1490 | b = d->mItemList.findRef( old ); |
1488 | from = a < b ? a : b; | 1491 | from = a < b ? a : b; |
1489 | to = a > b ? a : b; | 1492 | to = a > b ? a : b; |
1490 | 1493 | ||
1491 | if ( to - from > 1 ) | 1494 | if ( to - from > 1 ) |
1492 | { | 1495 | { |
1493 | bool b = signalsBlocked(); | 1496 | bool b = signalsBlocked(); |
1494 | blockSignals(true); | 1497 | blockSignals(true); |
1495 | selectAll(false); | 1498 | selectAll(false); |
1496 | blockSignals(b); | 1499 | blockSignals(b); |
1497 | } | 1500 | } |
1498 | 1501 | ||
1499 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; | 1502 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; |
1500 | CardViewItem *item; | 1503 | CardViewItem *item; |
1501 | for ( ; from <= to; from++ ) | 1504 | for ( ; from <= to; from++ ) |
1502 | { | 1505 | { |
1503 | item = d->mItemList.at( from ); | 1506 | item = d->mItemList.at( from ); |
1504 | item->setSelected( s ); | 1507 | item->setSelected( s ); |
1505 | repaintItem( item ); | 1508 | repaintItem( item ); |
1506 | } | 1509 | } |
1507 | emit selectionChanged(); | 1510 | emit selectionChanged(); |
1508 | } | 1511 | } |
1509 | else if ( (e->state() & ControlButton) ) | 1512 | else if ( (e->state() & ControlButton) ) |
1510 | { | 1513 | { |
1511 | // control button: do nothing | 1514 | // control button: do nothing |
1512 | } | 1515 | } |
1513 | else | 1516 | else |
1514 | { | 1517 | { |
1515 | // no button: move selection to this item | 1518 | // no button: move selection to this item |
1516 | bool b = signalsBlocked(); | 1519 | bool b = signalsBlocked(); |
1517 | blockSignals(true); | 1520 | blockSignals(true); |
1518 | selectAll(false); | 1521 | selectAll(false); |
1519 | blockSignals(b); | 1522 | blockSignals(b); |
1520 | 1523 | ||
1521 | setSelected( aItem, true ); | 1524 | setSelected( aItem, true ); |
1522 | emit selectionChanged(); | 1525 | emit selectionChanged(); |
1523 | } | 1526 | } |
1524 | } | 1527 | } |
1525 | } | 1528 | } |
1526 | } | 1529 | } |
1527 | 1530 | ||
1528 | void CardView::contentsWheelEvent( QWheelEvent * e ) | 1531 | void CardView::contentsWheelEvent( QWheelEvent * e ) |
1529 | { | 1532 | { |
1530 | scrollBy(2*e->delta()/-3, 0); | 1533 | scrollBy(2*e->delta()/-3, 0); |
1531 | } | 1534 | } |
1532 | 1535 | ||
1533 | void CardView::setLayoutDirty(bool dirty) | 1536 | void CardView::setLayoutDirty(bool dirty) |
1534 | { | 1537 | { |
1535 | if (d->mLayoutDirty != dirty) | 1538 | if (d->mLayoutDirty != dirty) |
1536 | { | 1539 | { |
1537 | d->mLayoutDirty = dirty; | 1540 | d->mLayoutDirty = dirty; |
1538 | repaint(); | 1541 | repaint(); |
1539 | } | 1542 | } |
1540 | } | 1543 | } |
1541 | 1544 | ||
1542 | void CardView::setDrawCardBorder(bool enabled) | 1545 | void CardView::setDrawCardBorder(bool enabled) |
1543 | { | 1546 | { |
1544 | if (enabled != d->mDrawCardBorder) | 1547 | if (enabled != d->mDrawCardBorder) |
1545 | { | 1548 | { |
1546 | d->mDrawCardBorder = enabled; | 1549 | d->mDrawCardBorder = enabled; |
1547 | repaint(); | 1550 | repaint(); |
1548 | } | 1551 | } |
1549 | } | 1552 | } |
1550 | 1553 | ||
1551 | bool CardView::drawCardBorder() const | 1554 | bool CardView::drawCardBorder() const |
1552 | { | 1555 | { |
1553 | return d->mDrawCardBorder; | 1556 | return d->mDrawCardBorder; |