| 1 | /* |
| 2 | * Copyright 2014 Mihai Niculescu <[email protected]> |
| 3 | * |
| 4 | * This file is part of EqualX Project (https://launchpad.net/equalx/) |
| 5 | * |
| 6 | * EqualX is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * EqualX is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include <QDebug> |
| 21 | #include <QDragEnterEvent> |
| 22 | |
| 23 | #include "BookmarkItem.h" |
| 24 | #include "BookmarksPanel/BookmarksItemModel.h" |
| 25 | #include "BookmarksPanel/BookmarksView.h" |
| 26 | |
| 27 | BookmarksView::BookmarksView(QWidget *parent) : |
| 28 | QTreeView(parent), |
| 29 | mModel(0) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | void BookmarksView::setModel(BookmarksItemModel *model) |
| 34 | { |
| 35 | mModel=model; |
| 36 | QTreeView::setModel(model); |
| 37 | |
| 38 | } |
| 39 | |
| 40 | void BookmarksView::contextMenuEvent(QContextMenuEvent *ev) |
| 41 | { |
| 42 | qDebug() << "contextMenuEvent();"; |
| 43 | |
| 44 | QTreeView::contextMenuEvent(ev); |
| 45 | } |
| 46 | |
| 47 | BookmarkItem *BookmarksView::currentItem() |
| 48 | { |
| 49 | QModelIndex curIdx = currentIndex(); |
| 50 | |
| 51 | return mModel->itemFromIndex(curIdx); |
| 52 | } |
| 53 | /* |
| 54 | void BookmarksView::dragEnterEvent(QDragEnterEvent *event) |
| 55 | { |
| 56 | if (event->mimeData()->hasFormat("application/x-equalx-library-modeldata")) |
| 57 | event->accept(); |
| 58 | else |
| 59 | event->ignore(); |
| 60 | } |
| 61 | |
| 62 | void BookmarksView::dragMoveEvent(QDragMoveEvent *event) |
| 63 | { |
| 64 | if (event->mimeData()->hasFormat("application/x-equalx-library-modeldata")) { |
| 65 | event->setDropAction(Qt::MoveAction); |
| 66 | event->accept(); |
| 67 | } else |
| 68 | event->ignore(); |
| 69 | } |
| 70 | |
| 71 | void BookmarksView::dropEvent(QDropEvent *event) |
| 72 | { |
| 73 | if (event->mimeData()->hasFormat("application/x-equalx-library-modeldata")) { |
| 74 | QByteArray rowData = event->mimeData()->data("application/x-equalx-library-modeldata"); |
| 75 | QDataStream dataStream(&rowData, QIODevice::ReadOnly); |
| 76 | LibraryModelData rowModelData; |
| 77 | dataStream >> rowModelData; |
| 78 | |
| 79 | addPiece(rowModelData); |
| 80 | |
| 81 | event->setDropAction(Qt::MoveAction); |
| 82 | event->accept(); |
| 83 | } else |
| 84 | event->ignore(); |
| 85 | } |
| 86 | |
| 87 | void BookmarksView::addPiece(const LibraryModelData &rowData) |
| 88 | { |
| 89 | BookmarkItem *item = new BookmarkItem(rowData); |
| 90 | } |
| 91 | |
| 92 | void BookmarksView::startDrag(Qt::DropActions supportedActions) |
| 93 | { |
| 94 | BookmarkItem *item = currentItem(); |
| 95 | |
| 96 | QByteArray itemData; |
| 97 | QDataStream dataStream(&itemData, QIODevice::WriteOnly); |
| 98 | |
| 99 | dataStream << item->data(); |
| 100 | |
| 101 | QMimeData *mimeData = new QMimeData; |
| 102 | mimeData->setData("application/x-equalx-library-modeldata", itemData); |
| 103 | |
| 104 | QDrag *drag = new QDrag(this); |
| 105 | drag->setMimeData(mimeData); |
| 106 | //drag->setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2)); |
| 107 | //drag->setPixmap(pixmap); |
| 108 | |
| 109 | drag->exec(Qt::MoveAction); |
| 110 | // if (drag->exec(Qt::MoveAction) == Qt::MoveAction) delete takeItem(row(item)); |
| 111 | } |
| 112 | */ |