summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views/cardview.cpp
Unidiff
Diffstat (limited to 'kaddressbook/views/cardview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/cardview.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/kaddressbook/views/cardview.cpp b/kaddressbook/views/cardview.cpp
index 03df444..84d3116 100644
--- a/kaddressbook/views/cardview.cpp
+++ b/kaddressbook/views/cardview.cpp
@@ -12,48 +12,49 @@
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#include <qapplication.h>
36 37
37#include "kabprefs.h" 38#include "kabprefs.h"
38#include <kdebug.h> 39#include <kdebug.h>
39#include <kglobalsettings.h> 40#include <kglobalsettings.h>
40//END includes 41//END includes
41 42
42#define MIN_ITEM_WIDTH 80 43#define MIN_ITEM_WIDTH 80
43 44
44//BEGIN Helpers 45//BEGIN Helpers
45////////////////////////////////////// 46//////////////////////////////////////
46// CardViewTip 47// CardViewTip
47class CardViewTip : public QLabel { 48class CardViewTip : public QLabel {
48 public: 49 public:
49 CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name ) 50 CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name )
50 { 51 {
51 setPalette( QToolTip::palette() ); 52 setPalette( QToolTip::palette() );
52 setFrameStyle( Panel|Plain ); 53 setFrameStyle( Panel|Plain );
53 setMidLineWidth(0); 54 setMidLineWidth(0);
54 setIndent(1); 55 setIndent(1);
55 } 56 }
56 57
57 ~CardViewTip() {}; 58 ~CardViewTip() {};
58 protected: 59 protected:
59 void leaveEvent( QEvent * ) 60 void leaveEvent( QEvent * )
@@ -618,48 +619,50 @@ CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const
618 if ( iy <= ypos ) 619 if ( iy <= ypos )
619 return 0; 620 return 0;
620 // try find a field 621 // try find a field
621 bool showEmpty = mView->showEmptyFields(); 622 bool showEmpty = mView->showEmptyFields();
622 int fh = mView->d->mFm->height(); 623 int fh = mView->d->mFm->height();
623 int maxLines = mView->maxFieldLines(); 624 int maxLines = mView->maxFieldLines();
624 Field *f; 625 Field *f;
625 for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) 626 for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() )
626 { 627 {
627 if ( showEmpty || !f->second.isEmpty() ) 628 if ( showEmpty || !f->second.isEmpty() )
628 ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2; 629 ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2;
629 if ( iy <= ypos ) 630 if ( iy <= ypos )
630 break; 631 break;
631 } 632 }
632 return f ? f : 0; 633 return f ? f : 0;
633} 634}
634//END CardViewItem 635//END CardViewItem
635 636
636//BEGIN CardView 637//BEGIN CardView
637 638
638CardView::CardView(QWidget *parent, const char *name) 639CardView::CardView(QWidget *parent, const char *name)
639 : QScrollView(parent, name), 640 : QScrollView(parent, name),
640 d(new CardViewPrivate()) 641 d(new CardViewPrivate())
641{ 642{
643 mFlagKeyPressed = false;
644 mFlagBlockKeyPressed = false;
642 d->mItemList.setAutoDelete(true); 645 d->mItemList.setAutoDelete(true);
643 d->mSeparatorList.setAutoDelete(true); 646 d->mSeparatorList.setAutoDelete(true);
644 647
645 QFont f = font(); 648 QFont f = font();
646 d->mFm = new QFontMetrics(f); 649 d->mFm = new QFontMetrics(f);
647 f.setBold(true); 650 f.setBold(true);
648 d->mHeaderFont = f; 651 d->mHeaderFont = f;
649 d->mBFm = new QFontMetrics(f); 652 d->mBFm = new QFontMetrics(f);
650 d->mTip = ( new CardViewTip( viewport() ) ), 653 d->mTip = ( new CardViewTip( viewport() ) ),
651 d->mTip->hide(); 654 d->mTip->hide();
652 d->mTimer = ( new QTimer(this, "mouseTimer") ), 655 d->mTimer = ( new QTimer(this, "mouseTimer") ),
653 656
654 viewport()->setMouseTracking( true ); 657 viewport()->setMouseTracking( true );
655 viewport()->setFocusProxy(this); 658 viewport()->setFocusProxy(this);
656 viewport()->setFocusPolicy(WheelFocus); 659 viewport()->setFocusPolicy(WheelFocus);
657 viewport()->setBackgroundMode(PaletteBase); 660 viewport()->setBackgroundMode(PaletteBase);
658 661
659 connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); 662 connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) );
660 663
661//US setBackgroundMode(PaletteBackground, PaletteBase); 664//US setBackgroundMode(PaletteBackground, PaletteBase);
662 setBackgroundMode(PaletteBackground); 665 setBackgroundMode(PaletteBackground);
663 666
664 // no reason for a vertical scrollbar 667 // no reason for a vertical scrollbar
665 setVScrollBarMode(AlwaysOff); 668 setVScrollBarMode(AlwaysOff);
@@ -1330,49 +1333,57 @@ void CardView::focusInEvent( QFocusEvent * )
1330{ 1333{
1331 if (!d->mCurrentItem && d->mItemList.count() ) 1334 if (!d->mCurrentItem && d->mItemList.count() )
1332 { 1335 {
1333 setCurrentItem( d->mItemList.first() ); 1336 setCurrentItem( d->mItemList.first() );
1334 } 1337 }
1335 else if ( d->mCurrentItem ) 1338 else if ( d->mCurrentItem )
1336 { 1339 {
1337 d->mCurrentItem->repaintCard(); 1340 d->mCurrentItem->repaintCard();
1338 } 1341 }
1339} 1342}
1340 1343
1341void CardView::focusOutEvent( QFocusEvent * ) 1344void CardView::focusOutEvent( QFocusEvent * )
1342{ 1345{
1343 if (d->mCurrentItem) 1346 if (d->mCurrentItem)
1344 d->mCurrentItem->repaintCard(); 1347 d->mCurrentItem->repaintCard();
1345} 1348}
1346 1349
1347void CardView::keyPressEvent( QKeyEvent *e ) 1350void CardView::keyPressEvent( QKeyEvent *e )
1348{ 1351{
1349 if ( ! ( childCount() && d->mCurrentItem ) ) 1352 if ( ! ( childCount() && d->mCurrentItem ) )
1350 { 1353 {
1351 e->ignore(); 1354 e->ignore();
1352 return; 1355 return;
1353 } 1356 }
1354 1357 if ( mFlagBlockKeyPressed )
1358 return;
1359 qApp->processEvents();
1360 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
1361 e->accept();
1362 return;
1363 }
1364 if (! e->isAutoRepeat() )
1365 mFlagKeyPressed = true;
1355 uint pos = d->mItemList.findRef( d->mCurrentItem ); 1366 uint pos = d->mItemList.findRef( d->mCurrentItem );
1356 CardViewItem *aItem = 0L; // item that gets the focus 1367 CardViewItem *aItem = 0L; // item that gets the focus
1357 CardViewItem *old = d->mCurrentItem; 1368 CardViewItem *old = d->mCurrentItem;
1358 1369
1359 switch ( e->key() ) 1370 switch ( e->key() )
1360 { 1371 {
1361 case Key_Up: 1372 case Key_Up:
1362 if ( pos > 0 ) 1373 if ( pos > 0 )
1363 { 1374 {
1364 aItem = d->mItemList.at( pos - 1 ); 1375 aItem = d->mItemList.at( pos - 1 );
1365 setCurrentItem( aItem ); 1376 setCurrentItem( aItem );
1366 } 1377 }
1367 break; 1378 break;
1368 case Key_Down: 1379 case Key_Down:
1369 if ( pos < d->mItemList.count() - 1 ) 1380 if ( pos < d->mItemList.count() - 1 )
1370 { 1381 {
1371 aItem = d->mItemList.at( pos + 1 ); 1382 aItem = d->mItemList.at( pos + 1 );
1372 setCurrentItem( aItem ); 1383 setCurrentItem( aItem );
1373 } 1384 }
1374 break; 1385 break;
1375 case Key_Left: 1386 case Key_Left:
1376 { 1387 {
1377 // look for an item in the previous/next column, starting from 1388 // look for an item in the previous/next column, starting from
1378 // the vertical middle of the current item. 1389 // the vertical middle of the current item.
@@ -1694,29 +1705,47 @@ void CardView::setFont( const QFont &fnt )
1694 d->mFm = new QFontMetrics( fnt ); 1705 d->mFm = new QFontMetrics( fnt );
1695} 1706}
1696 1707
1697int CardView::separatorWidth() 1708int CardView::separatorWidth()
1698{ 1709{
1699 return d->mSepWidth; 1710 return d->mSepWidth;
1700} 1711}
1701 1712
1702void CardView::setSeparatorWidth( int width ) 1713void CardView::setSeparatorWidth( int width )
1703{ 1714{
1704 d->mSepWidth = width; 1715 d->mSepWidth = width;
1705 setLayoutDirty( true ); // hmm, actually I could just adjust the x'es... 1716 setLayoutDirty( true ); // hmm, actually I could just adjust the x'es...
1706} 1717}
1707 1718
1708int CardView::maxFieldLines() const 1719int CardView::maxFieldLines() const
1709{ 1720{
1710 return d->mMaxFieldLines; 1721 return d->mMaxFieldLines;
1711} 1722}
1712 1723
1713void CardView::setMaxFieldLines( int howmany ) 1724void CardView::setMaxFieldLines( int howmany )
1714{ 1725{
1715 d->mMaxFieldLines = howmany ? howmany : INT_MAX; 1726 d->mMaxFieldLines = howmany ? howmany : INT_MAX;
1716 // FIXME update, forcing the items to recalc height!! 1727 // FIXME update, forcing the items to recalc height!!
1717} 1728}
1729
1730void CardView::keyReleaseEvent ( QKeyEvent * e )
1731{
1732 if ( mFlagBlockKeyPressed )
1733 return;
1734 if ( !e->isAutoRepeat() ) {
1735 mFlagBlockKeyPressed = true;
1736 qApp->processEvents();
1737 mFlagBlockKeyPressed = false;
1738 mFlagKeyPressed = false;
1739 }
1740 QScrollView::keyReleaseEvent ( e );
1741}
1742
1743
1744
1745
1746
1718//END Cardview 1747//END Cardview
1719 1748
1720#ifndef KAB_EMBEDDED 1749#ifndef KAB_EMBEDDED
1721#include "cardview.moc" 1750#include "cardview.moc"
1722#endif //KAB_EMBEDDED 1751#endif //KAB_EMBEDDED