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 <QDrag>
25 #include <QPixmap>
26 #include <QPainter>
27 #include <iostream>
28 #include <qfiledialog.h>
29 #include <qclipboard.h>
30 
31 #include "CollectionsTreeView.h"
32 #include "ObjectExplorerModel.h"
33 
35  QTreeView(parent)
36 {
37 }
38 
39 void gui::CollectionsTreeView::startDrag(Qt::DropActions supportedActions)
40 {
41  QModelIndexList indexes = selectedIndexes();
42  gui::ObjectExplorerModel* objectExplorerModel = dynamic_cast<gui::ObjectExplorerModel*>(model());
43 
44  if (indexes.count() == 1 && objectExplorerModel)
45  {
46  // we only support single selection
47  QPixmap pixmap = objectExplorerModel->getItemPixmap(indexes.at(0));
48 
49  // create drag object
50  QDrag* drag = new QDrag(this);
51  drag->setPixmap(pixmap);
52  drag->setMimeData(objectExplorerModel->mimeData(indexes));
53  drag->setHotSpot(QPoint(pixmap.size().width() / 2, pixmap.size().height() / 2));
54 
55  if (drag->start(supportedActions) == Qt::MoveAction)
56  {
57  std::cerr << "Qt::MoveAction not supported" << std::endl;
58  }
59  }
60  // create the qdrag object like in stock view
61  else
62  {
63  QTreeView::startDrag(supportedActions);
64  }
65 }
gui::CollectionsTreeView::CollectionsTreeView
CollectionsTreeView(QWidget *parent=0)
Constructor.
Definition: CollectionsTreeView.cpp:34
gui::ObjectExplorerModel::getItemPixmap
QPixmap getItemPixmap(const QModelIndex &index) const
Returns the Icon of the class at index.
Definition: ObjectExplorerModel.cpp:109
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:39
gui::ObjectExplorerModel
This class provides a model for storing classes from memoryxcontroller::PriorKnowledgeController and ...
Definition: ObjectExplorerModel.h:44
ObjectExplorerModel.h