Browse Source

Use OpenGL for overlay for better blending. Improve routing.

chirpmodem-v8.0.0
Jon Beniston 2 months ago
parent
commit
97e1cc1601
  1. 1347
      sdrgui/gui/connectionoverlay.cpp
  2. 97
      sdrgui/gui/connectionoverlay.h
  3. 40
      sdrgui/mainwindow.cpp

1347
sdrgui/gui/connectionoverlay.cpp

File diff suppressed because it is too large Load Diff

97
sdrgui/gui/connectionoverlay.h

@ -28,13 +28,18 @@ @@ -28,13 +28,18 @@
#include <QVector>
#include <QPointer>
#include <QTimer>
#include <QWidget>
#include <QOpenGLWidget>
class QMdiArea;
class QMdiSubWindow;
class QOpenGLFramebufferObject;
class QOpenGLShaderProgram;
class QPainter;
// A non-interactive drawing layer above one workspace's MDI windows, showing connections between windows.
class ConnectionOverlay : public QWidget
// It is an OpenGL widget stacked on top, so it blends over OpenGL spectra too; a translucent
// ordinary widget shows black where it overlaps them.
class ConnectionOverlay : public QOpenGLWidget
{
Q_OBJECT
public:
@ -42,19 +47,20 @@ public: @@ -42,19 +47,20 @@ public:
enum Direction { NoDirection, Forward, Reverse, BothDirections };
struct Connection {
QPointer<QMdiSubWindow> source;
QPointer<QMdiSubWindow> target;
QString sourceLabel;
QString targetLabel;
QString flowLabel;
int sourceWorkspace = -1;
int targetWorkspace = -1;
Kind kind = DeviceLink;
Direction direction = Forward;
QColor color;
QPointer<QMdiSubWindow> m_source;
QPointer<QMdiSubWindow> m_target;
QString m_sourceLabel;
QString m_targetLabel;
QString m_flowLabel;
int m_sourceWorkspace = -1;
int m_targetWorkspace = -1;
Kind m_kind = DeviceLink;
Direction m_direction = Forward;
QColor m_color;
};
explicit ConnectionOverlay(QMdiArea *mdi);
~ConnectionOverlay() override;
void setConnections(const QList<Connection>& connections);
void setOverlayVisible(bool visible);
@ -62,57 +68,72 @@ protected: @@ -62,57 +68,72 @@ protected:
bool eventFilter(QObject *object, QEvent *event) override;
void changeEvent(QEvent *event) override;
void showEvent(QShowEvent *event) override;
void paintEvent(QPaintEvent *event) override;
void initializeGL() override;
void paintGL() override;
private:
// Geometry for one drawn connection, cached until windows move or connections change.
struct Route {
QPainterPath path;
qreal length = 0;
QRect bounds;
QPointF from;
QPointF to;
QColor color;
Kind kind = DeviceLink;
Direction direction = Forward;
QString flowLabel;
QRectF flowLabelRect;
QString marker;
QRectF markerRect;
QPainterPath m_path;
qreal m_length = 0;
QPointF m_from;
QPointF m_to;
QColor m_color;
Kind m_kind = DeviceLink;
Direction m_direction = Forward;
QString m_flowLabel;
QRectF m_flowLabelRect;
QString m_marker;
QRectF m_markerRect;
// Inputs to connectionPath(), kept so a stub can be rerouted to follow its label.
int fromSide = 0;
int toSide = 0;
QRectF sourceBox;
QRectF targetBox;
int stubTip = 0; // Cross-workspace stub: 1 if to is its tip, -1 if from is
int m_fromSide = 0;
int m_toSide = 0;
QRectF m_sourceBox;
QRectF m_targetBox;
QVector<QRectF> m_obstacles; // Other windows the route should avoid
int m_stubTip = 0; // Cross-workspace stub: 1 if m_to is its tip, -1 if m_from is
QMdiSubWindow *m_source = nullptr; // For hover highlighting; compared, never dereferenced
QMdiSubWindow *m_target = nullptr;
bool m_local = false; // Both ends in this workspace, so it can be rerouted around other links
QVector<quint32> m_cells; // Lane cells the route reserves, see Occupancy in the .cpp
};
struct Pulse {
QPointF tail;
QPointF head;
QColor color;
QPointF m_tail;
QPointF m_head;
QColor m_color;
};
QMdiArea *m_mdi;
QList<Connection> m_connections;
QHash<QMdiSubWindow*, QPointer<QWidget>> m_indexLabels;
QList<QPointer<QMdiSubWindow>> m_windows; // Windows with links, to watch for moves
QList<QPointer<QObject>> m_watched;
QVector<Route> m_routes;
QRegion m_clipRegion; // Everything except the title ID labels
QRegion m_pulseRegion; // Area covered by the pulses last painted
qreal m_phase = 0;
QPointer<QMdiSubWindow> m_hovered; // Window under the mouse, if it has links
bool m_highlightActive = false; // Dim links that do not touch m_hovered
bool m_layoutDirty = true; // Cached routes no longer match the windows
bool m_relayoutPending = false; // A queued relayout() is outstanding
QElapsedTimer m_clock;
QTimer m_animationTimer;
// QPainter draws premultiplied alpha, but Qt composites an OpenGL widget as straight
// alpha, which darkens anything translucent. So paint offscreen, then copy through a
// shader that converts to straight alpha.
QOpenGLFramebufferObject *m_paintBuffer = nullptr; // Multisampled, painted by QPainter
QOpenGLFramebufferObject *m_resolveBuffer = nullptr; // Plain texture the shader reads
QOpenGLShaderProgram *m_unpremultiply = nullptr;
static bool sameConnections(const QList<Connection>& a, const QList<Connection>& b);
void watchWindows();
void invalidateLayout();
void relayout();
bool computeLayout(); // Returns true if the mask changed
void computeLayout();
QVector<Pulse> pulses() const;
QRegion pulsesRegion(const QVector<Pulse>& pulses) const;
void animate();
void setHovered(QMdiSubWindow *window);
void updateHighlight();
bool isDimmed(const Route& route) const;
void paintRoutes(QPainter& painter);
void releaseGL();
};
#endif // SDRGUI_GUI_CONNECTIONOVERLAY_H_

