-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathObjectBrowser.cpp
48 lines (40 loc) · 1.68 KB
/
ObjectBrowser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// MapMaker (c) 2016 Andrey Fidrya. MIT license. See LICENSE for more information.
#include <QListView>
#include <QVBoxLayout>
#include "ObjectBrowser.h"
#include "Models/LevelObjectsModel.h"
#include "Utils/WidgetUtils.h"
#include "Utils/Utils.h"
ObjectBrowser::ObjectBrowser(QWidget *parent) : QWidget(parent)
{
//WidgetUtils::setBackgroundColor(this, Qt::blue);
listView_ = new QListView;
listView_->setModel(LevelObjectsModel::sharedInstance());
listView_->setSpacing(5);
listView_->setViewMode(QListView::IconMode);
listView_->setAlternatingRowColors(false);
listView_->setSelectionMode(QAbstractItemView::SingleSelection);
listView_->setMovement(QListView::Static);
listView_->setResizeMode(QListView::Adjust);
listView_->setUniformItemSizes(false);
listView_->setDragDropMode(QAbstractItemView::DragOnly);
listView_->setDragEnabled(true);
connect(listView_, SIGNAL(pressed(QModelIndex)),
this, SLOT(onPressed(QModelIndex)));
QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(listView_);
setLayout(layout);
}
void ObjectBrowser::onPressed(const QModelIndex &index)
{
Q_UNUSED(index);
QRect visualRect = listView_->visualRect(index);
QPoint pos = listView_->viewport()->mapFromGlobal(QCursor::pos());
//QPoint pos = listView_->viewport()->mapFromGlobal(listView_->cursor().pos());
//qerr << "viewport.mar=" << listView_->viewportMargins().top() << endl;
// Compensate 3 pixel offset ListView bug.
// See LevelObjectsModel.cpp, SizeHintRole:
pos.setY(pos.y() - 3);
LevelObjectsModel::sharedInstance()->setDragOffset(pos - visualRect.topLeft());
}