--- a/ganeswidgets/ganeswidgets.pro Fri Aug 06 09:27:34 2010 +0300
+++ b/ganeswidgets/ganeswidgets.pro Mon Aug 23 13:45:39 2010 +0300
@@ -49,8 +49,8 @@
src/hglongpressvisualizer.cpp \
src/hgcoverflowcontainer.cpp \
src/hggridcontainer.cpp \
-# src/hgindexfeedback.cpp \
-# src/hgindexfeedback_p.cpp \
+ src/hgindexfeedback.cpp \
+ src/hgindexfeedback_p.cpp \
src/hggrid.cpp \
src/hggrid_p.cpp \
src/hgmediawall.cpp \
@@ -75,7 +75,7 @@
inc/hglongpressvisualizer.h \
inc/hgcoverflowcontainer.h \
inc/hggridcontainer.h \
-# inc/hgindexfeedback.h \
+ inc/hgindexfeedback.h \
inc/hgqtquadrenderer.h \
inc/hgtransformedquad.h \
inc/hgtransformedquadrenderer.h \
--- a/ganeswidgets/inc/hgindexfeedback.h Fri Aug 06 09:27:34 2010 +0300
+++ b/ganeswidgets/inc/hgindexfeedback.h Mon Aug 23 13:45:39 2010 +0300
@@ -49,16 +49,14 @@
void setWidget(HgWidget *itemView);
HgWidget* widget() const;
- virtual QGraphicsItem *primitive(HbStyle::Primitive primitive) const;
-
protected:
virtual void polish( HbStyleParameters& params);
virtual bool sceneEventFilter(QGraphicsItem* watched, QEvent* event);
virtual bool eventFilter(QObject *obj, QEvent *event);
- void initStyleOption(HbStyleOptionIndexFeedback *option) const;
+ HgIndexFeedbackPrivate * const p_ptr;
private:
- Q_DECLARE_PRIVATE_D(d_ptr, HgIndexFeedback)
+ Q_DECLARE_PRIVATE_D(p_ptr, HgIndexFeedback)
Q_DISABLE_COPY(HgIndexFeedback)
Q_PRIVATE_SLOT(d_func(), void _q_scrollPositionChanged(qreal, Qt::Orientation))
--- a/ganeswidgets/inc/hgindexfeedback_p.h Fri Aug 06 09:27:34 2010 +0300
+++ b/ganeswidgets/inc/hgindexfeedback_p.h Mon Aug 23 13:45:39 2010 +0300
@@ -19,7 +19,7 @@
#define HGINDEXFEEDBACKPRIVATE_H
#include "hgindexfeedback.h"
-#include <hbwidget_p.h>
+#include <HbFontSpec>
#define HB_INDEXFEEDBACK_TYPE "indexfeedback"
#define EFFECT_IFAPPEAR "appear"
@@ -32,7 +32,7 @@
class QItemSelectionModel;
QT_END_NAMESPACE
-class HgIndexFeedbackPrivate: public HbWidgetPrivate
+class HgIndexFeedbackPrivate
{
Q_DECLARE_PUBLIC( HgIndexFeedback )
@@ -47,7 +47,7 @@
void scrollBarPressed();
void scrollBarReleased();
- void connectScrollBarToIndexFeedback(HbScrollBar* scrollBar);
+ void connectWidgetToIndexFeedback();
void disconnectItemView();
void connectModelToIndexFeedback(QItemSelectionModel* model);
@@ -66,6 +66,10 @@
QString displayText(const QVariant &data) const;
+ HbFontSpec FontSpec() const;
+
+ HgIndexFeedback *q_ptr;
+
public:
int mIndexFeedbackPressTimeout;
int mIndexFeedbackDwellTimeout;
--- a/ganeswidgets/inc/hgwidgets_p.h Fri Aug 06 09:27:34 2010 +0300
+++ b/ganeswidgets/inc/hgwidgets_p.h Mon Aug 23 13:45:39 2010 +0300
@@ -141,7 +141,8 @@
bool mHandleLongPress;
bool mForeground;
int mBufferSize;
-// HgIndexFeedback *mIndexFeedback;
+ HgIndexFeedback *mIndexFeedback;
+ HgWidget::IndexFeedbackPolicy mIndexFeedbackPolicy;
bool mStaticScrollDirection;
};
--- a/ganeswidgets/src/hgcontainer.cpp Fri Aug 06 09:27:34 2010 +0300
+++ b/ganeswidgets/src/hgcontainer.cpp Mon Aug 23 13:45:39 2010 +0300
@@ -456,7 +456,7 @@
{
Q_UNUSED(option)
Q_UNUSED(widget)
-
+
// update spring position at paint if needed,
// this is hack for scrollbar, since dragging it
// causes also paint events in here
@@ -470,7 +470,6 @@
QPainter::RenderHints hints = painter->renderHints();
painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
-
// interpolate spring velocity towards zero, this is done
// so that spring velocity for rendering doesn't drop directly to
// zero when dragging starts
@@ -554,6 +553,8 @@
{
FUNC_LOG;
+ setFlag( QGraphicsItem::ItemClipsToShape, true );
+
mRenderer = createRenderer(scrollDirection);
mOrientation = scrollDirection;
@@ -698,7 +699,7 @@
{
if (mRenderer->coverflowModeEnabled() || !mSpring.isActive()) {
mIgnoreGestureAction = false;
-
+
if (mHandleLongPress) {
if (mRenderer->coverflowModeEnabled()) {
// in coverflow mode we react to longtap only if animation is not on and
--- a/ganeswidgets/src/hgindexfeedback.cpp Fri Aug 06 09:27:34 2010 +0300
+++ b/ganeswidgets/src/hgindexfeedback.cpp Mon Aug 23 13:45:39 2010 +0300
@@ -19,7 +19,6 @@
#include "hgindexfeedback_p.h"
#include <HbScrollbar>
-#include <HbStyleOptionIndexFeedback>
#include <HbStyleParameters>
#include <HbStyle>
#include <HbDeviceProfile>
@@ -30,7 +29,6 @@
#include <QObject>
#include <QGraphicsScene>
-
/* rather than magic numbers, let's define some constants. */
namespace {
/*
@@ -58,7 +56,7 @@
Constructs a new HgIndexFeedback with a parent.
*/
HgIndexFeedback::HgIndexFeedback(QGraphicsItem *parent)
- : HbWidget( *new HgIndexFeedbackPrivate, parent, 0)
+ : HbWidget(parent), p_ptr(new HgIndexFeedbackPrivate)
{
Q_D( HgIndexFeedback );
@@ -75,6 +73,7 @@
HgIndexFeedback::~HgIndexFeedback()
{
HbStyleLoader::unregisterFilePath(":/hgindexfeedback.css");
+ delete p_ptr;
}
/*!
@@ -135,7 +134,7 @@
d->connectModelToIndexFeedback(d->mWidget->selectionModel());
- d->connectScrollBarToIndexFeedback(d->mWidget->scrollBar());
+ d->connectWidgetToIndexFeedback();
connect(d->mWidget, SIGNAL(destroyed(QObject*)),
this, SLOT(_q_itemViewDestroyed()));
@@ -161,37 +160,6 @@
return d->mWidget;
}
-/*!
- Returns the primitives used in HgIndexFeedback.
-
- \param primitive The primitive type requested.
-
- \return A pointer for the primitive requested.
-*/
-QGraphicsItem* HgIndexFeedback::primitive(HbStyle::Primitive primitive) const
-{
- Q_D( const HgIndexFeedback );
-
- QGraphicsItem* retVal = HbWidget::primitive(primitive);
-
- switch (primitive) {
- case HbStyle::P_IndexFeedback_popup_text:
- retVal = d->mTextItem;
- break;
-
- case HbStyle::P_IndexFeedback_popup_background:
- retVal = d->mPopupItem;
- break;
-
- default:
- qt_noop();
- break;
- }
-
- return retVal;
-}
-
-
/*
A scene event filter. It's purpose is to call calculatePopupRects on
a resize event for the item view.
@@ -202,6 +170,7 @@
if (ev->type() == QEvent::GraphicsSceneResize) {
d->calculatePopupRects();
+ d->updatePrimitives();
}
return QGraphicsItem::sceneEventFilter(watched, ev);
@@ -217,96 +186,42 @@
bool HgIndexFeedback::eventFilter(QObject *obj, QEvent *ev)
{
Q_D( HgIndexFeedback );
- HbScrollBar* scrollBar = qobject_cast<HbScrollBar*>(obj);
-
- if (d->mIndexFeedbackPolicy != HgWidget::IndexFeedbackNone
- && scrollBar) {
- switch (ev->type()) {
- case QEvent::GraphicsSceneMousePress:
- case QEvent::MouseButtonPress:
- if (scrollBar->isInteractive()) {
- d->scrollBarPressed();
- }
- break;
-
- case QEvent::GraphicsSceneMouseRelease:
- case QEvent::MouseButtonRelease:
- if (scrollBar->isInteractive()) {
- d->scrollBarReleased();
- }
- break;
-
- case QEvent::GraphicsSceneResize:
- case QEvent::Resize:
- d->_q_hideIndexFeedbackNow();
- d->calculatePopupRects();
- d->updatePrimitives();
- break;
-
- default:
- // do nothing, ignore other events.
- break;
+ HbScrollBar *scrollBar = qobject_cast<HbScrollBar*>(obj);
+ HgWidget *widget = qobject_cast<HgWidget*>(obj);
+
+ if (d->mIndexFeedbackPolicy != HgWidget::IndexFeedbackNone) {
+ if (scrollBar) {
+ switch (ev->type()) {
+ case QEvent::GraphicsSceneMousePress:
+ case QEvent::MouseButtonPress:
+ if (scrollBar->isInteractive()) {
+ d->scrollBarPressed();
+ }
+ break;
+
+ case QEvent::GraphicsSceneMouseRelease:
+ case QEvent::MouseButtonRelease:
+ if (scrollBar->isInteractive()) {
+ d->scrollBarReleased();
+ }
+ break;
+ default:
+ // do nothing, ignore other events.
+ break;
+ }
+ }
+ if (widget && (ev->type() == QEvent::GraphicsSceneResize || ev->type() == QEvent::Resize)) {
+ // widget size has changed and size of the popup letter box depends from it
+ // so recalculate the popup rects
+ d->_q_hideIndexFeedbackNow();
+ d->calculatePopupRects();
+ d->updatePrimitives();
}
}
return QObject::eventFilter(obj, ev);
}
-/*
- For use with HbStyle.
-
- Provide the correct data to use in the 'model.'
-*/
-void HgIndexFeedback::initStyleOption(HbStyleOptionIndexFeedback *option) const
-{
- Q_D( const HgIndexFeedback );
-
- HbWidget::initStyleOption(option);
-
- if (!d->mWidget) {
- return;
- }
-
- HbFontSpec fontSpec;
- qreal margin = 0;
-
- style()->parameter(QLatin1String("hb-param-margin-gene-popup"), margin);
-
- switch (d->mIndexFeedbackPolicy) {
- case HgWidget::IndexFeedbackSingleCharacter:
- {
- fontSpec = HbFontSpec(HbFontSpec::Primary);
- fontSpec.setTextHeight(d->textHeight());
- }
- break;
-
- case HgWidget::IndexFeedbackThreeCharacter:
- {
- fontSpec = HbFontSpec(HbFontSpec::Primary);
- fontSpec.setTextHeight(d->textHeight());
- }
- break;
-
- case HgWidget::IndexFeedbackString:
- {
- fontSpec = HbFontSpec(HbFontSpec::Primary);
- qreal textPaneHeight = 0;
- style()->parameter(QLatin1String("hb-param-text-height-primary"), textPaneHeight);
- fontSpec.setTextHeight( textPaneHeight );
- }
- break;
-
- case HgWidget::IndexFeedbackNone:
- // leave the HbStyleOption uninitialized
- return;
- }
-
- option->text = d->mPopupContent;
- option->fontSpec = fontSpec;
- option->textRect = d->mPopupTextRect;
- option->popupRect = d->mPopupBackgroundRect;
-}
-
void HgIndexFeedback::polish(HbStyleParameters& params)
{
Q_D( HgIndexFeedback );
@@ -324,6 +239,7 @@
d->mStringOffset = params.value( STRING_OFFSET ).toDouble();
d->calculatePopupRects();
+ d->updatePrimitives();
}
#include "moc_hgindexfeedback.cpp"
--- a/ganeswidgets/src/hgindexfeedback_p.cpp Fri Aug 06 09:27:34 2010 +0300
+++ b/ganeswidgets/src/hgindexfeedback_p.cpp Mon Aug 23 13:45:39 2010 +0300
@@ -22,7 +22,8 @@
#include <HbStyle>
#include <HbApplication>
#include <HbEffect>
-#include <HbStyleOptionIndexFeedback>
+#include <HbFrameItem>
+#include <HbTextItem>
#include <hgwidgets/hgwidgets.h>
#include <QTimer>
@@ -329,13 +330,17 @@
{
Q_Q( HgIndexFeedback );
- HbStyleOptionIndexFeedback option;
- q->initStyleOption(&option);
if (mTextItem) {
- q->style()->updatePrimitive(mTextItem, HbStyle::P_IndexFeedback_popup_text, &option);
+ if (HbTextItem* textItem = qgraphicsitem_cast<HbTextItem*>(mTextItem)) {
+ textItem->setFontSpec(FontSpec());
+ textItem->setGeometry(mPopupTextRect);
+ textItem->setText(mPopupContent);
+ }
}
if (mPopupItem) {
- q->style()->updatePrimitive(mPopupItem, HbStyle::P_IndexFeedback_popup_background, &option);
+ if (HbFrameItem* frameItem = qgraphicsitem_cast<HbFrameItem*>(mPopupItem)) {
+ frameItem->setGeometry(mPopupBackgroundRect);
+ }
}
}
@@ -349,13 +354,26 @@
mPopupItemList.clear();
if (!mTextItem) {
- mTextItem = q->style()->createPrimitive(HbStyle::P_IndexFeedback_popup_text, q);
+ HbTextItem *textItem = new HbTextItem(q);
+ textItem->setAlignment(Qt::AlignCenter);
+ textItem->setTextWrapping(Hb::TextNoWrap);
+ HbStyle::setItemName(textItem, QLatin1String("index-text"));
+ textItem->setZValue(q->zValue()+2);
+ mTextItem = textItem;
mTextItem->hide();
mPopupItemList.append(mTextItem);
}
if (!mPopupItem) {
- mPopupItem = q->style()->createPrimitive(HbStyle::P_IndexFeedback_popup_background, q);
+ HbFrameItem *frame = new HbFrameItem(q);
+ frame->frameDrawer().setFrameGraphicsName("qtg_fr_popup_preview");
+ frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
+ qreal cornerPieceSize = 0;
+ q->style()->parameter(QLatin1String("hb-param-background-popup-preview"),cornerPieceSize);
+ frame->frameDrawer().setBorderWidths(cornerPieceSize, cornerPieceSize);
+ HbStyle::setItemName(frame, QLatin1String("index-background"));
+ frame->setZValue(q->zValue()+1);
+ mPopupItem = frame;
mPopupItem->hide();
mPopupItemList.append(mPopupItem);
}
@@ -373,7 +391,8 @@
mWidget->disconnect(q);
// uninstall the event filters;
mWidget->scrollBar()->removeEventFilter(q);
-
+ mWidget->removeEventFilter(q);
+
mWidget->removeSceneEventFilter(q);
if (mWidget->scene()) {
mWidget->scene()->removeItem(q);
@@ -386,13 +405,18 @@
/*
Hooks up the private slots & event filter to a scrollbar.
*/
-void HgIndexFeedbackPrivate::connectScrollBarToIndexFeedback(HbScrollBar* scrollBar)
+void HgIndexFeedbackPrivate::connectWidgetToIndexFeedback()
{
Q_Q( HgIndexFeedback );
+ if(!mWidget) return;
+
+ // Install event filter so we receive resize events from parent widget.
+ mWidget->installEventFilter(q);
+
+ // Install eventfilter to scrollbar so we can receive mousepress and released events
+ HbScrollBar *scrollBar = mWidget->scrollBar();
if (scrollBar) {
- //q->connect(scrollBar, SIGNAL(valueChanged(qreal, Qt::Orientation)),
- // q, SLOT(_q_scrollPositionChanged(qreal, Qt::Orientation)));
scrollBar->installEventFilter(q);
}
}
@@ -410,7 +434,7 @@
return;
}
- QRectF contentRect = mWidget->rect();
+ QRectF contentRect = mWidget->boundingRect();
HbScrollBar *scrollBar = mWidget->scrollBar();
if (scrollBar->isInteractive() && mWidget->scrollDirection() == Qt::Vertical) {
@@ -426,7 +450,7 @@
if (contentRect == mItemViewContentsRect) {
return;
}
-
+
qreal margin = 0;
q->style()->parameter(QLatin1String("hb-param-margin-gene-popup"), margin);
@@ -564,4 +588,32 @@
updateIndex();
}
+HbFontSpec HgIndexFeedbackPrivate::FontSpec() const
+{
+ HbFontSpec fontSpec(HbFontSpec::Primary);
+ switch (mIndexFeedbackPolicy) {
+ case HgWidget::IndexFeedbackSingleCharacter:
+ {
+ fontSpec.setTextHeight(textHeight());
+ }
+ break;
+ case HgWidget::IndexFeedbackThreeCharacter:
+ {
+ fontSpec.setTextHeight(textHeight());
+ }
+ break;
+ case HgWidget::IndexFeedbackString:
+ {
+ qreal textPaneHeight = 0;
+ Q_Q(const HgIndexFeedback);
+ q->style()->parameter(QLatin1String("hb-param-text-height-primary"), textPaneHeight);
+ fontSpec.setTextHeight( textPaneHeight );
+ }
+ break;
+ case HgWidget::IndexFeedbackNone:
+ default:
+ break;
+ }
+ return fontSpec;
+}
--- a/ganeswidgets/src/hgwidgets.cpp Fri Aug 06 09:27:34 2010 +0300
+++ b/ganeswidgets/src/hgwidgets.cpp Mon Aug 23 13:45:39 2010 +0300
@@ -221,27 +221,8 @@
bool HgWidget::eventFilter(QObject *obj,QEvent *event)
{
- Q_D(HgWidget);
- switch (event->type() )
- {
- case QEvent::ApplicationActivate:
- {
-// d->gainedForeground();
- break;
- }
- case QEvent::ApplicationDeactivate:
- {
-// d->lostForeground();
- break;
- }
- case QEvent::GraphicsSceneResize:
- {
- d->adjustGeometry();
- break;
- }
- default:
- break;
- }
+ // function is not used anymore, that is, event filter is not installed.
+ // Kept to keep the binary compability.
return QObject::eventFilter(obj, event);
}
--- a/ganeswidgets/src/hgwidgets_p.cpp Fri Aug 06 09:27:34 2010 +0300
+++ b/ganeswidgets/src/hgwidgets_p.cpp Mon Aug 23 13:45:39 2010 +0300
@@ -26,7 +26,7 @@
#include "hgscrollbuffermanager.h"
#include "hgwidgetitem.h"
#include "trace.h"
-//#include "hgindexfeedback.h"
+#include "hgindexfeedback.h"
static const int INITIAL_SCROLLBAR_HIDE_TIMEOUT(4000);
static const int DEFAULT_BUFFER_SIZE(25);
@@ -40,7 +40,9 @@
mAbleToScroll(false),
mHandleLongPress(false),
mBufferSize(DEFAULT_BUFFER_SIZE),
- mStaticScrollDirection(false)
+ mStaticScrollDirection(false),
+ mIndexFeedback(0),
+ mIndexFeedbackPolicy(HgWidget::IndexFeedbackNone)
{
FUNC_LOG;
}
@@ -63,7 +65,6 @@
mScrollBarHideTimer->setSingleShot(true);
q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- q->setFlag( QGraphicsItem::ItemClipsChildrenToShape, true );
q->setFocusPolicy(Qt::StrongFocus);
createScrollBar(container->scrollDirection());
@@ -86,10 +87,6 @@
q->connect( HbTheme::instance(), SIGNAL(changed()), q, SLOT(_q_themeChanged()));
mContainer->setHandleLongPress(mHandleLongPress);
-
-// mIndexFeedback = new HgIndexFeedback(q);
-// mIndexFeedback->setWidget(q);
-
}
void HgWidgetPrivate::setModel( QAbstractItemModel *model )
@@ -143,13 +140,16 @@
}
if (mContainer->selectionModel()) {
-// if (mIndexFeedback) {
-// delete mIndexFeedback;
-// mIndexFeedback = 0;
-// }
-// mIndexFeedback = new HgIndexFeedback(q);
-// mIndexFeedback->setWidget(q);
-
+ // TODO, optimize this, do we really need to destroy the instance.
+ if (mIndexFeedback) {
+ delete mIndexFeedback;
+ mIndexFeedback = 0;
+ }
+ if (mIndexFeedbackPolicy != HgWidget::IndexFeedbackNone) {
+ mIndexFeedback = new HgIndexFeedback(q);
+ mIndexFeedback->setWidget(q);
+ mIndexFeedback->setIndexFeedbackPolicy(mIndexFeedbackPolicy);
+ }
}
}
}
@@ -673,7 +673,7 @@
return;
mContainer->resize(scrollAreaBoundingRect.size());
-
+
updateScrollMetrics(mContainer->scrollPosition());
}
@@ -765,13 +765,25 @@
void HgWidgetPrivate::setIndexFeedbackPolicy( HgWidget::IndexFeedbackPolicy policy)
{
Q_UNUSED(policy)
-// mIndexFeedback->setIndexFeedbackPolicy(policy);
+ Q_Q(HgWidget);
+ mIndexFeedbackPolicy = policy;
+ if (!mIndexFeedback && policy != HgWidget::IndexFeedbackNone) {
+ mIndexFeedback = new HgIndexFeedback(q);
+ mIndexFeedback->setWidget(q);
+ } else if (mIndexFeedback && policy == HgWidget::IndexFeedbackNone) {
+ delete mIndexFeedback;
+ mIndexFeedback = 0;
+ }
+
+ if (mIndexFeedback && policy != HgWidget::IndexFeedbackNone) {
+ mIndexFeedback->setIndexFeedbackPolicy(policy);
+ }
}
HgWidget::IndexFeedbackPolicy HgWidgetPrivate::indexFeedbackPolicy() const
-{
-// return mIndexFeedback->indexFeedbackPolicy();
- return HgWidget::IndexFeedbackNone;
+{
+ return mIndexFeedback ? mIndexFeedback->indexFeedbackPolicy() :
+ HgWidget::IndexFeedbackNone;
}
void HgWidgetPrivate::setDefaultImage(QImage defaultImage)