CollectionsTreeView.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::gui-plugins::SceneEditor
19  * @date 2015
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #include "CollectionsTreeView.h"
25 
26 #include <iostream>
27 
28 #include <QDrag>
29 #include <QPainter>
30 #include <QPixmap>
31 #include <qclipboard.h>
32 #include <qfiledialog.h>
33 
34 #include "ObjectExplorerModel.h"
35 
36 gui::CollectionsTreeView::CollectionsTreeView(QWidget* parent) : QTreeView(parent)
37 {
38 }
39 
40 void
41 gui::CollectionsTreeView::startDrag(Qt::DropActions supportedActions)
42 {
43  QModelIndexList indexes = selectedIndexes();
44  gui::ObjectExplorerModel* objectExplorerModel =
45  dynamic_cast<gui::ObjectExplorerModel*>(model());
46 
47  if (indexes.count() == 1 && objectExplorerModel)
48  {
49  // we only support single selection
50  QPixmap pixmap = objectExplorerModel->getItemPixmap(indexes.at(0));
51 
52  // create drag object
53  QDrag* drag = new QDrag(this);
54  drag->setPixmap(pixmap);
55  drag->setMimeData(objectExplorerModel->mimeData(indexes));
56  drag->setHotSpot(QPoint(pixmap.size().width() / 2, pixmap.size().height() / 2));
57 
58  if (drag->start(supportedActions) == Qt::MoveAction)
59  {
60  std::cerr << "Qt::MoveAction not supported" << std::endl;
61  }
62  }
63  // create the qdrag object like in stock view
64  else
65  {
66  QTreeView::startDrag(supportedActions);
67  }
68 }
gui::CollectionsTreeView::CollectionsTreeView
CollectionsTreeView(QWidget *parent=0)
Constructor.
Definition: CollectionsTreeView.cpp:36
gui::ObjectExplorerModel::getItemPixmap
QPixmap getItemPixmap(const QModelIndex &index) const
Returns the Icon of the class at index.
Definition: ObjectExplorerModel.cpp:118
CollectionsTreeView.h
gui::CollectionsTreeView::startDrag
void startDrag(Qt::DropActions supportedActions) override
Starts a drag with a dragable QPixmap using the given supportedActions.
Definition: CollectionsTreeView.cpp:41
gui::ObjectExplorerModel
This class provides a model for storing classes from memoryxcontroller::PriorKnowledgeController and ...
Definition: ObjectExplorerModel.h:44
ObjectExplorerModel.h