Qt/EPG: update and synchronise as in master
[vlc/solaris.git] / modules / gui / qt4 / components / epg / EPGItem.cpp
blobec2d1f9bf4de50b48877b3950e70499933ab1b83
1 /*****************************************************************************
2 * EPGItem.cpp: EPGItem
3 ****************************************************************************
4 * Copyright © 2009-2010 VideoLAN
5 * $Id$
7 * Authors: Ludovic Fauvet <etix@l0cal.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include <QTransform>
25 #include <QFont>
26 #include <QFontMetrics>
27 #include <QDebug>
28 #include <QDateTime>
29 #include <QFocusEvent>
30 #include <QGraphicsScene>
32 #include "EPGItem.hpp"
33 #include "EPGView.hpp"
34 #include "EPGEvent.hpp"
36 EPGItem::EPGItem( EPGView *view )
37 : m_view( view )
39 m_current = false;
41 m_boundingRect.setHeight( TRACKS_HEIGHT );
42 setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
45 QRectF EPGItem::boundingRect() const
47 return m_boundingRect;
50 void EPGItem::paint( QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
52 // Draw in view's coordinates
53 painter->setWorldMatrixEnabled( false );
55 // Draw high-quality items
56 //painter->setRenderHint( QPainter::Antialiasing );
58 // Get the transformations required to map the text on the viewport
59 QTransform viewPortTransform = m_view->viewportTransform();
60 QRectF mapped = deviceTransform( viewPortTransform ).mapRect( boundingRect() );
62 if ( m_current )
64 painter->setBrush( QBrush( QColor( 244, 102, 146 ) ) );
65 painter->setPen( QPen( QColor( 244, 102, 146 ) ) );
67 else
69 painter->setBrush( QBrush( QColor( 201, 217, 242 ) ) );
70 painter->setPen( QPen( QColor( 201, 217, 242 ) ) );
73 mapped.adjust( 1, 2, -1, -2 );
74 painter->drawRoundedRect( mapped, 10, 10 );
76 /* Draw text */
78 // Setup the font
79 QFont f = painter->font();
81 // Get the font metrics
82 QFontMetrics fm = painter->fontMetrics();
84 // Adjust the drawing rect
85 mapped.adjust( 6, 6, -6, -6 );
87 painter->setPen( Qt::black );
88 /* Draw the title. */
89 painter->drawText( mapped, Qt::AlignTop | Qt::AlignLeft, fm.elidedText( m_name, Qt::ElideRight, mapped.width() ) );
91 mapped.adjust( 0, 20, 0, 0 );
92 QDateTime m_end = m_start.addSecs( m_duration );
93 f.setPixelSize( 10 );
94 f.setItalic( true );
95 painter->setFont( f );
97 /* Draw the hours. */
98 painter->drawText( mapped, Qt::AlignTop | Qt::AlignLeft,
99 fm.elidedText( m_start.toString( "hh:mm" ) + " - " +
100 m_end.toString( "hh:mm" ),
101 Qt::ElideRight, mapped.width() ) );
104 const QDateTime& EPGItem::start() const
106 return m_start;
109 int EPGItem::duration() const
111 return m_duration;
114 void EPGItem::setChannel( int channelNb )
116 //qDebug() << "Channel" << channelNb;
117 m_channelNb = channelNb;
118 updatePos();
121 void EPGItem::setStart( const QDateTime& start )
123 m_start = start;
124 updatePos();
127 void EPGItem::setDuration( int duration )
129 m_duration = duration;
130 m_boundingRect.setWidth( duration );
133 void EPGItem::setName( const QString& name )
135 m_name = name;
138 void EPGItem::setDescription( const QString& description )
140 m_description = description;
143 void EPGItem::setShortDescription( const QString& shortDescription )
145 m_shortDescription = shortDescription;
148 void EPGItem::setCurrent( bool current )
150 m_current = current;
153 void EPGItem::updatePos()
155 int x = m_view->startTime().secsTo( m_start );
156 setPos( x, m_channelNb * TRACKS_HEIGHT );
159 void EPGItem::focusInEvent( QFocusEvent * event )
161 EPGEvent *evEPG = new EPGEvent( m_name );
162 evEPG->description = m_description;
163 evEPG->shortDescription = m_shortDescription;
164 evEPG->start = m_start;
165 evEPG->duration = m_duration;
166 m_view->eventFocused( evEPG );