Add selection highlight to connections list
This commit is contained in:
parent
0aa7ddf27d
commit
7c6b33da1b
10 changed files with 92 additions and 42 deletions
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>176</width>
|
<width>178</width>
|
||||||
<height>153</height>
|
<height>157</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -16,6 +16,9 @@
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_Map">
|
<widget class="QLabel" name="label_Map">
|
||||||
|
|
|
@ -260,7 +260,7 @@
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>2</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="movable" stdset="0">
|
<property name="movable" stdset="0">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
@ -769,8 +769,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>256</width>
|
<width>423</width>
|
||||||
<height>74</height>
|
<height>79</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_12">
|
<layout class="QHBoxLayout" name="horizontalLayout_12">
|
||||||
|
@ -888,8 +888,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>256</width>
|
<width>423</width>
|
||||||
<height>74</height>
|
<height>79</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||||
|
@ -990,10 +990,10 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>8</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>91</width>
|
<width>411</width>
|
||||||
<height>74</height>
|
<height>446</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -1193,8 +1193,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>91</width>
|
<width>427</width>
|
||||||
<height>512</height>
|
<height>594</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_7">
|
<layout class="QGridLayout" name="gridLayout_7">
|
||||||
|
@ -1413,8 +1413,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>93</width>
|
<width>382</width>
|
||||||
<height>460</height>
|
<height>699</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_14">
|
<layout class="QVBoxLayout" name="verticalLayout_14">
|
||||||
|
|
|
@ -119,7 +119,6 @@ public:
|
||||||
bool readMapGroups();
|
bool readMapGroups();
|
||||||
Map* addNewMapToGroup(QString, int, Map*, bool, bool);
|
Map* addNewMapToGroup(QString, int, Map*, bool, bool);
|
||||||
QString getNewMapName();
|
QString getNewMapName();
|
||||||
bool isExistingMapName(const QString&);
|
|
||||||
QString getProjectTitle();
|
QString getProjectTitle();
|
||||||
|
|
||||||
QString readMapLayoutId(QString map_name);
|
QString readMapLayoutId(QString map_name);
|
||||||
|
|
|
@ -33,6 +33,9 @@ public:
|
||||||
bool getEditable();
|
bool getEditable();
|
||||||
void updateHighlight(bool selected);
|
void updateHighlight(bool selected);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool highlighted = false;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
@ -42,6 +45,7 @@ signals:
|
||||||
void connectionItemSelected(ConnectionPixmapItem* connectionItem);
|
void connectionItemSelected(ConnectionPixmapItem* connectionItem);
|
||||||
void connectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
|
void connectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
|
||||||
void connectionMoved(MapConnection*);
|
void connectionMoved(MapConnection*);
|
||||||
|
void highlightChanged(bool highlighted);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONNECTIONPIXMAPITEM_H
|
#endif // CONNECTIONPIXMAPITEM_H
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "mapconnection.h"
|
#include "mapconnection.h"
|
||||||
|
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ConnectionsListItem;
|
class ConnectionsListItem;
|
||||||
|
@ -22,14 +23,20 @@ public:
|
||||||
~ConnectionsListItem();
|
~ConnectionsListItem();
|
||||||
|
|
||||||
void updateUI();
|
void updateUI();
|
||||||
|
void setSelected(bool selected);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ConnectionsListItem *ui;
|
Ui::ConnectionsListItem *ui;
|
||||||
MapConnection * const connection;
|
MapConnection * const connection;
|
||||||
|
bool isSelected = false;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void edited();
|
void edited();
|
||||||
void deleted();
|
void deleted();
|
||||||
|
void selected();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_comboBox_Direction_currentTextChanged(const QString &direction);
|
void on_comboBox_Direction_currentTextChanged(const QString &direction);
|
||||||
|
|
|
@ -755,15 +755,29 @@ void Editor::addConnectionToList(ConnectionPixmapItem * connectionItem) {
|
||||||
ConnectionsListItem *listItem = new ConnectionsListItem(ui->scrollAreaContents_ConnectionsList, connectionItem->connection, project->mapNames);
|
ConnectionsListItem *listItem = new ConnectionsListItem(ui->scrollAreaContents_ConnectionsList, connectionItem->connection, project->mapNames);
|
||||||
ui->layout_ConnectionsList->insertWidget(ui->layout_ConnectionsList->count() - 1, listItem); // Insert above the vertical spacer
|
ui->layout_ConnectionsList->insertWidget(ui->layout_ConnectionsList->count() - 1, listItem); // Insert above the vertical spacer
|
||||||
|
|
||||||
|
// Connect the pixmap item to the list item
|
||||||
connect(connectionItem, &ConnectionPixmapItem::connectionMoved, listItem, &ConnectionsListItem::updateUI);
|
connect(connectionItem, &ConnectionPixmapItem::connectionMoved, listItem, &ConnectionsListItem::updateUI);
|
||||||
|
connect(connectionItem, &ConnectionPixmapItem::highlightChanged, listItem, &ConnectionsListItem::setSelected);
|
||||||
|
if (connectionItem == selected_connection_item)
|
||||||
|
listItem->setSelected(true);
|
||||||
|
|
||||||
// TODO: This is probably slower than necessary (we don't need a full redraw if we're just moving it)
|
// Connect the list item to the pixmap item
|
||||||
// TODO: Handle mirroring
|
connect(listItem, &ConnectionsListItem::selected, [this, connectionItem] {
|
||||||
|
if (connectionItem == selected_connection_item) {
|
||||||
|
// Already selected, no change
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Deselect old connection and select new connection
|
||||||
|
if (selected_connection_item) selected_connection_item->updateHighlight(false);
|
||||||
|
selected_connection_item = connectionItem;
|
||||||
|
selected_connection_item->updateHighlight(true);
|
||||||
|
});
|
||||||
connect(listItem, &ConnectionsListItem::edited, [this, connectionItem] {
|
connect(listItem, &ConnectionsListItem::edited, [this, connectionItem] {
|
||||||
|
// TODO: This is probably slower than necessary (we don't need a full redraw if we're just moving it)
|
||||||
|
// TODO: Handle mirroring
|
||||||
redrawConnection(connectionItem);
|
redrawConnection(connectionItem);
|
||||||
emit editedMapData();
|
emit editedMapData();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(listItem, &ConnectionsListItem::deleted, [this, connectionItem] {
|
connect(listItem, &ConnectionsListItem::deleted, [this, connectionItem] {
|
||||||
removeConnection(connectionItem);
|
removeConnection(connectionItem);
|
||||||
});
|
});
|
||||||
|
@ -834,16 +848,11 @@ void Editor::redrawConnection(ConnectionPixmapItem* connectionItem) {
|
||||||
connectionItem->basePixmap = pixmap;
|
connectionItem->basePixmap = pixmap;
|
||||||
QPoint pos = calculateConnectionPosition(connectionItem->connection, pixmap);
|
QPoint pos = calculateConnectionPosition(connectionItem->connection, pixmap);
|
||||||
|
|
||||||
if (connectionItem == selected_connection_item) {
|
connectionItem->blockSignals(true);
|
||||||
QPainter painter(&pixmap);
|
|
||||||
painter.setPen(QColor(255, 0, 255));
|
|
||||||
painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
|
||||||
painter.end();
|
|
||||||
}
|
|
||||||
connectionItem->setPixmap(pixmap);
|
connectionItem->setPixmap(pixmap);
|
||||||
|
connectionItem->updateHighlight(connectionItem == selected_connection_item);
|
||||||
connectionItem->initialX = pos.x();
|
connectionItem->initialX = pos.x();
|
||||||
connectionItem->initialY = pos.y();
|
connectionItem->initialY = pos.y();
|
||||||
connectionItem->blockSignals(true);
|
|
||||||
connectionItem->setX(pos.x());
|
connectionItem->setX(pos.x());
|
||||||
connectionItem->setY(pos.y());
|
connectionItem->setY(pos.y());
|
||||||
connectionItem->setZValue(-1);
|
connectionItem->setZValue(-1);
|
||||||
|
@ -888,8 +897,6 @@ void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
|
||||||
selected_connection_item = connectionItem;
|
selected_connection_item = connectionItem;
|
||||||
for (ConnectionPixmapItem* item : connection_items)
|
for (ConnectionPixmapItem* item : connection_items)
|
||||||
item->updateHighlight(item == selected_connection_item);
|
item->updateHighlight(item == selected_connection_item);
|
||||||
|
|
||||||
// TODO: Handle the highlight done in redrawConnection?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Inaccurate if there are multiple connections from the same map
|
// TODO: Inaccurate if there are multiple connections from the same map
|
||||||
|
@ -1851,7 +1858,7 @@ void Editor::toggleBorderVisibility(bool visible, bool enableScriptCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::updateBorderVisibility() {
|
void Editor::updateBorderVisibility() {
|
||||||
// On the connections tab, the border is always visible, and the connections can be edited.
|
// On the connections tab the border is always visible, and the connections can be edited.
|
||||||
bool editingConnections = (ui->mainTabBar->currentIndex() == MainTab::Connections);
|
bool editingConnections = (ui->mainTabBar->currentIndex() == MainTab::Connections);
|
||||||
bool visible = (editingConnections || ui->checkBox_ToggleBorder->isChecked());
|
bool visible = (editingConnections || ui->checkBox_ToggleBorder->isChecked());
|
||||||
|
|
||||||
|
|
|
@ -2569,26 +2569,27 @@ void MainWindow::on_pushButton_ConfigureEncountersJSON_clicked() {
|
||||||
|
|
||||||
void MainWindow::on_button_OpenDiveMap_clicked() {
|
void MainWindow::on_button_OpenDiveMap_clicked() {
|
||||||
const QString mapName = ui->comboBox_DiveMap->currentText();
|
const QString mapName = ui->comboBox_DiveMap->currentText();
|
||||||
if (editor->project->isExistingMapName(mapName))
|
if (mapName != DYNAMIC_MAP_NAME && editor->project->mapNames.contains(mapName))
|
||||||
userSetMap(mapName, true);
|
userSetMap(mapName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_button_OpenEmergeMap_clicked() {
|
void MainWindow::on_button_OpenEmergeMap_clicked() {
|
||||||
const QString mapName = ui->comboBox_EmergeMap->currentText();
|
const QString mapName = ui->comboBox_EmergeMap->currentText();
|
||||||
if (editor->project->isExistingMapName(mapName))
|
if (mapName != DYNAMIC_MAP_NAME && editor->project->mapNames.contains(mapName))
|
||||||
userSetMap(mapName, true);
|
userSetMap(mapName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Mirror change to/from other maps
|
// TODO: Mirror change to/from other maps
|
||||||
void MainWindow::on_comboBox_DiveMap_currentTextChanged(const QString &mapName) {
|
void MainWindow::on_comboBox_DiveMap_currentTextChanged(const QString &mapName) {
|
||||||
if (editor->project->isExistingMapName(mapName)) {
|
// Include empty names as an update (user is deleting the connection)
|
||||||
|
if (mapName.isEmpty() || editor->project->mapNames.contains(mapName)) {
|
||||||
editor->updateDiveMap(mapName);
|
editor->updateDiveMap(mapName);
|
||||||
markMapEdited();
|
markMapEdited();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_comboBox_EmergeMap_currentTextChanged(const QString &mapName) {
|
void MainWindow::on_comboBox_EmergeMap_currentTextChanged(const QString &mapName) {
|
||||||
if (editor->project->isExistingMapName(mapName)) {
|
if (mapName.isEmpty() || editor->project->mapNames.contains(mapName)) {
|
||||||
editor->updateEmergeMap(mapName);
|
editor->updateEmergeMap(mapName);
|
||||||
markMapEdited();
|
markMapEdited();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1800,10 +1800,6 @@ QString Project::getNewMapName() {
|
||||||
return newMapName;
|
return newMapName;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Project::isExistingMapName(const QString &mapName) {
|
|
||||||
return !mapName.isEmpty() && mapName != DYNAMIC_MAP_NAME && this->mapNames.contains(mapName);
|
|
||||||
}
|
|
||||||
|
|
||||||
Project::DataQualifiers Project::getDataQualifiers(QString text, QString label) {
|
Project::DataQualifiers Project::getDataQualifiers(QString text, QString label) {
|
||||||
Project::DataQualifiers qualifiers;
|
Project::DataQualifiers qualifiers;
|
||||||
|
|
||||||
|
|
|
@ -56,13 +56,23 @@ bool ConnectionPixmapItem::getEditable() {
|
||||||
return (this->flags() & ItemIsMovable) != 0;
|
return (this->flags() & ItemIsMovable) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Consider whether it still makes sense to highlight the "current" connection (given you can edit them at any point now)
|
||||||
void ConnectionPixmapItem::updateHighlight(bool selected) {
|
void ConnectionPixmapItem::updateHighlight(bool selected) {
|
||||||
bool editable = this->getEditable();
|
const int normalZ = -1;
|
||||||
int zValue = (selected || !editable) ? -1 : -2;
|
const qreal normalOpacity = 1.0;
|
||||||
qreal opacity = (selected || !editable) ? 1 : 0.75;
|
|
||||||
this->setZValue(zValue);
|
// When editing is inactive the current selection is ignored, all connections should appear normal.
|
||||||
this->render(opacity);
|
if (!this->getEditable()) {
|
||||||
if (editable && selected) {
|
this->setZValue(normalZ);
|
||||||
|
this->render(normalOpacity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->setZValue(selected ? normalZ : -2);
|
||||||
|
this->render(selected ? normalOpacity : 0.75);
|
||||||
|
|
||||||
|
if (selected) {
|
||||||
|
// Draw highlight
|
||||||
QPixmap pixmap = this->pixmap();
|
QPixmap pixmap = this->pixmap();
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
painter.setPen(QColor(255, 0, 255));
|
painter.setPen(QColor(255, 0, 255));
|
||||||
|
@ -70,6 +80,11 @@ void ConnectionPixmapItem::updateHighlight(bool selected) {
|
||||||
painter.end();
|
painter.end();
|
||||||
this->setPixmap(pixmap);
|
this->setPixmap(pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Let the list UI know if the selection highlight changes so it can update accordingly
|
||||||
|
if (this->highlighted != selected)
|
||||||
|
emit highlightChanged(selected);
|
||||||
|
this->highlighted = selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *) {
|
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *) {
|
||||||
|
|
|
@ -42,9 +42,25 @@ void ConnectionsListItem::updateUI() {
|
||||||
ui->spinBox_Offset->setValue(this->connection->offset);
|
ui->spinBox_Offset->setValue(this->connection->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Frame shifts slightly when style changes
|
||||||
|
void ConnectionsListItem::setSelected(bool selected) {
|
||||||
|
if (selected == this->isSelected)
|
||||||
|
return;
|
||||||
|
this->isSelected = selected;
|
||||||
|
|
||||||
|
this->setStyleSheet(selected ? ".ConnectionsListItem { border: 1px solid rgb(255, 0, 255); }" : "");
|
||||||
|
if (selected)
|
||||||
|
emit this->selected();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectionsListItem::mousePressEvent(QMouseEvent *) {
|
||||||
|
this->setSelected(true);
|
||||||
|
}
|
||||||
|
|
||||||
void ConnectionsListItem::on_comboBox_Direction_currentTextChanged(const QString &direction)
|
void ConnectionsListItem::on_comboBox_Direction_currentTextChanged(const QString &direction)
|
||||||
{
|
{
|
||||||
this->connection->direction = direction;
|
this->connection->direction = direction;
|
||||||
|
this->setSelected(true);
|
||||||
emit this->edited();
|
emit this->edited();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +68,7 @@ void ConnectionsListItem::on_comboBox_Map_currentTextChanged(const QString &mapN
|
||||||
{
|
{
|
||||||
if (ui->comboBox_Map->findText(mapName) >= 0) {
|
if (ui->comboBox_Map->findText(mapName) >= 0) {
|
||||||
this->connection->map_name = mapName;
|
this->connection->map_name = mapName;
|
||||||
|
this->setSelected(true);
|
||||||
emit this->edited();
|
emit this->edited();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,6 +76,7 @@ void ConnectionsListItem::on_comboBox_Map_currentTextChanged(const QString &mapN
|
||||||
void ConnectionsListItem::on_spinBox_Offset_valueChanged(int offset)
|
void ConnectionsListItem::on_spinBox_Offset_valueChanged(int offset)
|
||||||
{
|
{
|
||||||
this->connection->offset = offset;
|
this->connection->offset = offset;
|
||||||
|
this->setSelected(true);
|
||||||
emit this->edited();
|
emit this->edited();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue