Adorn portList linkState icon with transmit/capture indicators

The new 'exclusive' indicator may need more work in the future
This commit is contained in:
Srivats P 2018-12-03 21:14:05 +05:30
parent 7409a98b6a
commit f550cb0605
12 changed files with 69 additions and 27 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

View File

@ -1,6 +1,5 @@
<RCC>
<qresource prefix="/">
<file>icons/transmit_on.png</file>
<file>icons/about.png</file>
<file>icons/add.png</file>
<file>icons/arrow_down.png</file>
@ -15,12 +14,17 @@
<file>icons/bullet_yellow.png</file>
<file>icons/control_play.png</file>
<file>icons/control_stop.png</file>
<file>icons/deco_exclusive.png</file>
<file>icons/delete.png</file>
<file>icons/devicegroup_add.png</file>
<file>icons/devicegroup_delete.png</file>
<file>icons/devicegroup_edit.png</file>
<file>icons/exit.png</file>
<file>icons/frag_capture.png</file>
<file>icons/frag_exclusive.png</file>
<file>icons/frag_link_down.png</file>
<file>icons/frag_link_unknown.png</file>
<file>icons/frag_link_up.png</file>
<file>icons/frag_transmit.png</file>
<file>icons/gaps.png</file>
<file>icons/help.png</file>
<file>icons/logo.png</file>
@ -45,5 +49,6 @@
<file>icons/stream_duplicate.png</file>
<file>icons/stream_edit.png</file>
<file>icons/stream_stats.png</file>
<file>icons/transmit_on.png</file>
</qresource>
</RCC>

View File

@ -531,7 +531,9 @@ void Port::updateStats(OstProto::PortStats *portStats)
oldState = stats.state();
stats.MergeFrom(*portStats);
if (oldState.link_state() != stats.state().link_state())
if ((oldState.link_state() != stats.state().link_state())
|| (oldState.is_transmit_on() != stats.state().is_transmit_on())
|| (oldState.is_capture_on() != stats.state().is_capture_on()))
{
qDebug("portstate changed");
emit portDataChanged(mPortGroupId, mPortId);

View File

@ -130,6 +130,10 @@ public:
}
OstProto::LinkState linkState()
{ return stats.state().link_state(); }
bool isTransmitting()
{ return stats.state().is_transmit_on(); }
bool isCapturing()
{ return stats.state().is_capture_on(); }
OstProto::PortStats getStats() { return stats; }
QTemporaryFile* getCaptureFile()

View File

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include <QIcon>
#include <QPainter>
#include <QPixmapCache>
#if 0
#define DBG0(x) qDebug(x)
@ -35,23 +36,6 @@ PortModel::PortModel(PortGroupList *p, QObject *parent)
: QAbstractItemModel(parent)
{
pgl = p;
portIconFactory[OstProto::LinkStateUnknown][false] =
QIcon(":/icons/bullet_white.png");
portIconFactory[OstProto::LinkStateDown][false] =
QIcon(":/icons/bullet_red.png");
portIconFactory[OstProto::LinkStateUp][false] =
QIcon(":/icons/bullet_green.png");
for (int linkState = 0; linkState < kLinkStatesCount; linkState++)
{
QPixmap pixmap(":/icons/deco_exclusive.png");
QPainter painter(&pixmap);
QIcon icon = portIconFactory[linkState][false];
painter.drawPixmap(0, 0, icon.pixmap(QSize(32,32)));
portIconFactory[linkState][true] = QIcon(pixmap);
}
}
int PortModel::rowCount(const QModelIndex &parent) const
@ -185,7 +169,11 @@ QVariant PortModel::data(const QModelIndex &index, int role) const
}
else if (role == Qt::DecorationRole)
{
return portIconFactory[port->linkState()][port->hasExclusiveControl()];
return statusIcon(
port->linkState(),
port->hasExclusiveControl(),
port->isTransmitting(),
port->isCapturing());
}
else if (role == Qt::ForegroundRole)
{
@ -294,7 +282,50 @@ quint32 PortModel::portId(const QModelIndex& index)
return (index.internalId()) & 0xFFFF;
}
QPixmap PortModel::statusIcon(
int linkState, bool exclusive, bool transmit, bool capture) const
{
QPixmap pixmap;
QString key = QString("$ost:portStatusIcon:%1:%2:%3:%4")
.arg(linkState).arg(exclusive).arg(transmit).arg(capture);
if (QPixmapCache::find(key, pixmap))
return pixmap;
static int sz = QPixmap(":/icons/frag_link_up.png").width();
// All frag_* icons must be of same size and can be overlayed
// on top of each other; assume square icons
pixmap = QPixmap(sz, sz);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
switch (linkState) {
case OstProto::LinkStateUp:
painter.drawPixmap(0, 0, QPixmap(":/icons/frag_link_up.png"));
break;
case OstProto::LinkStateDown:
painter.drawPixmap(0, 0, QPixmap(":/icons/frag_link_down.png"));
break;
case OstProto::LinkStateUnknown:
painter.drawPixmap(0, 0, QPixmap(":/icons/frag_link_unknown.png"));
break;
}
if (exclusive)
painter.drawPixmap(0, 0, QPixmap(":/icons/frag_exclusive.png"));
if (transmit)
painter.drawPixmap(0, 0, QPixmap(":/icons/frag_transmit.png"));
if (capture)
painter.drawPixmap(0, 0, QPixmap(":/icons/frag_capture.png"));
QPixmapCache::insert(key, pixmap);
return pixmap;
}
// ----------------------------------------------
// Slots

View File

@ -50,12 +50,6 @@ public:
quint32 portGroupId(const QModelIndex& index);
quint32 portId(const QModelIndex& index);
private:
PortGroupList *pgl;
static const int kLinkStatesCount = 3;
static const int kExclusiveStatesCount = 2;
QIcon portIconFactory[kLinkStatesCount][kExclusiveStatesCount];
private slots:
// FIXME: these are invoked from outside - how come they are "private"?
void when_portGroupDataChanged(int portGroupId, int portId);
@ -71,6 +65,12 @@ private slots:
void triggerLayoutAboutToBeChanged();
void triggerLayoutChanged();
#endif
private:
QPixmap statusIcon(int linkState, bool exclusive,
bool transmit, bool capture) const;
PortGroupList *pgl;
};
#endif