From d3756e23310ec7b02310d884c19a7d98695a2168 Mon Sep 17 00:00:00 2001 From: dmeltzer Date: Thu, 30 Aug 2007 12:37:34 +0000 Subject: [PATCH] Create an applet to replace the coverbling widget. Still a definate work in progress. The applet shows up but is covered by a white box for some reason git-svn-id: svn+ssh://svn.kde.org/home/kde/trunk/extragear/multimedia/amarok@706442 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/MainWindow.cpp | 4 +- src/context/CMakeLists.txt | 38 +++- src/context/CoverBling.cpp | 2 +- src/context/applets/CMakeLists.txt | 1 + src/context/applets/coverbling/CMakeLists.txt | 21 +++ .../coverbling/CoverBlingApplet.cpp} | 205 ++++++++++----------- src/context/applets/coverbling/CoverBlingApplet.h | 50 +++++ .../amarok-context-applet-coverbling.desktop | 18 ++ 8 files changed, 221 insertions(+), 118 deletions(-) create mode 100644 src/context/applets/coverbling/CMakeLists.txt copy src/context/{CoverBling.cpp => applets/coverbling/CoverBlingApplet.cpp} (51%) create mode 100644 src/context/applets/coverbling/CoverBlingApplet.h create mode 100644 src/context/applets/coverbling/amarok-context-applet-coverbling.desktop diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 6d00ee1ae..df3361d55 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -241,8 +241,8 @@ void MainWindow::init() { QVBoxLayout* layout = new QVBoxLayout( contextWidget ); layout->addWidget( Context::ContextView::self() ); - if( AmarokConfig::useCoverBling() && QGLFormat::hasOpenGL() ) - layout->addWidget( new CoverBling( this ) ); +// if( AmarokConfig::useCoverBling() && QGLFormat::hasOpenGL() ) +// layout->addWidget( new CoverBling( this ) ); ControlBox* m_controlBox = new ControlBox( contextWidget ); m_controlBox->show(); // TODO fix the location of the controlbox so its not a few pixels out of the diff --git a/src/context/CMakeLists.txt b/src/context/CMakeLists.txt index d984acc93..2f9b7da05 100644 --- a/src/context/CMakeLists.txt +++ b/src/context/CMakeLists.txt @@ -1,14 +1,16 @@ # NOTE we link libplasma here instead of in the CMakeLists in plasma/ because we need control over the installation of header files and library name # this requires periodic syncing of this file with plasma/CMakeLists.txt as it changes, but thats better than the alternative. (the only option really.) +find_package(OpenGL) + add_subdirectory( applets ) add_subdirectory( engines ) -include_directories( ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/.. - ${CMAKE_CURRENT_SOURCE_DIR}/../amarokcore - ${CMAKE_CURRENT_SOURCE_DIR}/widgets - ${CMAKE_CURRENT_SOURCE_DIR}/plasma +include_directories( ${CMAKE_CURRENT_SOURCE_DIR} + .. + ../amarokcore + widgets + plasma ${CMAKE_CURRENT_BINARY_DIR}/..) @@ -41,22 +43,38 @@ set(plasma_LIB_SRCS plasma/widgets/boxlayout.cpp plasma/widgets/checkbox.cpp plasma/widgets/hboxlayout.cpp + plasma/widgets/flash.cpp plasma/widgets/icon.cpp + plasma/widgets/label.cpp + plasma/widgets/layout.cpp + plasma/widgets/layoutanimator.cpp + plasma/widgets/layoutitem.cpp plasma/widgets/lineedit.cpp plasma/widgets/pushbutton.cpp plasma/widgets/radiobutton.cpp plasma/widgets/widget.cpp - plasma/widgets/layout.cpp - plasma/widgets/layoutanimator.cpp - plasma/widgets/layoutitem.cpp plasma/widgets/vboxlayout.cpp - plasma/widgets/flash.cpp plasma/shadowitem.cpp + plasma/widgets/signalplotter.cpp ) + +if(QT_QTOPENGL_FOUND AND OPENGL_FOUND) +message(STATUS "Found opengl with plasma! ~Yay") +set(plasma_LIB_SRCS + ${plasma_LIB_SRCS} + plasma/glapplet.cpp) +endif(QT_QTOPENGL_FOUND AND OPENGL_FOUND) + kde4_add_library(amarokplasma SHARED ${plasma_LIB_SRCS}) -target_link_libraries(amarokplasma ${KDE4_KIO_LIBS} ${QT_QTUITOOLS_LIBRARY}) +target_link_libraries(amarokplasma +${KDE4_KIO_LIBS} +${QT_QTUITOOLS_LIBRARY} +${QT_QTOPENGL_LIBRARY} +${OPENGL_gl_LIBRARY} +${OPENGL_glu_LIBRARY} +) set_target_properties(amarokplasma PROPERTIES VERSION 1.0.0 SOVERSION 1) install(TARGETS amarokplasma DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/context/CoverBling.cpp b/src/context/CoverBling.cpp index 02eef9cda..76433ad15 100644 --- a/src/context/CoverBling.cpp +++ b/src/context/CoverBling.cpp @@ -102,7 +102,7 @@ CoverBling::initializeGL() //reimplemented glEnable( GL_BLEND ); //glBlendFunc( GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - + glBegin (GL_QUADS); glTexCoord2f (0.0, 0.0); glColor4f( 1.0, 1.0, 1.0, 0.3 ); diff --git a/src/context/applets/CMakeLists.txt b/src/context/applets/CMakeLists.txt index 819062e90..6b3baf700 100644 --- a/src/context/applets/CMakeLists.txt +++ b/src/context/applets/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory( currenttrack ) add_subdirectory( lyrics ) add_subdirectory( serviceinfo ) add_subdirectory( wikipedia ) +add_subdirectory( coverbling ) \ No newline at end of file diff --git a/src/context/applets/coverbling/CMakeLists.txt b/src/context/applets/coverbling/CMakeLists.txt new file mode 100644 index 000000000..62412f6a1 --- /dev/null +++ b/src/context/applets/coverbling/CMakeLists.txt @@ -0,0 +1,21 @@ +project(context-coverbling) + +set(coverbling_SRCS +CoverBlingApplet.cpp) + +include_directories( ../../.. + ../.. + ${KDE4_INCLUDE_DIR}/amarok ) # this way we don't need to prefix it with amarok/ (and it compiles this way too :) + +kde4_add_plugin(amarok_context_applet_coverbling ${coverbling_SRCS}) + +target_link_libraries(amarok_context_applet_coverbling + amaroklib + ${QT_QTOPENGL_LIBRARY} + ${OPENGL_gl_LIBRARY} + ${OPENGL_glu_LIBRARY} + ${KDE4_KIO_LIBS} +) + +install(TARGETS amarok_context_applet_coverbling DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES amarok-context-applet-coverbling.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/src/context/CoverBling.cpp b/src/context/applets/coverbling/CoverBlingApplet.cpp similarity index 51% copy from src/context/CoverBling.cpp copy to src/context/applets/coverbling/CoverBlingApplet.cpp index 02eef9cda..5fd4cc05d 100644 --- a/src/context/CoverBling.cpp +++ b/src/context/applets/coverbling/CoverBlingApplet.cpp @@ -1,43 +1,36 @@ /*************************************************************************** - * Copyright (C) 2007 by Mark Kretschmann * + * copyright : (C) 2007 Leo Franchi * + **************************************************************************/ + +/*************************************************************************** * * * 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. * ***************************************************************************/ -#define DEBUG_PREFIX "CoverBling" +#include "CoverBlingApplet.h" #include "debug.h" -#include "CoverBling.h" - #include -#include #include -#define TEXTURE_SIZE QSize( 256, 256 ) +#include +#define TEXTURE_SIZE QSize( 256, 256 ) -CoverBling::CoverBling( QWidget* parent ) - : QGLWidget( QGLFormat(QGL::DepthBuffer|QGL::SampleBuffers|QGL::AlphaChannel|QGL::DoubleBuffer), parent ) - , m_xOffset( 0.0 ) - , m_zOffset( M_PI / 2 ) +CoverBlingApplet::CoverBlingApplet( QObject* parent, const QVariantList& args ) + : Plasma::GLApplet( parent, args ) + , m_xOffset( 0.0 ) + , m_zOffset( M_PI / 2 ) { DEBUG_BLOCK - setFixedHeight( 200 ); + setHasConfigurationInterface( false ); + setDrawStandardBackground( true ); m_coverPaths << "amarok/images/album_cover_1.jpg"; m_coverPaths << "amarok/images/album_cover_2.jpg"; @@ -48,18 +41,13 @@ CoverBling::CoverBling( QWidget* parent ) m_coverPaths << "amarok/images/album_cover_7.jpg"; m_coverPaths << "amarok/images/album_cover_8.jpg"; m_coverPaths << "amarok/images/album_cover_9.jpg"; - - QTimer* timer = new QTimer( this ); - connect( timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) ); - timer->start( 20 ); //50fps -} -void -CoverBling::initializeGL() //reimplemented -{ - DEBUG_BLOCK +// QTimer* timer = new QTimer( this ); +// connect( timer, SIGNAL( timeout() ), this, SLOT( update( const QRectF) ) ); +// timer->start( 20 ); //50fps - //generate all textures + //FIXME: this probably shouldn't be here but not sure where else to put it.. + //generate all textures foreach( QString path, m_coverPaths ) { QImage image( KStandardDirs().findResource( "data", path ) ); image = image.scaled( TEXTURE_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation ); @@ -67,91 +55,101 @@ CoverBling::initializeGL() //reimplemented } glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glShadeModel(GL_SMOOTH); - qglClearColor( Qt::black ); + glShadeModel(GL_SMOOTH); + //TODO:PORT + glClearColor( 0.0, 0.0, 0.0, 0.0 ); glEnable( GL_MULTISAMPLE ); //enable anti aliasing glEnable( GL_DEPTH_TEST ); glDepthMask( true ); - + //Display list for drawing a textured rectangle m_texturedRectList = glGenLists( 1 ); glNewList( m_texturedRectList, GL_COMPILE ); - glBegin (GL_QUADS); - glTexCoord2f (0.0, 0.0); - glColor3f( 1.0, 1.0, 1.0 ); - glVertex3f (-1.0, -1.0, -1.0); - glTexCoord2f (1.0, 0.0); - glColor3f( 0.1, 0.1, 0.1 ); - glVertex3f (1.0, -1.0, -1.0); - glTexCoord2f (1.0, 1.0); - glColor3f( 0.1, 0.1, 0.1 ); - glVertex3f (1.0, 1.0, -1.0); - glTexCoord2f (0.0, 1.0); - glColor3f( 1.0, 1.0, 1.0 ); - glVertex3f (-1.0, 1.0, -1.0); - glEnd (); + glBegin (GL_QUADS); + glTexCoord2f (0.0, 0.0); + glColor3f( 1.0, 1.0, 1.0 ); + glVertex3f (-1.0, -1.0, -1.0); + glTexCoord2f (1.0, 0.0); + glColor3f( 0.1, 0.1, 0.1 ); + glVertex3f (1.0, -1.0, -1.0); + glTexCoord2f (1.0, 1.0); + glColor3f( 0.1, 0.1, 0.1 ); + glVertex3f (1.0, 1.0, -1.0); + glTexCoord2f (0.0, 1.0); + glColor3f( 1.0, 1.0, 1.0 ); + glVertex3f (-1.0, 1.0, -1.0); + glEnd (); //glDisable( GL_DEPTH_TEST ); glEndList(); //Display list for drawing reflection of the textured rectangle m_texturedRectReflectedList = glGenLists( 1 ); glNewList( m_texturedRectReflectedList, GL_COMPILE ); - glTranslatef( 0.0, -2.0, 0.0 ); - glScalef( 1.0, -1.0, 1.0 ); + glTranslatef( 0.0, -2.0, 0.0 ); + glScalef( 1.0, -1.0, 1.0 ); - glEnable( GL_BLEND ); + glEnable( GL_BLEND ); //glBlendFunc( GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR ); - glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - - glBegin (GL_QUADS); - glTexCoord2f (0.0, 0.0); - glColor4f( 1.0, 1.0, 1.0, 0.3 ); - glVertex3f (-1.0, -1.0, -1.0); - glColor4f( 1.0, 1.0, 1.0, 0.3 - 0.15 ); - glTexCoord2f (1.0, 0.0); - glVertex3f (1.0, -1.0, -1.0); - glColor4f( 1.0, 1.0, 1.0, 0.02 - 0.15 ); - glTexCoord2f (1.0, 1.0); - glVertex3f (1.0, 1.0, -1.0); - glColor4f( 1.0, 1.0, 1.0, 0.02 ); - glTexCoord2f (0.0, 1.0); - glVertex3f (-1.0, 1.0, -1.0); - glEnd (); - - glDisable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + + glBegin (GL_QUADS); + glTexCoord2f (0.0, 0.0); + glColor4f( 1.0, 1.0, 1.0, 0.3 ); + glVertex3f (-1.0, -1.0, -1.0); + glColor4f( 1.0, 1.0, 1.0, 0.3 - 0.15 ); + glTexCoord2f (1.0, 0.0); + glVertex3f (1.0, -1.0, -1.0); + glColor4f( 1.0, 1.0, 1.0, 0.02 - 0.15 ); + glTexCoord2f (1.0, 1.0); + glVertex3f (1.0, 1.0, -1.0); + glColor4f( 1.0, 1.0, 1.0, 0.02 ); + glTexCoord2f (0.0, 1.0); + glVertex3f (-1.0, 1.0, -1.0); + glEnd (); + + glDisable( GL_BLEND ); glEndList(); } +CoverBlingApplet::~CoverBlingApplet() +{ + DEBUG_BLOCK +} + void -CoverBling::resizeGL( int width, int height ) //reimplemented +CoverBlingApplet::resize( qreal width, qreal height ) { DEBUG_BLOCK glViewport( 0, 0, (GLint)width, (GLint)height ); - glMatrixMode(GL_PROJECTION); + glMatrixMode( GL_PROJECTION ); glLoadIdentity(); //glFrustum( -0.5f, 0.5f, -0.5f, 0.5f, 0.3f, 4.5f ); setPerspective(); - glMatrixMode(GL_MODELVIEW); + glMatrixMode( GL_MODELVIEW ); } void -CoverBling::setPerspective() +CoverBlingApplet::setPerspective() { - gluPerspective( 30, (double)width() / height(), 1.0, 20.0 ); + gluPerspective( 30, (double)boundingRect().width() / boundingRect().height(), 1.0, 20.0 ); } void -CoverBling::paintGL() //reimplemented +CoverBlingApplet::paintGLInterface( QPainter *, const QStyleOptionGraphicsItem * ) { + DEBUG_BLOCK + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - const QPoint mousePos = mapFromGlobal( QCursor::pos() ); - draw( objectAtPosition( mousePos ) ); + //TODO:no mapFromGlobal() +// const QPoint mousePos = mapFromGlobal( QCursor::pos() ); + const QPoint mousePos = QPoint( 300, 200 ); + draw( objectAtPosition(mousePos) ); } void -CoverBling::draw( GLuint selected ) +CoverBlingApplet::draw( GLuint selected ) { GLuint objectName = 1; @@ -182,25 +180,25 @@ CoverBling::draw( GLuint selected ) foreach( GLuint id, m_textureIds ) { glBindTexture( GL_TEXTURE_2D, id ); glPushMatrix(); - const float xsin = sin( xoffset ); - const float zsin = sin( zoffset ); - xoffset += 1.0; - zoffset += 0.1; - glTranslatef( xoffset, yoffset, zoffset ); - glRotatef( 8, 0.0, 1.0, 0.0 ); + const float xsin = sin( xoffset ); + const float zsin = sin( zoffset ); + xoffset += 1.0; + zoffset += 0.1; + glTranslatef( xoffset, yoffset, zoffset ); + glRotatef( 8, 0.0, 1.0, 0.0 ); //draw the cover - if( objectName == selected ) - glColor3f( 1.0, 0.0, 0.0 ); - glLoadName( objectName++ ); - glCallList( m_texturedRectList ); - glColor4f( 1.0, 1.0, 1.0, 1.0 ); + if( objectName == selected ) + glColor3f( 1.0, 0.0, 0.0 ); + glLoadName( objectName++ ); + glCallList( m_texturedRectList ); + glColor4f( 1.0, 1.0, 1.0, 1.0 ); //draw reflection on the ground - glLoadName( 0 ); - glPushMatrix(); - glCallList( m_texturedRectReflectedList ); - glPopMatrix(); + glLoadName( 0 ); + glPushMatrix(); + glCallList( m_texturedRectReflectedList ); + glPopMatrix(); glPopMatrix(); glColor4f( 1.0, 1.0, 1.0, 1.0 ); } @@ -209,7 +207,7 @@ CoverBling::draw( GLuint selected ) } GLuint -CoverBling::objectAtPosition( const QPoint& pos ) +CoverBlingApplet::objectAtPosition( const QPoint& pos ) { // this is the same as in every OpenGL picking example const int MaxSize = 512; // see below for an explanation on the buffer content @@ -226,11 +224,11 @@ CoverBling::objectAtPosition( const QPoint& pos ) glMatrixMode(GL_PROJECTION); glPushMatrix(); - glLoadIdentity(); - gluPickMatrix((GLdouble)pos.x(), (GLdouble)(viewport[3] - pos.y()), 5.0, 5.0, viewport); - setPerspective(); - draw(); - glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPickMatrix((GLdouble)pos.x(), (GLdouble)(viewport[3] - pos.y()), 5.0, 5.0, viewport); + setPerspective(); + draw(); + glMatrixMode(GL_PROJECTION); glPopMatrix(); const int hits = glRenderMode( GL_RENDER ); @@ -240,17 +238,14 @@ CoverBling::objectAtPosition( const QPoint& pos ) //determine object with the lowest Z value uint hitZValue = UINT_MAX; uint hit = UINT_MAX; - for( int i = 0; i < hits; i++ ) { - if( buffer[(i*4)+1] < hitZValue ) { + for( int i = 0; i < hits; i++ ) { + if( buffer[(i*4)+1] < hitZValue ) { hit = buffer[(i*4)+3]; hitZValue = buffer[(i*4)+1]; } } - + // return the name of the clicked surface return hit; } - - -#include "CoverBling.moc" - +#include "CoverBlingApplet.moc" diff --git a/src/context/applets/coverbling/CoverBlingApplet.h b/src/context/applets/coverbling/CoverBlingApplet.h new file mode 100644 index 000000000..f167a4c67 --- /dev/null +++ b/src/context/applets/coverbling/CoverBlingApplet.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * copyright : (C) 2007 Leo Franchi * + **************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef CURRENT_TRACK_APPLET_H +#define CURRENT_TRACK_APPLET_H + +#include "Applet.h" +#include "plasma/glapplet.h" + +#include + +class CoverBlingApplet : public Plasma::GLApplet +{ + Q_OBJECT +public: + CoverBlingApplet( QObject* parent, const QVariantList& args ); + ~CoverBlingApplet(); + + virtual void paintGLInterface( QPainter *painter, const QStyleOptionGraphicsItem *option ); + +protected: + void draw( GLuint selected = 0 ); + void resize( qreal width, qreal height ); + void setPerspective(); + GLuint objectAtPosition( const QPoint& pos ); + QSizeF contentSize() const { return QSizeF(400.0, 200.0 ); } + +private: + QStringList m_coverPaths; + QList m_textureIds; + GLuint m_texturedRectList; + GLuint m_texturedRectReflectedList; + float m_xOffset; + float m_zOffset; + +}; + +K_EXPORT_AMAROK_APPLET( coverbling, CoverBlingApplet ) + +#endif diff --git a/src/context/applets/coverbling/amarok-context-applet-coverbling.desktop b/src/context/applets/coverbling/amarok-context-applet-coverbling.desktop new file mode 100644 index 000000000..c9f97e1ea --- /dev/null +++ b/src/context/applets/coverbling/amarok-context-applet-coverbling.desktop @@ -0,0 +1,18 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Coverbling +Type=Service +ServiceTypes=Plasma/Applet + +X-KDE-Library=amarok_context_applet_coverbling +X-KDE-PluginInfo-Author=Leo Franchi +X-KDE-PluginInfo-Email=lfranchi@gmail.com +X-KDE-PluginInfo-Name=currenttrack +X-KDE-PluginInfo-Version=pre0.1 +X-KDE-PluginInfo-Website= +X-KDE-PluginInfo-Category= +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-ParentApp=amarok +X-KDE-PluginInfo-Category=Current \ No newline at end of file -- 2.11.4.GIT