/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. #include "ContextPage.h"
  19. #include <QGraphicsLinearLayout>
  20. #include "PlaylistInterface.h"
  21. #include "utils/StyleHelper.h"
  22. #include "utils/TomahawkUtilsGui.h"
  23. using namespace Tomahawk;
  24. void
  25. ContextProxyPage::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
  26. {
  27. painter->save();
  28. painter->setRenderHint( QPainter::Antialiasing, true );
  29. painter->setPen( StyleHelper::headerHighlightColor() );
  30. painter->setBrush( StyleHelper::headerHighlightColor() );
  31. painter->drawRoundedRect( option->rect, 4.0, 4.0 );
  32. QFont f( font() );
  33. f.setBold( true );
  34. f.setPointSize( TomahawkUtils::defaultFontSize() - 1 );
  35. painter->setFont( f );
  36. painter->setPen( Qt::white );
  37. QFontMetrics fm( f );
  38. QRect r( 1, 1, option->rect.width(), fm.height() * 1.1 );
  39. QTextOption to( Qt::AlignCenter );
  40. painter->drawText( r, m_page->title(), to );
  41. painter->restore();
  42. QGraphicsWidget::paint( painter, option, widget );
  43. }
  44. void
  45. ContextProxyPage::setPage( Tomahawk::ContextPage* page )
  46. {
  47. m_page = page;
  48. #ifdef Q_WS_X11 //FIXME: why do we need this? maybe it's only oxygen style misbehaving?
  49. QGraphicsWebView* testWebView = qobject_cast<QGraphicsWebView*>( page->widget() );
  50. if ( testWebView )
  51. {
  52. setContentsMargins( 4, 4, 4, 4 );
  53. }
  54. #endif
  55. QFont f( font() );
  56. f.setBold( true );
  57. f.setPointSize( TomahawkUtils::defaultFontSize() - 1 );
  58. QFontMetrics fm( f );
  59. QGraphicsLinearLayout* layout = new QGraphicsLinearLayout();
  60. layout->setContentsMargins( 4, fm.height() * 1.1, 4, 4 );
  61. layout->addItem( page->widget() );
  62. setLayout( layout );
  63. page->widget()->installEventFilter( this );
  64. }
  65. bool
  66. ContextProxyPage::eventFilter( QObject* watched, QEvent* event )
  67. {
  68. if ( event->type() == QEvent::GrabMouse )
  69. {
  70. emit focused();
  71. }
  72. return QGraphicsWidget::eventFilter( watched, event );
  73. }
  74. bool
  75. ContextProxyPage::sceneEvent( QEvent* event )
  76. {
  77. if ( event->type() == QEvent::GrabMouse )
  78. {
  79. emit focused();
  80. }
  81. return QGraphicsWidget::sceneEvent( event );
  82. }