![]() |
Mixxx
|
00001 #include <QSqlTableModel> 00002 #include "widget/wwidget.h" 00003 #include "widget/wskincolor.h" 00004 #include "library/preparelibrarytablemodel.h" 00005 #include "transposeproxymodel.h" 00006 #include "widget/wpreparecratestableview.h" 00007 #include "widget/wpreparelibrarytableview.h" 00008 #include "library/trackcollection.h" 00009 #include "dlgprepare.h" 00010 00011 00012 DlgPrepare::DlgPrepare(QWidget* parent, 00013 ConfigObject<ConfigValue>* pConfig, 00014 TrackCollection* pTrackCollection) 00015 : QWidget(parent), Ui::DlgPrepare(), 00016 m_pConfig(pConfig), 00017 m_pTrackCollection(pTrackCollection), 00018 m_bAnalysisActive(false) { 00019 setupUi(this); 00020 m_songsButtonGroup.addButton(radioButtonRecentlyAdded); 00021 m_songsButtonGroup.addButton(radioButtonAllSongs); 00022 00023 m_pPrepareLibraryTableView = new WPrepareLibraryTableView(this, pConfig, pTrackCollection, 00024 ConfigKey(), ConfigKey()); 00025 connect(m_pPrepareLibraryTableView, SIGNAL(loadTrack(TrackPointer)), 00026 this, SIGNAL(loadTrack(TrackPointer))); 00027 connect(m_pPrepareLibraryTableView, SIGNAL(loadTrackToPlayer(TrackPointer, QString)), 00028 this, SIGNAL(loadTrackToPlayer(TrackPointer, QString))); 00029 00030 QBoxLayout* box = dynamic_cast<QBoxLayout*>(layout()); 00031 Q_ASSERT(box); //Assumes the form layout is a QVBox/QHBoxLayout! 00032 box->removeWidget(m_pTrackTablePlaceholder); 00033 m_pTrackTablePlaceholder->hide(); 00034 box->insertWidget(1, m_pPrepareLibraryTableView); 00035 00036 m_pPrepareLibraryTableModel = new PrepareLibraryTableModel(this, pTrackCollection); 00037 m_pPrepareLibraryTableView->loadTrackModel(m_pPrepareLibraryTableModel); 00038 00039 /* 00040 m_pCrateView = new CrateView(this, pTrackCollection); 00041 00042 m_pPrepareCratesTableView = new WPrepareCratesTableView(this, pTrackCollection); 00043 box = dynamic_cast<QBoxLayout*>(horizontalLayoutCrates); 00044 Q_ASSERT(box); //Assumes the form layout is a QVBox/QHBoxLayout! 00045 box->removeWidget(m_pCratesViewPlaceholder); 00046 m_pCratesViewPlaceholder->hide(); 00047 //box->insertWidget(1, m_pPrepareCratesTableView); 00048 box->insertWidget(1, m_pCrateView); 00049 m_pCrateView->show(); 00050 00051 m_pCratesTableModel = new QSqlTableModel(this); 00052 m_pCratesTableModel->setTable("crates"); 00053 m_pCratesTableModel->removeColumn(m_pCratesTableModel->fieldIndex("id")); 00054 m_pCratesTableModel->removeColumn(m_pCratesTableModel->fieldIndex("show")); 00055 m_pCratesTableModel->removeColumn(m_pCratesTableModel->fieldIndex("count")); 00056 m_pCratesTableModel->setSort(m_pCratesTableModel->fieldIndex("name"), 00057 Qt::AscendingOrder); 00058 m_pCratesTableModel->setFilter("show = 1"); 00059 m_pCratesTableModel->select(); 00060 TransposeProxyModel* transposeProxy = new TransposeProxyModel(this); 00061 transposeProxy->setSourceModel(m_pCratesTableModel); 00062 m_pPrepareCratesTableView->setModel(m_pCratesTableModel); 00063 */ 00064 00065 connect(radioButtonRecentlyAdded, SIGNAL(clicked()), 00066 this, SLOT(showRecentSongs())); 00067 connect(radioButtonAllSongs, SIGNAL(clicked()), 00068 this, SLOT(showAllSongs())); 00069 00070 radioButtonRecentlyAdded->click(); 00071 00072 labelProgress->setText(""); 00073 pushButtonAnalyze->setEnabled(false); 00074 connect(pushButtonAnalyze, SIGNAL(clicked()), 00075 this, SLOT(analyze())); 00076 00077 connect(pushButtonSelectAll, SIGNAL(clicked()), 00078 this, SLOT(selectAll())); 00079 00080 connect(m_pPrepareLibraryTableView->selectionModel(), 00081 SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection&)), 00082 this, 00083 SLOT(tableSelectionChanged(const QItemSelection &, const QItemSelection&))); 00084 } 00085 00086 DlgPrepare::~DlgPrepare() { 00087 } 00088 00089 void DlgPrepare::onShow() 00090 { 00091 //Refresh crates 00092 //m_pCratesTableModel->select(); 00093 } 00094 00095 void DlgPrepare::setup(QDomNode node) 00096 { 00097 00098 } 00099 00100 void DlgPrepare::onSearchStarting() 00101 { 00102 } 00103 00104 void DlgPrepare::onSearchCleared() 00105 { 00106 } 00107 00108 void DlgPrepare::onSearch(const QString& text) 00109 { 00110 m_pPrepareLibraryTableModel->search(text); 00111 } 00112 00113 void DlgPrepare::loadSelectedTrack() { 00114 m_pPrepareLibraryTableView->loadSelectedTrack(); 00115 } 00116 00117 void DlgPrepare::loadSelectedTrackToGroup(QString group) { 00118 m_pPrepareLibraryTableView->loadSelectedTrackToGroup(group); 00119 } 00120 00121 void DlgPrepare::moveSelection(int delta) { 00122 m_pPrepareLibraryTableView->moveSelection(delta); 00123 } 00124 00125 void DlgPrepare::tableSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) 00126 { 00127 if (selected == QItemSelection()) //Empty selection 00128 pushButtonAnalyze->setEnabled(false); 00129 else 00130 pushButtonAnalyze->setEnabled(true); 00131 } 00132 00133 void DlgPrepare::selectAll() { 00134 m_pPrepareLibraryTableView->selectAll(); 00135 } 00136 00137 void DlgPrepare::analyze() { 00138 //qDebug() << this << "analyze()"; 00139 if (m_bAnalysisActive) { 00140 emit(stopAnalysis()); 00141 } else { 00142 QList<int> trackIds; 00143 00144 QModelIndexList selectedIndexes = m_pPrepareLibraryTableView->selectionModel()->selectedRows(); 00145 foreach(QModelIndex selectedIndex, selectedIndexes) { 00146 bool ok; 00147 int trackId = selectedIndex.sibling( 00148 selectedIndex.row(), 00149 m_pPrepareLibraryTableModel->fieldIndex(LIBRARYTABLE_ID)).data().toInt(&ok); 00150 if (ok) { 00151 trackIds.append(trackId); 00152 } 00153 } 00154 emit(analyzeTracks(trackIds)); 00155 } 00156 } 00157 00158 void DlgPrepare::analysisActive(bool bActive) { 00159 qDebug() << this << "analysisActive" << bActive; 00160 m_bAnalysisActive = bActive; 00161 if (bActive) { 00162 pushButtonAnalyze->setEnabled(true); 00163 pushButtonAnalyze->setText(tr("Stop Analysis")); 00164 } else { 00165 pushButtonAnalyze->setText(tr("Analyze")); 00166 labelProgress->setText(""); 00167 } 00168 } 00169 00170 void DlgPrepare::trackAnalysisFinished(TrackPointer tio) { 00171 qDebug() << "Analysis finished on track:" << tio->getInfo(); 00172 } 00173 00174 void DlgPrepare::trackAnalysisProgress(TrackPointer tio, int progress) { 00175 if (m_bAnalysisActive) { 00176 QString text = tr("Analyzing %1%").arg(progress); 00177 labelProgress->setText(text); 00178 } 00179 } 00180 00181 void DlgPrepare::showRecentSongs() 00182 { 00183 int datetimeColumn = m_pPrepareLibraryTableModel->fieldIndex(LIBRARYTABLE_DATETIMEADDED); 00184 // Don't tell the TableView to sortByColumn() because this generates excess 00185 // select()'s. Use setSort() on the model, and it will take effect when 00186 // showRecentSongs() select()'s. 00187 m_pPrepareLibraryTableModel->setSort(datetimeColumn, Qt::DescendingOrder); 00188 m_pPrepareLibraryTableModel->showRecentSongs(); 00189 } 00190 00191 void DlgPrepare::showAllSongs() 00192 { 00193 m_pPrepareLibraryTableModel->showAllSongs(); 00194 } 00195 00196 void DlgPrepare::installEventFilter(QObject* pFilter) { 00197 QWidget::installEventFilter(pFilter); 00198 m_pPrepareLibraryTableView->installEventFilter(pFilter); 00199 }