src/hbcore/gui/hbdialog.cpp
changeset 28 b7da29130b0e
parent 21 4633027730f5
child 30 80e4d18b72f5
--- a/src/hbcore/gui/hbdialog.cpp	Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbcore/gui/hbdialog.cpp	Fri Sep 17 08:32:10 2010 +0300
@@ -32,6 +32,8 @@
 #include "hbevent.h"
 #include "hbtoolbar_p.h"
 #include "hbglobal_p.h"
+#include "hbstyletextprimitivedata.h"
+#include "hbstyleframeprimitivedata.h"
 
 #include <QPainter>
 #include <QGraphicsSceneMouseEvent>
@@ -47,7 +49,6 @@
 
 #ifdef HB_EFFECTS
 #include "hbeffectinternal_p.h"
-#define HB_POPUP_ITEM_TYPE "HB_POPUP"
 #endif
 
 /*!
@@ -212,7 +213,8 @@
     secondaryAction(0),
     closingAction(0),
     toolBar(0),
-    dismissOnAction(true)
+    dismissOnAction(true),
+    headingFrameItem(0)
 {
 }
 
@@ -243,6 +245,21 @@
     q->updateGeometry();
 }
 
+void HbDialogPrivate::createHeadingBackground()
+{
+    Q_Q(HbDialog);
+    if (!headingFrameItem) {
+        headingFrameItem = q->style()->createPrimitive(HbStyle::PT_FrameItem, "background", q);
+        HbStyleFramePrimitiveData data;
+        q->initPrimitiveData(&data, headingFrameItem);
+        data.fillWholeRect = true;
+        data.frameType = HbFrameDrawer::ThreePiecesHorizontal;
+        data.frameGraphicsName = QLatin1String("qtg_fr_popup_heading");
+        q->style()->updatePrimitive(headingFrameItem, &data, q);
+        headingFrameItem->update();
+    }
+}
+
 void HbDialogPrivate::_q_actionTriggered() {
     Q_Q(HbDialog);
     if (dismissOnAction) {
@@ -327,13 +344,73 @@
     if (d->headingWidget)
         delete d->headingWidget;
     d->headingWidget = headingWidget;
+    d->headingText = QString();
     if (headingWidget) {
         setProperty("heading_layout", true);
-        headingWidget->setParentItem(this);
+        d->headingWidget->setParentItem(this);
+        d->headingWidget->setZValue(zValue()+1);
         HbStyle::setItemName(headingWidget,"heading");
     } else {
         setProperty("heading_layout", false);
     }
+
+    if (headingWidget) {
+        d->createHeadingBackground();
+    } else {
+        if (d->headingFrameItem) {
+            delete d->headingFrameItem;
+            d->headingFrameItem = 0;
+        }
+    }
+    repolish();
+}
+
+/*!
+    Returns the heading text, if one has been added to the dialog; otherwise this
+    function returns empty string.
+    \sa setHeadingText()
+*/
+QString HbDialog::headingText() const
+{
+    Q_D(const HbDialog);
+    return d->headingText;
+}
+
+/*!
+    Sets \a heading as the title of the dialog.
+
+    To remove the title from the dialog, set an empty string as \a heading.
+    \sa headingText()
+*/
+void HbDialog::setHeadingText(const QString &heading)
+{
+    Q_D(HbDialog);
+    if (d->headingWidget) {
+        delete d->headingWidget;
+        d->headingWidget = 0;
+    }
+
+    d->headingText = heading;
+
+    if (!heading.isEmpty()) {
+        d->headingWidget = qobject_cast<QGraphicsWidget *>(style()->createPrimitive(HbStyle::PT_TextItem, "heading", this));
+        d->headingWidget->setZValue(zValue()+1);
+        HbStyleTextPrimitiveData data;
+        initPrimitiveData(&data, d->headingWidget);
+        data.text = heading;
+        style()->updatePrimitive(d->headingWidget, &data, this);
+        d->headingWidget->update();
+
+        d->createHeadingBackground();
+
+        setProperty("heading_layout", true);
+    } else {
+        setProperty("heading_layout", false);
+        if (d->headingFrameItem) {
+            delete d->headingFrameItem;
+            d->headingFrameItem = 0;
+        }
+    }
     repolish();
 }
 
@@ -372,6 +449,11 @@
     d->contentWidget = contentWidget;
     if (contentWidget) {
         contentWidget->setParentItem(this);
+        if (contentWidget->inherits("HbAbstractItemView")) {
+            setProperty("list_content", true);
+        } else {
+            setProperty("list_content", false);
+        }
         HbStyle::setItemName(contentWidget,"content");
     }
     repolish();