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>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>176</width>
|
||||
<height>153</height>
|
||||
<width>178</width>
|
||||
<height>157</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -16,6 +16,9 @@
|
|||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_Map">
|
||||
|
|
|
@ -260,7 +260,7 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="movable" stdset="0">
|
||||
<bool>false</bool>
|
||||
|
@ -769,8 +769,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>256</width>
|
||||
<height>74</height>
|
||||
<width>423</width>
|
||||
<height>79</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_12">
|
||||
|
@ -888,8 +888,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>256</width>
|
||||
<height>74</height>
|
||||
<width>423</width>
|
||||
<height>79</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
|
@ -990,10 +990,10 @@
|
|||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<x>8</x>
|
||||
<y>0</y>
|
||||
<width>91</width>
|
||||
<height>74</height>
|
||||
<width>411</width>
|
||||
<height>446</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -1193,8 +1193,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>91</width>
|
||||
<height>512</height>
|
||||
<width>427</width>
|
||||
<height>594</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_7">
|
||||
|
@ -1413,8 +1413,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>93</width>
|
||||
<height>460</height>
|
||||
<width>382</width>
|
||||
<height>699</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_14">
|
||||
|
|
|
@ -119,7 +119,6 @@ public:
|
|||
bool readMapGroups();
|
||||
Map* addNewMapToGroup(QString, int, Map*, bool, bool);
|
||||
QString getNewMapName();
|
||||
bool isExistingMapName(const QString&);
|
||||
QString getProjectTitle();
|
||||
|
||||
QString readMapLayoutId(QString map_name);
|
||||
|
|
|
@ -33,6 +33,9 @@ public:
|
|||
bool getEditable();
|
||||
void updateHighlight(bool selected);
|
||||
|
||||
private:
|
||||
bool highlighted = false;
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
|
@ -42,6 +45,7 @@ signals:
|
|||
void connectionItemSelected(ConnectionPixmapItem* connectionItem);
|
||||
void connectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
|
||||
void connectionMoved(MapConnection*);
|
||||
void highlightChanged(bool highlighted);
|
||||
};
|
||||
|
||||
#endif // CONNECTIONPIXMAPITEM_H
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "mapconnection.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QMouseEvent>
|
||||
|
||||
namespace Ui {
|
||||
class ConnectionsListItem;
|
||||
|
@ -22,14 +23,20 @@ public:
|
|||
~ConnectionsListItem();
|
||||
|
||||
void updateUI();
|
||||
void setSelected(bool selected);
|
||||
|
||||
private:
|
||||
Ui::ConnectionsListItem *ui;
|
||||
MapConnection * const connection;
|
||||
bool isSelected = false;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
|
||||
signals:
|
||||
void edited();
|
||||
void deleted();
|
||||
void selected();
|
||||
|
||||
private slots:
|
||||
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);
|
||||
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::highlightChanged, listItem, &ConnectionsListItem::setSelected);
|
||||
if (connectionItem == selected_connection_item)
|
||||
listItem->setSelected(true);
|
||||
|
||||
// Connect the list item to the pixmap item
|
||||
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] {
|
||||
// TODO: This is probably slower than necessary (we don't need a full redraw if we're just moving it)
|
||||
// TODO: Handle mirroring
|
||||
connect(listItem, &ConnectionsListItem::edited, [this, connectionItem] {
|
||||
redrawConnection(connectionItem);
|
||||
emit editedMapData();
|
||||
});
|
||||
|
||||
connect(listItem, &ConnectionsListItem::deleted, [this, connectionItem] {
|
||||
removeConnection(connectionItem);
|
||||
});
|
||||
|
@ -834,16 +848,11 @@ void Editor::redrawConnection(ConnectionPixmapItem* connectionItem) {
|
|||
connectionItem->basePixmap = pixmap;
|
||||
QPoint pos = calculateConnectionPosition(connectionItem->connection, pixmap);
|
||||
|
||||
if (connectionItem == selected_connection_item) {
|
||||
QPainter painter(&pixmap);
|
||||
painter.setPen(QColor(255, 0, 255));
|
||||
painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
||||
painter.end();
|
||||
}
|
||||
connectionItem->blockSignals(true);
|
||||
connectionItem->setPixmap(pixmap);
|
||||
connectionItem->updateHighlight(connectionItem == selected_connection_item);
|
||||
connectionItem->initialX = pos.x();
|
||||
connectionItem->initialY = pos.y();
|
||||
connectionItem->blockSignals(true);
|
||||
connectionItem->setX(pos.x());
|
||||
connectionItem->setY(pos.y());
|
||||
connectionItem->setZValue(-1);
|
||||
|
@ -888,8 +897,6 @@ void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
|
|||
selected_connection_item = connectionItem;
|
||||
for (ConnectionPixmapItem* item : connection_items)
|
||||
item->updateHighlight(item == selected_connection_item);
|
||||
|
||||
// TODO: Handle the highlight done in redrawConnection?
|
||||
}
|
||||
|
||||
// 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() {
|
||||
// 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 visible = (editingConnections || ui->checkBox_ToggleBorder->isChecked());
|
||||
|
||||
|
|
|
@ -2569,26 +2569,27 @@ void MainWindow::on_pushButton_ConfigureEncountersJSON_clicked() {
|
|||
|
||||
void MainWindow::on_button_OpenDiveMap_clicked() {
|
||||
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);
|
||||
}
|
||||
|
||||
void MainWindow::on_button_OpenEmergeMap_clicked() {
|
||||
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);
|
||||
}
|
||||
|
||||
// TODO: Mirror change to/from other maps
|
||||
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);
|
||||
markMapEdited();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
markMapEdited();
|
||||
}
|
||||
|
|
|
@ -1800,10 +1800,6 @@ QString Project::getNewMapName() {
|
|||
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 qualifiers;
|
||||
|
||||
|
|
|
@ -56,13 +56,23 @@ bool ConnectionPixmapItem::getEditable() {
|
|||
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) {
|
||||
bool editable = this->getEditable();
|
||||
int zValue = (selected || !editable) ? -1 : -2;
|
||||
qreal opacity = (selected || !editable) ? 1 : 0.75;
|
||||
this->setZValue(zValue);
|
||||
this->render(opacity);
|
||||
if (editable && selected) {
|
||||
const int normalZ = -1;
|
||||
const qreal normalOpacity = 1.0;
|
||||
|
||||
// When editing is inactive the current selection is ignored, all connections should appear normal.
|
||||
if (!this->getEditable()) {
|
||||
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();
|
||||
QPainter painter(&pixmap);
|
||||
painter.setPen(QColor(255, 0, 255));
|
||||
|
@ -70,6 +80,11 @@ void ConnectionPixmapItem::updateHighlight(bool selected) {
|
|||
painter.end();
|
||||
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 *) {
|
||||
|
|
|
@ -42,9 +42,25 @@ void ConnectionsListItem::updateUI() {
|
|||
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)
|
||||
{
|
||||
this->connection->direction = direction;
|
||||
this->setSelected(true);
|
||||
emit this->edited();
|
||||
}
|
||||
|
||||
|
@ -52,6 +68,7 @@ void ConnectionsListItem::on_comboBox_Map_currentTextChanged(const QString &mapN
|
|||
{
|
||||
if (ui->comboBox_Map->findText(mapName) >= 0) {
|
||||
this->connection->map_name = mapName;
|
||||
this->setSelected(true);
|
||||
emit this->edited();
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +76,7 @@ void ConnectionsListItem::on_comboBox_Map_currentTextChanged(const QString &mapN
|
|||
void ConnectionsListItem::on_spinBox_Offset_valueChanged(int offset)
|
||||
{
|
||||
this->connection->offset = offset;
|
||||
this->setSelected(true);
|
||||
emit this->edited();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue