diff --git a/src/ComparePane.cpp b/src/ComparePane.cpp index a3e31cd57..634b22bf2 100644 --- a/src/ComparePane.cpp +++ b/src/ComparePane.cpp @@ -17,6 +17,8 @@ */ #include "ComparePane.h" +#include "Context.h" +#include "Athlete.h" ComparePane::ComparePane(QWidget *parent, CompareMode mode) : mode_(mode), QWidget(parent) { @@ -34,8 +36,8 @@ ComparePane::ComparePane(QWidget *parent, CompareMode mode) : mode_(mode), QWidg void ComparePane::dragEnterEvent(QDragEnterEvent *event) { - if (event->mimeData()->formats().contains("application/x-gc-intervals") || - event->mimeData()->formats().contains("application/x-gc-seasons")) { + if ((mode_ == interval && event->mimeData()->formats().contains("application/x-gc-intervals")) || + (mode_ == season && event->mimeData()->formats().contains("application/x-gc-seasons"))) { event->acceptProposedAction(); } } @@ -57,4 +59,19 @@ ComparePane::dropEvent(QDropEvent *event) event->accept(); // here we can unpack and add etc... + // lets get the context! + QString fmt = (mode_ == interval) ? "application/x-gc-intervals" : "application/x-gc-seasons"; + + // get the context out + QByteArray rawData = event->encodedData(fmt.toLatin1()); + QDataStream stream(&rawData, QIODevice::ReadOnly); + stream.setVersion(QDataStream::Qt_4_6); + + // pack data + quint64 from; + stream >> from; // where did this come from? + + // lets look at the context.. + Context *c = (Context*)(from); + qDebug()<athlete->cyclist<<"compare pane: dropped:"<mimeData()->formats(); } diff --git a/src/DragBar.cpp b/src/DragBar.cpp new file mode 100644 index 000000000..061edca7f --- /dev/null +++ b/src/DragBar.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2014 Mark Liversedge (liversedge@gmail.com) + * + * 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 "DragBar.h" +#include + +DragBar::DragBar(QWidget*parent) : QTabBar(parent) +{ + setAcceptDrops(true); +} + +void +DragBar::dragEnterEvent(QDragEnterEvent*event) +{ + if (tabAt(event->pos()) != -1 && tabAt(event->pos()) != currentIndex()) { + setCurrentIndex(tabAt(event->pos())); + } +} + +void +DragBar::dragLeaveEvent(QDragLeaveEvent*) {} + +void +DragBar::dragMoveEvent(QDragMoveEvent *event) // we don't get these without accepting dragevent +{ // and that would be a bad idea + if (tabAt(event->pos()) != -1 && tabAt(event->pos()) != currentIndex()) { + setCurrentIndex(tabAt(event->pos())); + } +} + +void +DragBar::dropEvent(QDropEvent *) {} diff --git a/src/DragBar.h b/src/DragBar.h new file mode 100644 index 000000000..94f3a48ee --- /dev/null +++ b/src/DragBar.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2014 Mark Liversedge (liversedge@gmail.com) + * + * 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_DragBar_h +#define _GC_DragBar_h + +#include +#include +#include +#include +#include + +class DragBar : public QTabBar +{ + Q_OBJECT; + + public: + DragBar(QWidget*parent); + + void dragEnterEvent(QDragEnterEvent*); + void dragLeaveEvent(QDragLeaveEvent*); + void dragMoveEvent(QDragMoveEvent*); + void dropEvent(QDropEvent *); + + signals: + void dragTab(int index); // let them know we dragged onto a tab +}; + +#endif diff --git a/src/IntervalTreeView.cpp b/src/IntervalTreeView.cpp index d69f2ce88..69e3ec791 100644 --- a/src/IntervalTreeView.cpp +++ b/src/IntervalTreeView.cpp @@ -65,6 +65,7 @@ IntervalTreeView::mimeData (const QList items) const stream.setVersion(QDataStream::Qt_4_6); // pack data + stream << (quint64)(context); // where did this come from? stream << items.count(); foreach (QTreeWidgetItem *p, items) { @@ -73,7 +74,7 @@ IntervalTreeView::mimeData (const QList items) const // serialize stream << p->text(0); // name - stream << static_cast(i->ride); + stream << (quint64)(i->ride); stream << i->start << i->stop; // start and stop in secs stream << i->startKM << i->stopKM; // start and stop km stream << i->displaySequence; diff --git a/src/LTMSidebar.cpp b/src/LTMSidebar.cpp index c6ca05301..03bf583e4 100644 --- a/src/LTMSidebar.cpp +++ b/src/LTMSidebar.cpp @@ -62,7 +62,7 @@ LTMSidebar::LTMSidebar(Context *context) : QWidget(context->mainWindow), context seasonsWidget->addAction(moreSeasonAct); connect(moreSeasonAct, SIGNAL(triggered(void)), this, SLOT(dateRangePopup(void))); - dateRangeTree = new SeasonTreeView; + dateRangeTree = new SeasonTreeView(context); // context needed for drag/drop across contexts allDateRanges=dateRangeTree->invisibleRootItem(); // Drop for Seasons allDateRanges->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a09155edd..844b517d4 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -457,7 +457,7 @@ MainWindow::MainWindow(const QDir &home) * Central Widget *--------------------------------------------------------------------*/ - tabbar = new QTabBar(this); + tabbar = new DragBar(this); tabbar->setAutoFillBackground(true); tabbar->setShape(QTabBar::RoundedSouth); tabbar->setDrawBase(false); @@ -478,6 +478,7 @@ MainWindow::MainWindow(const QDir &home) tabStack->addWidget(currentTab); tabStack->setCurrentIndex(0); + connect(tabbar, SIGNAL(dragTab(int)), this, SLOT(switchTab(int))); connect(tabbar, SIGNAL(currentChanged(int)), this, SLOT(switchTab(int))); connect(tabbar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTabClicked(int))); @@ -1068,8 +1069,10 @@ MainWindow::dragEnterEvent(QDragEnterEvent *event) if (url.toString().startsWith("http")) accept = false; - if (accept) event->acceptProposedAction(); // whatever you wanna drop we will try and process! - else event->ignore(); + if (accept) { + event->acceptProposedAction(); // whatever you wanna drop we will try and process! + raise(); + } else event->ignore(); } void diff --git a/src/MainWindow.h b/src/MainWindow.h index aec032145..f70772f35 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -28,6 +28,7 @@ #include #include "RideItem.h" #include "TimeUtils.h" +#include "DragBar.h" #ifdef Q_OS_MAC // What versions are supported by this SDK? @@ -216,8 +217,8 @@ class MainWindow : public QMainWindow QIcon importIcon, composeIcon, intervalIcon, splitIcon, deleteIcon, sidebarIcon, lowbarIcon, tabbedIcon, tiledIcon; #endif - // tab bar - QTabBar *tabbar; + // tab bar (that supports swtitching on drag and drop) + DragBar *tabbar; QStackedWidget *tabStack; // window and tab menu diff --git a/src/Season.cpp b/src/Season.cpp index 7d7e607fb..413f33b42 100644 --- a/src/Season.cpp +++ b/src/Season.cpp @@ -388,7 +388,7 @@ Seasons::writeSeasons() seasonsChanged(); // signal! } -SeasonTreeView::SeasonTreeView() +SeasonTreeView::SeasonTreeView(Context *context) : context(context) { setDragDropMode(QAbstractItemView::InternalMove); setDragDropOverwriteMode(true); @@ -433,6 +433,7 @@ SeasonTreeView::mimeData (const QList items) const stream.setVersion(QDataStream::Qt_4_6); // pack data + stream << (quint64)(context); // where did this come from? stream << items.count(); foreach (QTreeWidgetItem *p, items) { diff --git a/src/Season.h b/src/Season.h index 3f2b24aa8..2e06da399 100644 --- a/src/Season.h +++ b/src/Season.h @@ -159,7 +159,7 @@ class SeasonTreeView : public QTreeWidget Q_OBJECT public: - SeasonTreeView(); + SeasonTreeView(Context *); // for drag/drop QStringList mimeTypes () const; @@ -170,6 +170,7 @@ class SeasonTreeView : public QTreeWidget protected: void dropEvent(QDropEvent* event); + Context *context; }; diff --git a/src/src.pro b/src/src.pro index 32dd44e42..bd75807c8 100644 --- a/src/src.pro +++ b/src/src.pro @@ -293,6 +293,7 @@ HEADERS += \ DeviceConfiguration.h \ DialWindow.h \ DiarySidebar.h \ + DragBar.h \ DownloadRideDialog.h \ ErgFile.h \ ErgDB.h \ @@ -483,6 +484,7 @@ SOURCES += \ DialWindow.cpp \ DiarySidebar.cpp \ DownloadRideDialog.cpp \ + DragBar.cpp \ ErgDB.cpp \ ErgDBDownloadDialog.cpp \ ErgFile.cpp \