Skip to content

Commit

Permalink
chore: connection list icon
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Jan 12, 2023
1 parent 6a344bc commit 51e00ee
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 19 deletions.
1 change: 1 addition & 0 deletions res/icon/material/cancel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/icon/material/history.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/icon/material/swap-vertical.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions res/neko.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<file alias="icon/b-system-software-update.svg">icon/system-software-update.svg</file>
<file>icon/material/lock-open-outline.svg</file>
<file>icon/material/lock-outline.svg</file>
<file>icon/material/cancel.svg</file>
<file>icon/material/history.svg</file>
<file>icon/material/swap-vertical.svg</file>
</qresource>
<qresource prefix="/neko">
<file alias="nekobox.png">public/nekobox.png</file>
Expand Down
4 changes: 2 additions & 2 deletions translations/fa_IR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,11 +1177,11 @@ Split by line.</source>
</message>
<message>
<source>End</source>
<translation>پایان</translation>
<translation type="vanished">پایان</translation>
</message>
<message>
<source>Active</source>
<translation>فعال</translation>
<translation type="vanished">فعال</translation>
</message>
<message>
<source>Start: %1
Expand Down
4 changes: 2 additions & 2 deletions translations/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,11 +1009,11 @@
</message>
<message>
<source>End</source>
<translation>结束</translation>
<translation type="vanished">结束</translation>
</message>
<message>
<source>Active</source>
<translation>活动</translation>
<translation type="vanished">活动</translation>
</message>
<message>
<source>Start: %1
Expand Down
4 changes: 2 additions & 2 deletions ui/Icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <QPainter>

QIcon Icon::GetTrayIcon(Icon::TrayIconStatus status) {
QPixmap Icon::GetTrayIcon(Icon::TrayIconStatus status) {
QPixmap pixmap;

// software embedded icon
Expand Down Expand Up @@ -47,7 +47,7 @@ QIcon Icon::GetTrayIcon(Icon::TrayIconStatus status) {
return pixmap;
}

QIcon Icon::GetMaterialIcon(const QString &name) {
QPixmap Icon::GetMaterialIcon(const QString &name) {
QPixmap pixmap(":/icon/material/" + name + ".svg");
return pixmap;
}
6 changes: 3 additions & 3 deletions ui/Icon.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <QIcon>
#include <QPixmap>

namespace Icon {

Expand All @@ -11,8 +11,8 @@ namespace Icon {
VPN,
};

QIcon GetTrayIcon(TrayIconStatus status);
QPixmap GetTrayIcon(TrayIconStatus status);

QIcon GetMaterialIcon(const QString &name);
QPixmap GetMaterialIcon(const QString &name);

} // namespace Icon
29 changes: 19 additions & 10 deletions ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1438,27 +1438,36 @@ void MainWindow::refresh_connection_list(const QJsonArray &arr) {
row++;
ui->tableWidget_conn->insertRow(row);

auto f0 = std::make_unique<QTableWidgetItem>();
f0->setData(114514, item["ID"].toInt());

// C0: Status
auto *f = new QTableWidgetItem("");
f->setData(114514, item["ID"].toInt());
auto c0 = new QLabel;
auto start_t = item["Start"].toInt();
auto end_t = item["End"].toInt();
if (end_t > 0) {
f->setText(tr("End"));
// icon
auto outboundTag = item["Tag"].toString();
if (outboundTag == "block") {
c0->setPixmap(Icon::GetMaterialIcon("cancel"));
} else {
f->setText(tr("Active"));
if (end_t > 0) {
c0->setPixmap(Icon::GetMaterialIcon("history"));
} else {
c0->setPixmap(Icon::GetMaterialIcon("swap-vertical"));
}
}
f->setToolTip(tr("Start: %1\nEnd: %2").arg(DisplayTime(start_t), end_t > 0 ? DisplayTime(end_t) : ""));
ui->tableWidget_conn->setItem(row, 0, f);
c0->setAlignment(Qt::AlignCenter);
c0->setToolTip(tr("Start: %1\nEnd: %2").arg(DisplayTime(start_t), end_t > 0 ? DisplayTime(end_t) : ""));
ui->tableWidget_conn->setCellWidget(row, 0, c0);

// C1: Outbound
f = f->clone();
auto f = f0->clone();
f->setToolTip("");
f->setText(item["Tag"].toString());
f->setText(outboundTag);
ui->tableWidget_conn->setItem(row, 1, f);

// C2: Destination
f = f->clone();
f = f0->clone();
QString target1 = item["Dest"].toString();
QString target2 = item["RDest"].toString();
if (target2.isEmpty() || target1 == target2) {
Expand Down

0 comments on commit 51e00ee

Please sign in to comment.