summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Unidiff
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/cardview.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/kaddressbook/views/cardview.cpp b/kaddressbook/views/cardview.cpp
index 84d3116..b6e053f 100644
--- a/kaddressbook/views/cardview.cpp
+++ b/kaddressbook/views/cardview.cpp
@@ -747,402 +747,401 @@ CardViewItem *CardView::itemAt(const QPoint &viewPos)
747 //if (item->d->mRect.contains(viewPos)) 747 //if (item->d->mRect.contains(viewPos))
748 if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos)) 748 if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos))
749 found = true; 749 found = true;
750 } 750 }
751 751
752 if (found) 752 if (found)
753 return item; 753 return item;
754 754
755 return 0; 755 return 0;
756} 756}
757 757
758QRect CardView::itemRect(const CardViewItem *item) 758QRect CardView::itemRect(const CardViewItem *item)
759{ 759{
760 //return item->d->mRect; 760 //return item->d->mRect;
761 return QRect(item->d->x, item->d->y, d->mItemWidth, item->height()); 761 return QRect(item->d->x, item->d->y, d->mItemWidth, item->height());
762} 762}
763 763
764void CardView::ensureItemVisible(const CardViewItem *item) 764void CardView::ensureItemVisible(const CardViewItem *item)
765{ 765{
766 ensureVisible(item->d->x , item->d->y, d->mItemSpacing, 0); 766 ensureVisible(item->d->x , item->d->y, d->mItemSpacing, 0);
767 ensureVisible(item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0); 767 ensureVisible(item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0);
768} 768}
769 769
770void CardView::repaintItem(const CardViewItem *item) 770void CardView::repaintItem(const CardViewItem *item)
771{ 771{
772 //repaintContents(item->d->mRect); 772 //repaintContents(item->d->mRect);
773 repaintContents( QRect(item->d->x, item->d->y, d->mItemWidth, item->height()) ); 773 repaintContents( QRect(item->d->x, item->d->y, d->mItemWidth, item->height()) );
774} 774}
775 775
776void CardView::setSelectionMode(CardView::SelectionMode mode) 776void CardView::setSelectionMode(CardView::SelectionMode mode)
777{ 777{
778 selectAll(false); 778 selectAll(false);
779 779
780 d->mSelectionMode = mode; 780 d->mSelectionMode = mode;
781} 781}
782 782
783CardView::SelectionMode CardView::selectionMode() const 783CardView::SelectionMode CardView::selectionMode() const
784{ 784{
785 return d->mSelectionMode; 785 return d->mSelectionMode;
786} 786}
787 787
788void CardView::selectAll(bool state) 788void CardView::selectAll(bool state)
789{ 789{
790 QPtrListIterator<CardViewItem> iter(d->mItemList); 790 QPtrListIterator<CardViewItem> iter(d->mItemList);
791 if (!state) 791 if (!state)
792 { 792 {
793 for (iter.toFirst(); iter.current(); ++iter) 793 for (iter.toFirst(); iter.current(); ++iter)
794 { 794 {
795 if ((*iter)->isSelected()) 795 if ((*iter)->isSelected())
796 { 796 {
797 (*iter)->setSelected(false); 797 (*iter)->setSelected(false);
798 (*iter)->repaintCard(); 798 (*iter)->repaintCard();
799 } 799 }
800 } 800 }
801 //emit selectionChanged(); // WARNING FIXME 801 //emit selectionChanged(); // WARNING FIXME
802 emit selectionChanged(0); 802 emit selectionChanged(0);
803 } 803 }
804 else if (d->mSelectionMode != CardView::Single) 804 else if (d->mSelectionMode != CardView::Single)
805 { 805 {
806 for (iter.toFirst(); iter.current(); ++iter) 806 for (iter.toFirst(); iter.current(); ++iter)
807 { 807 {
808 (*iter)->setSelected(true); 808 (*iter)->setSelected(true);
809 } 809 }
810 810
811 if (d->mItemList.count() > 0) 811 if (d->mItemList.count() > 0)
812 { 812 {
813 // emit, since there must have been at least one selected 813 // emit, since there must have been at least one selected
814 emit selectionChanged(); 814 emit selectionChanged();
815 //repaint();//??? 815 //repaint();//???
816 viewport()->update(); 816 viewport()->update();
817 } 817 }
818 } 818 }
819} 819}
820 820
821void CardView::setSelected(CardViewItem *item, bool selected) 821void CardView::setSelected(CardViewItem *item, bool selected)
822{ 822{
823 if ((item == 0) || (item->isSelected() == selected)) 823 if ((item == 0) || (item->isSelected() == selected))
824 return; 824 return;
825 825
826 if ( selected && d->mCurrentItem != item ) 826 if ( selected && d->mCurrentItem != item )
827 { 827 {
828 CardViewItem *it = d->mCurrentItem; 828 CardViewItem *it = d->mCurrentItem;
829 d->mCurrentItem = item; 829 d->mCurrentItem = item;
830 if ( it ) 830 if ( it )
831 it->repaintCard(); 831 it->repaintCard();
832 } 832 }
833 833
834 if (d->mSelectionMode == CardView::Single) 834 if (d->mSelectionMode == CardView::Single)
835 { 835 {
836 bool b = signalsBlocked(); 836 bool b = signalsBlocked();
837 blockSignals(true); 837 blockSignals(true);
838 selectAll(false); 838 selectAll(false);
839 blockSignals(b); 839 blockSignals(b);
840 840
841 if (selected) 841 if (selected)
842 { 842 {
843 item->setSelected(selected); 843 item->setSelected(selected);
844 item->repaintCard(); 844 item->repaintCard();
845 emit selectionChanged(); 845 emit selectionChanged();
846 emit selectionChanged(item); 846 emit selectionChanged(item);
847 } 847 }
848 else 848 else
849 { 849 {
850 emit selectionChanged(); 850 emit selectionChanged();
851 emit selectionChanged(0); 851 emit selectionChanged(0);
852 } 852 }
853 } 853 }
854 else if (d->mSelectionMode == CardView::Multi) 854 else if (d->mSelectionMode == CardView::Multi)
855 { 855 {
856 item->setSelected(selected); 856 item->setSelected(selected);
857 item->repaintCard(); 857 item->repaintCard();
858 emit selectionChanged(); 858 emit selectionChanged();
859 } 859 }
860 else if (d->mSelectionMode == CardView::Extended) 860 else if (d->mSelectionMode == CardView::Extended)
861 { 861 {
862 bool b = signalsBlocked(); 862 bool b = signalsBlocked();
863 blockSignals(true); 863 blockSignals(true);
864 selectAll(false); 864 selectAll(false);
865 blockSignals(b); 865 blockSignals(b);
866 866
867 item->setSelected(selected); 867 item->setSelected(selected);
868 item->repaintCard(); 868 item->repaintCard();
869 emit selectionChanged(); 869 emit selectionChanged();
870 } 870 }
871} 871}
872 872
873bool CardView::isSelected(CardViewItem *item) const 873bool CardView::isSelected(CardViewItem *item) const
874{ 874{
875 return (item && item->isSelected()); 875 return (item && item->isSelected());
876} 876}
877 877
878CardViewItem *CardView::selectedItem() const 878CardViewItem *CardView::selectedItem() const
879{ 879{
880 // find the first selected item 880 // find the first selected item
881 QPtrListIterator<CardViewItem> iter(d->mItemList); 881 QPtrListIterator<CardViewItem> iter(d->mItemList);
882 for (iter.toFirst(); iter.current(); ++iter) 882 for (iter.toFirst(); iter.current(); ++iter)
883 { 883 {
884 if ((*iter)->isSelected()) 884 if ((*iter)->isSelected())
885 return *iter; 885 return *iter;
886 } 886 }
887 887
888 return 0; 888 return 0;
889} 889}
890 890
891CardViewItem *CardView::firstItem() const 891CardViewItem *CardView::firstItem() const
892{ 892{
893 return d->mItemList.first(); 893 return d->mItemList.first();
894} 894}
895 895
896int CardView::childCount() const 896int CardView::childCount() const
897{ 897{
898 return d->mItemList.count(); 898 return d->mItemList.count();
899} 899}
900/*US 900/*US
901CardViewItem *CardView::findItem(const QString &text, const QString &label, 901CardViewItem *CardView::findItem(const QString &text, const QString &label,
902 Qt::StringComparisonMode compare) 902 Qt::StringComparisonMode compare)
903{ 903{
904 // IF the text is empty, we will return null, since empty text will 904 // IF the text is empty, we will return null, since empty text will
905 // match anything! 905 // match anything!
906 if (text.isEmpty()) 906 if (text.isEmpty())
907 return 0; 907 return 0;
908 908
909 QPtrListIterator<CardViewItem> iter(d->mItemList); 909 QPtrListIterator<CardViewItem> iter(d->mItemList);
910 if (compare & Qt::BeginsWith) 910 if (compare & Qt::BeginsWith)
911 { 911 {
912 QString value; 912 QString value;
913 for (iter.toFirst(); iter.current(); ++iter) 913 for (iter.toFirst(); iter.current(); ++iter)
914 { 914 {
915 value = (*iter)->fieldValue(label).upper(); 915 value = (*iter)->fieldValue(label).upper();
916 if (value.startsWith(text.upper())) 916 if (value.startsWith(text.upper()))
917 return *iter; 917 return *iter;
918 } 918 }
919 } 919 }
920 else 920 else
921 { 921 {
922 kdDebug(5720) << "CardView::findItem: search method not implemented" << endl; 922 kdDebug(5720) << "CardView::findItem: search method not implemented" << endl;
923 } 923 }
924 924
925 return 0; 925 return 0;
926} 926}
927*/ 927*/
928 928
929uint CardView::columnWidth() 929uint CardView::columnWidth()
930{ 930{
931 return d->mDrawSeparators ? 931 return d->mDrawSeparators ?
932 d->mItemWidth + ( 2 * d->mItemSpacing ) + d->mSepWidth : 932 d->mItemWidth + ( 2 * d->mItemSpacing ) + d->mSepWidth :
933 d->mItemWidth + d->mItemSpacing; 933 d->mItemWidth + d->mItemSpacing;
934} 934}
935 935
936void CardView::drawContents(QPainter *p, int clipx, int clipy, 936void CardView::drawContents(QPainter *p, int clipx, int clipy,
937 int clipw, int cliph) 937 int clipw, int cliph)
938{ 938{
939 QScrollView::drawContents(p, clipx, clipy, clipw, cliph); 939 //QScrollView::drawContents(p, clipx, clipy, clipw, cliph);
940
941 if (d->mLayoutDirty) 940 if (d->mLayoutDirty)
942 calcLayout(); 941 calcLayout();
943 942
944 //kdDebug() << "CardView::drawContents: " << clipx << ", " << clipy 943 //kdDebug() << "CardView::drawContents: " << clipx << ", " << clipy
945 // << ", " << clipw << ", " << cliph << endl; 944 // << ", " << clipw << ", " << cliph << endl;
946 945
947 QColorGroup cg = viewport()->palette().active(); // allow setting costum colors in the viewport pale 946 QColorGroup cg = viewport()->palette().active(); // allow setting costum colors in the viewport pale
948 947 int cX, cY;
948 contentsToViewport ( clipx, clipy, cX, cY );
949 QRect clipRect(clipx, clipy, clipw, cliph); 949 QRect clipRect(clipx, clipy, clipw, cliph);
950 QRect cardRect; 950 QRect cardRect;
951 QRect sepRect; 951 QRect sepRect;
952 CardViewItem *item; 952 CardViewItem *item;
953 CardViewSeparator *sep; 953 CardViewSeparator *sep;
954
955 // make sure the viewport is a pure background 954 // make sure the viewport is a pure background
956 viewport()->erase(clipRect); 955 viewport()->erase( QRect ( cX, cY , clipw, cliph ) );
957 956
958 // Now tell the cards to draw, if they are in the clip region 957 // Now tell the cards to draw, if they are in the clip region
959 QPtrListIterator<CardViewItem> iter(d->mItemList); 958 QPtrListIterator<CardViewItem> iter(d->mItemList);
960 for (iter.toFirst(); iter.current(); ++iter) 959 for (iter.toFirst(); iter.current(); ++iter)
961 { 960 {
962 item = *iter; 961 item = *iter;
963 cardRect.setRect( item->d->x, item->d->y, d->mItemWidth, item->height() ); 962 cardRect.setRect( item->d->x, item->d->y, d->mItemWidth, item->height() );
964 963
965 if (clipRect.intersects(cardRect) || clipRect.contains(cardRect)) 964 if (clipRect.intersects(cardRect) || clipRect.contains(cardRect))
966 { 965 {
967 //kdDebug() << "\trepainting card at: " << cardRect.x() << ", " 966 //kdDebug() << "\trepainting card at: " << cardRect.x() << ", "
968 // << cardRect.y() << endl; 967 // << cardRect.y() << endl;
969 968
970 // Tell the card to paint 969 // Tell the card to paint
971 p->save(); 970 p->save();
972 p->translate(cardRect.x(), cardRect.y()); 971 p->translate(cardRect.x(), cardRect.y());
973 item->paintCard(p, cg); 972 item->paintCard(p, cg);
974 p->restore(); 973 p->restore();
975 } 974 }
976 } 975 }
977 976
978 // Followed by the separators if they are in the clip region 977 // Followed by the separators if they are in the clip region
979 QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList); 978 QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList);
980 for (sepIter.toFirst(); sepIter.current(); ++sepIter) 979 for (sepIter.toFirst(); sepIter.current(); ++sepIter)
981 { 980 {
982 sep = *sepIter; 981 sep = *sepIter;
983 sepRect = sep->mRect; 982 sepRect = sep->mRect;
984 983
985 if (clipRect.intersects(sepRect) || clipRect.contains(sepRect)) 984 if (clipRect.intersects(sepRect) || clipRect.contains(sepRect))
986 { 985 {
987 p->save(); 986 p->save();
988 p->translate(sepRect.x(), sepRect.y()); 987 p->translate(sepRect.x(), sepRect.y());
989 sep->paintSeparator(p, cg); 988 sep->paintSeparator(p, cg);
990 p->restore(); 989 p->restore();
991 } 990 }
992 } 991 }
993} 992}
994 993
995void CardView::resizeEvent(QResizeEvent *e) 994void CardView::resizeEvent(QResizeEvent *e)
996{ 995{
997 QScrollView::resizeEvent(e); 996 QScrollView::resizeEvent(e);
998 997
999 setLayoutDirty(true); 998 setLayoutDirty(true);
1000} 999}
1001 1000
1002void CardView::calcLayout() 1001void CardView::calcLayout()
1003{ 1002{
1004 //kdDebug() << "CardView::calcLayout:" << endl; 1003 //kdDebug() << "CardView::calcLayout:" << endl;
1005 1004
1006 // Start in the upper left corner and layout all the 1005 // Start in the upper left corner and layout all the
1007 // cars using their height and width 1006 // cars using their height and width
1008 int maxWidth = 0; 1007 int maxWidth = 0;
1009 int maxHeight = 0; 1008 int maxHeight = 0;
1010 int xPos = 0; 1009 int xPos = 0;
1011 int yPos = 0; 1010 int yPos = 0;
1012 int cardSpacing = d->mItemSpacing; 1011 int cardSpacing = d->mItemSpacing;
1013 1012
1014 // delete the old separators 1013 // delete the old separators
1015 d->mSeparatorList.clear(); 1014 d->mSeparatorList.clear();
1016 1015
1017 QPtrListIterator<CardViewItem> iter(d->mItemList); 1016 QPtrListIterator<CardViewItem> iter(d->mItemList);
1018 CardViewItem *item = 0; 1017 CardViewItem *item = 0;
1019 CardViewSeparator *sep = 0; 1018 CardViewSeparator *sep = 0;
1020 xPos += cardSpacing; 1019 xPos += cardSpacing;
1021 1020
1022 for (iter.toFirst(); iter.current(); ++iter) 1021 for (iter.toFirst(); iter.current(); ++iter)
1023 { 1022 {
1024 item = *iter; 1023 item = *iter;
1025 1024
1026 yPos += cardSpacing; 1025 yPos += cardSpacing;
1027 1026
1028 if (yPos + item->height() + cardSpacing >= height() - horizontalScrollBar()->height()) 1027 if (yPos + item->height() + cardSpacing >= height() - horizontalScrollBar()->height())
1029 { 1028 {
1030 maxHeight = QMAX(maxHeight, yPos); 1029 maxHeight = QMAX(maxHeight, yPos);
1031 1030
1032 // Drawing in this column would be greater than the height 1031 // Drawing in this column would be greater than the height
1033 // of the scroll view, so move to next column 1032 // of the scroll view, so move to next column
1034 yPos = cardSpacing; 1033 yPos = cardSpacing;
1035 xPos += cardSpacing + maxWidth; 1034 xPos += cardSpacing + maxWidth;
1036 if (d->mDrawSeparators) 1035 if (d->mDrawSeparators)
1037 { 1036 {
1038 // Create a separator since the user asked 1037 // Create a separator since the user asked
1039 sep = new CardViewSeparator(this); 1038 sep = new CardViewSeparator(this);
1040 sep->mRect.moveTopLeft(QPoint(xPos, yPos+d->mItemMargin)); 1039 sep->mRect.moveTopLeft(QPoint(xPos, yPos+d->mItemMargin));
1041 xPos += d->mSepWidth + cardSpacing; 1040 xPos += d->mSepWidth + cardSpacing;
1042 d->mSeparatorList.append(sep); 1041 d->mSeparatorList.append(sep);
1043 } 1042 }
1044 1043
1045 maxWidth = 0; 1044 maxWidth = 0;
1046 } 1045 }
1047 1046
1048 item->d->x = xPos; 1047 item->d->x = xPos;
1049 item->d->y = yPos; 1048 item->d->y = yPos;
1050 1049
1051 yPos += item->height(); 1050 yPos += item->height();
1052 maxWidth = QMAX(maxWidth, d->mItemWidth); 1051 maxWidth = QMAX(maxWidth, d->mItemWidth);
1053 } 1052 }
1054 1053
1055 xPos += maxWidth; 1054 xPos += maxWidth;
1056 resizeContents( xPos + cardSpacing, maxHeight ); 1055 resizeContents( xPos + cardSpacing, maxHeight );
1057 1056
1058 // Update the height of all the separators now that we know the 1057 // Update the height of all the separators now that we know the
1059 // max height of a column 1058 // max height of a column
1060 QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList); 1059 QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList);
1061 for (sepIter.toFirst(); sepIter.current(); ++sepIter) 1060 for (sepIter.toFirst(); sepIter.current(); ++sepIter)
1062 { 1061 {
1063 (*sepIter)->mRect.setHeight(maxHeight - 2*cardSpacing - 2*d->mItemMargin); 1062 (*sepIter)->mRect.setHeight(maxHeight - 2*cardSpacing - 2*d->mItemMargin);
1064 } 1063 }
1065 1064
1066 d->mLayoutDirty = false; 1065 d->mLayoutDirty = false;
1067} 1066}
1068 1067
1069CardViewItem *CardView::itemAfter(CardViewItem *item) 1068CardViewItem *CardView::itemAfter(CardViewItem *item)
1070{ 1069{
1071 /*int pos = */d->mItemList.findRef(item); 1070 /*int pos = */d->mItemList.findRef(item);
1072 return d->mItemList.next();//at(pos+1); 1071 return d->mItemList.next();//at(pos+1);
1073} 1072}
1074 1073
1075uint CardView::itemMargin() 1074uint CardView::itemMargin()
1076{ 1075{
1077 return d->mItemMargin; 1076 return d->mItemMargin;
1078} 1077}
1079 1078
1080void CardView::setItemMargin( uint margin ) 1079void CardView::setItemMargin( uint margin )
1081{ 1080{
1082 if ( margin == d->mItemMargin ) 1081 if ( margin == d->mItemMargin )
1083 return; 1082 return;
1084 1083
1085 d->mItemMargin = margin; 1084 d->mItemMargin = margin;
1086 setLayoutDirty( true ); 1085 setLayoutDirty( true );
1087} 1086}
1088 1087
1089uint CardView::itemSpacing() 1088uint CardView::itemSpacing()
1090{ 1089{
1091 return d->mItemSpacing; 1090 return d->mItemSpacing;
1092} 1091}
1093 1092
1094void CardView::setItemSpacing( uint spacing ) 1093void CardView::setItemSpacing( uint spacing )
1095{ 1094{
1096 if ( spacing == d->mItemSpacing ) 1095 if ( spacing == d->mItemSpacing )
1097 return; 1096 return;
1098 1097
1099 d->mItemSpacing = spacing; 1098 d->mItemSpacing = spacing;
1100 setLayoutDirty( true ); 1099 setLayoutDirty( true );
1101} 1100}
1102 1101
1103void CardView::contentsMousePressEvent(QMouseEvent *e) 1102void CardView::contentsMousePressEvent(QMouseEvent *e)
1104{ 1103{
1105 QScrollView::contentsMousePressEvent(e); 1104 QScrollView::contentsMousePressEvent(e);
1106 1105
1107 QPoint pos = e->pos(); 1106 QPoint pos = e->pos();
1108 d->mLastClickPos = pos; 1107 d->mLastClickPos = pos;
1109 1108
1110 CardViewItem *item = itemAt(pos); 1109 CardViewItem *item = itemAt(pos);
1111 1110
1112 if (item == 0) 1111 if (item == 0)
1113 { 1112 {
1114 d->mLastClickOnItem = false; 1113 d->mLastClickOnItem = false;
1115 if ( d->mOnSeparator) 1114 if ( d->mOnSeparator)
1116 { 1115 {
1117 d->mResizeAnchor = e->x()+contentsX(); 1116 d->mResizeAnchor = e->x()+contentsX();
1118 d->colspace = (2*d->mItemSpacing) /*+ (2*d->mItemMargin)*/; 1117 d->colspace = (2*d->mItemSpacing) /*+ (2*d->mItemMargin)*/;
1119 int ccw = d->mItemWidth + d->colspace + d->mSepWidth; 1118 int ccw = d->mItemWidth + d->colspace + d->mSepWidth;
1120 d->first = (contentsX()+d->mSepWidth)/ccw; 1119 d->first = (contentsX()+d->mSepWidth)/ccw;
1121 d->pressed = (d->mResizeAnchor+d->mSepWidth)/ccw; 1120 d->pressed = (d->mResizeAnchor+d->mSepWidth)/ccw;
1122 d->span = d->pressed - d->first; 1121 d->span = d->pressed - d->first;
1123 d->firstX = d->first * ccw; 1122 d->firstX = d->first * ccw;
1124 if ( d->firstX ) d->firstX -= d->mSepWidth; // (no sep in col 0) 1123 if ( d->firstX ) d->firstX -= d->mSepWidth; // (no sep in col 0)
1125 } 1124 }
1126 else 1125 else
1127 { 1126 {
1128 selectAll(false); 1127 selectAll(false);
1129 } 1128 }
1130 return; 1129 return;
1131 } 1130 }
1132 1131
1133 d->mLastClickOnItem = true; 1132 d->mLastClickOnItem = true;
1134 1133
1135 CardViewItem *other = d->mCurrentItem; 1134 CardViewItem *other = d->mCurrentItem;
1136 setCurrentItem( item ); 1135 setCurrentItem( item );
1137 1136
1138 // Always emit the selection 1137 // Always emit the selection
1139 emit clicked(item); 1138 emit clicked(item);
1140 1139
1141 // Check the selection type and update accordingly 1140 // Check the selection type and update accordingly
1142 if (d->mSelectionMode == CardView::Single) 1141 if (d->mSelectionMode == CardView::Single)
1143 { 1142 {
1144 // make sure it isn't already selected 1143 // make sure it isn't already selected
1145 if (item->isSelected()) 1144 if (item->isSelected())
1146 return; 1145 return;
1147 1146
1148 bool b = signalsBlocked(); 1147 bool b = signalsBlocked();