mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Rubber band for selection
This commit is contained in:
parent
8dc0682d81
commit
20d1d346bb
@ -853,12 +853,11 @@ void MainWindow::on_toolErase_clicked()
|
||||
ui->tabWidget->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void MainWindow::preparePreview(const QModelIndex &index, bool createNew)
|
||||
void MainWindow::preparePreview(const QModelIndex &index)
|
||||
{
|
||||
scenePreview->clear();
|
||||
|
||||
auto data = objectsModel.itemFromIndex(objectBrowser->mapToSource(index))->data().toJsonObject();
|
||||
|
||||
if(!data.empty())
|
||||
{
|
||||
auto preview = data["preview"];
|
||||
@ -866,29 +865,12 @@ void MainWindow::preparePreview(const QModelIndex &index, bool createNew)
|
||||
{
|
||||
QPixmap objPreview = pixmapFromJson(preview);
|
||||
scenePreview->addPixmap(objPreview);
|
||||
|
||||
auto objId = data["id"].toInt();
|
||||
auto objSubId = data["subid"].toInt();
|
||||
auto templateId = data["template"].toInt();
|
||||
|
||||
if(controller.discardObject(mapLevel) || createNew)
|
||||
{
|
||||
auto factory = VLC->objtypeh->getHandlerFor(objId, objSubId);
|
||||
auto templ = factory->getTemplates()[templateId];
|
||||
controller.createObject(mapLevel, factory->create(templ));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::treeViewSelected(const QModelIndex & index, const QModelIndex & deselected)
|
||||
{
|
||||
preparePreview(index, false);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_treeView_activated(const QModelIndex &index)
|
||||
{
|
||||
ui->toolBrush->setChecked(false);
|
||||
ui->toolBrush2->setChecked(false);
|
||||
@ -896,11 +878,10 @@ void MainWindow::on_treeView_activated(const QModelIndex &index)
|
||||
ui->toolArea->setChecked(false);
|
||||
ui->toolLasso->setChecked(false);
|
||||
ui->mapView->selectionTool = MapView::SelectionTool::None;
|
||||
|
||||
preparePreview(index, true);
|
||||
|
||||
preparePreview(index);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_terrainFilterCombo_currentTextChanged(const QString &arg1)
|
||||
{
|
||||
if(!objectBrowser)
|
||||
|
@ -74,8 +74,6 @@ private slots:
|
||||
|
||||
void on_toolErase_clicked();
|
||||
|
||||
void on_treeView_activated(const QModelIndex &index);
|
||||
|
||||
void on_terrainFilterCombo_currentTextChanged(const QString &arg1);
|
||||
|
||||
void on_filter_textChanged(const QString &arg1);
|
||||
@ -113,7 +111,7 @@ public slots:
|
||||
void displayStatus(const QString& message, int timeout = 2000);
|
||||
|
||||
private:
|
||||
void preparePreview(const QModelIndex &index, bool createNew);
|
||||
void preparePreview(const QModelIndex & index);
|
||||
void addGroupIntoCatalog(const std::string & groupName, bool staticOnly);
|
||||
void addGroupIntoCatalog(const std::string & groupName, bool useCustomName, bool staticOnly, int ID);
|
||||
|
||||
|
@ -65,12 +65,10 @@ MapView::MapView(QWidget * parent):
|
||||
|
||||
void MapView::cameraChanged(const QPointF & pos)
|
||||
{
|
||||
//ui->mapView->translate(pos.x(), pos.y());
|
||||
horizontalScrollBar()->setValue(pos.x());
|
||||
verticalScrollBar()->setValue(pos.y());
|
||||
}
|
||||
|
||||
|
||||
void MapView::setController(MapController * ctrl)
|
||||
{
|
||||
controller = ctrl;
|
||||
@ -86,7 +84,12 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
||||
|
||||
auto pos = mapToScene(mouseEvent->pos()); //TODO: do we need to check size?
|
||||
int3 tile(pos.x() / 32, pos.y() / 32, sc->level);
|
||||
|
||||
|
||||
//if scene will be scrolled without mouse movement, selection, object moving and rubber band will not be updated
|
||||
//to change this behavior, all this logic should be placed in viewportEvent
|
||||
if(rubberBand)
|
||||
rubberBand->setGeometry(QRect(mapFromScene(mouseStart), mouseEvent->pos()).normalized());
|
||||
|
||||
if(tile == tilePrev) //do not redraw
|
||||
return;
|
||||
|
||||
@ -162,7 +165,7 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
||||
|
||||
if(sh.x || sh.y)
|
||||
{
|
||||
if(sc->selectionObjectsView.newObject && (mouseEvent->buttons() & Qt::LeftButton))
|
||||
if(!sc->selectionObjectsView.newObject && (mouseEvent->buttons() & Qt::LeftButton))
|
||||
{
|
||||
if(sc->selectionObjectsView.selectionMode == SelectionObjectsLayer::SELECTION)
|
||||
{
|
||||
@ -291,6 +294,11 @@ void MapView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
sc->selectionObjectsView.clear();
|
||||
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::SELECTION;
|
||||
|
||||
if(!rubberBand)
|
||||
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
|
||||
rubberBand->setGeometry(QRect(mapFromScene(mouseStart), QSize()));
|
||||
rubberBand->show();
|
||||
}
|
||||
}
|
||||
sc->selectionObjectsView.shift = QPoint(0, 0);
|
||||
@ -309,6 +317,9 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
|
||||
auto * sc = static_cast<MapScene*>(scene());
|
||||
if(!sc || !controller->map())
|
||||
return;
|
||||
|
||||
if(rubberBand)
|
||||
rubberBand->hide();
|
||||
|
||||
switch(selectionTool)
|
||||
{
|
||||
@ -319,18 +330,6 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
|
||||
bool tab = false;
|
||||
if(sc->selectionObjectsView.selectionMode == SelectionObjectsLayer::MOVEMENT)
|
||||
{
|
||||
/*if(sc->selectionObjectsView.newObject)
|
||||
{
|
||||
QString errorMsg;
|
||||
if(controller->canPlaceObject(sc->level, sc->selectionObjectsView.newObject, errorMsg))
|
||||
controller->commitObjectCreate(sc->level);
|
||||
else
|
||||
{
|
||||
QMessageBox::information(this, "Can't place object", errorMsg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else*/
|
||||
controller->commitObjectShift(sc->level);
|
||||
}
|
||||
else
|
||||
@ -448,7 +447,6 @@ bool MapView::viewportEvent(QEvent *event)
|
||||
{
|
||||
if(auto * sc = static_cast<MapScene*>(scene()))
|
||||
{
|
||||
//auto rect = sceneRect();
|
||||
auto rect = mapToScene(viewport()->geometry()).boundingRect();
|
||||
controller->miniScene(sc->level)->viewport.setViewport(rect.x() / 32, rect.y() / 32, rect.width() / 32, rect.height() / 32);
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ protected:
|
||||
|
||||
private:
|
||||
MapController * controller = nullptr;
|
||||
QRubberBand * rubberBand = nullptr;
|
||||
QPointF mouseStart;
|
||||
int3 tileStart;
|
||||
int3 tilePrev;
|
||||
|
@ -101,17 +101,17 @@ QMimeData * ObjectBrowserProxyModel::mimeData(const QModelIndexList & indexes) c
|
||||
assert(standardModel);
|
||||
|
||||
QModelIndex index = indexes.front();
|
||||
QMimeData * mimeData = new QMimeData;
|
||||
QByteArray encodedData;
|
||||
|
||||
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
||||
|
||||
if(index.isValid())
|
||||
{
|
||||
auto text = standardModel->itemFromIndex(mapToSource(index))->data().toJsonObject();
|
||||
stream << text;
|
||||
}
|
||||
if(!index.isValid())
|
||||
return nullptr;
|
||||
|
||||
auto text = standardModel->itemFromIndex(mapToSource(index))->data().toJsonObject();
|
||||
stream << text;
|
||||
|
||||
QMimeData * mimeData = new QMimeData;
|
||||
mimeData->setData("application/vcmi.object", encodedData);
|
||||
return mimeData;
|
||||
}
|
||||
@ -119,5 +119,21 @@ QMimeData * ObjectBrowserProxyModel::mimeData(const QModelIndexList & indexes) c
|
||||
ObjectBrowser::ObjectBrowser(QWidget * parent):
|
||||
QTreeView(parent)
|
||||
{
|
||||
|
||||
setDropIndicatorShown(false);
|
||||
}
|
||||
|
||||
void ObjectBrowser::startDrag(Qt::DropActions supportedActions)
|
||||
{
|
||||
QDrag *drag = new QDrag(this);
|
||||
auto indexes = selectedIndexes();
|
||||
if(indexes.isEmpty())
|
||||
return;
|
||||
|
||||
QMimeData * mimeData = model()->mimeData(indexes);
|
||||
if(!mimeData)
|
||||
return;
|
||||
|
||||
drag->setMimeData(mimeData);
|
||||
|
||||
Qt::DropAction dropAction = drag->exec();
|
||||
}
|
||||
|
@ -36,4 +36,7 @@ class ObjectBrowser : public QTreeView
|
||||
{
|
||||
public:
|
||||
ObjectBrowser(QWidget * parent);
|
||||
|
||||
protected:
|
||||
void startDrag(Qt::DropActions supportedActions) override;
|
||||
};
|
||||
|
@ -144,7 +144,6 @@ public:
|
||||
void deselectObject(CGObjectInstance *);
|
||||
bool isSelected(const CGObjectInstance *) const;
|
||||
std::set<CGObjectInstance*> getSelection() const;
|
||||
void moveSelection(int x, int y);
|
||||
void clear();
|
||||
|
||||
QPoint shift;
|
||||
|
Loading…
Reference in New Issue
Block a user