--- a/src/hbinput/inputwidgets/hbinputbutton.cpp Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbinput/inputwidgets/hbinputbutton.cpp Wed Aug 18 10:05:37 2010 +0300
@@ -27,6 +27,12 @@
/// @cond
+// Defines how much the button size should be increased from its original size.
+const qreal HbInputThresholdMultiplier = 0.25;
+
+// Threshold for touch point position comparison
+const qreal HbInputTouchThreshold = 5.0;
+
class HbInputButtonPrivate
{
public:
@@ -40,6 +46,7 @@
HbInputButton::HbInputButtonType mType;
HbInputButton::HbInputButtonState mState;
+ HbInputButton::HbInputButtonState mPreviousState;
QPoint mPosition;
QSize mSize;
int mKeyCode;
@@ -48,11 +55,13 @@
QString mMappedCharacters;
QList<HbIcon> mIcons;
QRectF mBoundingRect;
+ QPointF mLastInteractionPoint;
};
HbInputButtonPrivate::HbInputButtonPrivate()
: mType(HbInputButton::ButtonTypeNormal), mState(HbInputButton::ButtonStateReleased),
- mPosition(0, 0), mSize(1, 1), mKeyCode(-1), mAutoRepeat(false)
+ mPreviousState(HbInputButton::ButtonStateReleased), mPosition(0, 0), mSize(1, 1),
+ mKeyCode(-1), mAutoRepeat(false), mLastInteractionPoint(-1, -1)
{
for (int i = 0; i < HbInputButton::ButtonTextIndexCount; ++i) {
mTexts.append("");
@@ -65,7 +74,8 @@
HbInputButtonPrivate::HbInputButtonPrivate(int keyCode, const QPoint &position, const QSize &size)
: mType(HbInputButton::ButtonTypeNormal), mState(HbInputButton::ButtonStateReleased),
- mPosition(position), mSize(size), mKeyCode(keyCode), mAutoRepeat(false)
+ mPreviousState(HbInputButton::ButtonStateReleased), mPosition(position),
+ mSize(size), mKeyCode(keyCode), mAutoRepeat(false)
{
for (int i = 0; i < HbInputButton::ButtonTextIndexCount; ++i) {
mTexts.append("");
@@ -97,8 +107,8 @@
HbInputButtonPrivate::HbInputButtonPrivate(HbInputButton::HbInputButtonType type, HbInputButton::HbInputButtonState state,
const QPoint &position, const QSize &size, int keyCode, bool autoRepeat,
const QList<QString> &texts, const QString &mappedCharacters, const QList<HbIcon> &icons)
- : mType(type), mState(state), mPosition(position), mSize(size), mKeyCode(keyCode), mAutoRepeat(autoRepeat),
- mMappedCharacters(mappedCharacters)
+ : mType(type), mState(state), mPreviousState(state), mPosition(position), mSize(size),
+ mKeyCode(keyCode), mAutoRepeat(autoRepeat), mMappedCharacters(mappedCharacters)
{
for (int i = 0; i < HbInputButton::ButtonTextIndexCount; ++i) {
if (i < texts.count()) {
@@ -127,35 +137,72 @@
void HbInputButtonPrivate::setDefaultGraphics(int keyCode)
{
switch(keyCode) {
- case HbInputButton::ButtonKeyCodeDelete:
- mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconDelete));
- break;
- case HbInputButton::ButtonKeyCodeShift:
- mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconShift));
- break;
- case HbInputButton::ButtonKeyCodeSymbol:
- mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSymbol));
- break;
- case HbInputButton::ButtonKeyCodeEnter:
- mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconEnter));
- break;
- case HbInputButton::ButtonKeyCodeSpace:
- mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSpace));
- break;
- case HbInputButton::ButtonKeyCodeAlphabet:
- mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSymbol));
- break;
- case HbInputButton::ButtonKeyCodeSmiley:
- mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSmiley));
- break;
- default:
- break;
+ case HbInputButton::ButtonKeyCodeDelete:
+ mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconDelete));
+ break;
+ case HbInputButton::ButtonKeyCodeShift:
+ mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconShift));
+ break;
+ case HbInputButton::ButtonKeyCodeSymbol:
+ mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSymbol));
+ break;
+ case HbInputButton::ButtonKeyCodeEnter:
+ mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconEnter));
+ break;
+ case HbInputButton::ButtonKeyCodeSpace:
+ mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSpace));
+ break;
+ case HbInputButton::ButtonKeyCodeAlphabet:
+ mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSymbol));
+ break;
+ case HbInputButton::ButtonKeyCodeSmiley:
+ mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSmiley));
+ break;
+ default:
+ break;
}
}
/// @endcond
/*!
+ \enum HbInputButton::HbInputButtonKeyCode
+
+ This enum defines a set of predefined key codes for input button. ButtonKeyCodeCustom should
+ always be the last item so that all values bigger than ButtonKeyCodeCustom can be interpreted
+ as custom key codes
+ */
+
+/*!
+ \enum HbInputButton::HbInputButtonType
+
+ This enum defines different button types. Button's graphics, text layout and functionality
+ depend of the this type. ButtonTypeCount should always be the last value.
+ */
+
+/*!
+ \enum HbInputButton::HbInputButtonState
+
+ This enum defines button states. State mostly affects the button's visual look in addition
+ to what can be done with the button (i.e. no interaction with disabled buttons, released and
+ latched buttons can be pressed). ButtonStateCount should always be the last value.
+ */
+
+/*!
+ \enum HbInputButton::HbInputButtonTextIndex
+
+ This enum defines set of text indices that can be used when setting texts to different parts of
+ a button using setText function. ButtonTextIndexCount should always be the last value.
+ */
+
+/*!
+ \enum HbInputButton::HbInputButtonIconIndex
+
+ This enum defines set of icon indices that can be used when setting icons to different parts of
+ a button using setIcon function. ButtonIconIndexCount should always be the last value.
+ */
+
+/*!
Constructor
*/
HbInputButton::HbInputButton()
@@ -210,6 +257,8 @@
/*!
Updates button's state.
+State change sequence latched, pressed, released will result
+in a latched state. Otherwise the new state will be the given state.
\sa state
*/
@@ -217,7 +266,14 @@
{
Q_D(HbInputButton);
- d->mState = state;
+ if (d->mState == ButtonStatePressed &&
+ d->mPreviousState == ButtonStateLatched &&
+ state == ButtonStateReleased) {
+ d->mState = d->mPreviousState;
+ } else {
+ d->mPreviousState = d->mState;
+ d->mState = state;
+ }
}
/*!
@@ -517,4 +573,63 @@
return d->mBoundingRect;
}
+/*!
+\brief Returns an active touch area for current button.
+
+Button contains bounding rectangle for actual size of the item, while touch area
+can actually extend over buttons physical boundaries. This is to make interacting
+with button easier.
+
+\return Active touch area as a rectangle, centered to its button.
+\sa setBoundingRect
+*/
+QRectF HbInputButton::activeTouchArea() const
+{
+ Q_D(const HbInputButton);
+
+ QRectF threshold(d->mBoundingRect);
+
+ qreal mod_w = d->mBoundingRect.width() * HbInputThresholdMultiplier;
+ qreal mod_h = d->mBoundingRect.height() * HbInputThresholdMultiplier;
+ threshold.adjust(-mod_w, -mod_h, mod_w, mod_h);
+
+ return threshold;
+}
+
+/*!
+\brief Set position where last user interaction occurred.
+*/
+void HbInputButton::setLastTriggeredPosition(const QPointF &position)
+{
+ Q_D(HbInputButton);
+
+ d->mLastInteractionPoint = position;
+}
+
+/*!
+\brief Clear last user interaction data.
+*/
+void HbInputButton::clearLastTriggeredPosition()
+{
+ Q_D(HbInputButton);
+
+ d->mLastInteractionPoint = QPointF(-1, -1);
+}
+
+/*!
+Checks whether the new touch point position is close enough to the previous
+one that hit this button so that the new touch point can
+be interpreted as the same as the old one.
+*/
+bool HbInputButton::wasTriggeredAt(const QPointF &position) const
+{
+ Q_D(const HbInputButton);
+
+ QRectF rect(d->mLastInteractionPoint.x() - HbInputTouchThreshold, d->mLastInteractionPoint.y() - HbInputTouchThreshold,
+ 2 * HbInputTouchThreshold, 2 * HbInputTouchThreshold);
+
+ return rect.contains(position);
+}
+
+
// End of file