--- a/src/hbwidgets/popups/hbmessagebox.cpp Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbwidgets/popups/hbmessagebox.cpp Wed Aug 18 10:05:37 2010 +0300
@@ -30,89 +30,85 @@
#include <hbmainwindow.h>
#include <hbaction.h>
#include <hblineedit.h>
+#include <hblabel.h>
#include <hbscrollbar.h>
#include <hbscrollarea.h>
#include "hbglobal_p.h"
#include <QGraphicsItem>
#include <QGraphicsSceneMouseEvent>
#include <QTimer>
-#include <QTextOption>
+#include <QGraphicsLinearLayout>
+#include <QTextDocument>
+
#ifdef Q_OS_SYMBIAN
#include <systemtoneservice.h>
#endif
class HbStyle;
-class HbMessageBoxEditor : public HbLineEdit
+class HbMessageBoxWidget : public HbLabel
{
- Q_OBJECT
-public:
- HbMessageBoxEditor(QGraphicsItem* parent =0) : HbLineEdit(parent),mText()
- {
- setReadOnly(true);
- setCursorVisibility(Hb::TextCursorHidden);
- HbScrollArea *scroll = scrollArea();
- scroll->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
- clearContextMenuFlag(Hb::ShowTextContextMenuOnLongPress);
- clearContextMenuFlag(Hb::ShowTextContextMenuOnSelectionClicked);
- setBackgroundItem(0,0);
- }
-
- void focusInEvent(QFocusEvent * event)
- {
- Q_UNUSED(event);
- }
- void focusOutEvent(QFocusEvent * event)
+ Q_OBJECT
+ public:
+ HbLabel *mTextEdit;
+ HbMessageBoxWidget(QGraphicsItem* parent =0):HbLabel(parent){
+ setTextWrapping(Hb::TextWordWrap);
+ }
+ HbMessageBoxWidget(const QString& text, QGraphicsItem *parent=0):HbLabel(text, parent){
+ HbStyle::setItemName(this, "text");
+ }
+};
+class HbMessageBoxScrollArea : public HbScrollArea
+{
+ public:
+ HbMessageBoxWidget *widget;
+ HbMessageBoxScrollArea(QGraphicsItem* parent =0):HbScrollArea(parent),widget(0)
{
- Q_UNUSED(event);
+ setScrollDirections(Qt::Vertical);
+ widget = new HbMessageBoxWidget(this);
+ setContentWidget(widget);
+ setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
+ setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
+ setClampingStyle(HbScrollArea::StrictClamping);
+ setFlag(QGraphicsItem::ItemIsFocusable, false);
+ setFrictionEnabled(true);
}
-
- void setHtmlText(const QString &text)
+ void triggerPolish()
{
- mText = text;
- if(Qt::mightBeRichText(mText)){
- setHtml(text);
- }
- else {
- QString htmlString = Qt::convertFromPlainText(mText);
- setHtml(htmlString);
- }
- }
-
- QString htmlText() const
- {
- return mText;
+ repolish();
}
-private:
- QString mText;
-
};
+
class HbMessageBoxContentWidget : public HbWidget
{
Q_OBJECT
-
-public:
+ public:
HbMessageBoxPrivate *d;
- HbMessageBoxEditor *mTextEdit;
QGraphicsItem *mIconItem;
+ HbMessageBoxScrollArea *mScrollArea;
+
HbMessageBoxContentWidget(HbMessageBoxPrivate *priv,
- QGraphicsItem* parent =0) : HbWidget(parent),d(priv),mTextEdit(0),mIconItem(0)
+ QGraphicsItem* parent =0) : HbWidget(parent),d(priv),mIconItem(0),mScrollArea(0)
{
+ mScrollArea = new HbMessageBoxScrollArea(this);
+ mIconItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_MessageBox_icon, this);
+ setProperty("hasIcon",true);
+ HbStyle::setItemName(mScrollArea, "scrollArea");
+ HbStyle::setItemName(mIconItem, "icon");
+ }
- mTextEdit = new HbMessageBoxEditor(this);
- mIconItem = style()->createPrimitive(HbStyle::P_MessageBox_icon, this);
- setProperty("hasIcon",true);
- HbStyle::setItemName(mTextEdit, "text");
- HbStyle::setItemName(mIconItem, "icon");
+ void triggerPolish()
+ {
+ repolish();
}
+
enum { Type = HbPrivate::ItemType_MessageNoteContentWidget };
int type() const { return Type; }
};
/*
constructor
-
*/
HbMessageBoxPrivate::HbMessageBoxPrivate() :
@@ -144,7 +140,7 @@
{
Q_Q(HbMessageBox);
- mMessageBoxContentWidget = new HbMessageBoxContentWidget( this );
+ mMessageBoxContentWidget = new HbMessageBoxContentWidget(this);
q->setContentWidget( mMessageBoxContentWidget );
q->setDismissPolicy(HbPopup::NoDismiss);
q->setTimeout(HbPopup::NoTimeout);
@@ -165,30 +161,32 @@
}
void HbMessageBoxPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status)
{
+
#ifdef Q_OS_SYMBIAN
-
- if ( (status.reason == Hb::EffectFinished) || ( (status.reason == Hb::EffectCancelled) && (!mStartEffect) )) {
- CSystemToneService *pSystemTone = systemToneService();
- if(!pSystemTone) {
- return ;
- }
- switch(mMessageBoxType) {
- case HbMessageBox::MessageTypeInformation:
- pSystemTone->PlayTone(CSystemToneService::EInformationBeep);
- break;
- case HbMessageBox::MessageTypeWarning:
- pSystemTone->PlayTone(CSystemToneService::EWarningBeep);
- break;
- case HbMessageBox::MessageTypeQuestion:
- pSystemTone->PlayTone(CSystemToneService::EConfirmationBeep);
- break;
- default:
- break;
- }
+
- }
-#else
- Q_UNUSED(status);
+ if ( (status.reason == Hb::EffectFinished) || ( (status.reason == Hb::EffectCancelled) && (!mStartEffect) )) {
+ CSystemToneService *pSystemTone = systemToneService();
+ if(!pSystemTone) {
+ return ;
+ }
+ switch(mMessageBoxType) {
+ case HbMessageBox::MessageTypeInformation:
+ pSystemTone->PlayTone(CSystemToneService::EInformationBeep);
+ break;
+ case HbMessageBox::MessageTypeWarning:
+ pSystemTone->PlayTone(CSystemToneService::EWarningBeep);
+ break;
+ case HbMessageBox::MessageTypeQuestion:
+ pSystemTone->PlayTone(CSystemToneService::EConfirmationBeep);
+ break;
+ default:
+ break;
+ }
+ }
+#else
+ Q_UNUSED(status);
+
#endif // Q_OS_SYMBIAN
}
@@ -199,9 +197,9 @@
\brief HbMessageBox is a convenience modal dialog class. HbMessageBox can be used to launch a information,question,warning or any other
general messages.
- \image html information.PNG "An information MessageBox"
- \image html question.PNG "A question MessageBox"
- \image html warning.PNG "A warning MessageBox"
+ \image html information.PNG "An information MessageBox"
+ \image html question.PNG "A question MessageBox"
+ \image html warning.PNG "A warning MessageBox"
Using HbMessageBox, the following dialogs can be created:
@@ -299,6 +297,7 @@
d->mMessageBoxType = type;
d->q_ptr = this;
d->init();
+ setModal(true);
}
/*!
@@ -314,7 +313,8 @@
d->mMessageBoxType = type;
d->q_ptr = this;
d->init();
- d->mMessageBoxContentWidget->mTextEdit->setHtmlText(text);
+ setText(text);
+
}
/*!
@@ -349,7 +349,7 @@
{
Q_D(const HbMessageBox);
switch (primitive) {
- case HbStyle::P_MessageBox_icon:
+ case HbStylePrivate::P_MessageBox_icon:
return d->mMessageBoxContentWidget->mIconItem;
default:
return 0;
@@ -363,8 +363,8 @@
{
Q_D(const HbMessageBox);
HbDialog::initStyleOption(option);
- option->icon = d->mIcon;
- option->messageBoxType = d->mMessageBoxType;
+ option->icon = d->mIcon;
+ option->messageBoxType = d->mMessageBoxType;
}
/*!
@@ -373,13 +373,12 @@
void HbMessageBox::updatePrimitives()
{
Q_D(HbMessageBox);
- HbDialog::updatePrimitives();
+ HbDialog::updatePrimitives();
HbStyleOptionMessageBox option;
initStyleOption(&option);
if (d->mMessageBoxContentWidget->mIconItem) {
- style()->updatePrimitive(d->mMessageBoxContentWidget->mIconItem, HbStyle::P_MessageBox_icon, &option);
+ HbStylePrivate::updatePrimitive(d->mMessageBoxContentWidget->mIconItem, HbStylePrivate::P_MessageBox_icon, &option);
}
-
}
/*!
@@ -390,8 +389,19 @@
void HbMessageBox::setText(const QString &text)
{
Q_D(HbMessageBox);
- if ( text != d->mMessageBoxContentWidget->mTextEdit->htmlText() ) {
- d->mMessageBoxContentWidget->mTextEdit->setHtmlText(text);
+ if ( text != d->mBoxText ) {
+ d->mBoxText = text;
+ if (d->mMessageBoxContentWidget->mScrollArea->widget) {
+
+ if(Qt::mightBeRichText(text)){
+ d->mMessageBoxContentWidget->mScrollArea->widget->setHtml(text);
+
+ }
+ else {
+ d->mMessageBoxContentWidget->mScrollArea->widget->setPlainText(text);
+ }
+ }
+ d->mMessageBoxContentWidget->mScrollArea->triggerPolish();
}
}
@@ -402,7 +412,7 @@
QString HbMessageBox::text() const
{
Q_D(const HbMessageBox);
- return d->mMessageBoxContentWidget->mTextEdit->htmlText();
+ return d->mBoxText;
}
/*!
@@ -418,13 +428,14 @@
if (d->mMessageBoxContentWidget->mIconItem) {
HbStyleOptionMessageBox option;
initStyleOption(&option);
- style()->updatePrimitive(d->mMessageBoxContentWidget->mIconItem, HbStyle::P_MessageBox_icon, &option);
+ HbStylePrivate::updatePrimitive(d->mMessageBoxContentWidget->mIconItem, HbStylePrivate::P_MessageBox_icon, &option);
}
if(iconVisible() ) {
d->mMessageBoxContentWidget->mIconItem->show();
d->mMessageBoxContentWidget->setProperty("hasIcon",true);
}
}
+
}
/*!
@@ -459,7 +470,7 @@
}
d->mIconVisible = visible;
- repolish();
+ d->mMessageBoxContentWidget->triggerPolish();
}
}