File: EPGRuler.cpp

package info (click to toggle)
vlc 2.2.7-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 191,124 kB
  • sloc: ansic: 356,116; cpp: 94,295; objc: 34,063; sh: 6,765; makefile: 4,272; xml: 1,538; asm: 1,251; python: 240; perl: 77; sed: 16
file content (119 lines) | stat: -rw-r--r-- 3,768 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*****************************************************************************
 * EPGRuler.cpp: EPGRuler
 ****************************************************************************
 * Copyright © 2009-2010 VideoLAN
 * $Id: bd7ccaca7282cb95db9e88ee09fbfc3e6e637dd0 $
 *
 * Authors: Ludovic Fauvet <etix@l0cal.com>
 *
 * 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 "EPGRuler.hpp"

class QPaintEvent;
#include <QPainter>
#include <QDateTime>
#include <QPoint>
#include <QRect>
#include <QSize>
#include <QPalette>
#include <QColor>

EPGRuler::EPGRuler( QWidget* parent )
    : QWidget( parent )
{
    setContentsMargins( 0, 0, 0, 0 );
    setMinimumHeight( height() );
    setMaximumHeight( height() );
    m_offset = 0;
}

void EPGRuler::setScale( double scale )
{
    m_scale = scale;
    update();
}

void EPGRuler::setStartTime( const QDateTime& startTime )
{
    m_startTime = startTime;
    update();
}

void EPGRuler::setDuration( int duration )
{
    m_duration = duration;
    update();
}

void EPGRuler::setOffset( int offset )
{
    m_offset = offset;
    update();
}

void EPGRuler::paintEvent( QPaintEvent *event )
{
    Q_UNUSED( event );
    const QSize margin( 0, contentsMargins().top() );
    const QSize header( 0, maximumHeight() - contentsMargins().top() );
    const int spacing = m_scale * 3600;
    QPainter p( this );

    QDateTime localStartTime;
    localStartTime = m_startTime.addSecs( m_offset / m_scale );

    QDateTime diff( localStartTime );
    diff.setTime( QTime( localStartTime.time().hour(), 0, 0, 0 ) );

    int secondsToHour = localStartTime.secsTo( diff );

    /* draw hour blocks, with right bound being hourmark */
    QPoint here( secondsToHour * m_scale, margin.height() );
    QPoint previous( -1, 0 );
    QDateTime current( localStartTime.addSecs( secondsToHour ) );
    current = current.addSecs( -3600 );

    QColor fillColor;
    while ( here.rx() < width() + spacing )
    {
        QRect area( QPoint( previous.x() + 1, margin.height() ), here );
        area.adjust( 0, 0, 0, header.height() );
        QString timeString = current.toString( "hh'h'" );
        /* Show Day */
        if ( current.time().hour() == 0 )
            timeString += current.date().toString( " ddd dd" );

        if ( m_startTime.date().daysTo( current.date() ) % 2 == 0 )
            fillColor = palette().color( QPalette::Window );
        else
            fillColor = palette().color( QPalette::Dark );
        p.fillRect( area, fillColor );
        p.drawLine( area.topRight(), area.bottomRight() );
        p.drawText( area, Qt::AlignLeft, timeString );
        previous = here;
        here.rx() += spacing;
        current = current.addSecs( 3600 );
    }

    /* draw current time line */
    here.rx() = localStartTime.secsTo( QDateTime::currentDateTime() ) * m_scale;
    if ( here.x() <= width() && here.x() >= 0 )
    {
        p.setPen( QPen( QColor( 255, 0 , 0, 128 ) ) );
        p.drawLine( here, QPoint( here.x(), here.y() + header.height() ) );
    }
}