PageRenderTime 192ms CodeModel.GetById 40ms app.highlight 31ms RepoModel.GetById 60ms app.codeStats 0ms

/src/libtomahawk/context/ContextPage.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 104 lines | 65 code | 22 blank | 17 comment | 5 complexity | e1d88ff554d380daad93146d2edfe1cb MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *
  5 *   Tomahawk is free software: you can redistribute it and/or modify
  6 *   it under the terms of the GNU General Public License as published by
  7 *   the Free Software Foundation, either version 3 of the License, or
  8 *   (at your option) any later version.
  9 *
 10 *   Tomahawk is distributed in the hope that it will be useful,
 11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 13 *   GNU General Public License for more details.
 14 *
 15 *   You should have received a copy of the GNU General Public License
 16 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 17 */
 18
 19#include "ContextPage.h"
 20
 21#include <QGraphicsLinearLayout>
 22
 23#include "PlaylistInterface.h"
 24#include "utils/StyleHelper.h"
 25#include "utils/TomahawkUtilsGui.h"
 26
 27using namespace Tomahawk;
 28
 29
 30void
 31ContextProxyPage::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
 32{
 33    painter->save();
 34
 35    painter->setRenderHint( QPainter::Antialiasing, true );
 36    painter->setPen( StyleHelper::headerHighlightColor() );
 37    painter->setBrush( StyleHelper::headerHighlightColor() );
 38    painter->drawRoundedRect( option->rect, 4.0, 4.0 );
 39
 40    QFont f( font() );
 41    f.setBold( true );
 42    f.setPointSize( TomahawkUtils::defaultFontSize() - 1 );
 43    painter->setFont( f );
 44    painter->setPen( Qt::white );
 45
 46    QFontMetrics fm( f );
 47    QRect r( 1, 1, option->rect.width(), fm.height() * 1.1 );
 48    QTextOption to( Qt::AlignCenter );
 49    painter->drawText( r, m_page->title(), to );
 50
 51    painter->restore();
 52
 53    QGraphicsWidget::paint( painter, option, widget );
 54}
 55
 56
 57void
 58ContextProxyPage::setPage( Tomahawk::ContextPage* page )
 59{
 60    m_page = page;
 61
 62#ifdef Q_WS_X11 //FIXME: why do we need this? maybe it's only oxygen style misbehaving?
 63    QGraphicsWebView* testWebView = qobject_cast<QGraphicsWebView*>( page->widget() );
 64    if ( testWebView )
 65    {
 66        setContentsMargins( 4, 4, 4, 4 );
 67    }
 68#endif
 69
 70    QFont f( font() );
 71    f.setBold( true );
 72    f.setPointSize( TomahawkUtils::defaultFontSize() - 1 );
 73    QFontMetrics fm( f );
 74    QGraphicsLinearLayout* layout = new QGraphicsLinearLayout();
 75    layout->setContentsMargins( 4, fm.height() * 1.1, 4, 4 );
 76    layout->addItem( page->widget() );
 77    setLayout( layout );
 78
 79    page->widget()->installEventFilter( this );
 80}
 81
 82
 83bool
 84ContextProxyPage::eventFilter( QObject* watched, QEvent* event )
 85{
 86    if ( event->type() == QEvent::GrabMouse )
 87    {
 88        emit focused();
 89    }
 90
 91    return QGraphicsWidget::eventFilter( watched, event );
 92}
 93
 94
 95bool
 96ContextProxyPage::sceneEvent( QEvent* event )
 97{
 98    if ( event->type() == QEvent::GrabMouse )
 99    {
100        emit focused();
101    }
102
103    return QGraphicsWidget::sceneEvent( event );
104}