mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
optimize QR dialog & bug fix
This commit is contained in:
@@ -32,7 +32,7 @@ namespace NekoRay::fmt {
|
|||||||
url.setPort(serverPort);
|
url.setPort(serverPort);
|
||||||
if (!name.isEmpty()) url.setFragment(UrlSafe_encode(name));
|
if (!name.isEmpty()) url.setFragment(UrlSafe_encode(name));
|
||||||
if (!stream->sni.isEmpty()) query.addQueryItem("sni", stream->sni);
|
if (!stream->sni.isEmpty()) query.addQueryItem("sni", stream->sni);
|
||||||
query.addQueryItem("security", "tls");
|
query.addQueryItem("security", stream->security);
|
||||||
query.addQueryItem("type", stream->network);
|
query.addQueryItem("type", stream->network);
|
||||||
|
|
||||||
if (stream->network == "ws" || stream->network == "http") {
|
if (stream->network == "ws" || stream->network == "http") {
|
||||||
|
|||||||
@@ -247,8 +247,8 @@
|
|||||||
<translation>复制成功</translation>
|
<translation>复制成功</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Copy profile share links (Nekoray)</source>
|
<source>Copy profile share links (Neko Links)</source>
|
||||||
<translation>复制分组内配置的分享链接 (Nekoray)</translation>
|
<translation>复制分组内配置的分享链接 (Neko Links)</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
@@ -1142,8 +1142,8 @@ End: %2</source>
|
|||||||
<translation>克隆 %1 个项目</translation>
|
<translation>克隆 %1 个项目</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Copy links of selected (Nekoray)</source>
|
<source>Copy links of selected (Neko Links)</source>
|
||||||
<translation>批量复制选中项目的分享链接 (Nekoray)</translation>
|
<translation>批量复制选中项目的分享链接 (Neko Links)</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Allow other devices to connect</source>
|
<source>Allow other devices to connect</source>
|
||||||
|
|||||||
@@ -130,7 +130,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="copy_links_nkr">
|
<widget class="QPushButton" name="copy_links_nkr">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Copy profile share links (Nekoray)</string>
|
<string>Copy profile share links (Neko Links)</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
// Setup Tray
|
// Setup Tray
|
||||||
tray = new QSystemTrayIcon(this);//初始化托盘对象tray
|
tray = new QSystemTrayIcon(this);//初始化托盘对象tray
|
||||||
|
tray->setIcon(TrayIcon::GetIcon(TrayIcon::NONE));
|
||||||
tray->setContextMenu(ui->menu_program);//创建托盘菜单
|
tray->setContextMenu(ui->menu_program);//创建托盘菜单
|
||||||
tray->show();//让托盘图标显示在系统托盘上
|
tray->show();//让托盘图标显示在系统托盘上
|
||||||
connect(tray, &QSystemTrayIcon::activated, this,
|
connect(tray, &QSystemTrayIcon::activated, this,
|
||||||
@@ -1057,61 +1058,76 @@ void MainWindow::display_qr_link(bool nkrFormat) {
|
|||||||
auto ents = get_now_selected();
|
auto ents = get_now_selected();
|
||||||
if (ents.count() != 1) return;
|
if (ents.count() != 1) return;
|
||||||
|
|
||||||
auto link = ents.first()->bean->ToShareLink();
|
|
||||||
if (nkrFormat) {
|
|
||||||
link = ents.first()->bean->ToNekorayShareLink(ents.first()->type);
|
|
||||||
}
|
|
||||||
|
|
||||||
qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(link.toUtf8().data(),
|
|
||||||
qrcodegen::QrCode::Ecc::MEDIUM);
|
|
||||||
qint32 sz = qr.getSize();
|
|
||||||
QImage im(sz, sz, QImage::Format_RGB32);
|
|
||||||
QRgb black = qRgb(0, 0, 0);
|
|
||||||
QRgb white = qRgb(255, 255, 255);
|
|
||||||
for (int y = 0; y < sz; y++)
|
|
||||||
for (int x = 0; x < sz; x++)
|
|
||||||
im.setPixel(x, y, qr.getModule(x, y) ? black : white);
|
|
||||||
|
|
||||||
class W : public QDialog {
|
class W : public QDialog {
|
||||||
public:
|
public:
|
||||||
QLabel *l = nullptr;
|
QLabel *l = nullptr;
|
||||||
|
QCheckBox *cb = nullptr;
|
||||||
|
//
|
||||||
QPlainTextEdit *l2 = nullptr;
|
QPlainTextEdit *l2 = nullptr;
|
||||||
QImage im;
|
QImage im;
|
||||||
|
//
|
||||||
|
QString link;
|
||||||
|
QString link_nk;
|
||||||
|
|
||||||
void set(QLabel *qLabel, QPlainTextEdit *pl, QImage qImage) {
|
void show_qr(const QSize &size) const {
|
||||||
this->l = qLabel;
|
auto side = size.height() - 20 - l2->size().height() - cb->size().height();
|
||||||
this->l2 = pl;
|
|
||||||
this->im = std::move(qImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent *resizeEvent) override {
|
|
||||||
auto size = resizeEvent->size();
|
|
||||||
auto side = size.height() - 20 - l2->size().height();
|
|
||||||
l->setPixmap(QPixmap::fromImage(im.scaled(side, side, Qt::KeepAspectRatio, Qt::FastTransformation),
|
l->setPixmap(QPixmap::fromImage(im.scaled(side, side, Qt::KeepAspectRatio, Qt::FastTransformation),
|
||||||
Qt::MonoOnly));
|
Qt::MonoOnly));
|
||||||
l->resize(side, side);
|
l->resize(side, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refresh(bool is_nk) {
|
||||||
|
auto link_display = is_nk ? link_nk : link;
|
||||||
|
l2->setPlainText(link_display);
|
||||||
|
//
|
||||||
|
qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(link_display.toUtf8().data(),
|
||||||
|
qrcodegen::QrCode::Ecc::MEDIUM);
|
||||||
|
qint32 sz = qr.getSize();
|
||||||
|
im = QImage(sz, sz, QImage::Format_RGB32);
|
||||||
|
QRgb black = qRgb(0, 0, 0);
|
||||||
|
QRgb white = qRgb(255, 255, 255);
|
||||||
|
for (int y = 0; y < sz; y++)
|
||||||
|
for (int x = 0; x < sz; x++)
|
||||||
|
im.setPixel(x, y, qr.getModule(x, y) ? black : white);
|
||||||
|
show_qr(size());
|
||||||
|
}
|
||||||
|
|
||||||
|
W(const QString &link_, const QString &link_nk_) {
|
||||||
|
link = link_;
|
||||||
|
link_nk = link_nk_;
|
||||||
|
//
|
||||||
|
setLayout(new QVBoxLayout);
|
||||||
|
setMinimumSize(256, 256);
|
||||||
|
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||||
|
sizePolicy.setHeightForWidth(true);
|
||||||
|
setSizePolicy(sizePolicy);
|
||||||
|
//
|
||||||
|
l = new QLabel();
|
||||||
|
l->setMinimumSize(256, 256);
|
||||||
|
l->setMargin(6);
|
||||||
|
l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
|
l->setScaledContents(true);
|
||||||
|
layout()->addWidget(l);
|
||||||
|
cb = new QCheckBox;
|
||||||
|
cb->setText("Neko Links");
|
||||||
|
layout()->addWidget(cb);
|
||||||
|
l2 = new QPlainTextEdit();
|
||||||
|
l2->setReadOnly(true);
|
||||||
|
layout()->addWidget(l2);
|
||||||
|
//
|
||||||
|
connect(cb, &QCheckBox::toggled, this, &W::refresh);
|
||||||
|
refresh(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void resizeEvent(QResizeEvent *resizeEvent) override {
|
||||||
|
show_qr(resizeEvent->size());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto w = new W();
|
auto link = ents.first()->bean->ToShareLink();
|
||||||
auto l = new QLabel(w);
|
auto link_nk = ents.first()->bean->ToNekorayShareLink(ents.first()->type);
|
||||||
w->setLayout(new QVBoxLayout);
|
auto w = new W(link, link_nk);
|
||||||
w->setMinimumSize(256, 256);
|
|
||||||
l->setMinimumSize(256, 256);
|
|
||||||
l->setMargin(6);
|
|
||||||
l->setAlignment(Qt::AlignmentFlag::AlignCenter);
|
|
||||||
l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
||||||
l->setScaledContents(true);
|
|
||||||
w->layout()->addWidget(l);
|
|
||||||
auto l2 = new QPlainTextEdit(w);
|
|
||||||
l2->setPlainText(link);
|
|
||||||
l2->setReadOnly(true);
|
|
||||||
w->layout()->addWidget(l2);
|
|
||||||
w->set(l, l2, im);
|
|
||||||
w->setWindowTitle(ents.first()->bean->DisplayTypeAndName());
|
w->setWindowTitle(ents.first()->bean->DisplayTypeAndName());
|
||||||
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|
||||||
sizePolicy.setHeightForWidth(true);
|
|
||||||
w->setSizePolicy(sizePolicy);
|
|
||||||
w->exec();
|
w->exec();
|
||||||
w->deleteLater();
|
w->deleteLater();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -776,7 +776,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="menu_copy_links_nkr">
|
<action name="menu_copy_links_nkr">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Copy links of selected (Nekoray)</string>
|
<string>Copy links of selected (Neko Links)</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string notr="true">Ctrl+Alt+C</string>
|
<string notr="true">Ctrl+Alt+C</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user