calendarui/views/dayview/src/calendayitem.cpp
changeset 83 5aadd1120515
parent 64 1881ad52dc45
equal deleted inserted replaced
82:dcd0ca396fa1 83:5aadd1120515
    20 #include <HbFrameItem>
    20 #include <HbFrameItem>
    21 #include <HbTextItem>
    21 #include <HbTextItem>
    22 #include <HbStyle>
    22 #include <HbStyle>
    23 #include <HbColorScheme>
    23 #include <HbColorScheme>
    24 #include <agendaentry.h>
    24 #include <agendaentry.h>
       
    25 #include <QGraphicsSceneMoveEvent>
    25 
    26 
    26 // User includes
    27 // User includes
    27 #include "calendaycommonheaders.h"
    28 #include "calendaycommonheaders.h"
    28 #include "calendayitem.h"
    29 #include "calendayitem.h"
    29 #include "calendaystatusstrip.h"
    30 #include "calendaystatusstrip.h"
    34 
    35 
    35 /*!
    36 /*!
    36  \brief Constructor.
    37  \brief Constructor.
    37  */
    38  */
    38 CalenDayItem::CalenDayItem(const CalenDayContainer *container) :
    39 CalenDayItem::CalenDayItem(const CalenDayContainer *container) :
    39     mContainer(container), mUpdated(false), mBg(0), mEventDesc(0),
    40     mUpdated(false), mEventDescMinWidth(0.0), mFrameMinWidth(0.0),
    40         mColorStripe(0), mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
    41 	mBg(0), mEventDesc(0), mColorStripe(0),
       
    42 	mContainer(container), mBackgroundType(EStaticBackground)
    41 {
    43 {
    42 }
    44 }
    43 
    45 
    44 /*!
    46 /*!
    45  \brief Constructor.
    47  \brief Constructor.
    46  */
    48  */
    47 CalenDayItem::CalenDayItem(const CalenDayItem & source) :
    49 CalenDayItem::CalenDayItem(const CalenDayItem & source) :
    48     HbAbstractViewItem(source), mContainer(source.container()),
    50     HbAbstractViewItem(source), 
    49         mUpdated(false), mBg(0), mEventDesc(0), mColorStripe(0),
    51         mUpdated(false), mEventDescMinWidth(0.0),
    50         mEventDescMinWidth(0.0), mFrameMinWidth(0.0)
    52 		mFrameMinWidth(0.0), mBg(0), mEventDesc(0),
    51 {
    53 		mColorStripe(0), mContainer(source.container()),
    52     mBg = new HbFrameItem("qtg_fr_cal_meeting_bg", HbFrameDrawer::NinePieces,
    54         mBackgroundType(EStaticBackground)
    53         this);
    55 {
       
    56     mBg = new HbFrameItem("qtg_fr_cal_meeting_bg", HbFrameDrawer::NinePieces, this);
       
    57     
    54     mEventDesc = new HbTextItem(this);
    58     mEventDesc = new HbTextItem(this);
    55     // TODO: probably ElideLeft needed for mirrored layout
    59     // TODO: probably ElideLeft needed for mirrored layout
    56     mEventDesc->setElideMode(Qt::ElideRight);
    60     mEventDesc->setElideMode(Qt::ElideRight);
    57     mEventDesc->setTextWrapping(Hb::TextWrapAnywhere);
    61     mEventDesc->setTextWrapping(Hb::TextWrapAnywhere);
    58     mColorStripe = new CalenDayStatusStrip(this);
    62     mColorStripe = new CalenDayStatusStrip(this);
    72         * deviceProfile.unitValue();
    76         * deviceProfile.unitValue();
    73     
    77     
    74     // Minimum width is assured by widgetml and css, additionally called here 
    78     // Minimum width is assured by widgetml and css, additionally called here 
    75     // to prevent minimum size hint caching inside effectiveSizeHint
    79     // to prevent minimum size hint caching inside effectiveSizeHint
    76     setMinimumWidth(stripeWidth);
    80     setMinimumWidth(stripeWidth);
       
    81     
       
    82     connect(this, SIGNAL(backgroundTypeChanged(const CalenDayItem*)), mContainer, SLOT(updateFloatingItemsList(const CalenDayItem*)));
    77 }
    83 }
    78 
    84 
    79 /*!
    85 /*!
    80  \brief Destructor.
    86  \brief Destructor.
    81  */
    87  */
   208 void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event)
   214 void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event)
   209 {
   215 {
   210     Q_UNUSED(event)
   216     Q_UNUSED(event)
   211 
   217 
   212     qreal width = rect().width();
   218     qreal width = rect().width();
       
   219     qreal height = rect().height();
       
   220     
       
   221     //Backround height can't be bigger the screen. If event is long enough
       
   222     //backround will start to float together with view content.
       
   223     mBg->setMaximumHeight(CalenDayUtils::instance()->screenHeight());
   213 
   224 
   214     HbDeviceProfile deviceProfile;
   225     HbDeviceProfile deviceProfile;
   215     if (width < mEventDescMinWidth) {
   226     if (width < mEventDescMinWidth) {
   216         mColorStripe->setPreferredWidth(KCalenMinTimeStripWidth
   227         mColorStripe->setPreferredWidth(KCalenMinTimeStripWidth
   217             * deviceProfile.unitValue());
   228             * deviceProfile.unitValue());
       
   229         mBg->setMaximumWidth(KCalenMinEventWidth
       
   230             * deviceProfile.unitValue());        
   218         mEventDesc->hide();
   231         mEventDesc->hide();
   219     }
   232     }
   220     else {
   233     else {
   221         mColorStripe->setPreferredWidth(KCalenTimeStripWidth
   234         mColorStripe->setPreferredWidth(KCalenTimeStripWidth
   222             * deviceProfile.unitValue());
   235             * deviceProfile.unitValue());
       
   236         mBg->setMaximumWidth(CalenDayUtils::instance()->screenWidth());
   223         mEventDesc->show();
   237         mEventDesc->show();
   224     }
   238     }
   225 
   239 
   226     if (width < mFrameMinWidth) {
   240     if (width < mFrameMinWidth) {
   227         mBg->hide();
   241         mBg->hide();
   228     }
   242     }
   229     else {
   243     else {
   230         mBg->show();
   244         mBg->show();
   231     }
   245     }
       
   246     
       
   247     //If following condition is fulfilled then background item needs to be
       
   248     //switched to floating one.
       
   249     if (height > CalenDayUtils::instance()->screenHeight()) {
       
   250 
       
   251         //If background item is floating then it needs to be removed from
       
   252         //layout (see css & widgetml). In this case we need to take care of setting its
       
   253         //geometry by ourselves.
       
   254         QRectF newRect = rect();
       
   255         qreal baseY = pos().y();
       
   256         qreal mappedY = mapFromScene(pos()).y();
       
   257         qreal normalizedY = mappedY - baseY; //aligns background to the top of viewport
       
   258         //Check whether background won't go out of the event's rectangle
       
   259         if(normalizedY < newRect.top()){
       
   260             normalizedY = newRect.top();
       
   261         }
       
   262         newRect.setY(normalizedY);
       
   263         mBg->setGeometry(newRect);
       
   264 
       
   265         //Notify the container about background type change.
       
   266         //From now on this object is going to receive information
       
   267         //about scrolling.
       
   268         if (mBackgroundType == EStaticBackground) {
       
   269             mBackgroundType = EFloatingBackground;
       
   270             emit backgroundTypeChanged(this);
       
   271         }
       
   272     }else if (mBackgroundType == EFloatingBackground) {
       
   273         mBackgroundType = EStaticBackground;
       
   274         emit backgroundTypeChanged(this);
       
   275     }
   232 
   276 
   233     // Necessary to switch layout
   277     // Necessary to switch layout
   234     repolish();
   278     repolish();
   235 }
   279 }
   236 
   280 
       
   281 /*!
       
   282  \brief This slot is triggered when backround type is set as EFloatingBackground.
       
   283         It allows to scroll backround along with view content.
       
   284  
       
   285  \param pos Positoin to which backround needs to be scrolled.
       
   286  */
       
   287 void CalenDayItem::scrollBackground(const QPointF &pos)
       
   288 {
       
   289     qreal newY = mapFromParent(pos).y();
       
   290     //margin to ensure that rounded corners will stay hidden
       
   291     const qreal margin = 5.0;
       
   292 
       
   293     if (newY > rect().top() && newY + mBg->rect().height() < rect().bottom()) {
       
   294 
       
   295         mBg->setY(newY - margin);
       
   296     }
       
   297     else if (newY < rect().top()) { //condition for top boundary
       
   298 
       
   299         mBg->setY(rect().top());
       
   300     
       
   301     }else if (newY + mBg->rect().height() > rect().bottom()) { //condition for bottom boundary
       
   302 
       
   303         mBg->setY(rect().bottom() - mBg->rect().height());
       
   304     }
       
   305 }
       
   306 
   237 // End of File
   307 // End of File