calendarui/views/src/calenthicklinesdrawer.cpp
branchRCL_3
changeset 65 12af337248b1
equal deleted inserted replaced
60:96907930389d 65:12af337248b1
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CalenThickLinesDrawer implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <QtGui>
       
    20 #include <QPainter>
       
    21 #include <QPen>
       
    22 #include <hbdeviceprofile.h>
       
    23 #include <hbcolorscheme.h>
       
    24 #include <hbtheme.h>
       
    25 
       
    26 // User includes
       
    27 #include "calenthicklinesdrawer.h"
       
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "calenthicklinesdrawerTraces.h"
       
    31 #endif
       
    32 
       
    33 
       
    34 // CONSTANTS
       
    35 #define CALENTHICKLINEWIDTH     0.15 // Units
       
    36 #define CALENDAYNAMEANDGRIDSEPERATOR    0.75 // Units
       
    37 
       
    38 /*!
       
    39  \class CalenThickLinesDrawer
       
    40 
       
    41  Class to draw day names widget a,d week number widget seperators
       
    42  */
       
    43 
       
    44 /*!
       
    45  Constructor
       
    46  */
       
    47 CalenThickLinesDrawer::CalenThickLinesDrawer( CalendarNamespace::WidgetType type, 
       
    48 	QGraphicsItem* parent):
       
    49 	HbWidget(parent)
       
    50 {
       
    51     OstTraceFunctionEntry0( CALENTHICKLINESDRAWER_CALENTHICKLINESDRAWER_ENTRY );
       
    52     
       
    53 	typeOfWidget = type;
       
    54 	mGridBorderColor = HbColorScheme::color("qtc_cal_grid_line");
       
    55 	setFlag(QGraphicsItem::ItemHasNoContents, false);
       
    56 	
       
    57 	connect(
       
    58 				HbTheme::instance(), SIGNAL(changed()),
       
    59 				this, SLOT(handleThemeChange()));
       
    60 	
       
    61 	OstTraceFunctionExit0( CALENTHICKLINESDRAWER_CALENTHICKLINESDRAWER_EXIT );
       
    62 }
       
    63 
       
    64 /*!
       
    65  To paint grid item border
       
    66  */
       
    67 CalenThickLinesDrawer::~CalenThickLinesDrawer()
       
    68 {
       
    69     OstTraceFunctionEntry0( DUP1_CALENTHICKLINESDRAWER_CALENTHICKLINESDRAWER_ENTRY );
       
    70 
       
    71     OstTraceFunctionExit0( DUP1_CALENTHICKLINESDRAWER_CALENTHICKLINESDRAWER_EXIT );
       
    72 }
       
    73 
       
    74 /*!
       
    75  To paint grid item border
       
    76  */
       
    77 void CalenThickLinesDrawer::paint(QPainter* painter,
       
    78 								const QStyleOptionGraphicsItem* option,
       
    79 								QWidget* widget)
       
    80 {
       
    81     OstTraceFunctionEntry0( CALENTHICKLINESDRAWER_PAINT_ENTRY );
       
    82     
       
    83 	Q_UNUSED(option);
       
    84 	Q_UNUSED(widget);
       
    85 	QPen pen;
       
    86 	pen.setStyle(Qt::SolidLine);
       
    87 
       
    88 	// Get the proper width, layout specificaiton says, width has to be 0.15un
       
    89 	// Convert 0.15un to pixels
       
    90 	HbDeviceProfile deviceProf;
       
    91 	qreal unitValue = deviceProf.unitValue();
       
    92 	qreal widthInPixels = CALENTHICKLINEWIDTH * unitValue;
       
    93 	pen.setWidth(widthInPixels);
       
    94 	pen.setBrush(mGridBorderColor);
       
    95 	
       
    96 	// Store the old pen
       
    97     QPen oldPen = painter->pen();
       
    98 	    
       
    99 	painter->setPen(pen);
       
   100 	QRectF controlRect = this->boundingRect();
       
   101 
       
   102 	// Check the type of the widget and paint the necessary things
       
   103 	if ( typeOfWidget == CalendarNamespace::CalenDayNameWidget ) {
       
   104 		// Calculate the seperation to be added so that line coincides with 
       
   105 		// top border of the grid
       
   106 		qreal seperation = CALENDAYNAMEANDGRIDSEPERATOR * unitValue;
       
   107 		// Adjust the seperation with the thickness of the line
       
   108 		seperation = seperation - widthInPixels;
       
   109 		// Get the start point and end point to draw the line
       
   110 		QPointF startPoint(controlRect.bottomLeft().x(), controlRect.bottomLeft().y() + seperation);
       
   111 		QPointF endPoint(controlRect.bottomRight().x(), controlRect.bottomRight().y() + seperation);
       
   112 		painter->drawLine(startPoint, endPoint);
       
   113 	} else if ( typeOfWidget == CalendarNamespace::CalenWeekNumWidget ) {
       
   114 		// Check if this widget is visible
       
   115 		if(this->isEnabled()) {
       
   116 			// Get the start point and end point to draw the line
       
   117 			QPointF startPoint = controlRect.topRight();
       
   118 			QPointF endPoint = controlRect.bottomRight();
       
   119 			painter->drawLine(startPoint, endPoint);
       
   120 		}
       
   121 	}
       
   122 	
       
   123 	// Set the old pen back
       
   124     painter->setPen(oldPen);
       
   125     
       
   126     OstTraceFunctionExit0( CALENTHICKLINESDRAWER_PAINT_EXIT );
       
   127 }
       
   128 
       
   129 /*!
       
   130  Slot to handle the change in theme
       
   131  */
       
   132 void CalenThickLinesDrawer::handleThemeChange()
       
   133 {
       
   134 	OstTraceFunctionEntry0(CALENTHICKLINESDRAWER_HANDLETHEMECHANGE_ENTRY);
       
   135 	
       
   136 	mGridBorderColor = HbColorScheme::color("qtc_cal_grid_line");
       
   137 	
       
   138 	OstTraceFunctionExit0(CALENTHICKLINESDRAWER_HANDLETHEMECHANGE_EXIT);
       
   139 }
       
   140 
       
   141 // End of file  --Don't remove this.