Skip to content

Commit

Permalink
* Added initial ContextView. Yikes.
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli authored and Michael Zanetti committed Sep 4, 2011
1 parent c0edc3a commit 03f726f
Show file tree
Hide file tree
Showing 30 changed files with 1,551 additions and 256 deletions.
15 changes: 15 additions & 0 deletions src/libtomahawk/CMakeLists.txt
Expand Up @@ -40,6 +40,13 @@ set( libSources

audio/audioengine.cpp

context/ContextPage.cpp
context/ContextWidget.cpp
context/pages/TopTracksContext.cpp
context/pages/RelatedArtistsContext.cpp
context/pages/WikipediaContext.cpp
context/pages/WebContext.cpp

database/database.cpp
database/fuzzyindex.cpp
database/databasecollection.cpp
Expand Down Expand Up @@ -234,6 +241,13 @@ set( libHeaders

audio/audioengine.h

context/ContextPage.h
context/ContextWidget.h
context/pages/TopTracksContext.h
context/pages/RelatedArtistsContext.h
context/pages/WikipediaContext.h
context/pages/WebContext.h

database/database.h
database/fuzzyindex.h
database/databaseworker.h
Expand Down Expand Up @@ -417,6 +431,7 @@ set( libUI ${libUI}
widgets/infowidgets/AlbumInfoWidget.ui
playlist/topbar/topbar.ui
playlist/infobar/infobar.ui
context/ContextWidget.ui
)

include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/.. ..
Expand Down
94 changes: 94 additions & 0 deletions src/libtomahawk/context/ContextPage.cpp
@@ -0,0 +1,94 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/

#include "ContextPage.h"

#include <QGraphicsLinearLayout>

using namespace Tomahawk;


void
ContextProxyPage::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
{
painter->save();

painter->setRenderHint( QPainter::Antialiasing, true );
painter->setPen( StyleHelper::headerHighlightColor() );
painter->setBrush( StyleHelper::headerHighlightColor() );
painter->drawRoundedRect( option->rect, 4.0, 4.0 );

QFont f( font() );
f.setBold( true );
f.setPixelSize( 14 );
painter->setFont( f );
painter->setPen( Qt::white );

QRect r( 1, 1, option->rect.width(), 19 );
QTextOption to( Qt::AlignCenter );
painter->drawText( r, m_page->title(), to );

painter->restore();

QGraphicsWidget::paint( painter, option, widget );
}


void
ContextProxyPage::setPage( Tomahawk::ContextPage* page )
{
m_page = page;

QGraphicsWebView* testWebView = qobject_cast<QGraphicsWebView*>( page->widget() );
if ( testWebView )
{
setContentsMargins( 4, 4, 4, 4 );
}

QGraphicsLinearLayout* layout = new QGraphicsLinearLayout();
layout->setContentsMargins( 4, 20, 4, 4 );
layout->addItem( page->widget() );
setLayout( layout );

page->widget()->installEventFilter( this );
page->widget()->installSceneEventFilter( this );
}


bool
ContextProxyPage::eventFilter( QObject* watched, QEvent* event )
{
if ( event->type() == QEvent::GrabMouse )
{
emit focused();
}

return QGraphicsWidget::eventFilter( watched, event );
}


bool
ContextProxyPage::sceneEvent( QEvent* event )
{
if ( event->type() == QEvent::GrabMouse )
{
emit focused();
}

return QGraphicsWidget::sceneEvent( event );
}
91 changes: 91 additions & 0 deletions src/libtomahawk/context/ContextPage.h
@@ -0,0 +1,91 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CONTEXTPAGE_H
#define CONTEXTPAGE_H

#include <QGraphicsProxyWidget>
#include <QGraphicsWebView>
#include <QStyleOptionGraphicsItem>

#include "typedefs.h"
#include "playlistinterface.h"
#include "utils/stylehelper.h"
#include "utils/tomahawkutils.h"

#include "dllmacro.h"
#include <signal.h>

namespace Tomahawk
{

class DLLEXPORT ContextPage : public QObject
{
Q_OBJECT

public:
ContextPage() {}
virtual ~ContextPage() {}

virtual QGraphicsWidget* widget() = 0;
virtual Tomahawk::PlaylistInterface* playlistInterface() const = 0;

virtual QString title() const = 0;
virtual QString description() const = 0;
virtual QPixmap pixmap() const { return QPixmap( RESPATH "icons/tomahawk-icon-128x128.png" ); }

virtual bool jumpToCurrentTrack() = 0;

public slots:
virtual void setQuery( const Tomahawk::query_ptr& query ) = 0;

signals:
void nameChanged( const QString& );
void descriptionChanged( const QString& );
void pixmapChanged( const QPixmap& );
void destroyed( QWidget* widget );
};


class DLLEXPORT ContextProxyPage : public QGraphicsWidget
{
Q_OBJECT

public:
ContextProxyPage() : QGraphicsWidget()
{}

Tomahawk::ContextPage* page() const { return m_page; }
void setPage( Tomahawk::ContextPage* page );

virtual bool eventFilter( QObject* watched, QEvent* event );

signals:
void focused();

protected:
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget );
virtual bool sceneEvent( QEvent* event );

private:
Tomahawk::ContextPage* m_page;
};

}; // ns

#endif //CONTEXTPAGE_H

0 comments on commit 03f726f

Please sign in to comment.