diff --git a/src/AllPlotWindow.cpp b/src/AllPlotWindow.cpp index 75f69688e..67b0dd1a5 100644 --- a/src/AllPlotWindow.cpp +++ b/src/AllPlotWindow.cpp @@ -1011,6 +1011,7 @@ AllPlotWindow::setEndSelection(AllPlot* plot, double xValue, bool newInterval, Q QTreeWidgetItem *last = new IntervalItem(ride->ride(), name, duration1, duration2, distance1, distance2, allIntervals->childCount()+1); + last->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); allIntervals->addChild(last); // select this new interval diff --git a/src/BestIntervalDialog.cpp b/src/BestIntervalDialog.cpp index 202b53325..69f8f236a 100644 --- a/src/BestIntervalDialog.cpp +++ b/src/BestIntervalDialog.cpp @@ -326,6 +326,7 @@ BestIntervalDialog::addClicked() ride->timeToDistance(start), ride->timeToDistance(stop), allIntervals->childCount()+1); + last->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); // add allIntervals->addChild(last); } diff --git a/src/IntervalTreeView.cpp b/src/IntervalTreeView.cpp new file mode 100644 index 000000000..664ccc423 --- /dev/null +++ b/src/IntervalTreeView.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012 Damien Grauser (Damien.Grauser@pev-geneve.ch) + * + * 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 + */ + +#include "IntervalTreeView.h" +#include "IntervalItem.h" +#include "MainWindow.h" + + +IntervalTreeView::IntervalTreeView(MainWindow *mainWindow) : mainWindow(mainWindow) +{ + setDragDropMode(QAbstractItemView::InternalMove); + setDragDropOverwriteMode(true); + setDropIndicatorShown(true); + invisibleRootItem()->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); +} + +void +IntervalTreeView::dropEvent(QDropEvent* event) +{ + IntervalItem* item1 = (IntervalItem *)itemAt(event->pos()); + QTreeWidget::dropEvent(event); + IntervalItem* item2 = (IntervalItem *)itemAt(event->pos()); + + if (item1==topLevelItem(0) || item1 != item2) + QTreeWidget::itemChanged(item2, 0); +} diff --git a/src/IntervalTreeView.h b/src/IntervalTreeView.h new file mode 100644 index 000000000..4a411374a --- /dev/null +++ b/src/IntervalTreeView.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012 Damien Grauser (Damien.Grauser@pev-geneve.ch) + * + * 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 + */ + +#ifndef _GC_IntervalTreeView_h +#define _GC_IntervalTreeView_h 1 +#include "GoldenCheetah.h" + +#include + +class MainWindow; + +class IntervalTreeView : public QTreeWidget +{ + Q_OBJECT; + + public: + IntervalTreeView(MainWindow *main); + + protected: + MainWindow *mainWindow; + + void dropEvent(QDropEvent* event); + + + + +}; +#endif // _GC_IntervalTreeView_h diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 001c5a8e7..ce7726cd4 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -33,6 +33,7 @@ #include "ManualRideDialog.h" #include "RideItem.h" #include "IntervalItem.h" +#include "IntervalTreeView.h" #include "IntervalSummaryWindow.h" #ifdef GC_HAVE_ICAL #include "DiaryWindow.h" @@ -381,7 +382,7 @@ MainWindow::MainWindow(const QDir &home) : // INTERVALS intervalSummaryWindow = new IntervalSummaryWindow(this); - intervalWidget = new QTreeWidget(); + intervalWidget = new IntervalTreeView(this); intervalWidget->setColumnCount(1); intervalWidget->setIndentation(5); intervalWidget->setSortingEnabled(false); @@ -394,6 +395,8 @@ MainWindow::MainWindow(const QDir &home) : intervalWidget->setFrameStyle(QFrame::NoFrame); allIntervals = new QTreeWidgetItem(intervalWidget, FOLDER_TYPE); + allIntervals->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); + allIntervals->setText(0, tr("Intervals")); intervalWidget->expandItem(allIntervals); @@ -892,6 +895,7 @@ MainWindow::rideTreeWidgetSelectionChanged() selected->timeToDistance(intervals.at(i).start), selected->timeToDistance(intervals.at(i).stop), allIntervals->childCount()+1); + add->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); allIntervals->addChild(add); } } @@ -1653,6 +1657,7 @@ MainWindow::addIntervalForPowerPeaksForSecs(RideFile *ride, int windowSizeSecs, ride->timeToDistance(i.start), ride->timeToDistance(i.stop), allIntervals->childCount()+1); + peak->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); allIntervals->addChild(peak); } @@ -1779,6 +1784,7 @@ MainWindow::intervalTreeWidgetSelectionChanged() intervalSelected(); } + /*---------------------------------------------------------------------- * Utility *--------------------------------------------------------------------*/ diff --git a/src/MainWindow.h b/src/MainWindow.h index 9ad674171..ba8518213 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -28,6 +28,7 @@ #include #include "RideItem.h" #include "IntervalItem.h" +#include "IntervalTreeView.h" #include "GcWindowRegistry.h" #include "QuarqdClient.h" #include "RealtimeData.h" @@ -358,7 +359,7 @@ class MainWindow : public QMainWindow QSplitter *metaSplitter; QTreeWidget *treeWidget; QSplitter *intervalSplitter; - QTreeWidget *intervalWidget; + IntervalTreeView *intervalWidget; // Miscellany QuarqdClient *client; diff --git a/src/src.pro b/src/src.pro index fe906c324..d114c5a31 100644 --- a/src/src.pro +++ b/src/src.pro @@ -241,6 +241,7 @@ HEADERS += \ HrPwWindow.h \ IntervalItem.h \ IntervalSummaryWindow.h \ + IntervalTreeView.h \ JsonRideFile.h \ LogTimeScaleDraw.h \ LogTimeScaleEngine.h \ @@ -421,6 +422,7 @@ SOURCES += \ HrPwWindow.cpp \ IntervalItem.cpp \ IntervalSummaryWindow.cpp \ + IntervalTreeView.cpp \ LogTimeScaleDraw.cpp \ LogTimeScaleEngine.cpp \ LTMCanvasPicker.cpp \