mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 05:07:46 +02:00
chore:add qr code support for login
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
32
libraries/qt-qrcodegenerator/CMakeLists.txt
Normal file
32
libraries/qt-qrcodegenerator/CMakeLists.txt
Normal file
@ -0,0 +1,32 @@
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
|
||||
project(qrcode)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED true)
|
||||
set(CMAKE_C_STANDARD_REQUIRED true)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
|
||||
if(QT_VERSION_MAJOR EQUAL 5)
|
||||
find_package(Qt5 COMPONENTS Core Gui REQUIRED)
|
||||
elseif(Launcher_QT_VERSION_MAJOR EQUAL 6)
|
||||
find_package(Qt6 COMPONENTS Core Gui Core5Compat REQUIRED)
|
||||
list(APPEND systeminfo_LIBS Qt${QT_VERSION_MAJOR}::Core5Compat)
|
||||
endif()
|
||||
|
||||
add_library(qrcode STATIC qr.h qr.cpp QR-Code-generator/cpp/qrcodegen.cpp QR-Code-generator/cpp/qrcodegen.hpp )
|
||||
|
||||
target_link_libraries(qrcode Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui ${systeminfo_LIBS})
|
||||
|
||||
|
||||
# needed for statically linked qrcode in shared libs on x86_64
|
||||
set_target_properties(qrcode
|
||||
PROPERTIES POSITION_INDEPENDENT_CODE TRUE
|
||||
)
|
||||
|
||||
target_include_directories(qrcode PUBLIC ./ PRIVATE QR-Code-generator/cpp/)
|
||||
|
1
libraries/qt-qrcodegenerator/QR-Code-generator
Submodule
1
libraries/qt-qrcodegenerator/QR-Code-generator
Submodule
Submodule libraries/qt-qrcodegenerator/QR-Code-generator added at f40366c40d
29
libraries/qt-qrcodegenerator/qr.cpp
Normal file
29
libraries/qt-qrcodegenerator/qr.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
#include "qr.h"
|
||||
#include "qrcodegen.hpp"
|
||||
|
||||
void paintQR(QPainter& painter, const QSize sz, const QString& data, QColor fg)
|
||||
{
|
||||
// NOTE: At this point you will use the API to get the encoding and format you want, instead of my hardcoded stuff:
|
||||
qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(data.toUtf8().constData(), qrcodegen::QrCode::Ecc::LOW);
|
||||
const int s = qr.getSize() > 0 ? qr.getSize() : 1;
|
||||
const double w = sz.width();
|
||||
const double h = sz.height();
|
||||
const double aspect = w / h;
|
||||
const double size = ((aspect > 1.0) ? h : w);
|
||||
const double scale = size / (s + 2);
|
||||
// NOTE: For performance reasons my implementation only draws the foreground parts in supplied color.
|
||||
// It expects background to be prepared already (in white or whatever is preferred).
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(fg);
|
||||
for (int y = 0; y < s; y++) {
|
||||
for (int x = 0; x < s; x++) {
|
||||
const int color = qr.getModule(x, y); // 0 for white, 1 for black
|
||||
if (0 != color) {
|
||||
const double rx1 = (x + 1) * scale, ry1 = (y + 1) * scale;
|
||||
QRectF r(rx1, ry1, scale, scale);
|
||||
painter.drawRects(&r, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
libraries/qt-qrcodegenerator/qr.h
Normal file
8
libraries/qt-qrcodegenerator/qr.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include <QSize>
|
||||
|
||||
// https://stackoverflow.com/questions/21400254/how-to-draw-a-qr-code-with-qt-in-native-c-c
|
||||
void paintQR(QPainter& painter, const QSize sz, const QString& data, QColor fg);
|
Reference in New Issue
Block a user