--- a/src/hbinput/inputwidgets/hbinputexactwordpopup.cpp Thu Jul 15 14:03:49 2010 +0100
+++ b/src/hbinput/inputwidgets/hbinputexactwordpopup.cpp Thu Jul 22 16:36:53 2010 +0100
@@ -28,10 +28,8 @@
#include <QIcon>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsLinearLayout>
-#if QT_VERSION >= 0x040600
-#include <QGraphicsDropShadowEffect>
-#endif
+#include <hbinputregioncollector_p.h>
#include "hbdeviceprofile.h"
#include "hbdialog.h"
#include "hblabel.h"
@@ -41,11 +39,9 @@
#include "hbinputsettingproxy.h"
#include "hbframeitem.h"
#include "hbframedrawer.h"
-#include "hbcolorscheme.h"
#include "hbdialog_p.h"
-const QSizeF HbExactWordPopupSize(10,10);
-const QPointF HbExactWordPopupStartupDisplay(12, 33);
+const qreal HbExactWordPopupHeight = 50.0;
class HbExactWordPopupPrivate : public HbDialogPrivate
{
@@ -59,45 +55,36 @@
public:
HbLabel *mText;
- HbStyleOptionLabel *mOption;
- HbIconItem *iconPrim;
HbFrameItem *mPopupBackground;
};
-HbExactWordPopupPrivate::HbExactWordPopupPrivate(){
- mText = 0;
- mOption = 0;
- iconPrim = 0;
+HbExactWordPopupPrivate::HbExactWordPopupPrivate()
+ : mText(0), mPopupBackground(0)
+{
}
-HbExactWordPopupPrivate::~HbExactWordPopupPrivate(){
- delete mOption;
- mOption = 0;
+HbExactWordPopupPrivate::~HbExactWordPopupPrivate()
+{
}
void HbExactWordPopupPrivate::initBackground()
{
Q_Q(HbExactWordPopup);
- mPopupBackground = static_cast<HbFrameItem*>(q->primitive( HbStyle::P_Popup_background));
+ mPopupBackground = static_cast<HbFrameItem*>(q->primitive(HbStyle::P_Popup_background));
- if( mPopupBackground == 0 ) {
+ if (!mPopupBackground) {
mPopupBackground = static_cast<HbFrameItem*>(q->style()->createPrimitive((HbStyle::Primitive)(HbStyle::P_Popup_background), q));
}
- if ( mPopupBackground->frameDrawer().isNull()) {
- HbFrameDrawer* fd = new HbFrameDrawer("qtg_fr_popup_secondary", HbFrameDrawer::NinePieces);
+ if (mPopupBackground->frameDrawer().isNull()) {
+ HbFrameDrawer *fd = new HbFrameDrawer("qtg_fr_popup_secondary", HbFrameDrawer::NinePieces);
mPopupBackground->setFrameDrawer(fd);
}
-
- // the size of the layout in the base class has been set to 0, reset it by passing an invalid size to setMinimumSize
- if(mainLayout) {
- mainLayout->setMinimumSize(-1, -1);
- }
-
}
-HbExactWordPopup* HbExactWordPopup::instance( HbExactWordPopupIndicator indicatorArrow ) {
+HbExactWordPopup* HbExactWordPopup::instance(HbExactWordPopupIndicator indicatorArrow)
+{
static QPointer<HbExactWordPopup> exactWordPopup;
if (!exactWordPopup) {
// HbExactWordPopup is owned by the scene
@@ -110,51 +97,33 @@
Constructor.
\param parent An optional parameter.
*/
-HbExactWordPopup::HbExactWordPopup(QGraphicsWidget *parent, HbExactWordPopupIndicator indicatorArrow ) :
- HbDialog(*new HbExactWordPopupPrivate(), parent)
+HbExactWordPopup::HbExactWordPopup(QGraphicsWidget *parent, HbExactWordPopupIndicator indicatorArrow)
+ : HbDialog(*new HbExactWordPopupPrivate(), parent)
{
Q_D(HbExactWordPopup);
- d->mText = new HbLabel(this);
+ HbInputRegionCollector::instance()->attach(this);
+
+ d->mText = new HbLabel();
d->mText->setAlignment(Qt::AlignCenter);
+ d->mText->setFontSpec(HbFontSpec(HbFontSpec::Primary));
+ d->mText->setContentsMargins(0, 0, 0, 0);
- d->setPriority(HbPopupPrivate::VirtualKeyboard + 1); // Should be shown on top of virtual keyboard.
+ setContentWidget(d->mText);
d->initBackground();
setTimeout(HbPopup::NoTimeout);
setBackgroundFaded(false);
- setVisible(false);
setDismissPolicy(HbPopup::TapInside);
setFocusPolicy(Qt::ClickFocus);
- setContentWidget(d->mText);
setModal(false);
+ setContentsMargins(0, 0, 0, 0);
-#if QT_VERSION >= 0x040600
- // Make sure the excat word popup never steals focus.
+ // Make sure the exact word popup never steals focus.
setFlag(QGraphicsItem::ItemIsPanel, true);
setActive(false);
- // enable drop shadow for the preview pane
- QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
- effect->setBlurRadius(8);
- setGraphicsEffect(effect);
-#endif
-
- d->mOption = new HbStyleOptionLabel();
- if(d->mOption != 0 ) {
- d->mOption->text = QString(" ");
- d->mOption->boundingRect = QRectF(HbExactWordPopupStartupDisplay,HbExactWordPopupSize);
- // for hardware keypad, we need to show the arrow to indicate the word
- // and in virtual keypad this is not needed, so set the image accordingly
- setIndicatorArrow( indicatorArrow );
- d->mOption->alignment = Qt::AlignCenter;
- }
-
- d->iconPrim = static_cast<HbIconItem*>(primitive(HbStyle::P_Label_icon));
- if(d->iconPrim == 0) {
- d->iconPrim = static_cast<HbIconItem*>(style()->createPrimitive((HbStyle::Primitive)(HbStyle::P_Label_icon), this));
- }
- style()->updatePrimitive(d->iconPrim, (HbStyle::Primitive)(HbStyle::P_Label_icon), d->mOption);
+ setIndicatorArrow(indicatorArrow);
}
/*!
@@ -178,9 +147,6 @@
{
Q_D(HbExactWordPopup);
d->mText->setPlainText(newText);
-
- QRectF ps=QRectF(QPointF(0,0), d->mText->preferredSize()).adjusted(-9,-9,9,9);
- resize(ps.size());
}
/*!
@@ -190,37 +156,17 @@
*/
void HbExactWordPopup::showText(QPointF pos)
{
- // the popup should know at this stage in which main window/scene it's been launched at.
- int screenWidth = 0;
- if ( mainWindow() ) {
- screenWidth = HbDeviceProfile::profile(this).logicalSize().width();
- } else {
- // this is the fall-back if the main window is not know - can be removed when popup
- // is not relying on the primary window anymore.
- screenWidth = HbDeviceProfile::profile(mainWindow()).logicalSize().width();
- }
+ Q_D(HbExactWordPopup);
+
+ QFontMetrics fontMetrics(HbFontSpec(HbFontSpec::Primary).font());
+ qreal width = fontMetrics.width(text());
- const QRectF br = boundingRect();
- const qreal brCenter = br.width()/2;
- pos.setX(pos.x()-brCenter);
- // fix x position to keep tooltip visible
- const qreal requiredWidth = pos.x()+br.width();
- if (requiredWidth > screenWidth) {
- pos.setX(pos.x()-(requiredWidth-screenWidth));
- } else if (0 > pos.x()) {
- pos.setX(0);
- }
- pos.setY(pos.y()-br.height());
+ d->mText->setMinimumWidth(width);
+ d->mText->setMaximumWidth(width);
+
+ pos.setY(pos.y() - HbExactWordPopupHeight);
setPos(pos);
- QSizeF mySize = size();
- mySize.setHeight(HbExactWordPopupSize.height());
- resize(mySize);
-
- Q_D(HbExactWordPopup);
- d->mOption->boundingRect = QRectF(rect().center().x() - (HbExactWordPopupSize.width()/2),rect().bottom(),HbExactWordPopupSize.width(),HbExactWordPopupSize.height());
- style()->updatePrimitive(d->iconPrim, (HbStyle::Primitive)(HbStyle::P_Label_icon), d->mOption);
-
show();
}
@@ -249,27 +195,22 @@
void HbExactWordPopup::updatePrimitives()
{
- Q_D( HbExactWordPopup );
+ Q_D(HbExactWordPopup);
d->mPopupBackground->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
d->mPopupBackground->frameDrawer().setFrameGraphicsName("qtg_fr_popup_secondary");
d->mPopupBackground->setGeometry(boundingRect());
-
- QColor col = HbColorScheme::color( "qtc_editor_normal" ); //popupforeground
- if (col.isValid()) {
- d->mText->setTextColor(col);
- }
}
// this method is called whenever there is a switch of keypad usage from h/w to virtual
// h/w keypad needs an indicator, whereas virtual does not, hence set the image appropriately.
-void HbExactWordPopup::setIndicatorArrow( HbExactWordPopupIndicator indicatorArrow )
+void HbExactWordPopup::setIndicatorArrow(HbExactWordPopupIndicator indicatorArrow)
{
- Q_D( HbExactWordPopup );
+ Q_D(HbExactWordPopup);
if (indicatorArrow == HbNoIndicatorArrow) {
- d->mOption->icon = (QString(""));
+ d->mText->setIcon(HbIcon());
} else {
- d->mOption->icon = (QString("qtg_graf_inpu_swipe"));
+ d->mText->setIcon(HbIcon("qtg_graf_inpu_swipe"));
}
}