author | zautrix <zautrix> | 2004-10-29 10:42:31 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-29 10:42:31 (UTC) |
commit | d96b4fd7188145c49120dd159b0ac00c987f4972 (patch) (unidiff) | |
tree | ba8f3910a72938aa44aa82a477bbd84f5414a214 | |
parent | e152dd9c19c69e6efff6c593b2bf081bc426c7d5 (diff) | |
download | kdepimpi-d96b4fd7188145c49120dd159b0ac00c987f4972.zip kdepimpi-d96b4fd7188145c49120dd159b0ac00c987f4972.tar.gz kdepimpi-d96b4fd7188145c49120dd159b0ac00c987f4972.tar.bz2 |
made cardview handling singleclick and return pressed
-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 | |||
@@ -635,48 +635,49 @@ CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const | |||
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 | { |
@@ -1245,50 +1246,50 @@ void CardView::contentsMouseReleaseEvent(QMouseEvent *e) | |||
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? |
@@ -1431,51 +1432,53 @@ void CardView::keyPressEvent( QKeyEvent *e ) | |||
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 |