author | zautrix <zautrix> | 2004-10-29 10:53:31 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-29 10:53:31 (UTC) |
commit | 67146a3d92727f6fe3e92eacdb51da58bc7b0adf (patch) (unidiff) | |
tree | 140ab8d70bab73ca75aae64c4d2fdfccd73b388a | |
parent | d96b4fd7188145c49120dd159b0ac00c987f4972 (diff) | |
download | kdepimpi-67146a3d92727f6fe3e92eacdb51da58bc7b0adf.zip kdepimpi-67146a3d92727f6fe3e92eacdb51da58bc7b0adf.tar.gz kdepimpi-67146a3d92727f6fe3e92eacdb51da58bc7b0adf.tar.bz2 |
fixed single click in cardview
-rw-r--r-- | kaddressbook/views/cardview.cpp | 6 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.cpp | 5 |
2 files changed, 8 insertions, 3 deletions
diff --git a/kaddressbook/views/cardview.cpp b/kaddressbook/views/cardview.cpp index 6351c11..da552c3 100644 --- a/kaddressbook/views/cardview.cpp +++ b/kaddressbook/views/cardview.cpp | |||
@@ -1,132 +1,133 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | //BEGIN Includes | 24 | //BEGIN Includes |
25 | #include "cardview.h" | 25 | #include "cardview.h" |
26 | 26 | ||
27 | #include <limits.h> | 27 | #include <limits.h> |
28 | 28 | ||
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | #include <qdatetime.h> | 31 | #include <qdatetime.h> |
32 | #include <qlabel.h> | 32 | #include <qlabel.h> |
33 | #include <qstyle.h> | 33 | #include <qstyle.h> |
34 | #include <qcursor.h> | 34 | #include <qcursor.h> |
35 | #include <qtooltip.h> | 35 | #include <qtooltip.h> |
36 | 36 | ||
37 | #include "kabprefs.h" | ||
37 | #include <kdebug.h> | 38 | #include <kdebug.h> |
38 | #include <kglobalsettings.h> | 39 | #include <kglobalsettings.h> |
39 | //END includes | 40 | //END includes |
40 | 41 | ||
41 | #define MIN_ITEM_WIDTH 80 | 42 | #define MIN_ITEM_WIDTH 80 |
42 | 43 | ||
43 | //BEGIN Helpers | 44 | //BEGIN Helpers |
44 | ////////////////////////////////////// | 45 | ////////////////////////////////////// |
45 | // CardViewTip | 46 | // CardViewTip |
46 | class CardViewTip : public QLabel { | 47 | class CardViewTip : public QLabel { |
47 | public: | 48 | public: |
48 | CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name ) | 49 | CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name ) |
49 | { | 50 | { |
50 | setPalette( QToolTip::palette() ); | 51 | setPalette( QToolTip::palette() ); |
51 | setFrameStyle( Panel|Plain ); | 52 | setFrameStyle( Panel|Plain ); |
52 | setMidLineWidth(0); | 53 | setMidLineWidth(0); |
53 | setIndent(1); | 54 | setIndent(1); |
54 | } | 55 | } |
55 | 56 | ||
56 | ~CardViewTip() {}; | 57 | ~CardViewTip() {}; |
57 | protected: | 58 | protected: |
58 | void leaveEvent( QEvent * ) | 59 | void leaveEvent( QEvent * ) |
59 | { | 60 | { |
60 | hide(); | 61 | hide(); |
61 | } | 62 | } |
62 | }; | 63 | }; |
63 | 64 | ||
64 | ////////////////////////////////////// | 65 | ////////////////////////////////////// |
65 | // CardViewItemList | 66 | // CardViewItemList |
66 | 67 | ||
67 | 68 | ||
68 | // | 69 | // |
69 | // Warning: make sure you use findRef() instead of find() to find an | 70 | // Warning: make sure you use findRef() instead of find() to find an |
70 | // item! Only the pointer value is unique in the list. | 71 | // item! Only the pointer value is unique in the list. |
71 | // | 72 | // |
72 | class CardViewItemList : public QPtrList<CardViewItem> | 73 | class CardViewItemList : public QPtrList<CardViewItem> |
73 | { | 74 | { |
74 | protected: | 75 | protected: |
75 | virtual int compareItems(QPtrCollection::Item item1, | 76 | virtual int compareItems(QPtrCollection::Item item1, |
76 | QPtrCollection::Item item2) | 77 | QPtrCollection::Item item2) |
77 | { | 78 | { |
78 | CardViewItem *cItem1 = (CardViewItem*)item1; | 79 | CardViewItem *cItem1 = (CardViewItem*)item1; |
79 | CardViewItem *cItem2 = (CardViewItem*)item2; | 80 | CardViewItem *cItem2 = (CardViewItem*)item2; |
80 | 81 | ||
81 | if ( cItem1 == cItem2 ) | 82 | if ( cItem1 == cItem2 ) |
82 | return 0; | 83 | return 0; |
83 | 84 | ||
84 | if ((cItem1 == 0) || (cItem2 == 0)) | 85 | if ((cItem1 == 0) || (cItem2 == 0)) |
85 | return cItem1 ? -1 : 1; | 86 | return cItem1 ? -1 : 1; |
86 | 87 | ||
87 | if (cItem1->caption() < cItem2->caption()) | 88 | if (cItem1->caption() < cItem2->caption()) |
88 | return -1; | 89 | return -1; |
89 | 90 | ||
90 | else if (cItem1->caption() > cItem2->caption()) | 91 | else if (cItem1->caption() > cItem2->caption()) |
91 | return 1; | 92 | return 1; |
92 | 93 | ||
93 | return 0; | 94 | return 0; |
94 | } | 95 | } |
95 | 96 | ||
96 | private: | 97 | private: |
97 | /*int find( const CardViewItem * ) | 98 | /*int find( const CardViewItem * ) |
98 | { | 99 | { |
99 | qDebug("DON'T USE CardViewItemList::find( item )! Use findRef( item )!"); | 100 | qDebug("DON'T USE CardViewItemList::find( item )! Use findRef( item )!"); |
100 | }*/ | 101 | }*/ |
101 | }; | 102 | }; |
102 | 103 | ||
103 | ////////////////////////////////////// | 104 | ////////////////////////////////////// |
104 | // CardViewSeparator | 105 | // CardViewSeparator |
105 | class CardViewSeparator | 106 | class CardViewSeparator |
106 | { | 107 | { |
107 | friend class CardView; | 108 | friend class CardView; |
108 | 109 | ||
109 | public: | 110 | public: |
110 | CardViewSeparator(CardView *view) | 111 | CardViewSeparator(CardView *view) |
111 | : mView(view) | 112 | : mView(view) |
112 | { | 113 | { |
113 | mRect = QRect(0, 0, view->separatorWidth(), 0); | 114 | mRect = QRect(0, 0, view->separatorWidth(), 0); |
114 | } | 115 | } |
115 | 116 | ||
116 | ~CardViewSeparator() {} | 117 | ~CardViewSeparator() {} |
117 | 118 | ||
118 | void paintSeparator(QPainter *p, QColorGroup &cg) | 119 | void paintSeparator(QPainter *p, QColorGroup &cg) |
119 | { | 120 | { |
120 | p->fillRect(0, 0, mRect.width(), mRect.height(), | 121 | p->fillRect(0, 0, mRect.width(), mRect.height(), |
121 | cg.brush(QColorGroup::Button)); | 122 | cg.brush(QColorGroup::Button)); |
122 | } | 123 | } |
123 | 124 | ||
124 | void repaintSeparator() | 125 | void repaintSeparator() |
125 | { | 126 | { |
126 | mView->repaintContents(mRect); | 127 | mView->repaintContents(mRect); |
127 | } | 128 | } |
128 | 129 | ||
129 | private: | 130 | private: |
130 | CardView *mView; | 131 | CardView *mView; |
131 | QRect mRect; | 132 | QRect mRect; |
132 | }; | 133 | }; |
@@ -563,193 +564,192 @@ void CardViewItem::showFullString( const QPoint &itempos, CardViewTip *tip ) | |||
563 | int maxLines = mView->maxFieldLines(); | 564 | int maxLines = mView->maxFieldLines(); |
564 | bool se = mView->showEmptyFields(); | 565 | bool se = mView->showEmptyFields(); |
565 | int fh = mView->d->mFm->height(); | 566 | int fh = mView->d->mFm->height(); |
566 | // { | 567 | // { |
567 | Field *_f; | 568 | Field *_f; |
568 | for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next()) | 569 | for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next()) |
569 | if ( se || ! _f->second.isEmpty() ) | 570 | if ( se || ! _f->second.isEmpty() ) |
570 | y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2; | 571 | y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2; |
571 | // } | 572 | // } |
572 | if ( isLabel && itempos.y() > y + fh ) | 573 | if ( isLabel && itempos.y() > y + fh ) |
573 | return; | 574 | return; |
574 | // label or data? | 575 | // label or data? |
575 | s = isLabel ? f->first : f->second; | 576 | s = isLabel ? f->first : f->second; |
576 | // trimmed? | 577 | // trimmed? |
577 | int colonWidth = mView->d->mFm->width(":"); | 578 | int colonWidth = mView->d->mFm->width(":"); |
578 | lw = drawLabels ? // label width | 579 | lw = drawLabels ? // label width |
579 | QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) : | 580 | QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) : |
580 | 0; | 581 | 0; |
581 | int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string | 582 | int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string |
582 | if ( isLabel ) | 583 | if ( isLabel ) |
583 | { | 584 | { |
584 | trimmed = mView->d->mFm->width( s ) > mw - colonWidth; | 585 | trimmed = mView->d->mFm->width( s ) > mw - colonWidth; |
585 | } else { | 586 | } else { |
586 | QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) ); | 587 | 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); | 588 | trimmed = r.width() > mw || r.height()/fh > QMIN(s.contains('\n') + 1, maxLines); |
588 | } | 589 | } |
589 | } | 590 | } |
590 | if ( trimmed ) | 591 | if ( trimmed ) |
591 | { | 592 | { |
592 | tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header | 593 | tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header |
593 | tip->setText( s ); | 594 | tip->setText( s ); |
594 | tip->adjustSize(); | 595 | tip->adjustSize(); |
595 | // find a proper position | 596 | // find a proper position |
596 | int lx; | 597 | int lx; |
597 | lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/; | 598 | lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/; |
598 | QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) )); | 599 | QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) )); |
599 | pnt += QPoint(lx, y); | 600 | pnt += QPoint(lx, y); |
600 | if ( pnt.x() < 0 ) | 601 | if ( pnt.x() < 0 ) |
601 | pnt.setX( 0 ); | 602 | pnt.setX( 0 ); |
602 | if ( pnt.x() + tip->width() > mView->visibleWidth() ) | 603 | if ( pnt.x() + tip->width() > mView->visibleWidth() ) |
603 | pnt.setX( mView->visibleWidth() - tip->width() ); | 604 | pnt.setX( mView->visibleWidth() - tip->width() ); |
604 | if ( pnt.y() + tip->height() > mView->visibleHeight() ) | 605 | if ( pnt.y() + tip->height() > mView->visibleHeight() ) |
605 | pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) ); | 606 | pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) ); |
606 | // show | 607 | // show |
607 | tip->move( pnt ); | 608 | tip->move( pnt ); |
608 | tip->show(); | 609 | tip->show(); |
609 | } | 610 | } |
610 | } | 611 | } |
611 | 612 | ||
612 | CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const | 613 | CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const |
613 | { | 614 | { |
614 | int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin; | 615 | int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin; |
615 | int iy = itempos.y(); | 616 | int iy = itempos.y(); |
616 | // skip below caption | 617 | // skip below caption |
617 | if ( iy <= ypos ) | 618 | if ( iy <= ypos ) |
618 | return 0; | 619 | return 0; |
619 | // try find a field | 620 | // try find a field |
620 | bool showEmpty = mView->showEmptyFields(); | 621 | bool showEmpty = mView->showEmptyFields(); |
621 | int fh = mView->d->mFm->height(); | 622 | int fh = mView->d->mFm->height(); |
622 | int maxLines = mView->maxFieldLines(); | 623 | int maxLines = mView->maxFieldLines(); |
623 | Field *f; | 624 | Field *f; |
624 | for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) | 625 | for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) |
625 | { | 626 | { |
626 | if ( showEmpty || !f->second.isEmpty() ) | 627 | if ( showEmpty || !f->second.isEmpty() ) |
627 | ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2; | 628 | ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2; |
628 | if ( iy <= ypos ) | 629 | if ( iy <= ypos ) |
629 | break; | 630 | break; |
630 | } | 631 | } |
631 | return f ? f : 0; | 632 | return f ? f : 0; |
632 | } | 633 | } |
633 | //END CardViewItem | 634 | //END CardViewItem |
634 | 635 | ||
635 | //BEGIN CardView | 636 | //BEGIN CardView |
636 | 637 | ||
637 | CardView::CardView(QWidget *parent, const char *name) | 638 | CardView::CardView(QWidget *parent, const char *name) |
638 | : QScrollView(parent, name), | 639 | : QScrollView(parent, name), |
639 | d(new CardViewPrivate()) | 640 | d(new CardViewPrivate()) |
640 | { | 641 | { |
641 | d->mItemList.setAutoDelete(true); | 642 | d->mItemList.setAutoDelete(true); |
642 | d->mSeparatorList.setAutoDelete(true); | 643 | d->mSeparatorList.setAutoDelete(true); |
643 | 644 | ||
644 | QFont f = font(); | 645 | QFont f = font(); |
645 | d->mFm = new QFontMetrics(f); | 646 | d->mFm = new QFontMetrics(f); |
646 | f.setBold(true); | 647 | f.setBold(true); |
647 | d->mHeaderFont = f; | 648 | d->mHeaderFont = f; |
648 | d->mBFm = new QFontMetrics(f); | 649 | d->mBFm = new QFontMetrics(f); |
649 | d->mTip = ( new CardViewTip( viewport() ) ), | 650 | d->mTip = ( new CardViewTip( viewport() ) ), |
650 | d->mTip->hide(); | 651 | d->mTip->hide(); |
651 | d->mTimer = ( new QTimer(this, "mouseTimer") ), | 652 | d->mTimer = ( new QTimer(this, "mouseTimer") ), |
652 | 653 | ||
653 | viewport()->setMouseTracking( true ); | 654 | viewport()->setMouseTracking( true ); |
654 | viewport()->setFocusProxy(this); | 655 | viewport()->setFocusProxy(this); |
655 | viewport()->setFocusPolicy(WheelFocus); | 656 | viewport()->setFocusPolicy(WheelFocus); |
656 | viewport()->setBackgroundMode(PaletteBase); | 657 | viewport()->setBackgroundMode(PaletteBase); |
657 | 658 | ||
658 | connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); | 659 | connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); |
659 | connect( this, SIGNAL(executed(CardViewItem *)), this, SIGNAL( doubleClicked(CardViewItem *)) ); | ||
660 | 660 | ||
661 | //US setBackgroundMode(PaletteBackground, PaletteBase); | 661 | //US setBackgroundMode(PaletteBackground, PaletteBase); |
662 | setBackgroundMode(PaletteBackground); | 662 | setBackgroundMode(PaletteBackground); |
663 | 663 | ||
664 | // no reason for a vertical scrollbar | 664 | // no reason for a vertical scrollbar |
665 | setVScrollBarMode(AlwaysOff); | 665 | setVScrollBarMode(AlwaysOff); |
666 | } | 666 | } |
667 | 667 | ||
668 | CardView::~CardView() | 668 | CardView::~CardView() |
669 | { | 669 | { |
670 | delete d->mFm; | 670 | delete d->mFm; |
671 | delete d->mBFm; | 671 | delete d->mBFm; |
672 | delete d; | 672 | delete d; |
673 | d = 0; | 673 | d = 0; |
674 | } | 674 | } |
675 | 675 | ||
676 | void CardView::insertItem(CardViewItem *item) | 676 | void CardView::insertItem(CardViewItem *item) |
677 | { | 677 | { |
678 | d->mItemList.inSort(item); | 678 | d->mItemList.inSort(item); |
679 | setLayoutDirty(true); | 679 | setLayoutDirty(true); |
680 | } | 680 | } |
681 | 681 | ||
682 | void CardView::takeItem(CardViewItem *item) | 682 | void CardView::takeItem(CardViewItem *item) |
683 | { | 683 | { |
684 | if ( d->mCurrentItem == item ) | 684 | if ( d->mCurrentItem == item ) |
685 | d->mCurrentItem = item->nextItem(); | 685 | d->mCurrentItem = item->nextItem(); |
686 | d->mItemList.take(d->mItemList.findRef(item)); | 686 | d->mItemList.take(d->mItemList.findRef(item)); |
687 | 687 | ||
688 | setLayoutDirty(true); | 688 | setLayoutDirty(true); |
689 | } | 689 | } |
690 | 690 | ||
691 | void CardView::clear() | 691 | void CardView::clear() |
692 | { | 692 | { |
693 | d->mItemList.clear(); | 693 | d->mItemList.clear(); |
694 | 694 | ||
695 | setLayoutDirty(true); | 695 | setLayoutDirty(true); |
696 | } | 696 | } |
697 | 697 | ||
698 | CardViewItem *CardView::currentItem() | 698 | CardViewItem *CardView::currentItem() |
699 | { | 699 | { |
700 | if ( ! d->mCurrentItem && d->mItemList.count() ) | 700 | if ( ! d->mCurrentItem && d->mItemList.count() ) |
701 | d->mCurrentItem = d->mItemList.first(); | 701 | d->mCurrentItem = d->mItemList.first(); |
702 | return d->mCurrentItem; | 702 | return d->mCurrentItem; |
703 | } | 703 | } |
704 | 704 | ||
705 | void CardView::setCurrentItem( CardViewItem *item ) | 705 | void CardView::setCurrentItem( CardViewItem *item ) |
706 | { | 706 | { |
707 | if ( !item ) | 707 | if ( !item ) |
708 | return; | 708 | return; |
709 | else if ( item->cardView() != this ) | 709 | else if ( item->cardView() != this ) |
710 | { | 710 | { |
711 | kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl; | 711 | kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl; |
712 | return; | 712 | return; |
713 | } | 713 | } |
714 | else if ( item == currentItem() ) | 714 | else if ( item == currentItem() ) |
715 | { | 715 | { |
716 | return; | 716 | return; |
717 | } | 717 | } |
718 | 718 | ||
719 | if ( d->mSelectionMode == Single ) | 719 | if ( d->mSelectionMode == Single ) |
720 | { | 720 | { |
721 | setSelected( item, true ); | 721 | setSelected( item, true ); |
722 | } | 722 | } |
723 | else | 723 | else |
724 | { | 724 | { |
725 | CardViewItem *it = d->mCurrentItem; | 725 | CardViewItem *it = d->mCurrentItem; |
726 | d->mCurrentItem = item; | 726 | d->mCurrentItem = item; |
727 | if ( it ) | 727 | if ( it ) |
728 | it->repaintCard(); | 728 | it->repaintCard(); |
729 | item->repaintCard(); | 729 | item->repaintCard(); |
730 | } | 730 | } |
731 | if ( ! d->mOnSeparator ) | 731 | if ( ! d->mOnSeparator ) |
732 | ensureItemVisible( item ); | 732 | ensureItemVisible( item ); |
733 | emit currentChanged( item ); | 733 | emit currentChanged( item ); |
734 | } | 734 | } |
735 | 735 | ||
736 | CardViewItem *CardView::itemAt(const QPoint &viewPos) | 736 | CardViewItem *CardView::itemAt(const QPoint &viewPos) |
737 | { | 737 | { |
738 | CardViewItem *item = 0; | 738 | CardViewItem *item = 0; |
739 | QPtrListIterator<CardViewItem> iter(d->mItemList); | 739 | QPtrListIterator<CardViewItem> iter(d->mItemList); |
740 | bool found = false; | 740 | bool found = false; |
741 | for (iter.toFirst(); iter.current() && !found; ++iter) | 741 | for (iter.toFirst(); iter.current() && !found; ++iter) |
742 | { | 742 | { |
743 | item = *iter; | 743 | item = *iter; |
744 | //if (item->d->mRect.contains(viewPos)) | 744 | //if (item->d->mRect.contains(viewPos)) |
745 | 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)) |
746 | found = true; | 746 | found = true; |
747 | } | 747 | } |
748 | 748 | ||
749 | if (found) | 749 | if (found) |
750 | return item; | 750 | return item; |
751 | 751 | ||
752 | return 0; | 752 | return 0; |
753 | } | 753 | } |
754 | 754 | ||
755 | QRect CardView::itemRect(const CardViewItem *item) | 755 | QRect CardView::itemRect(const CardViewItem *item) |
@@ -1154,210 +1154,210 @@ void CardView::contentsMousePressEvent(QMouseEvent *e) | |||
1154 | 1154 | ||
1155 | else if (d->mSelectionMode == CardView::Multi) | 1155 | else if (d->mSelectionMode == CardView::Multi) |
1156 | { | 1156 | { |
1157 | // toggle the selection | 1157 | // toggle the selection |
1158 | item->setSelected(!item->isSelected()); | 1158 | item->setSelected(!item->isSelected()); |
1159 | item->repaintCard(); | 1159 | item->repaintCard(); |
1160 | emit selectionChanged(); | 1160 | emit selectionChanged(); |
1161 | } | 1161 | } |
1162 | 1162 | ||
1163 | else if (d->mSelectionMode == CardView::Extended) | 1163 | else if (d->mSelectionMode == CardView::Extended) |
1164 | { | 1164 | { |
1165 | if ((e->button() & Qt::LeftButton) && | 1165 | if ((e->button() & Qt::LeftButton) && |
1166 | (e->state() & Qt::ShiftButton)) | 1166 | (e->state() & Qt::ShiftButton)) |
1167 | { | 1167 | { |
1168 | if ( item == other ) return; | 1168 | if ( item == other ) return; |
1169 | 1169 | ||
1170 | bool s = ! item->isSelected(); | 1170 | bool s = ! item->isSelected(); |
1171 | 1171 | ||
1172 | if ( s && ! (e->state() & ControlButton) ) | 1172 | if ( s && ! (e->state() & ControlButton) ) |
1173 | { | 1173 | { |
1174 | bool b = signalsBlocked(); | 1174 | bool b = signalsBlocked(); |
1175 | blockSignals(true); | 1175 | blockSignals(true); |
1176 | selectAll(false); | 1176 | selectAll(false); |
1177 | blockSignals(b); | 1177 | blockSignals(b); |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | int from, to, a, b; | 1180 | int from, to, a, b; |
1181 | a = d->mItemList.findRef( item ); | 1181 | a = d->mItemList.findRef( item ); |
1182 | b = d->mItemList.findRef( other ); | 1182 | b = d->mItemList.findRef( other ); |
1183 | from = a < b ? a : b; | 1183 | from = a < b ? a : b; |
1184 | to = a > b ? a : b; | 1184 | to = a > b ? a : b; |
1185 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; | 1185 | //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl; |
1186 | CardViewItem *aItem; | 1186 | CardViewItem *aItem; |
1187 | for ( ; from <= to; from++ ) | 1187 | for ( ; from <= to; from++ ) |
1188 | { | 1188 | { |
1189 | aItem = d->mItemList.at( from ); | 1189 | aItem = d->mItemList.at( from ); |
1190 | aItem->setSelected( s ); | 1190 | aItem->setSelected( s ); |
1191 | repaintItem( aItem ); | 1191 | repaintItem( aItem ); |
1192 | } | 1192 | } |
1193 | emit selectionChanged(); | 1193 | emit selectionChanged(); |
1194 | } | 1194 | } |
1195 | else if ((e->button() & Qt::LeftButton) && | 1195 | else if ((e->button() & Qt::LeftButton) && |
1196 | (e->state() & Qt::ControlButton)) | 1196 | (e->state() & Qt::ControlButton)) |
1197 | { | 1197 | { |
1198 | item->setSelected(!item->isSelected()); | 1198 | item->setSelected(!item->isSelected()); |
1199 | item->repaintCard(); | 1199 | item->repaintCard(); |
1200 | emit selectionChanged(); | 1200 | emit selectionChanged(); |
1201 | } | 1201 | } |
1202 | 1202 | ||
1203 | else if (e->button() & Qt::LeftButton) | 1203 | else if (e->button() & Qt::LeftButton) |
1204 | { | 1204 | { |
1205 | bool b = signalsBlocked(); | 1205 | bool b = signalsBlocked(); |
1206 | blockSignals(true); | 1206 | blockSignals(true); |
1207 | selectAll(false); | 1207 | selectAll(false); |
1208 | blockSignals(b); | 1208 | blockSignals(b); |
1209 | 1209 | ||
1210 | item->setSelected(true); | 1210 | item->setSelected(true); |
1211 | item->repaintCard(); | 1211 | item->repaintCard(); |
1212 | emit selectionChanged(); | 1212 | emit selectionChanged(); |
1213 | } | 1213 | } |
1214 | } | 1214 | } |
1215 | 1215 | ||
1216 | } | 1216 | } |
1217 | 1217 | ||
1218 | void CardView::contentsMouseReleaseEvent(QMouseEvent *e) | 1218 | void CardView::contentsMouseReleaseEvent(QMouseEvent *e) |
1219 | { | 1219 | { |
1220 | QScrollView::contentsMouseReleaseEvent(e); | 1220 | QScrollView::contentsMouseReleaseEvent(e); |
1221 | 1221 | ||
1222 | if ( d->mResizeAnchor ) | 1222 | if ( d->mResizeAnchor ) |
1223 | { | 1223 | { |
1224 | // finish the resizing: | 1224 | // finish the resizing: |
1225 | unsetCursor(); | 1225 | unsetCursor(); |
1226 | // hide rubber bands | 1226 | // hide rubber bands |
1227 | int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span); | 1227 | int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span); |
1228 | drawRubberBands( 0 ); | 1228 | drawRubberBands( 0 ); |
1229 | // 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. |
1230 | if ( contentsX() ) | 1230 | if ( contentsX() ) |
1231 | { | 1231 | { |
1232 | 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() ); |
1233 | setContentsPos( newX, contentsY() ); | 1233 | setContentsPos( newX, contentsY() ); |
1234 | } | 1234 | } |
1235 | // set new item width | 1235 | // set new item width |
1236 | setItemWidth( newiw ); | 1236 | setItemWidth( newiw ); |
1237 | // reset anchors | 1237 | // reset anchors |
1238 | d->mResizeAnchor = 0; | 1238 | d->mResizeAnchor = 0; |
1239 | d->mRubberBandAnchor = 0; | 1239 | d->mRubberBandAnchor = 0; |
1240 | return; | 1240 | return; |
1241 | } | 1241 | } |
1242 | 1242 | ||
1243 | // If there are accel keys, we will not emit signals | 1243 | // If there are accel keys, we will not emit signals |
1244 | if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton)) | 1244 | if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton)) |
1245 | return; | 1245 | return; |
1246 | 1246 | ||
1247 | // Get the item at this position | 1247 | // Get the item at this position |
1248 | CardViewItem *item = itemAt(e->pos()); | 1248 | CardViewItem *item = itemAt(e->pos()); |
1249 | 1249 | ||
1250 | if (item && KGlobalSettings::singleClick()) | 1250 | if (item && KABPrefs::instance()->mHonorSingleClick) |
1251 | { | 1251 | { |
1252 | emit executed(item); | 1252 | emit executed(item); |
1253 | } | 1253 | } |
1254 | } | 1254 | } |
1255 | 1255 | ||
1256 | void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e) | 1256 | void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e) |
1257 | { | 1257 | { |
1258 | QScrollView::contentsMouseDoubleClickEvent(e); | 1258 | QScrollView::contentsMouseDoubleClickEvent(e); |
1259 | 1259 | ||
1260 | CardViewItem *item = itemAt(e->pos()); | 1260 | CardViewItem *item = itemAt(e->pos()); |
1261 | 1261 | ||
1262 | if (item) | 1262 | if (item) |
1263 | { | 1263 | { |
1264 | d->mCurrentItem = item; | 1264 | d->mCurrentItem = item; |
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | if (item && !KGlobalSettings::singleClick()) | 1267 | if (item && !KABPrefs::instance()->mHonorSingleClick) |
1268 | { | 1268 | { |
1269 | emit executed(item); | 1269 | emit executed(item); |
1270 | } else | 1270 | } else |
1271 | emit doubleClicked(item); | 1271 | emit doubleClicked(item); |
1272 | } | 1272 | } |
1273 | 1273 | ||
1274 | void CardView::contentsMouseMoveEvent( QMouseEvent *e ) | 1274 | void CardView::contentsMouseMoveEvent( QMouseEvent *e ) |
1275 | { | 1275 | { |
1276 | // resizing | 1276 | // resizing |
1277 | if ( d->mResizeAnchor ) | 1277 | if ( d->mResizeAnchor ) |
1278 | { | 1278 | { |
1279 | int x = e->x(); | 1279 | int x = e->x(); |
1280 | if ( x != d->mRubberBandAnchor ) | 1280 | if ( x != d->mRubberBandAnchor ) |
1281 | drawRubberBands( x ); | 1281 | drawRubberBands( x ); |
1282 | return; | 1282 | return; |
1283 | } | 1283 | } |
1284 | 1284 | ||
1285 | if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) && | 1285 | if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) && |
1286 | ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) { | 1286 | ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) { |
1287 | 1287 | ||
1288 | startDrag(); | 1288 | startDrag(); |
1289 | return; | 1289 | return; |
1290 | } | 1290 | } |
1291 | 1291 | ||
1292 | d->mTimer->start( 500 ); | 1292 | d->mTimer->start( 500 ); |
1293 | 1293 | ||
1294 | // see if we are over a separator | 1294 | // see if we are over a separator |
1295 | // only if we actually have them painted? | 1295 | // only if we actually have them painted? |
1296 | if ( d->mDrawSeparators ) | 1296 | if ( d->mDrawSeparators ) |
1297 | { | 1297 | { |
1298 | int colcontentw = d->mItemWidth + (2*d->mItemSpacing); | 1298 | int colcontentw = d->mItemWidth + (2*d->mItemSpacing); |
1299 | int colw = colcontentw + d->mSepWidth; | 1299 | int colw = colcontentw + d->mSepWidth; |
1300 | int m = e->x()%colw; | 1300 | int m = e->x()%colw; |
1301 | if ( m >= colcontentw && m > 0 ) | 1301 | if ( m >= colcontentw && m > 0 ) |
1302 | { | 1302 | { |
1303 | setCursor( SplitVCursor ); // Why does this fail sometimes? | 1303 | setCursor( SplitVCursor ); // Why does this fail sometimes? |
1304 | d->mOnSeparator = true; | 1304 | d->mOnSeparator = true; |
1305 | } | 1305 | } |
1306 | else | 1306 | else |
1307 | { | 1307 | { |
1308 | setCursor( ArrowCursor ); | 1308 | setCursor( ArrowCursor ); |
1309 | d->mOnSeparator = false; | 1309 | d->mOnSeparator = false; |
1310 | } | 1310 | } |
1311 | } | 1311 | } |
1312 | } | 1312 | } |
1313 | 1313 | ||
1314 | void CardView::enterEvent( QEvent * ) | 1314 | void CardView::enterEvent( QEvent * ) |
1315 | { | 1315 | { |
1316 | d->mTimer->start( 500 ); | 1316 | d->mTimer->start( 500 ); |
1317 | } | 1317 | } |
1318 | 1318 | ||
1319 | void CardView::leaveEvent( QEvent * ) | 1319 | void CardView::leaveEvent( QEvent * ) |
1320 | { | 1320 | { |
1321 | d->mTimer->stop(); | 1321 | d->mTimer->stop(); |
1322 | if (d->mOnSeparator) | 1322 | if (d->mOnSeparator) |
1323 | { | 1323 | { |
1324 | d->mOnSeparator = false; | 1324 | d->mOnSeparator = false; |
1325 | setCursor( ArrowCursor ); | 1325 | setCursor( ArrowCursor ); |
1326 | } | 1326 | } |
1327 | } | 1327 | } |
1328 | 1328 | ||
1329 | void CardView::focusInEvent( QFocusEvent * ) | 1329 | void CardView::focusInEvent( QFocusEvent * ) |
1330 | { | 1330 | { |
1331 | if (!d->mCurrentItem && d->mItemList.count() ) | 1331 | if (!d->mCurrentItem && d->mItemList.count() ) |
1332 | { | 1332 | { |
1333 | setCurrentItem( d->mItemList.first() ); | 1333 | setCurrentItem( d->mItemList.first() ); |
1334 | } | 1334 | } |
1335 | else if ( d->mCurrentItem ) | 1335 | else if ( d->mCurrentItem ) |
1336 | { | 1336 | { |
1337 | d->mCurrentItem->repaintCard(); | 1337 | d->mCurrentItem->repaintCard(); |
1338 | } | 1338 | } |
1339 | } | 1339 | } |
1340 | 1340 | ||
1341 | void CardView::focusOutEvent( QFocusEvent * ) | 1341 | void CardView::focusOutEvent( QFocusEvent * ) |
1342 | { | 1342 | { |
1343 | if (d->mCurrentItem) | 1343 | if (d->mCurrentItem) |
1344 | d->mCurrentItem->repaintCard(); | 1344 | d->mCurrentItem->repaintCard(); |
1345 | } | 1345 | } |
1346 | 1346 | ||
1347 | void CardView::keyPressEvent( QKeyEvent *e ) | 1347 | void CardView::keyPressEvent( QKeyEvent *e ) |
1348 | { | 1348 | { |
1349 | if ( ! ( childCount() && d->mCurrentItem ) ) | 1349 | if ( ! ( childCount() && d->mCurrentItem ) ) |
1350 | { | 1350 | { |
1351 | e->ignore(); | 1351 | e->ignore(); |
1352 | return; | 1352 | return; |
1353 | } | 1353 | } |
1354 | 1354 | ||
1355 | uint pos = d->mItemList.findRef( d->mCurrentItem ); | 1355 | uint pos = d->mItemList.findRef( d->mCurrentItem ); |
1356 | CardViewItem *aItem = 0L; // item that gets the focus | 1356 | CardViewItem *aItem = 0L; // item that gets the focus |
1357 | CardViewItem *old = d->mCurrentItem; | 1357 | CardViewItem *old = d->mCurrentItem; |
1358 | 1358 | ||
1359 | switch ( e->key() ) | 1359 | switch ( e->key() ) |
1360 | { | 1360 | { |
1361 | case Key_Up: | 1361 | case Key_Up: |
1362 | if ( pos > 0 ) | 1362 | if ( pos > 0 ) |
1363 | { | 1363 | { |
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp index 7f33bb4..15f154e 100644 --- a/kaddressbook/views/kaddressbookcardview.cpp +++ b/kaddressbook/views/kaddressbookcardview.cpp | |||
@@ -149,202 +149,207 @@ KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, | |||
149 | mShowEmptyFields = false; | 149 | mShowEmptyFields = false; |
150 | 150 | ||
151 | // Init the GUI | 151 | // Init the GUI |
152 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); | 152 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); |
153 | 153 | ||
154 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); | 154 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); |
155 | mCardView->setSelectionMode(CardView::Extended); | 155 | mCardView->setSelectionMode(CardView::Extended); |
156 | layout->addWidget(mCardView); | 156 | layout->addWidget(mCardView); |
157 | 157 | ||
158 | // Connect up the signals | 158 | // Connect up the signals |
159 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 159 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
160 | this, SLOT(addresseeExecuted(CardViewItem *))); | 160 | this, SLOT(addresseeExecuted(CardViewItem *))); |
161 | connect(mCardView, SIGNAL(selectionChanged()), | 161 | connect(mCardView, SIGNAL(selectionChanged()), |
162 | this, SLOT(addresseeSelected())); | 162 | this, SLOT(addresseeSelected())); |
163 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), | 163 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), |
164 | this, SIGNAL(dropped(QDropEvent*))); | 164 | this, SIGNAL(dropped(QDropEvent*))); |
165 | connect(mCardView, SIGNAL(startAddresseeDrag()), | 165 | connect(mCardView, SIGNAL(startAddresseeDrag()), |
166 | this, SIGNAL(startDrag())); | 166 | this, SIGNAL(startDrag())); |
167 | } | 167 | } |
168 | 168 | ||
169 | KAddressBookCardView::~KAddressBookCardView() | 169 | KAddressBookCardView::~KAddressBookCardView() |
170 | { | 170 | { |
171 | } | 171 | } |
172 | void KAddressBookCardView::setFocusAV() | 172 | void KAddressBookCardView::setFocusAV() |
173 | { | 173 | { |
174 | if ( mCardView ) | 174 | if ( mCardView ) |
175 | mCardView->setFocus(); | 175 | mCardView->setFocus(); |
176 | 176 | ||
177 | } | 177 | } |
178 | void KAddressBookCardView::scrollUP() | 178 | void KAddressBookCardView::scrollUP() |
179 | { | 179 | { |
180 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); | 180 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); |
181 | QApplication::postEvent( mCardView, ev ); | 181 | QApplication::postEvent( mCardView, ev ); |
182 | 182 | ||
183 | } | 183 | } |
184 | void KAddressBookCardView::scrollDOWN() | 184 | void KAddressBookCardView::scrollDOWN() |
185 | { | 185 | { |
186 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); | 186 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); |
187 | QApplication::postEvent( mCardView, ev ); | 187 | QApplication::postEvent( mCardView, ev ); |
188 | } | 188 | } |
189 | void KAddressBookCardView::readConfig(KConfig *config) | 189 | void KAddressBookCardView::readConfig(KConfig *config) |
190 | { | 190 | { |
191 | KAddressBookView::readConfig(config); | 191 | KAddressBookView::readConfig(config); |
192 | 192 | ||
193 | // costum colors? | 193 | // costum colors? |
194 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) | 194 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) |
195 | { | 195 | { |
196 | QPalette p( mCardView->palette() ); | 196 | QPalette p( mCardView->palette() ); |
197 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); | 197 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); |
198 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); | 198 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); |
199 | c = p.color(QPalette::Normal, QColorGroup::Text ); | 199 | c = p.color(QPalette::Normal, QColorGroup::Text ); |
200 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); | 200 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); |
201 | c = p.color(QPalette::Normal, QColorGroup::Button ); | 201 | c = p.color(QPalette::Normal, QColorGroup::Button ); |
202 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); | 202 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); |
203 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); | 203 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); |
204 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); | 204 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); |
205 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); | 205 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); |
206 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); | 206 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); |
207 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); | 207 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); |
208 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); | 208 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); |
209 | mCardView->viewport()->setPalette( p ); | 209 | mCardView->viewport()->setPalette( p ); |
210 | } | 210 | } |
211 | else | 211 | else |
212 | { | 212 | { |
213 | // needed if turned off during a session. | 213 | // needed if turned off during a session. |
214 | mCardView->viewport()->setPalette( mCardView->palette() ); | 214 | mCardView->viewport()->setPalette( mCardView->palette() ); |
215 | } | 215 | } |
216 | 216 | ||
217 | //custom fonts? | 217 | //custom fonts? |
218 | QFont f( font() ); | 218 | QFont f( font() ); |
219 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | 219 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) |
220 | { | 220 | { |
221 | mCardView->setFont( config->readFontEntry( "TextFont", &f) ); | 221 | mCardView->setFont( config->readFontEntry( "TextFont", &f) ); |
222 | f.setBold( true ); | 222 | f.setBold( true ); |
223 | mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | 223 | mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); |
224 | } | 224 | } |
225 | else | 225 | else |
226 | { | 226 | { |
227 | mCardView->setFont( f ); | 227 | mCardView->setFont( f ); |
228 | f.setBold( true ); | 228 | f.setBold( true ); |
229 | mCardView->setHeaderFont( f ); | 229 | mCardView->setHeaderFont( f ); |
230 | } | 230 | } |
231 | 231 | ||
232 | mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); | 232 | mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); |
233 | mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", | 233 | mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", |
234 | true)); | 234 | true)); |
235 | mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); | 235 | mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); |
236 | mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); | 236 | mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); |
237 | 237 | ||
238 | mCardView->setShowEmptyFields( mShowEmptyFields ); | 238 | mCardView->setShowEmptyFields( mShowEmptyFields ); |
239 | 239 | ||
240 | mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); | 240 | mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); |
241 | mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); | 241 | mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); |
242 | mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); | 242 | mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); |
243 | mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); | 243 | mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); |
244 | 244 | ||
245 | #if 0 | ||
246 | // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven | ||
245 | disconnect(mCardView, SIGNAL(executed(CardViewItem *)), | 247 | disconnect(mCardView, SIGNAL(executed(CardViewItem *)), |
246 | this, SLOT(addresseeExecuted(CardViewItem *))); | 248 | this, SLOT(addresseeExecuted(CardViewItem *))); |
247 | 249 | ||
248 | if (KABPrefs::instance()->mHonorSingleClick) | 250 | if (KABPrefs::instance()->mHonorSingleClick) |
249 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 251 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
250 | this, SLOT(addresseeExecuted(CardViewItem *))); | 252 | this, SLOT(addresseeExecuted(CardViewItem *))); |
251 | else | 253 | else |
252 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), | 254 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), |
253 | this, SLOT(addresseeExecuted(CardViewItem *))); | 255 | this, SLOT(addresseeExecuted(CardViewItem *))); |
256 | #endif | ||
254 | 257 | ||
258 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), | ||
259 | this, SLOT(addresseeExecuted(CardViewItem *))); | ||
255 | } | 260 | } |
256 | 261 | ||
257 | void KAddressBookCardView::writeConfig( KConfig *config ) | 262 | void KAddressBookCardView::writeConfig( KConfig *config ) |
258 | { | 263 | { |
259 | config->writeEntry( "ItemWidth", mCardView->itemWidth() ); | 264 | config->writeEntry( "ItemWidth", mCardView->itemWidth() ); |
260 | KAddressBookView::writeConfig( config ); | 265 | KAddressBookView::writeConfig( config ); |
261 | } | 266 | } |
262 | void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) | 267 | void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) |
263 | { | 268 | { |
264 | mCardView->clear(); | 269 | mCardView->clear(); |
265 | if ( s.isEmpty() || s == "*" ) { | 270 | if ( s.isEmpty() || s == "*" ) { |
266 | refresh(); | 271 | refresh(); |
267 | return; | 272 | return; |
268 | } | 273 | } |
269 | QString pattern = s.lower()+"*"; | 274 | QString pattern = s.lower()+"*"; |
270 | QRegExp re; | 275 | QRegExp re; |
271 | re.setWildcard(true); // most people understand these better. | 276 | re.setWildcard(true); // most people understand these better. |
272 | re.setCaseSensitive(false); | 277 | re.setCaseSensitive(false); |
273 | re.setPattern( pattern ); | 278 | re.setPattern( pattern ); |
274 | if (!re.isValid()) | 279 | if (!re.isValid()) |
275 | return; | 280 | return; |
276 | mCardView->viewport()->setUpdatesEnabled( false ); | 281 | mCardView->viewport()->setUpdatesEnabled( false ); |
277 | KABC::Addressee::List addresseeList = addressees(); | 282 | KABC::Addressee::List addresseeList = addressees(); |
278 | KABC::Addressee::List::Iterator it; | 283 | KABC::Addressee::List::Iterator it; |
279 | if ( field ) { | 284 | if ( field ) { |
280 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 285 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
281 | #if QT_VERSION >= 300 | 286 | #if QT_VERSION >= 300 |
282 | if (re.search(field->value( *it ).lower()) != -1) | 287 | if (re.search(field->value( *it ).lower()) != -1) |
283 | #else | 288 | #else |
284 | if (re.match(field->value( *it ).lower()) != -1) | 289 | if (re.match(field->value( *it ).lower()) != -1) |
285 | #endif | 290 | #endif |
286 | new AddresseeCardViewItem(fields(), mShowEmptyFields, | 291 | new AddresseeCardViewItem(fields(), mShowEmptyFields, |
287 | addressBook(), *it, mCardView); | 292 | addressBook(), *it, mCardView); |
288 | 293 | ||
289 | } | 294 | } |
290 | } else { | 295 | } else { |
291 | KABC::Field::List fieldList = fields(); | 296 | KABC::Field::List fieldList = fields(); |
292 | KABC::Field::List::ConstIterator fieldIt; | 297 | KABC::Field::List::ConstIterator fieldIt; |
293 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 298 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
294 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 299 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
295 | #if QT_VERSION >= 300 | 300 | #if QT_VERSION >= 300 |
296 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) | 301 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) |
297 | #else | 302 | #else |
298 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) | 303 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) |
299 | #endif | 304 | #endif |
300 | { | 305 | { |
301 | new AddresseeCardViewItem(fields(), mShowEmptyFields, | 306 | new AddresseeCardViewItem(fields(), mShowEmptyFields, |
302 | addressBook(), *it, mCardView); | 307 | addressBook(), *it, mCardView); |
303 | continue; | 308 | continue; |
304 | } | 309 | } |
305 | } | 310 | } |
306 | } | 311 | } |
307 | } | 312 | } |
308 | mCardView->viewport()->setUpdatesEnabled( true ); | 313 | mCardView->viewport()->setUpdatesEnabled( true ); |
309 | mCardView->viewport()->update(); | 314 | mCardView->viewport()->update(); |
310 | if ( mCardView->firstItem() ) { | 315 | if ( mCardView->firstItem() ) { |
311 | mCardView->setCurrentItem ( mCardView->firstItem() ); | 316 | mCardView->setCurrentItem ( mCardView->firstItem() ); |
312 | mCardView->setSelected ( mCardView->firstItem() , true ); | 317 | mCardView->setSelected ( mCardView->firstItem() , true ); |
313 | } | 318 | } |
314 | else | 319 | else |
315 | emit selected(QString::null); | 320 | emit selected(QString::null); |
316 | } | 321 | } |
317 | QStringList KAddressBookCardView::selectedUids() | 322 | QStringList KAddressBookCardView::selectedUids() |
318 | { | 323 | { |
319 | QStringList uidList; | 324 | QStringList uidList; |
320 | CardViewItem *item; | 325 | CardViewItem *item; |
321 | AddresseeCardViewItem *aItem; | 326 | AddresseeCardViewItem *aItem; |
322 | 327 | ||
323 | for (item = mCardView->firstItem(); item; item = item->nextItem()) | 328 | for (item = mCardView->firstItem(); item; item = item->nextItem()) |
324 | { | 329 | { |
325 | if (item->isSelected()) | 330 | if (item->isSelected()) |
326 | { | 331 | { |
327 | #ifndef KAB_EMBEDDED | 332 | #ifndef KAB_EMBEDDED |
328 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 333 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
329 | #else //KAB_EMBEDDED | 334 | #else //KAB_EMBEDDED |
330 | aItem = (AddresseeCardViewItem*)(item); | 335 | aItem = (AddresseeCardViewItem*)(item); |
331 | #endif //KAB_EMBEDDED | 336 | #endif //KAB_EMBEDDED |
332 | if (aItem) | 337 | if (aItem) |
333 | uidList << aItem->addressee().uid(); | 338 | uidList << aItem->addressee().uid(); |
334 | } | 339 | } |
335 | } | 340 | } |
336 | 341 | ||
337 | return uidList; | 342 | return uidList; |
338 | } | 343 | } |
339 | 344 | ||
340 | void KAddressBookCardView::refresh(QString uid) | 345 | void KAddressBookCardView::refresh(QString uid) |
341 | { | 346 | { |
342 | CardViewItem *item; | 347 | CardViewItem *item; |
343 | AddresseeCardViewItem *aItem; | 348 | AddresseeCardViewItem *aItem; |
344 | 349 | ||
345 | if (uid.isNull()) | 350 | if (uid.isNull()) |
346 | { | 351 | { |
347 | // Rebuild the view | 352 | // Rebuild the view |
348 | mCardView->viewport()->setUpdatesEnabled( false ); | 353 | mCardView->viewport()->setUpdatesEnabled( false ); |
349 | mCardView->clear(); | 354 | mCardView->clear(); |
350 | 355 | ||