Commit 27912412 authored by Adrien Maglo's avatar Adrien Maglo Committed by Jean-Baptiste Kempf

Synchronise master and 1.1 branch Qt4 EPG

parent 081073b2
......@@ -53,6 +53,7 @@ nodist_SOURCES_qt4 = \
components/interface_widgets.moc.cpp \
components/controller.moc.cpp \
components/controller_widget.moc.cpp \
components/epg/EPGChannels.moc.cpp \
components/epg/EPGRuler.moc.cpp \
components/epg/EPGView.moc.cpp \
components/epg/EPGWidget.moc.cpp \
......@@ -251,6 +252,7 @@ SOURCES_qt4 = qt4.cpp \
components/interface_widgets.cpp \
components/controller.cpp \
components/controller_widget.cpp \
components/epg/EPGChannels.cpp \
components/epg/EPGItem.cpp \
components/epg/EPGRuler.cpp \
components/epg/EPGView.cpp \
......@@ -307,6 +309,7 @@ noinst_HEADERS = \
components/interface_widgets.hpp \
components/controller.hpp \
components/controller_widget.hpp \
components/epg/EPGChannels.hpp \
components/epg/EPGEvent.hpp \
components/epg/EPGItem.hpp \
components/epg/EPGRuler.hpp \
......
/*****************************************************************************
* EPGChannels.cpp: EPGChannels
****************************************************************************
* Copyright © 2009-2010 VideoLAN
*
* Authors: Adrien Maglo <magsoft@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "EPGChannels.hpp"
#include "EPGView.hpp"
#include <QPainter>
#include <QFont>
#include <QPaintEvent>
EPGChannels::EPGChannels( QWidget *parent, EPGView *m_epgView )
: QWidget( parent ), m_epgView( m_epgView ), m_offset( 0 )
{
setContentsMargins( 0, 0, 0, 0 );
}
void EPGChannels::setOffset( int offset )
{
m_offset = offset;
update();
}
void EPGChannels::paintEvent( QPaintEvent *event )
{
Q_UNUSED( event );
QPainter p( this );
/* Draw the top and the bottom lines. */
p.drawLine( 0, 0, width() - 1, 0 );
p.drawLine( 0, height() - 1, width(), height() - 1 );
p.setFont( QFont( "Verdana", 8 ) );
QList<QString> channels = m_epgView->getChannelList();
for( int i = 0; i < channels.count(); ++i )
{
p.drawText( 0, - m_offset + ( i + 0.5 ) * TRACKS_HEIGHT - 4,
width(), 20, Qt::AlignLeft, channels[i] );
int i_width = fontMetrics().width( channels[i] );
if( width() < i_width )
setMinimumWidth( i_width );
}
}
/*****************************************************************************
* EPGChannels.hpp : EPGChannels
****************************************************************************
* Copyright © 2009-2010 VideoLAN
*
* Authors: Adrien Maglo <magsoft@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef EPGCHANNELS_HPP
#define EPGCHANNELS_HPP
#include <QWidget>
class EPGView;
class EPGChannels : public QWidget
{
Q_OBJECT
public:
EPGChannels( QWidget *parent, EPGView *m_epgView );
virtual ~EPGChannels() { }
public slots:
void setOffset( int offset );
protected:
virtual void paintEvent( QPaintEvent *event );
private:
EPGView *m_epgView;
int m_offset;
};
#endif // EPGCHANNELS_HPP
......@@ -62,9 +62,9 @@ void EPGItem::paint( QPainter *painter, const QStyleOptionGraphicsItem*, QWidget
painter->setPen( QPen( Qt::black ) );
if ( m_current )
painter->setBrush( QBrush( Qt::red ) );
painter->setBrush( QBrush( QColor( 100, 100, 100 ) ) );
else
painter->setBrush( QBrush( Qt::blue ) );
painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) );
painter->drawRect( mapped );
......@@ -73,30 +73,28 @@ void EPGItem::paint( QPainter *painter, const QStyleOptionGraphicsItem*, QWidget
// Setup the font
QFont f = painter->font();
f.setBold( true );
painter->setFont( f );
// Get the font metrics
QFontMetrics fm = painter->fontMetrics();
// Adjust the drawing rect
mapped.adjust( 2, 2, -2, -2 );
mapped.adjust( 6, 6, -6, -6 );
painter->setPen( Qt::white );
/* Draw the title. */
painter->drawText( mapped, Qt::AlignTop | Qt::AlignLeft, fm.elidedText( m_name, Qt::ElideRight, mapped.width() ) );
f.setBold( false );
mapped.adjust( 0, 20, 0, 0 );
QDateTime m_end = m_start.addSecs( m_duration );
f.setPixelSize( 10 );
f.setItalic( true );
painter->setFont( f );
QTextOption textoption;
textoption.setWrapMode( QTextOption::WordWrap );
textoption.setAlignment( Qt::AlignTop | Qt::AlignLeft );
painter->drawText( mapped.adjusted( 0, 20, 0, 0 ),
m_shortDescription,
textoption );
/* Draw the hours. */
painter->drawText( mapped, Qt::AlignTop | Qt::AlignLeft,
fm.elidedText( m_start.toString( "hh:mm" ) + " - " +
m_end.toString( "hh:mm" ),
Qt::ElideRight, mapped.width() ) );
}
const QDateTime& EPGItem::start() const
......
......@@ -34,33 +34,14 @@
EPGView::EPGView( QWidget *parent ) : QGraphicsView( parent )
{
setContentsMargins( 0, 0, 0, 0 );
setFrameStyle( QFrame::NoFrame );
setFrameStyle( QFrame::Box );
setAlignment( Qt::AlignLeft | Qt::AlignTop );
setViewportUpdateMode( QGraphicsView::FullViewportUpdate );
m_startTime = QDateTime::currentDateTime();
QGraphicsScene *EPGscene = new QGraphicsScene( this );
setScene( EPGscene );
connect( horizontalScrollBar(), SIGNAL( valueChanged(int) ),
this, SLOT( updateOverlayPosition(int) ) );
m_overlay = EPGscene->addRect( 0, 0, 100, 1, QPen(), QBrush( QColor( 40, 86, 255, 220 ) ) );
m_overlay->setFlag( QGraphicsItem::ItemIgnoresTransformations );
m_overlay->setZValue( 100 );
sceneRectChanged( scene()->sceneRect() );
connect( scene(), SIGNAL( sceneRectChanged(QRectF) ),
this, SLOT( sceneRectChanged(QRectF) ) );
}
void EPGView::updateOverlayPosition( int value )
{
int pos = value * matrix().inverted().m11();
m_overlay->setPos( pos, 0 );
}
void EPGView::setScale( double scaleFactor )
......@@ -79,7 +60,11 @@ void EPGView::setStartTime( const QDateTime& startTime )
for ( int i = 0; i < itemList.count(); ++i )
{
#ifndef WIN32
EPGItem* item = dynamic_cast<EPGItem*>( itemList.at( i ) );
#else
EPGItem *item = NULL;
#endif
if ( !item ) continue;
item->setStart( item->start().addSecs( diff ) );
}
......@@ -98,13 +83,7 @@ const QDateTime& EPGView::startTime()
void EPGView::addEvent( EPGEvent* event )
{
if ( !m_channels.contains( event->channelName ) )
{
m_channels.append( event->channelName );
QGraphicsTextItem* channelTitle = new QGraphicsTextItem( event->channelName, m_overlay );
channelTitle->setZValue( 101 );
channelTitle->setPos( 0, m_channels.indexOf( event->channelName ) * TRACKS_HEIGHT );
channelTitle->setTextWidth( 100 );
}
EPGItem* item = new EPGItem( this );
item->setChannel( m_channels.indexOf( event->channelName ) );
......@@ -128,23 +107,6 @@ void EPGView::delEvent( EPGEvent* event )
//qDebug() << "Del event: " << event->name;
}
void EPGView::drawBackground( QPainter *painter, const QRectF &rect )
{
painter->setPen( QPen( QColor( 72, 72, 72 ) ) );
QPointF p = mapToScene( width(), 0 );
int y = 0;
for ( int i = 0; i < m_channels.count() + 1; ++i )
{
painter->drawLine( 0,
y * TRACKS_HEIGHT,
p.x(),
y * TRACKS_HEIGHT );
++y;
}
}
void EPGView::updateDuration()
{
QDateTime lastItem;
......@@ -152,7 +114,11 @@ void EPGView::updateDuration()
for ( int i = 0; i < list.count(); ++i )
{
#ifndef WIN32
EPGItem* item = dynamic_cast<EPGItem*>( list.at( i ) );
#else
EPGItem *item = NULL;
#endif
if ( !item ) continue;
QDateTime itemEnd = item->start().addSecs( item->duration() );
......@@ -163,12 +129,12 @@ void EPGView::updateDuration()
emit durationChanged( m_duration );
}
void EPGView::eventFocused( EPGEvent *ev )
QList<QString> EPGView::getChannelList()
{
emit eventFocusedChanged( ev );
return m_channels;
}
void EPGView::sceneRectChanged( const QRectF& rect )
void EPGView::eventFocused( EPGEvent *ev )
{
m_overlay->setRect( 0, 0, m_overlay->rect().width(), rect.height() );
emit eventFocusedChanged( ev );
}
......@@ -49,26 +49,21 @@ public:
void delEvent( EPGEvent* event );
void updateDuration();
QList<QString> getChannelList();
signals:
void startTimeChanged( const QDateTime& startTime );
void durationChanged( int seconds );
void eventFocusedChanged( EPGEvent * );
protected:
virtual void drawBackground( QPainter *painter, const QRectF &rect );
QList<QString> m_channels;
QDateTime m_startTime;
int m_scaleFactor;
int m_duration;
private:
QGraphicsRectItem* m_overlay;
public slots:
void eventFocused( EPGEvent * );
private slots:
void updateOverlayPosition( int value );
void sceneRectChanged( const QRectF& rect );
};
#endif // EPGVIEW_H
......@@ -37,13 +37,17 @@ EPGWidget::EPGWidget( QWidget *parent ) : QWidget( parent )
{
m_rulerWidget = new EPGRuler( this );
m_epgView = new EPGView( this );
m_channelsWidget = new EPGChannels( this, m_epgView );
m_channelsWidget->setMinimumWidth( 100 );
m_epgView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
setZoom( 1 );
QVBoxLayout* layout = new QVBoxLayout( this );
layout->addWidget( m_rulerWidget );
layout->addWidget( m_epgView );
QGridLayout* layout = new QGridLayout( this );
layout->addWidget( m_rulerWidget, 0, 1 );
layout->addWidget( m_channelsWidget, 1, 0 );
layout->addWidget( m_epgView, 1, 1 );
layout->setSpacing( 0 );
setLayout( layout );
......@@ -53,6 +57,8 @@ EPGWidget::EPGWidget( QWidget *parent ) : QWidget( parent )
m_rulerWidget, SLOT( setDuration(int) ) );
connect( m_epgView->horizontalScrollBar(), SIGNAL( valueChanged(int) ),
m_rulerWidget, SLOT( setOffset(int) ) );
connect( m_epgView->verticalScrollBar(), SIGNAL( valueChanged(int) ),
m_channelsWidget, SLOT( setOffset(int) ) );
connect( m_epgView, SIGNAL( eventFocusedChanged(EPGEvent*)),
this, SIGNAL(itemSelectionChanged(EPGEvent*)) );
}
......@@ -77,19 +83,22 @@ void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg )
EPGEvent *item = NULL;
vlc_epg_event_t *p_event = p_epg->pp_event[j];
QString eventName = qfu( p_event->psz_name );
QDateTime eventStart = QDateTime::fromTime_t( p_event->i_start );
QList<EPGEvent*> events = m_events.values( channelName );
for ( int k = 0; k < events.count(); ++k )
{
if ( events.at( k )->name == eventName &&
events.at( k )->channelName == channelName )
events.at( k )->channelName == channelName &&
events.at( k )->start == eventStart )
{
/* Update the event. */
item = events.at( k );
item->updated = true;
item->description = qfu( p_event->psz_description );
item->shortDescription = qfu( p_event->psz_short_description );
item->start = QDateTime::fromTime_t( p_event->i_start );
item->start = eventStart;
item->duration = p_event->i_duration;
item->current = ( p_epg->p_current == p_event ) ? true : false;
......@@ -106,7 +115,7 @@ void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg )
item = new EPGEvent( eventName );
item->description = qfu( p_event->psz_description );
item->shortDescription = qfu( p_event->psz_short_description );
item->start = QDateTime::fromTime_t( p_event->i_start );
item->start = eventStart;
item->duration = p_event->i_duration;
item->channelName = channelName;
item->current = ( p_epg->p_current == p_event ) ? true : false;
......
......@@ -27,6 +27,7 @@
#include "EPGView.hpp"
#include "EPGEvent.hpp"
#include "EPGRuler.hpp"
#include "EPGChannels.hpp"
#include <vlc_common.h>
#include <vlc_epg.h>
......@@ -49,6 +50,7 @@ public slots:
private:
EPGRuler* m_rulerWidget;
EPGView* m_epgView;
EPGChannels *m_channelsWidget;
QMultiMap<QString, EPGEvent*> m_events;
......
......@@ -33,6 +33,7 @@
#include <QLabel>
#include <QGroupBox>
#include <QPushButton>
#include <QTextEdit>
#include "qt4.hpp"
#include "input_manager.hpp"
......@@ -43,20 +44,18 @@ EpgDialog::EpgDialog( intf_thread_t *_p_intf ): QVLCFrame( _p_intf )
QVBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin( 0 );
QSplitter *splitter = new QSplitter( this );
epg = new EPGWidget( this );
splitter->addWidget( epg );
splitter->setOrientation(Qt::Vertical);
QGroupBox *descBox = new QGroupBox( qtr( "Description" ), this );
QVBoxLayout *boxLayout = new QVBoxLayout( descBox );
description = new QLabel( this );
description = new QTextEdit( this );
description->setReadOnly( true );
description->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel );
description->setAutoFillBackground( true );
description->setWordWrap( true );
description->setAlignment( Qt::AlignLeft | Qt::AlignTop );
description->setFixedHeight( 100 );
QPalette palette;
palette.setBrush(QPalette::Active, QPalette::Window, palette.brush( QPalette::Base ) );
......@@ -65,11 +64,10 @@ EpgDialog::EpgDialog( intf_thread_t *_p_intf ): QVLCFrame( _p_intf )
title = new QLabel( qtr( "Title" ), this );
boxLayout->addWidget( title );
boxLayout->addWidget( description, 10 );
boxLayout->addWidget( description );
splitter->addWidget( epg );
splitter->addWidget( descBox );
layout->addWidget( splitter );
layout->addWidget( epg, 10 );
layout->addWidget( descBox );
CONNECT( epg, itemSelectionChanged( EPGEvent *), this, showEvent( EPGEvent *) );
CONNECT( THEMIM->getIM(), epgChanged(), this, updateInfos() );
......
......@@ -28,8 +28,10 @@
#include "util/singleton.hpp"
class QLabel;
class QTextEdit;
class EPGEvent;
class EPGWidget;
class EpgDialog : public QVLCFrame, public Singleton<EpgDialog>
{
Q_OBJECT
......@@ -38,7 +40,7 @@ private:
virtual ~EpgDialog();
EPGWidget *epg;
QLabel *description;
QTextEdit *description;
QLabel *title;
friend class Singleton<EpgDialog>;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment