From 3e8bcabfbc3b5e2ac815895fbd36b80c7f1f5cd1 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Tue, 6 Sep 2011 11:19:18 +0200 Subject: [PATCH] Add TomahawkWindowDeclarative --- src/active/CMakeLists.txt | 30 +++++++++ src/active/tomahawkwindowdeclarative.cpp | 79 ++++++++++++++++++++++++ src/active/tomahawkwindowdeclarative.h | 56 +++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 src/active/CMakeLists.txt create mode 100644 src/active/tomahawkwindowdeclarative.cpp create mode 100644 src/active/tomahawkwindowdeclarative.h diff --git a/src/active/CMakeLists.txt b/src/active/CMakeLists.txt new file mode 100644 index 000000000..6daf6527d --- /dev/null +++ b/src/active/CMakeLists.txt @@ -0,0 +1,30 @@ + + +SET( touchmahawkSources ${final_src} ) +#LIST( REMOVE_ITEM touchmahawkSources "main.cpp" ) + +SET( touchmahawkHeaders + active/tomahawkwindowdeclarative.h +) + +SET( touchmahawkSources + ${touchmahawkSources} + active/tomahawkwindowdeclarative.cpp + +# active/main.cpp +) + + +qt4_wrap_cpp( touchmahawkMoc ${touchmahawkHeaders} ) + +SET( touchmahawkFinalSources ${touchmahawkMoc} ${touchmahawkSources} ) +SET( touchmahawkLinkLibraries + kdeclarative + ${tomahawkLinkLibraries} +) #${QT_QTDECLARATIVE_LIBRARY} + +ADD_EXECUTABLE( active-tomahawk ${touchmahawkFinalSources} ) +TARGET_LINK_LIBRARIES( active-tomahawk ${touchmahawkLinkLibraries} ) +SET_TARGET_PROPERTIES( active-tomahawk PROPERTIES COMPILE_FLAGS -DTOUCHMAHAWK ) +INSTALL( TARGETS active-tomahawk DESTINATION bin ) + diff --git a/src/active/tomahawkwindowdeclarative.cpp b/src/active/tomahawkwindowdeclarative.cpp new file mode 100644 index 000000000..419db8774 --- /dev/null +++ b/src/active/tomahawkwindowdeclarative.cpp @@ -0,0 +1,79 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Dominik Schmidt + * + * 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 . + */ + +#include "active/tomahawkwindowdeclarative.h" + +#include "utils/logger.h" +#include "audio/audioengine.h" +#include "globalactionmanager.h" + +#include +#include + +#define QMLGUI "/home/domme/dev/sources/tomahawk-qml" + +TomahawkWindowDeclarative::TomahawkWindowDeclarative() + : m_view(0) +{ + QFileSystemWatcher* watcher = new QFileSystemWatcher; + watcher->addPath( QMLGUI ); + + connect( watcher, SIGNAL( directoryChanged( QString ) ), SLOT( loadQml() )); + loadQml(); + + setCentralWidget( m_view ); + setWindowTitle("Touch-ma-hawk"); +} + + +TomahawkWindowDeclarative::~TomahawkWindowDeclarative() +{ + +} + + +void +TomahawkWindowDeclarative::loadQml() +{ + tLog() << Q_FUNC_INFO; + qmlRegisterType("org.tomahawkplayer.qmlcomponents", 1, 0, "AudioEngine"); + + if( !m_view ) + { + tLog()<< Q_FUNC_INFO << "create qml view"; + m_view = new QDeclarativeView; + m_view->setResizeMode(QDeclarativeView::SizeRootObjectToView); + m_view->show(); + } + + tLog()<< Q_FUNC_INFO << "clear component cache"; + m_view->engine()->clearComponentCache(); + + tLog()<< Q_FUNC_INFO << "set source"; + m_view->setSource( QUrl::fromLocalFile( QMLGUI "/main.qml" ) ); + + tLog()<< Q_FUNC_INFO << "set context property"; + QDeclarativeContext* context = m_view->rootContext(); + //context->setContextProperty( "myModel", m_superCollectionProxyModel ); + + context->setContextProperty( "audioEngine", AudioEngine::instance() ); + + context->setContextProperty( "globalActionManager", GlobalActionManager::instance() ); + + tLog()<< Q_FUNC_INFO << "finished"; +} diff --git a/src/active/tomahawkwindowdeclarative.h b/src/active/tomahawkwindowdeclarative.h new file mode 100644 index 000000000..70f66ff45 --- /dev/null +++ b/src/active/tomahawkwindowdeclarative.h @@ -0,0 +1,56 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Dominik Schmidt + * + * 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 . + */ + +#ifndef TOMAHAWKWINDOWDECLARATIVE_H +#define TOMAHAWKWINDOWDECLARATIVE_H + +#include +#include + +class TomahawkWindowDeclarative; +class QFileSystemWatcher; + + +class TomahawkWindowDeclarative : public QMainWindow +{ + Q_OBJECT + +public: + TomahawkWindowDeclarative(); + ~TomahawkWindowDeclarative(); + +public slots: + void play( const QModelIndex& index ); + +// protected: +// void changeEvent( QEvent* e ); +// void closeEvent( QCloseEvent* e ); +// void showEvent( QShowEvent* e ); +// void hideEvent( QHideEvent* e ); + +private slots: + void loadQml(); + +private: + QDeclarativeView* m_view; + QFileSystemWatcher* m_watcher; + +}; + +#endif // TOMAHAWKWINDOWDECLARATIVE_H +