calendarui/views/dayview/src/calendaystatusstrip.cpp
changeset 77 b0711afde476
parent 68 a5a1242fd2e8
equal deleted inserted replaced
68:a5a1242fd2e8 77:b0711afde476
    20 #include <QPen>
    20 #include <QPen>
    21 #include <HbColorScheme>
    21 #include <HbColorScheme>
    22 
    22 
    23 // User includes
    23 // User includes
    24 #include "calendaystatusstrip.h"
    24 #include "calendaystatusstrip.h"
       
    25 #include "calendayutils.h"
    25 
    26 
    26 // Constants
    27 // Constants
    27 qreal const CalenDayStatusStrip::mMinute = 60;
    28 qreal const CalenDayStatusStrip::mMinute = 60;
    28 qreal const CalenDayStatusStrip::mMinimumTime = 5;
    29 qreal const CalenDayStatusStrip::mMinimumTime = 5;
    29 
    30 
   121             mStartEndEventTime.first.minute() + mMinimumTime);
   122             mStartEndEventTime.first.minute() + mMinimumTime);
   122     }
   123     }
   123 }
   124 }
   124 
   125 
   125 /*!
   126 /*!
   126    \brief Reimplemented function...
   127  \brief Reimplemented function...
   127    
   128  
   128    Reimplemented function to draw status strip. 
   129  Reimplemented function to draw status strip. 
   129    It is based on CalenDayStatusStrip::DrawingStyle, range and color
   130  It is based on CalenDayStatusStrip::DrawingStyle, range and color
   130  */
   131  */
   131 void CalenDayStatusStrip::paint(
   132 void CalenDayStatusStrip::paint(
   132     QPainter *painter,
   133     QPainter *painter,
   133     const QStyleOptionGraphicsItem *option,
   134     const QStyleOptionGraphicsItem *option,
   134     QWidget *widget)
   135     QWidget *widget)
   135 {
   136 {
   136     Q_UNUSED(option);
   137     Q_UNUSED(option);
   137     Q_UNUSED(widget);
   138     Q_UNUSED(widget);
   138     
   139     
   139     //calculate bubble start and end time of bubble
       
   140     QPair<QTime, QTime> startEndEvent = 
       
   141         calculateStartEndPostion(mStartEndEventTime.first,
       
   142                                  mStartEndEventTime.second
       
   143                                 );
       
   144     //calculate how big is Minute
       
   145     qreal minuteHeight = calculateMinuteHeight(startEndEvent.first, 
       
   146                                                startEndEvent.second
       
   147                                               );
       
   148 
       
   149     painter->save();//   saves the painter state.
   140     painter->save();//   saves the painter state.
   150     
   141 
   151 
   142     // Calculate bubble start and end time of bubble
   152     //calculate how long is event in minutes
   143     QPair<QTime, QTime> startEndEvent = calculateStartEndPostion(
   153     qreal eventMinutes = 
   144         mStartEndEventTime.first, mStartEndEventTime.second);
   154            mStartEndEventTime.first.secsTo(mStartEndEventTime.second) / mMinute;
   145     // Calculate how high is Minute
   155     //calculate height and width of status stripe
   146     qreal minuteHeight = calculateMinuteHeight(startEndEvent.first,
       
   147         startEndEvent.second);
       
   148     // Calculate how long is event in minutes
       
   149     qreal eventMinutes = mStartEndEventTime.first.secsTo(
       
   150         mStartEndEventTime.second) / mMinute;
       
   151     // Calculate height and width of status stripe
   156     qreal dx = size().width() - 1;
   152     qreal dx = size().width() - 1;
   157     qreal dy = eventMinutes * minuteHeight;
   153     qreal dy = eventMinutes * minuteHeight;
   158 
   154 
   159     //calculate time from wehre it should be drawed
   155     // Calculate time from wehre it should be drawed
   160     qreal startTime = 
   156     qreal startTime = startEndEvent.first.secsTo(mStartEndEventTime.first)
   161                  startEndEvent.first.secsTo(mStartEndEventTime.first) / mMinute;
   157         / mMinute;
   162     //this is done because bubble can be drawed from half hour
   158     // This is done because bubble positioning accuracy is 15 minutes
   163     startTime = startTime > 30 ? startTime - 30 : startTime;
   159     startTime = startTime > 15 ? startTime - 15 : startTime;
   164     //calculate status stripe height
   160     // Calculate status stripe height
   165     qreal startTimeHeight = startTime * minuteHeight;
   161     qreal startTimeHeight = startTime * minuteHeight;
   166 
   162 
   167     //set bounding rect of drawed area
   163     // Set bounding rect of drawed area
   168     QRectF bounding(boundingRect());
   164     QRectF bounding(boundingRect());
   169     //set size smaller by 1px in each side
   165     // Set size smaller by 1px in each side
   170     bounding.setRect(bounding.left() + 1, bounding.top() + startTimeHeight, 
   166     bounding.setRect(bounding.left() + 1, bounding.top() + startTimeHeight, dx
   171                      dx - 1, dy - 1
   167         - 1, dy - 1);
   172                     );
   168 
   173 
   169     // Set clip region
   174     //set clip region
       
   175     painter->setClipRect(bounding, Qt::IntersectClip);
   170     painter->setClipRect(bounding, Qt::IntersectClip);
   176 
   171 
   177     //prepare brush and paint
   172     // Prepare brush and paint
   178     QBrush brush(HbColorScheme::color("qtc_cal_month_current_day"));
   173     QBrush brush(HbColorScheme::color("qtc_cal_month_current_day"));
   179     painter->setBrush(brush);
   174     painter->setBrush(brush);
   180     QPen pen;
   175     QPen pen;
   181     pen.setWidth(1);
   176     pen.setWidth(1);
   182     pen.setBrush(brush);
   177     pen.setBrush(brush);
   183     pen.setCapStyle(Qt::RoundCap);
   178     pen.setCapStyle(Qt::RoundCap);
   184     pen.setJoinStyle(Qt::RoundJoin);
   179     pen.setJoinStyle(Qt::RoundJoin);
   185 
   180 
   186     painter->setPen(pen);
   181     painter->setPen(pen);
   187     QPointF startPoint(0, dy + dx);
   182     QPointF startPoint(0, dy + dx);
   188     
   183 
   189     switch (mDrawingStyle) {
   184     switch (mDrawingStyle) {
   190         case StripWithLines:
   185         case StripWithLines:
   191             for (int i = 0; startPoint.y() > 0; i++) {
   186             for (int i = 0; startPoint.y() > 0; i++) {
   192                 painter->drawPolygon(diagonalLine(startPoint, dx, 3));
   187                 painter->drawPolygon(diagonalLine(startPoint, dx, 3));
   193                 startPoint.setY(startPoint.y() - 6 - mRange);
   188                 startPoint.setY(startPoint.y() - 6 - mRange);
   195         case OnlyFrame:
   190         case OnlyFrame:
   196             painter->setBrush(Qt::NoBrush);
   191             painter->setBrush(Qt::NoBrush);
   197             break;
   192             break;
   198     }
   193     }
   199 
   194 
   200     //draw rectangle
   195     // Draw rectangle
   201     painter->drawRect(bounding);
   196     painter->drawRect(bounding);
   202 
   197 
   203     // restore the painter
   198     // Restore the painter
   204     painter->restore();
   199     painter->restore();
   205 }
   200 }
   206 
   201 
   207 /*!
   202 /*!
   208    \brief It preapres points to draw filled polygon when StripWithLines style is
   203  \brief Prepares points to draw filled polygon when StripWithLines style is on.
   209    on.
   204  */
   210  */
   205 QPolygonF CalenDayStatusStrip::diagonalLine(
   211 QPolygonF 
   206     QPointF startPoint,
   212 CalenDayStatusStrip::diagonalLine(QPointF startPoint, qreal dx, qreal dy)
   207     qreal dx,
       
   208     qreal dy)
   213 {
   209 {
   214     QPolygonF polygon;
   210     QPolygonF polygon;
   215     polygon << QPointF(startPoint.x(), startPoint.y());
   211     polygon << QPointF(startPoint.x(), startPoint.y());
   216     polygon << QPointF(startPoint.x(), startPoint.y() - dy);
   212     polygon << QPointF(startPoint.x(), startPoint.y() - dy);
   217     polygon << QPointF(startPoint.x() + dx, startPoint.y() - 2 * dy);
   213     polygon << QPointF(startPoint.x() + dx, startPoint.y() - 2 * dy);
   218     polygon << QPointF(startPoint.x() + dx, startPoint.y() - dy);
   214     polygon << QPointF(startPoint.x() + dx, startPoint.y() - dy);
   219     return polygon;
   215     return polygon;
   220 }
   216 }
   221 
   217 
   222 /*!
   218 /*!
   223     Returns time for position 0 and height in widget 
   219  \brief Returns time for position 0 and height in widget 
   224     
   220  
   225     \param startTime Start of event
   221  \param startTime Start of event
   226     \param endTime End of event
   222  \param endTime End of event
   227     \return Draw region of bubble
   223  \return Draw region of bubble
   228   */
   224  */
   229  QPair<QTime,QTime> CalenDayStatusStrip::calculateStartEndPostion(
   225 QPair<QTime, QTime> CalenDayStatusStrip::calculateStartEndPostion(
   230                                                  const QTime &startTime, 
   226     const QTime &startTime,
   231                                                  const QTime &endTime
   227     const QTime &endTime)
   232                                              )
   228 {
   233 {
       
   234      
       
   235     QTime start;
   229     QTime start;
   236     QTime end;
   230     QTime end;
   237 
   231 
   238     if (startTime.minute() < 30) {
   232     if (startTime.minute() < 15) {
   239         start = QTime(startTime.hour(), 0);
   233         start = QTime(startTime.hour(), 0);
   240     }
   234     }
   241     else {
   235     else
   242         start = QTime(startTime.hour(), 30);
   236         if (startTime.minute() < 30) {
   243     }
   237             start = QTime(startTime.hour(), 15);
       
   238         }
       
   239         else
       
   240             if (startTime.minute() < 45) {
       
   241                 start = QTime(startTime.hour(), 30);
       
   242             }
       
   243             else {
       
   244                 start = QTime(startTime.hour(), 45);
       
   245             }
   244 
   246 
   245     if (endTime.minute() == 0) {
   247     if (endTime.minute() == 0) {
   246         end = endTime;
   248         end = endTime;
   247     }
   249     }
   248     else if (endTime.hour() == 23 and endTime.minute() > 30) {
   250     else
   249         end = QTime(endTime.hour(), 59);
   251         if (endTime.hour() == 23 and endTime.minute() > 45) {
   250     }
   252             end = QTime(endTime.hour(), 59);
   251     else if (endTime.minute() <= 30) {
   253         }
   252         end = QTime(endTime.hour(), 30);
   254         else
   253     }
   255             if (endTime.minute() <= 15) {
   254     else {
   256                 end = QTime(endTime.hour(), 15);
   255         end = QTime(endTime.hour() + 1, 0);
   257             }
   256     }
   258             else
       
   259                 if (endTime.minute() <= 30) {
       
   260                     end = QTime(endTime.hour(), 30);
       
   261                 }
       
   262                 else
       
   263                     if (endTime.minute() <= 45) {
       
   264                         end = QTime(endTime.hour(), 45);
       
   265                     }
       
   266                     else {
       
   267                         end = QTime(endTime.hour() + 1, 0);
       
   268                     }
   257 
   269 
   258     return QPair<QTime, QTime> (start, end);
   270     return QPair<QTime, QTime> (start, end);
   259 }
   271 }
   260 
   272 
   261 /*!
   273 /*!
   262    Calculates height of one minute from widget height, and start/end time. 
   274  Calculates height of one minute from widget height, and start/end time. 
   263  */
   275  */
   264 qreal CalenDayStatusStrip::calculateMinuteHeight(const QTime &start, 
   276 qreal CalenDayStatusStrip::calculateMinuteHeight(
   265                                                    const QTime &end)
   277     const QTime &start,
       
   278     const QTime &end)
   266 {
   279 {
   267     qreal min = start.secsTo(end) / mMinute;
   280     qreal min = start.secsTo(end) / mMinute;
   268 
   281 
   269     qreal height = size().height();
   282     // Events shorter than 30 minutes have bubble higher than 30 minutes,
       
   283     // so calculate minute's height using real hour-element slot height
       
   284     qreal height = 0.0;
       
   285     if (min > 30) {
       
   286         height = size().height();
       
   287     }
       
   288     else
       
   289         if (min > 15) {
       
   290             height = CalenDayUtils::instance()->hourElementHeight() / 2;
       
   291         }
       
   292         else {
       
   293             height = CalenDayUtils::instance()->hourElementHeight() / 4;
       
   294         }
   270 
   295 
   271     return height / min;
   296     return height / min;
   272 }
   297 }