Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/library/librarycontrol.cpp

Go to the documentation of this file.
00001 #include <QDebug>
00002 #include <QModelIndexList>
00003 #include <QModelIndex>
00004 #include <QItemSelectionModel>
00005 
00006 #include "controlobject.h"
00007 #include "controlobjectthreadmain.h"
00008 #include "playermanager.h"
00009 #include "widget/wlibrary.h"
00010 #include "widget/wlibrarysidebar.h"
00011 #include "library/librarycontrol.h"
00012 #include "library/libraryview.h"
00013 
00014 LoadToGroupController::LoadToGroupController(QObject* pParent, const QString group)
00015         : QObject(pParent),
00016           m_group(group) {
00017     m_pLoadControl = new ControlObject(ConfigKey(group, "LoadSelectedTrack"));
00018     m_pLoadCOTM = new ControlObjectThreadMain(m_pLoadControl);
00019     connect(m_pLoadCOTM, SIGNAL(valueChanged(double)),
00020             this, SLOT(slotLoadToGroup(double)));
00021 }
00022 
00023 LoadToGroupController::~LoadToGroupController() {
00024     delete m_pLoadCOTM;
00025     delete m_pLoadControl;
00026 }
00027 
00028 void LoadToGroupController::slotLoadToGroup(double v) {
00029     if (v > 0) {
00030         emit(loadToGroup(m_group));
00031     }
00032 }
00033 
00034 LibraryControl::LibraryControl(QObject* pParent) : QObject(pParent) {
00035     m_pLibraryWidget = NULL;
00036     m_pSidebarWidget = NULL;
00037 
00038     // Make controls for library navigation and track loading. Leaking all these CO's, but oh well?
00039 
00040     // We don't know how many decks or samplers there will be, so create 100 of them.
00041     for (int i = 0; i < 100; ++i) {
00042         LoadToGroupController* pLoadController = new LoadToGroupController(this, PlayerManager::groupForDeck(i));
00043         connect(pLoadController, SIGNAL(loadToGroup(QString)),
00044                 this, SLOT(slotLoadSelectedTrackToGroup(QString)));
00045         pLoadController = new LoadToGroupController(this, PlayerManager::groupForSampler(i));
00046         connect(pLoadController, SIGNAL(loadToGroup(QString)),
00047                 this, SLOT(slotLoadSelectedTrackToGroup(QString)));
00048     }
00049 
00050     m_pSelectNextTrack = new ControlObjectThreadMain(new ControlObject(ConfigKey("[Playlist]","SelectNextTrack")));
00051     connect(m_pSelectNextTrack, SIGNAL(valueChanged(double)),
00052             this, SLOT(slotSelectNextTrack(double)));
00053 
00054     m_pSelectPrevTrack = new ControlObjectThreadMain(new ControlObject(ConfigKey("[Playlist]","SelectPrevTrack")));
00055     connect(m_pSelectPrevTrack, SIGNAL(valueChanged(double)),
00056             this, SLOT(slotSelectPrevTrack(double)));
00057 
00058     m_pSelectNextPlaylist = new ControlObjectThreadMain(new ControlObject(ConfigKey("[Playlist]","SelectNextPlaylist")));
00059     connect(m_pSelectNextPlaylist, SIGNAL(valueChanged(double)),
00060             this, SLOT(slotSelectNextPlaylist(double)));
00061 
00062     m_pSelectPrevPlaylist = new ControlObjectThreadMain(new ControlObject(ConfigKey("[Playlist]","SelectPrevPlaylist")));
00063     connect(m_pSelectPrevPlaylist, SIGNAL(valueChanged(double)),
00064             this, SLOT(slotSelectPrevPlaylist(double)));
00065 
00066     m_pLoadSelectedIntoFirstStopped = new ControlObjectThreadMain(new ControlObject(ConfigKey("[Playlist]","LoadSelectedIntoFirstStopped")));
00067     connect(m_pLoadSelectedIntoFirstStopped, SIGNAL(valueChanged(double)),
00068             this, SLOT(slotLoadSelectedIntoFirstStopped(double)));
00069 
00070     m_pSelectTrackKnob = new ControlObjectThreadMain(new ControlObject(ConfigKey("[Playlist]","SelectTrackKnob")));
00071     connect(m_pSelectTrackKnob, SIGNAL(valueChanged(double)),
00072             this, SLOT(slotSelectTrackKnob(double)));
00073 }
00074 
00075 LibraryControl::~LibraryControl() {
00076    delete m_pSelectNextTrack;
00077    delete m_pSelectPrevTrack;
00078    delete m_pSelectNextPlaylist;
00079    delete m_pSelectPrevPlaylist;
00080    delete m_pLoadSelectedIntoFirstStopped;
00081    delete m_pSelectTrackKnob;
00082 }
00083 
00084 void LibraryControl::bindWidget(WLibrarySidebar* pSidebarWidget, WLibrary* pLibraryWidget, MixxxKeyboard* pKeyboard) {
00085     if (m_pSidebarWidget != NULL) {
00086         disconnect(m_pSidebarWidget, 0, this, 0);
00087     }
00088     m_pSidebarWidget = pSidebarWidget;
00089     connect(m_pSidebarWidget, SIGNAL(destroyed()),
00090             this, SLOT(sidebarWidgetDeleted()));
00091 
00092     if (m_pLibraryWidget != NULL) {
00093         disconnect(m_pLibraryWidget, 0, this, 0);
00094     }
00095     m_pLibraryWidget = pLibraryWidget;
00096     connect(m_pLibraryWidget, SIGNAL(destroyed()),
00097             this, SLOT(libraryWidgetDeleted()));
00098 }
00099 
00100 void LibraryControl::libraryWidgetDeleted() {
00101     m_pLibraryWidget = NULL;
00102 }
00103 
00104 void LibraryControl::sidebarWidgetDeleted() {
00105     m_pSidebarWidget = NULL;
00106 }
00107 
00108 void LibraryControl::slotLoadSelectedTrackToGroup(QString group) {
00109     if (m_pLibraryWidget == NULL)
00110         return;
00111 
00112     LibraryView* activeView = m_pLibraryWidget->getActiveView();
00113     if (!activeView) {
00114         return;
00115     }
00116     activeView->loadSelectedTrackToGroup(group);
00117 }
00118 
00119 void LibraryControl::slotLoadSelectedIntoFirstStopped(double v) {
00120     if (m_pLibraryWidget == NULL)
00121         return;
00122 
00123     if (v > 0)
00124     {
00125         LibraryView* activeView = m_pLibraryWidget->getActiveView();
00126         if (!activeView) {
00127             return;
00128         }
00129         activeView->loadSelectedTrack();
00130     }
00131 }
00132 
00133 void LibraryControl::slotSelectNextTrack(double v) {
00134     if (m_pLibraryWidget == NULL)
00135         return;
00136     if (v > 0) {
00137         LibraryView* activeView = m_pLibraryWidget->getActiveView();
00138         if (!activeView) {
00139             return;
00140         }
00141         activeView->moveSelection(1);
00142     }
00143 }
00144 
00145 void LibraryControl::slotSelectPrevTrack(double v) {
00146     if (m_pLibraryWidget == NULL)
00147         return;
00148     if (v > 0) {
00149         LibraryView* activeView = m_pLibraryWidget->getActiveView();
00150         if (!activeView) {
00151             return;
00152         }
00153         activeView->moveSelection(-1);
00154     }
00155 }
00156 
00157 void LibraryControl::slotSelectTrackKnob(double v)
00158 {
00159     if (m_pLibraryWidget == NULL)
00160         return;
00161 
00162     int i = (int)v;
00163 
00164     LibraryView* activeView = m_pLibraryWidget->getActiveView();
00165     if (!activeView) {
00166         return;
00167     }
00168     activeView->moveSelection(i);
00169 }
00170 
00171 
00172 void LibraryControl::slotSelectNextPlaylist(double v) {
00173     if (m_pSidebarWidget == NULL)
00174         return;
00175 
00176     QWidget* destWidget = m_pSidebarWidget;
00177     if (!destWidget) {
00178 
00179         return;
00180     }
00181 
00182     if (v > 0)
00183         QApplication::postEvent(destWidget,
00184                                 new QKeyEvent(QEvent::KeyPress, (int)Qt::Key_Down,
00185                                               Qt::NoModifier, QString(), true));
00186     else
00187         QApplication::postEvent(destWidget,
00188                                 new QKeyEvent(QEvent::KeyRelease, (int)Qt::Key_Down,
00189                                               Qt::NoModifier, QString(), true));
00190 
00191 }
00192 
00193 void LibraryControl::slotSelectPrevPlaylist(double v) {
00194     if (m_pSidebarWidget == NULL)
00195         return;
00196 
00197     QWidget* destWidget = m_pSidebarWidget;
00198     if (!destWidget) {
00199         return;
00200     }
00201 
00202     if (v)
00203         QApplication::postEvent(destWidget,
00204                                 new QKeyEvent(QEvent::KeyPress, (int)Qt::Key_Up,
00205                                               Qt::NoModifier, QString(), true));
00206     else
00207         QApplication::postEvent(destWidget,
00208                                 new QKeyEvent(QEvent::KeyRelease, (int)Qt::Key_Up,
00209                                               Qt::NoModifier, QString(), true));
00210 }
00211 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines