gui: ctrl click to select multiple elements

This commit is contained in:
Sergiusz Bazanski 2018-07-27 02:14:40 +01:00
parent 83371248fc
commit 1fe1b99a5a
5 changed files with 28 additions and 22 deletions

View File

@ -80,10 +80,10 @@ BaseMainWindow::BaseMainWindow(std::unique_ptr<Context> context, QWidget *parent
centralTabWidget->tabBar()->tabButton(0, QTabBar::RightSide)->resize(0, 0); centralTabWidget->tabBar()->tabButton(0, QTabBar::RightSide)->resize(0, 0);
connect(this, SIGNAL(contextChanged(Context *)), fpgaView, SLOT(newContext(Context *))); connect(this, SIGNAL(contextChanged(Context *)), fpgaView, SLOT(newContext(Context *)));
connect(designview, SIGNAL(selected(std::vector<DecalXY>)), fpgaView, connect(designview, SIGNAL(selected(std::vector<DecalXY>, bool)), fpgaView,
SLOT(onSelectedArchItem(std::vector<DecalXY>))); SLOT(onSelectedArchItem(std::vector<DecalXY>, bool)));
connect(fpgaView, SIGNAL(clickedBel(BelId)), designview, SLOT(onClickedBel(BelId))); connect(fpgaView, SIGNAL(clickedBel(BelId, bool)), designview, SLOT(onClickedBel(BelId, bool)));
connect(fpgaView, SIGNAL(clickedWire(WireId)), designview, SLOT(onClickedWire(WireId))); connect(fpgaView, SIGNAL(clickedWire(WireId, bool)), designview, SLOT(onClickedWire(WireId, bool)));
connect(designview, SIGNAL(highlight(std::vector<DecalXY>, int)), fpgaView, connect(designview, SIGNAL(highlight(std::vector<DecalXY>, int)), fpgaView,
SLOT(onHighlightGroupChanged(std::vector<DecalXY>, int))); SLOT(onHighlightGroupChanged(std::vector<DecalXY>, int)));

View File

@ -507,18 +507,18 @@ QtProperty *DesignWidget::addSubGroup(QtProperty *topItem, const QString &name)
return item; return item;
} }
void DesignWidget::onClickedBel(BelId bel) void DesignWidget::onClickedBel(BelId bel, bool keep)
{ {
QTreeWidgetItem *item = nameToItem[getElementIndex(ElementType::BEL)].value(ctx->getBelName(bel).c_str(ctx)); QTreeWidgetItem *item = nameToItem[getElementIndex(ElementType::BEL)].value(ctx->getBelName(bel).c_str(ctx));
treeWidget->setCurrentItem(item); treeWidget->setCurrentItem(item);
Q_EMIT selected(getDecals(ElementType::BEL, ctx->getBelName(bel))); Q_EMIT selected(getDecals(ElementType::BEL, ctx->getBelName(bel)), keep);
} }
void DesignWidget::onClickedWire(WireId wire) void DesignWidget::onClickedWire(WireId wire, bool keep)
{ {
QTreeWidgetItem *item = nameToItem[getElementIndex(ElementType::WIRE)].value(ctx->getWireName(wire).c_str(ctx)); QTreeWidgetItem *item = nameToItem[getElementIndex(ElementType::WIRE)].value(ctx->getWireName(wire).c_str(ctx));
treeWidget->setCurrentItem(item); treeWidget->setCurrentItem(item);
Q_EMIT selected(getDecals(ElementType::WIRE, ctx->getWireName(wire))); Q_EMIT selected(getDecals(ElementType::WIRE, ctx->getWireName(wire)), keep);
} }
void DesignWidget::onItemSelectionChanged() void DesignWidget::onItemSelectionChanged()
@ -534,7 +534,7 @@ void DesignWidget::onItemSelectionChanged()
std::vector<DecalXY> d = getDecals(type, value); std::vector<DecalXY> d = getDecals(type, value);
std::move(d.begin(), d.end(), std::back_inserter(decals)); std::move(d.begin(), d.end(), std::back_inserter(decals));
} }
Q_EMIT selected(decals); Q_EMIT selected(decals, false);
return; return;
} }
@ -555,7 +555,7 @@ void DesignWidget::onItemSelectionChanged()
clearProperties(); clearProperties();
IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData(); IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
Q_EMIT selected(getDecals(type, c)); Q_EMIT selected(getDecals(type, c), false);
if (type == ElementType::BEL) { if (type == ElementType::BEL) {
BelId bel = ctx->getBelByName(c); BelId bel = ctx->getBelByName(c);
@ -847,7 +847,7 @@ void DesignWidget::prepareMenuProperty(const QPoint &pos)
std::vector<DecalXY> d = getDecals(type, value); std::vector<DecalXY> d = getDecals(type, value);
std::move(d.begin(), d.end(), std::back_inserter(decals)); std::move(d.begin(), d.end(), std::back_inserter(decals));
} }
Q_EMIT selected(decals); Q_EMIT selected(decals, false);
}); });
menu.addAction(selectAction); menu.addAction(selectAction);

View File

@ -64,7 +64,7 @@ class DesignWidget : public QWidget
void updateHighlightGroup(QList<QTreeWidgetItem *> item, int group); void updateHighlightGroup(QList<QTreeWidgetItem *> item, int group);
Q_SIGNALS: Q_SIGNALS:
void info(std::string text); void info(std::string text);
void selected(std::vector<DecalXY> decal); void selected(std::vector<DecalXY> decal, bool keep);
void highlight(std::vector<DecalXY> decal, int group); void highlight(std::vector<DecalXY> decal, int group);
private Q_SLOTS: private Q_SLOTS:
@ -75,8 +75,8 @@ class DesignWidget : public QWidget
public Q_SLOTS: public Q_SLOTS:
void newContext(Context *ctx); void newContext(Context *ctx);
void updateTree(); void updateTree();
void onClickedBel(BelId bel); void onClickedBel(BelId bel, bool keep);
void onClickedWire(WireId wire); void onClickedWire(WireId wire, bool keep);
private: private:
Context *ctx; Context *ctx;

View File

@ -83,7 +83,7 @@ FPGAViewWidget::~FPGAViewWidget() {}
void FPGAViewWidget::newContext(Context *ctx) void FPGAViewWidget::newContext(Context *ctx)
{ {
ctx_ = ctx; ctx_ = ctx;
onSelectedArchItem(std::vector<DecalXY>()); onSelectedArchItem(std::vector<DecalXY>(), false);
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
onHighlightGroupChanged(std::vector<DecalXY>(), i); onHighlightGroupChanged(std::vector<DecalXY>(), i);
{ {
@ -508,11 +508,15 @@ void FPGAViewWidget::renderLines(void)
} }
} }
void FPGAViewWidget::onSelectedArchItem(std::vector<DecalXY> decals) void FPGAViewWidget::onSelectedArchItem(std::vector<DecalXY> decals, bool keep)
{ {
{ {
QMutexLocker locker(&rendererArgsLock_); QMutexLocker locker(&rendererArgsLock_);
rendererArgs_->selectedDecals = decals; if (keep) {
std::copy(decals.begin(), decals.end(), std::back_inserter(rendererArgs_->selectedDecals));
} else {
rendererArgs_->selectedDecals = decals;
}
rendererArgs_->changed = true; rendererArgs_->changed = true;
} }
pokeRenderer(); pokeRenderer();
@ -576,6 +580,8 @@ void FPGAViewWidget::mousePressEvent(QMouseEvent *event)
lastDragPos_ = event->pos(); lastDragPos_ = event->pos();
} }
if (event->buttons() & Qt::LeftButton) { if (event->buttons() & Qt::LeftButton) {
bool ctrl = QApplication::keyboardModifiers().testFlag(Qt::ControlModifier);
auto world = mouseToWorldCoordinates(event->x(), event->y()); auto world = mouseToWorldCoordinates(event->x(), event->y());
auto closestOr = pickElement(world.x(), world.y()); auto closestOr = pickElement(world.x(), world.y());
if (!closestOr) if (!closestOr)
@ -583,9 +589,9 @@ void FPGAViewWidget::mousePressEvent(QMouseEvent *event)
auto closest = closestOr.value(); auto closest = closestOr.value();
if (closest.type == ElementType::BEL) { if (closest.type == ElementType::BEL) {
clickedBel(closest.element.bel); clickedBel(closest.element.bel, ctrl);
} else if (closest.type == ElementType::WIRE) { } else if (closest.type == ElementType::WIRE) {
clickedWire(closest.element.wire); clickedWire(closest.element.wire, ctrl);
} }
} }
} }

View File

@ -110,7 +110,7 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
public Q_SLOTS: public Q_SLOTS:
void newContext(Context *ctx); void newContext(Context *ctx);
void onSelectedArchItem(std::vector<DecalXY> decals); void onSelectedArchItem(std::vector<DecalXY> decals, bool keep);
void onHighlightGroupChanged(std::vector<DecalXY> decals, int group); void onHighlightGroupChanged(std::vector<DecalXY> decals, int group);
void pokeRenderer(void); void pokeRenderer(void);
void zoomIn(); void zoomIn();
@ -119,8 +119,8 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
void zoomOutbound(); void zoomOutbound();
Q_SIGNALS: Q_SIGNALS:
void clickedBel(BelId bel); void clickedBel(BelId bel, bool add);
void clickedWire(WireId wire); void clickedWire(WireId wire, bool add);
private: private:
const float zoomNear_ = 0.1f; // do not zoom closer than this const float zoomNear_ = 0.1f; // do not zoom closer than this