--- a/ganeswidgets/src/HgContainer.cpp Tue Jul 06 15:29:26 2010 +0300
+++ b/ganeswidgets/src/HgContainer.cpp Wed Aug 18 10:52:49 2010 +0300
@@ -63,7 +63,8 @@
mItemSizePolicy(HgWidget::ItemSizeAutomatic),
mOrientation(Qt::Vertical),
mDelayedScrollToIndex(),
- mIgnoreGestureAction(false)
+ mIgnoreGestureAction(false),
+ mHandleLongPress(false)
{
FUNC_LOG;
@@ -96,6 +97,7 @@
}
}
+// TODO: This does exactly the same as HgContainer::imageCount(), should this be thus removed?
int HgContainer::itemCount() const
{
return mItems.count();
@@ -393,6 +395,7 @@
scrollTo(mSelectionModel->currentIndex());
}
+// TODO: This does exactly the same as HgContainer::itemCount(), should this be thus removed?
int HgContainer::imageCount() const
{
return mItems.count();
@@ -416,8 +419,13 @@
return 0;
}
-const HgImage *HgContainer::indicator(int flags) const
+const HgImage *HgContainer::indicator(int flags)
{
+ if (flags != 0 && (!mMarkImageOff || !mMarkImageOn)) {
+ // indicators haven't been loaded yet.
+ loadIndicatorGraphics();
+ }
+
if (flags & 1) {
return mMarkImageOn;
}
@@ -493,6 +501,10 @@
// set scrollto index to invalid value.
mDelayedScrollToIndex = QModelIndex();
}
+ // Indicator size depends from the item size so
+ // indicators need to be updated. Indicators are created
+ // in runtime only for need so if they dont exists they aren't created.
+ loadIndicatorGraphics(true);
}
// this needs to be implemented for gesture framework to work
@@ -516,7 +528,7 @@
HbTapGesture *tap = 0;
if (QGesture *gesture = event->gesture(Qt::TapGesture)) {
tap = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
- if (tap->tapStyleHint() == HbTapGesture::TapAndHold) {
+ if (mHandleLongPress && tap->tapStyleHint() == HbTapGesture::TapAndHold) {
eventHandled = handleLongTap(tap->state(),
mapFromScene(event->mapToGraphicsScene(tap->hotSpot())));
@@ -547,35 +559,6 @@
mQuadRenderer = mRenderer->getRenderer();
- // Fetch icons for marking mode (on and off states).
-
- mMarkImageOn = mQuadRenderer->createNativeImage();
- HANDLE_ERROR_NULL(mMarkImageOn);
- mMarkImageOff = mQuadRenderer->createNativeImage();
- HANDLE_ERROR_NULL(mMarkImageOff);
-
- // Since there is no way to create the icons directly currently
- // lets create HbCheckBox and ask primitives from it.
- HbCheckBox* checkBox = new HbCheckBox();
- checkBox->setCheckState(Qt::Checked);
- QGraphicsItem *icon = checkBox->HbWidget::primitive("icon");
- HbIconItem *iconItem = 0;
- if (icon) {
- iconItem = static_cast<HbIconItem*>(icon);
- if (mMarkImageOn) {
- mMarkImageOn->setPixmap(iconItem->icon().pixmap());
- }
- }
- checkBox->setCheckState(Qt::Unchecked);
- icon = checkBox->HbWidget::primitive("icon");
- if (icon) {
- iconItem = static_cast<HbIconItem*>(icon);
- if (mMarkImageOff) {
- mMarkImageOff->setPixmap(iconItem->icon().pixmap());
- }
- }
- delete checkBox;
-
connect(&mSpring, SIGNAL(updated()), SLOT(updateBySpringPosition()));
connect(&mSpring, SIGNAL(started()), SIGNAL(scrollingStarted()));
connect(&mSpring, SIGNAL(started()), SLOT(onScrollingStarted()));
@@ -611,14 +594,12 @@
FUNC_LOG;
qreal x = mSpring.endPos().x();
- x = qBound(qreal(0), x, worldWidth());
if (mRenderer->coverflowModeEnabled()) {
qreal i = floorf(x);
x = (x - i > 0.5f) ? ceilf(x) : i;
- mSpring.animateToPos(QPointF(x, 0));
}
- mSpring.animateToPos(QPointF(x, 0));
+ mSpring.animateToPosAfterPanning(QPointF(x, 0), worldWidth());
}
@@ -679,7 +660,9 @@
mDragged = false;
qreal newPos(0);
if (mDrag.finish(pos, mRenderer->coverflowModeEnabled(), newPos)) {
- mSpring.animateToPos(QPointF(qBound(qreal(0), newPos, worldWidth()), 0));
+
+ mSpring.animateToPosAfterPanning(QPointF(newPos, 0), worldWidth());
+
HgWidgetItem* item = itemByIndex(newPos);
if (item && item->modelIndex() != mSelectionModel->currentIndex()) {
// mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
@@ -707,7 +690,7 @@
FUNC_LOG;
bool handleGesture = false;
-
+
if (hasItemAt(pos)) {
switch (state)
{
@@ -715,9 +698,44 @@
{
if (mRenderer->coverflowModeEnabled() || !mSpring.isActive()) {
mIgnoreGestureAction = false;
- startLongPressWatcher(pos);
+
+ if (mHandleLongPress) {
+ if (mRenderer->coverflowModeEnabled()) {
+ // in coverflow mode we react to longtap only if animation is not on and
+ // center item is tapped.
+ int temp = 0;
+ if (getItemAt(pos,temp)->modelIndex() == mSelectionModel->currentIndex() &&
+ !mSpring.isActive()) {
+ startLongPressWatcher(pos);
+ }
+ } else {
+ startLongPressWatcher(pos);
+ }
+ }
} else if(mSpring.isActive()) {
- mSpring.cancel();
+
+ int rowCount = mRenderer->getRowCount();
+ if(rowCount != 0) //just in case, should not be zero
+ {
+ qreal springPos = mSpring.pos().x();
+ int gridTotalHeightInImages = ceilf( mItems.count() / rowCount );
+ qreal currentViewHeightInImages;
+ if (scrollDirection() == Qt::Horizontal ) {
+ int rowHeight = mRenderer->getImageSize().width() + mRenderer->getSpacing().width();
+ currentViewHeightInImages = rect().width() / rowHeight;
+ } else {
+ int rowHeight = mRenderer->getImageSize().height() + mRenderer->getSpacing().height();
+ currentViewHeightInImages = rect().height() / rowHeight;
+ }
+
+ // If list does not currently fill the whole screen (some theme background behind the list
+ // is visible), and list is moving, then do not react to tapping.
+ if( springPos >= 0
+ && springPos <= (gridTotalHeightInImages - currentViewHeightInImages) )
+ {
+ mSpring.cancel();
+ }
+ }
mIgnoreGestureAction = true;
}
break;
@@ -733,7 +751,7 @@
handleGesture = true;
} else {
- mIgnoreGestureAction = true;
+ mIgnoreGestureAction = true;
}
return handleGesture;
}
@@ -786,15 +804,24 @@
if (item && action != DoubleTap) {
if (action == LongTap) {
INFO("Long tap:" << item->modelIndex().row());
+
+ bool currentPressed = item->modelIndex() == mSelectionModel->currentIndex();
if (!mRenderer->coverflowModeEnabled()) {
selectItem(index);
} else {
mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
+ mSpring.animateToPos(QPointF(index, 0));
}
if (!mIgnoreGestureAction) {
- emit longPressed(item->modelIndex(), pos);
+ if (mRenderer->coverflowModeEnabled() && mHandleLongPress) {
+ if( currentPressed && !mSpring.isActive()) {
+ emit longPressed(item->modelIndex(), pos);
+ }
+ } else if (mHandleLongPress){
+ emit longPressed(item->modelIndex(), pos);
+ }
} else {
mSpring.resetVelocity();
update();
@@ -1153,6 +1180,10 @@
mRenderer->setImageSize(mUserItemSize);
mRenderer->setSpacing(mUserItemSpacing);
}
+ // Indicator size depends from the item size so
+ // indicators need to be updated. Indicators are created
+ // in runtime only for need so if they dont exists they aren't created.
+ loadIndicatorGraphics(true);
}
QSizeF HgContainer::getAutoItemSize() const
@@ -1175,4 +1206,47 @@
return mSpring.pos().x();
}
+void HgContainer::loadIndicatorGraphics(bool loadIfExists)
+{
+ if (loadIfExists && !mMarkImageOn && !mMarkImageOff) return;
+
+ if (!mMarkImageOn) {
+ mMarkImageOn = mQuadRenderer->createNativeImage();
+ }
+ HANDLE_ERROR_NULL(mMarkImageOn);
+ if (!mMarkImageOff) {
+ mMarkImageOff = mQuadRenderer->createNativeImage();
+ }
+
+ const QSizeF newIndicatorSize = itemSize()/2;
+
+ // Validate if loading marking icons is really needed by comparing the sizes.
+ // Both marking icons have the same size so its enough to check one.
+ if (mMarkImageOn && mMarkImageOn->width() == newIndicatorSize.width() &&
+ mMarkImageOn->height() == newIndicatorSize.height() ) return;
+
+ HANDLE_ERROR_NULL(mMarkImageOff);
+ HbIcon selectedIcon(QLatin1String("qtg_small_selected"));
+ HbIcon unselectedIcon(QLatin1String("qtg_small_unselected"));
+ selectedIcon.setSize(newIndicatorSize);
+ unselectedIcon.setSize(newIndicatorSize);
+
+ QPixmap selectedPixmap = selectedIcon.pixmap();
+ QPixmap unselectedPixmap = unselectedIcon.pixmap();
+
+ if (!selectedPixmap.isNull() && !unselectedPixmap.isNull()) {
+ if (mMarkImageOn) {
+ mMarkImageOn->setPixmap(selectedPixmap);
+ }
+ if (mMarkImageOff) {
+ mMarkImageOff->setPixmap(unselectedPixmap);
+ }
+ }
+}
+
+void HgContainer::setHandleLongPress(bool handheLongPress)
+{
+ // this is just a flag that is used in gesturehandling logic.
+ mHandleLongPress = handheLongPress;
+}
// EOF