From 4af1ca5d0fbb4ec1c9ae3e0689fdd6056cd83d62 Mon Sep 17 00:00:00 2001 From: w1z7ard Date: Fri, 28 Oct 2011 02:57:24 +0000 Subject: [PATCH] support for +/- keys to edit ratings. git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@1362 6778bc44-b910-0410-a7a0-be141de4315d --- src/libprojectM/KeyHandler.cpp | 33 +++++++++++++++++++++++ src/libprojectM/event.h | 3 +++ src/libprojectM/projectM.cpp | 5 +++- src/libprojectM/projectM.hpp | 3 +++ src/projectM-pulseaudio/CMakeLists.txt | 28 ++++++++++++++++++- src/projectM-qt/qplaylistmodel.cpp | 11 +++++--- src/projectM-qt/qplaylistmodel.hpp | 2 ++ src/projectM-qt/qprojectm.hpp | 9 +++++++ src/projectM-qt/qprojectm_mainwindow.cpp | 34 ++++++++++++++++++------ src/projectM-qt/qprojectm_mainwindow.hpp | 2 +- src/projectM-qt/qprojectmwidget.hpp | 9 +++++++ 11 files changed, 125 insertions(+), 14 deletions(-) diff --git a/src/libprojectM/KeyHandler.cpp b/src/libprojectM/KeyHandler.cpp index 7f664a944..3661f2bad 100755 --- a/src/libprojectM/KeyHandler.cpp +++ b/src/libprojectM/KeyHandler.cpp @@ -209,6 +209,39 @@ void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode break; case PROJECTM_K_t: break; + case PROJECTM_K_EQUALS: + case PROJECTM_K_PLUS: + + unsigned int index; + + if (selectedPresetIndex(index)) { + + const int oldRating = getPresetRating(index, HARD_CUT_RATING_TYPE); + + if (oldRating >= 6) + break; + + const int rating = oldRating + 1; + + changePresetRating(index, rating, HARD_CUT_RATING_TYPE); + } + + break; + + case PROJECTM_K_MINUS: + if (selectedPresetIndex(index)) { + + const int oldRating = getPresetRating(index, HARD_CUT_RATING_TYPE); + + if (oldRating <= 1) + break; + + const int rating = oldRating - 1; + + changePresetRating(index, rating, HARD_CUT_RATING_TYPE); + } + break; + default: break; } diff --git a/src/libprojectM/event.h b/src/libprojectM/event.h index c480926e3..88949f2fc 100755 --- a/src/libprojectM/event.h +++ b/src/libprojectM/event.h @@ -136,6 +136,9 @@ typedef enum { PROJECTM_K_y, PROJECTM_K_z, PROJECTM_K_NONE, + PROJECTM_K_PLUS, + PROJECTM_K_MINUS, + PROJECTM_K_EQUALS } projectMKeycode; typedef enum { diff --git a/src/libprojectM/projectM.cpp b/src/libprojectM/projectM.cpp index f255dd51b..5e230052f 100755 --- a/src/libprojectM/projectM.cpp +++ b/src/libprojectM/projectM.cpp @@ -866,8 +866,9 @@ void projectM::switchPreset(std::auto_ptr & targetPreset) { return m_presetLoader->size(); } - void projectM:: changePresetRating (unsigned int index, int rating, const PresetRatingType ratingType) { + void projectM::changePresetRating (unsigned int index, int rating, const PresetRatingType ratingType) { m_presetLoader->setRating(index, rating, ratingType); + presetRatingChanged(index, rating, ratingType); } void projectM::insertPresetURL(unsigned int index, const std::string & presetURL, const std::string & presetName, const RatingList & ratings) @@ -925,3 +926,5 @@ void projectM::changeTextureSize(int size) { void projectM::changePresetDuration(int seconds) { timeKeeper->ChangePresetDuration(seconds); } + + diff --git a/src/libprojectM/projectM.hpp b/src/libprojectM/projectM.hpp index 2b5752aa1..5fa38d302 100755 --- a/src/libprojectM/projectM.hpp +++ b/src/libprojectM/projectM.hpp @@ -244,6 +244,9 @@ public: virtual void presetSwitchedEvent(bool isHardCut, unsigned int index) const {}; virtual void shuffleEnabledValueChanged(bool isEnabled) const {}; + /// Occurs whenever preset rating has changed via changePresetRating() method + virtual void presetRatingChanged(unsigned int index, int rating, PresetRatingType ratingType) const {}; + inline PCM * pcm() { return _pcm; diff --git a/src/projectM-pulseaudio/CMakeLists.txt b/src/projectM-pulseaudio/CMakeLists.txt index 496b44fc7..b9cffe85b 100644 --- a/src/projectM-pulseaudio/CMakeLists.txt +++ b/src/projectM-pulseaudio/CMakeLists.txt @@ -4,6 +4,9 @@ cmake_minimum_required(VERSION 2.4.0) Include(cmake/CPack-projectM.cmake) +# Include the current dir as a source for find_package macro +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}) + set(QT_USE_OPENGL TRUE) cmake_policy(SET CMP0005 OLD) @@ -46,6 +49,29 @@ else (LIBPULSE_FOUND) MESSAGE(FATAL_ERROR "ERROR: Pulse Audio is NOT found. Please install pulse audio 0.9.8 or greater from www.pulseaudio.org.") endif(LIBPULSE_FOUND) +# GLEW - A cross plataform C/C++ extension loading library +find_package(GLEW) +if (GLEW_FOUND) + MESSAGE(STATUS "[projectm-pulseaudio] glew library detected.") + message(STATUS "GLEW_LIBRARY = ${GLEW_LIBRARY}") + message(STATUS "GLEW_LIBRARY_DIR = ${GLEW_LIBRARY_DIR}") + include_directories(${GLEW_INCLUDE_DIR}) + link_directories(${GLEW_LIBRARY_DIR}) +else (GLEW_FOUND) + MESSAGE(FATAL_ERROR "ERROR: glew library not detected. Please install it from glew.sourceforge.net") +endif (GLEW_FOUND) + +# ftgl - OpenGL library to use arbitrary fonts +pkg_search_module(FTGL REQUIRED ftgl) +if (FTGL_FOUND) + message(STATUS "[projectm-pulseaudio] ftgl library detected.") + message(STATUS "FTGL_LIBRARIES = ${FTGL_LIBRARIES}") + message(STATUS "FTGL_LIBRARY_DIRS = ${FTGL_LIBRARY_DIRS}") + include_directories(${FTGL_INCLUDE_DIRS}) + link_directories(${FTGL_LIBRARY_DIRS}) +else (FTGL_FOUND) + message(FATAL_ERROR "ERROR: ftgl library not detected. Please install it from ftgl.wiki.sourceforge.net") +endif (FTGL_FOUND) set(projectM_pulseaudio_SRCS qprojectM-pulseaudio.cpp ConfigFile.h ConfigFile.cpp QPulseAudioThread.cpp QPulseAudioDeviceChooser.cpp QPulseAudioDeviceModel.cpp @@ -91,7 +117,7 @@ endif(COMMAND cmake_policy) ADD_EXECUTABLE(projectM-pulseaudio ${projectM_pulseaudio_SRCS} ${projectM_pulseaudio_MOC_SRCS} ${projectM_pulseaudio_UIS_H}) -TARGET_LINK_LIBRARIES(projectM-pulseaudio projectM-qt projectM pulse ${QT_QTGUI_LIBRARIES} ${QT_QTOPENGL_LIBRARIES} ${QT_QTCORE_LIBRARIES} ${QT_LIBRARIES}) +TARGET_LINK_LIBRARIES(projectM-pulseaudio projectM-qt projectM pulse ${QT_QTGUI_LIBRARIES} ${QT_QTOPENGL_LIBRARIES} ${QT_QTCORE_LIBRARIES} ${QT_LIBRARIES} ${GLEW_LIBRARY} ${FTGL_LIBRARIES}) INSTALL(TARGETS projectM-pulseaudio DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) install(FILES "projectM-pulseaudio.desktop" DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) diff --git a/src/projectM-qt/qplaylistmodel.cpp b/src/projectM-qt/qplaylistmodel.cpp index 727520f4d..7a087e2a4 100644 --- a/src/projectM-qt/qplaylistmodel.cpp +++ b/src/projectM-qt/qplaylistmodel.cpp @@ -104,15 +104,12 @@ bool QPlaylistModel::setData ( const QModelIndex & index, const QVariant & value if ( role == QPlaylistModel::RatingRole ) { m_projectM.changePresetRating(index.row(), value.toInt(), HARD_CUT_RATING_TYPE); - emit ( dataChanged ( index, index ) ); return true; } else if (role == QPlaylistModel::BreedabilityRole) { m_projectM.changePresetRating(index.row(), value.toInt(), SOFT_CUT_RATING_TYPE); - emit ( dataChanged ( index, index ) ); return true; } else if (role == QPlaylistModel::NameRole) { m_projectM.changePresetName(index.row(), value.toString().toStdString()); - emit ( dataChanged ( index, index ) ); return true; } else @@ -429,3 +426,11 @@ bool QPlaylistModel::readPlaylist ( const QString & file ) return true; } +void QPlaylistModel::notifyDataChanged(unsigned int ind) +{ + + + QModelIndex modelIndex = index (ind, 1); + emit ( dataChanged ( modelIndex, modelIndex)); +} + diff --git a/src/projectM-qt/qplaylistmodel.hpp b/src/projectM-qt/qplaylistmodel.hpp index f518b2eef..3faa3a1da 100644 --- a/src/projectM-qt/qplaylistmodel.hpp +++ b/src/projectM-qt/qplaylistmodel.hpp @@ -81,6 +81,8 @@ inline Qt::DropActions supportedDropActions() const return Qt::MoveAction; } +void notifyDataChanged(unsigned int index); + inline QStringList mimeTypes () const { QStringList mimeTypes; mimeTypes << PRESET_MIME_TYPE; diff --git a/src/projectM-qt/qprojectm.hpp b/src/projectM-qt/qprojectm.hpp index 253448986..be037d427 100644 --- a/src/projectM-qt/qprojectm.hpp +++ b/src/projectM-qt/qprojectm.hpp @@ -34,8 +34,17 @@ class QProjectM : public QObject, public projectM { void presetSwitchedEvent(bool hardCut, unsigned int index) const { presetSwitchedSignal(hardCut, index); } + + void presetRatingChanged(unsigned int index, int rating, + PresetRatingType ratingType) const { + presetRatingChangedSignal(index, rating, ratingType); + } + signals: void presetSwitchedSignal(bool hardCut, unsigned int index) const; + void presetRatingChangedSignal(unsigned int index, int rating, + PresetRatingType ratingType) const; + public slots: diff --git a/src/projectM-qt/qprojectm_mainwindow.cpp b/src/projectM-qt/qprojectm_mainwindow.cpp index 35d992ae0..a605f7a36 100644 --- a/src/projectM-qt/qprojectm_mainwindow.cpp +++ b/src/projectM-qt/qprojectm_mainwindow.cpp @@ -310,7 +310,10 @@ void QProjectM_MainWindow::postProjectM_Initialize() connect ( m_QProjectMWidget->qprojectM(), SIGNAL ( presetSwitchedSignal ( bool,unsigned int ) ), this, SLOT ( updatePlaylistSelection ( bool,unsigned int ) ) ); - + + connect ( m_QProjectMWidget->qprojectM(), SIGNAL ( presetRatingChangedSignal ( unsigned int,int, PresetRatingType) ), + this, SLOT ( presetRatingChanged( unsigned int,int, PresetRatingType) )); + connect ( m_QProjectMWidget->qprojectM(), SIGNAL ( presetSwitchedSignal ( bool,unsigned int ) ), playlistModel, SLOT ( updateItemHighlights() ) ); @@ -500,21 +503,20 @@ void QProjectM_MainWindow::changePresetAttribute ( const QModelIndex & index ) return; PlaylistItemVector & lastCache = *historyHash[previousFilter]; - const long id = lastCache[index.row() ]; + const long id = lastCache[index.row()]; ui->presetPlayListDockWidget->setWindowModified ( true ); - if ( index.column() == 1 ) + if (index.column() == 1) { /// @bug get rid of hard coded rating boundaries - int newRating = ( ( playlistModel->data ( index, QPlaylistModel::RatingRole ).toInt() ) % 6 ) +1 ; - - - playlistItemMetaDataHash[id].rating = newRating; + const int newRating = ( ( playlistModel->data ( index, QPlaylistModel::RatingRole ).toInt() ) % 6 ) +1 ; playlistModel->setData ( index, newRating, QPlaylistModel::RatingRole ); + + } - else if ( index.column() == 2 ) + else if (index.column() == 2) { /// @bug get rid of hard coded breedability boundaries @@ -1281,3 +1283,19 @@ void QProjectM_MainWindow::updateFilteredPlaylist ( const QString & text ) qprojectMWidget()->releasePresetLock(); } + +void QProjectM_MainWindow::presetRatingChanged( unsigned int index, int rating, PresetRatingType ratingType) +{ + + PlaylistItemVector & lastCache = *historyHash[previousFilter]; + const long id = lastCache[index]; + + qDebug() << "preset rating changed: " << index << " (rating = " << rating << ")"; + + playlistItemMetaDataHash[id].rating = rating; + + ui->presetPlayListDockWidget->setWindowModified ( true ); + + playlistModel->notifyDataChanged(index); +} + diff --git a/src/projectM-qt/qprojectm_mainwindow.hpp b/src/projectM-qt/qprojectm_mainwindow.hpp index db40e4206..298d77356 100644 --- a/src/projectM-qt/qprojectm_mainwindow.hpp +++ b/src/projectM-qt/qprojectm_mainwindow.hpp @@ -115,7 +115,7 @@ protected: private slots: void dockLocationChanged(Qt::DockWidgetArea area); - +void presetRatingChanged(unsigned int, int, PresetRatingType); void presetHardCut(); void presetSoftCut(); void insertPresetsDialog() ; diff --git a/src/projectM-qt/qprojectmwidget.hpp b/src/projectM-qt/qprojectmwidget.hpp index 3756af67e..8755d1f95 100644 --- a/src/projectM-qt/qprojectmwidget.hpp +++ b/src/projectM-qt/qprojectmwidget.hpp @@ -231,6 +231,15 @@ class QProjectMWidget : public QGLWidget case Qt::Key_F5: pkey = PROJECTM_K_F5; break; + case Qt::Key_Plus: + pkey = PROJECTM_K_PLUS; + break; + case Qt::Key_Minus: + pkey = PROJECTM_K_MINUS; + break; + case Qt::Key_Equal: + pkey = PROJECTM_K_EQUALS; + break; default: e->ignore(); return;