40
sdrgui/mainwindow.cpp

@ -2801,15 +2801,15 @@ void MainWindow::updateConnectionOverlays() @@ -2801,15 +2801,15 @@ void MainWindow::updateConnectionOverlays()
return;
}
ConnectionOverlay::Connection connection;
connection.source = device;
connection.target = target;
connection.sourceLabel = deviceLabel;
connection.targetLabel = label;
connection.flowLabel = flowLabel;
connection.sourceWorkspace = device->getWorkspaceIndex();
connection.targetWorkspace = targetWorkspace;
connection.direction = direction;
connection.color = color;
connection.m_source = device;
connection.m_target = target;
connection.m_sourceLabel = deviceLabel;
connection.m_targetLabel = label;
connection.m_flowLabel = flowLabel;
connection.m_sourceWorkspace = device->getWorkspaceIndex();
connection.m_targetWorkspace = targetWorkspace;
connection.m_direction = direction;
connection.m_color = color;
connections.append(connection);
};
@ -2907,21 +2907,21 @@ void MainWindow::updateConnectionOverlays() @@ -2907,21 +2907,21 @@ void MainWindow::updateConnectionOverlays()
if (existingIndex >= 0)
{
if (audio) {
connections[existingIndex].flowLabel = audioLabel(source);
connections[existingIndex].m_flowLabel = audioLabel(source);
}
continue;
}
ConnectionOverlay::Connection connection;
connection.source = source.window;
connection.target = target.window;
connection.sourceLabel = source.label;
connection.targetLabel = target.label;
connection.flowLabel = audio ? audioLabel(source) : QString("Data");
connection.sourceWorkspace = source.workspace;
connection.targetWorkspace = target.workspace;
connection.kind = ConnectionOverlay::PipeLink;
connection.direction = ConnectionOverlay::Forward;
connection.color = source.linkColor.isValid() ? source.linkColor : target.linkColor;
connection.m_source = source.window;
connection.m_target = target.window;
connection.m_sourceLabel = source.label;
connection.m_targetLabel = target.label;
connection.m_flowLabel = audio ? audioLabel(source) : QString("Data");
connection.m_sourceWorkspace = source.workspace;
connection.m_targetWorkspace = target.workspace;
connection.m_kind = ConnectionOverlay::PipeLink;
connection.m_direction = ConnectionOverlay::Forward;
connection.m_color = source.linkColor.isValid() ? source.linkColor : target.linkColor;
pipeConnectionIndices[source.window].insert(target.window, connections.size());
connections.append(connection);
}

Loading…
Cancel
Save