src/hbcore/gui/hbdialog.cpp
changeset 28 b7da29130b0e
parent 21 4633027730f5
child 30 80e4d18b72f5
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    30 #include "hbstyleoptionpopup_p.h"
    30 #include "hbstyleoptionpopup_p.h"
    31 #include "hbdeviceprofile.h"
    31 #include "hbdeviceprofile.h"
    32 #include "hbevent.h"
    32 #include "hbevent.h"
    33 #include "hbtoolbar_p.h"
    33 #include "hbtoolbar_p.h"
    34 #include "hbglobal_p.h"
    34 #include "hbglobal_p.h"
       
    35 #include "hbstyletextprimitivedata.h"
       
    36 #include "hbstyleframeprimitivedata.h"
    35 
    37 
    36 #include <QPainter>
    38 #include <QPainter>
    37 #include <QGraphicsSceneMouseEvent>
    39 #include <QGraphicsSceneMouseEvent>
    38 #include <QStyleOptionGraphicsItem>
    40 #include <QStyleOptionGraphicsItem>
    39 #include <QShowEvent>
    41 #include <QShowEvent>
    45 
    47 
    46 #include <hbfeedbackmanager.h>
    48 #include <hbfeedbackmanager.h>
    47 
    49 
    48 #ifdef HB_EFFECTS
    50 #ifdef HB_EFFECTS
    49 #include "hbeffectinternal_p.h"
    51 #include "hbeffectinternal_p.h"
    50 #define HB_POPUP_ITEM_TYPE "HB_POPUP"
       
    51 #endif
    52 #endif
    52 
    53 
    53 /*!
    54 /*!
    54     @beta
    55     @beta
    55     @hbcore
    56     @hbcore
   210     headingWidget(0),
   211     headingWidget(0),
   211     primaryAction(0),
   212     primaryAction(0),
   212     secondaryAction(0),
   213     secondaryAction(0),
   213     closingAction(0),
   214     closingAction(0),
   214     toolBar(0),
   215     toolBar(0),
   215     dismissOnAction(true)
   216     dismissOnAction(true),
       
   217     headingFrameItem(0)
   216 {
   218 {
   217 }
   219 }
   218 
   220 
   219 HbDialogPrivate::~HbDialogPrivate()
   221 HbDialogPrivate::~HbDialogPrivate()
   220 {
   222 {
   239             headingWidget->setLayoutDirection(q->mainWindow()->layoutDirection());
   241             headingWidget->setLayoutDirection(q->mainWindow()->layoutDirection());
   240         }
   242         }
   241     }
   243     }
   242 
   244 
   243     q->updateGeometry();
   245     q->updateGeometry();
       
   246 }
       
   247 
       
   248 void HbDialogPrivate::createHeadingBackground()
       
   249 {
       
   250     Q_Q(HbDialog);
       
   251     if (!headingFrameItem) {
       
   252         headingFrameItem = q->style()->createPrimitive(HbStyle::PT_FrameItem, "background", q);
       
   253         HbStyleFramePrimitiveData data;
       
   254         q->initPrimitiveData(&data, headingFrameItem);
       
   255         data.fillWholeRect = true;
       
   256         data.frameType = HbFrameDrawer::ThreePiecesHorizontal;
       
   257         data.frameGraphicsName = QLatin1String("qtg_fr_popup_heading");
       
   258         q->style()->updatePrimitive(headingFrameItem, &data, q);
       
   259         headingFrameItem->update();
       
   260     }
   244 }
   261 }
   245 
   262 
   246 void HbDialogPrivate::_q_actionTriggered() {
   263 void HbDialogPrivate::_q_actionTriggered() {
   247     Q_Q(HbDialog);
   264     Q_Q(HbDialog);
   248     if (dismissOnAction) {
   265     if (dismissOnAction) {
   325     if (d->headingWidget == headingWidget)
   342     if (d->headingWidget == headingWidget)
   326         return;
   343         return;
   327     if (d->headingWidget)
   344     if (d->headingWidget)
   328         delete d->headingWidget;
   345         delete d->headingWidget;
   329     d->headingWidget = headingWidget;
   346     d->headingWidget = headingWidget;
       
   347     d->headingText = QString();
   330     if (headingWidget) {
   348     if (headingWidget) {
   331         setProperty("heading_layout", true);
   349         setProperty("heading_layout", true);
   332         headingWidget->setParentItem(this);
   350         d->headingWidget->setParentItem(this);
       
   351         d->headingWidget->setZValue(zValue()+1);
   333         HbStyle::setItemName(headingWidget,"heading");
   352         HbStyle::setItemName(headingWidget,"heading");
   334     } else {
   353     } else {
   335         setProperty("heading_layout", false);
   354         setProperty("heading_layout", false);
       
   355     }
       
   356 
       
   357     if (headingWidget) {
       
   358         d->createHeadingBackground();
       
   359     } else {
       
   360         if (d->headingFrameItem) {
       
   361             delete d->headingFrameItem;
       
   362             d->headingFrameItem = 0;
       
   363         }
       
   364     }
       
   365     repolish();
       
   366 }
       
   367 
       
   368 /*!
       
   369     Returns the heading text, if one has been added to the dialog; otherwise this
       
   370     function returns empty string.
       
   371     \sa setHeadingText()
       
   372 */
       
   373 QString HbDialog::headingText() const
       
   374 {
       
   375     Q_D(const HbDialog);
       
   376     return d->headingText;
       
   377 }
       
   378 
       
   379 /*!
       
   380     Sets \a heading as the title of the dialog.
       
   381 
       
   382     To remove the title from the dialog, set an empty string as \a heading.
       
   383     \sa headingText()
       
   384 */
       
   385 void HbDialog::setHeadingText(const QString &heading)
       
   386 {
       
   387     Q_D(HbDialog);
       
   388     if (d->headingWidget) {
       
   389         delete d->headingWidget;
       
   390         d->headingWidget = 0;
       
   391     }
       
   392 
       
   393     d->headingText = heading;
       
   394 
       
   395     if (!heading.isEmpty()) {
       
   396         d->headingWidget = qobject_cast<QGraphicsWidget *>(style()->createPrimitive(HbStyle::PT_TextItem, "heading", this));
       
   397         d->headingWidget->setZValue(zValue()+1);
       
   398         HbStyleTextPrimitiveData data;
       
   399         initPrimitiveData(&data, d->headingWidget);
       
   400         data.text = heading;
       
   401         style()->updatePrimitive(d->headingWidget, &data, this);
       
   402         d->headingWidget->update();
       
   403 
       
   404         d->createHeadingBackground();
       
   405 
       
   406         setProperty("heading_layout", true);
       
   407     } else {
       
   408         setProperty("heading_layout", false);
       
   409         if (d->headingFrameItem) {
       
   410             delete d->headingFrameItem;
       
   411             d->headingFrameItem = 0;
       
   412         }
   336     }
   413     }
   337     repolish();
   414     repolish();
   338 }
   415 }
   339 
   416 
   340 /*!
   417 /*!
   370         delete d->contentWidget;
   447         delete d->contentWidget;
   371     prepareGeometryChange(); // needed to paint screen properly
   448     prepareGeometryChange(); // needed to paint screen properly
   372     d->contentWidget = contentWidget;
   449     d->contentWidget = contentWidget;
   373     if (contentWidget) {
   450     if (contentWidget) {
   374         contentWidget->setParentItem(this);
   451         contentWidget->setParentItem(this);
       
   452         if (contentWidget->inherits("HbAbstractItemView")) {
       
   453             setProperty("list_content", true);
       
   454         } else {
       
   455             setProperty("list_content", false);
       
   456         }
   375         HbStyle::setItemName(contentWidget,"content");
   457         HbStyle::setItemName(contentWidget,"content");
   376     }
   458     }
   377     repolish();    
   459     repolish();    
   378 }
   460 }
   379 
   461