Ubuntu12.04.4_lts
2023-08-01 961efe36f62f7eba688d504ec0cdf3e1daa4dd74
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "codewidget.h"
 
CodeWidget::CodeWidget(QWidget *parent) :
    QWidget(parent)
{
    resize(180, 160);
    casesen = true;
    margin = 10;
    percent = 0.23;
    foreground = QColor("black");
    background = QColor("white");
    mode = MODE_8;
    level = LEVEL_Q;
}
 
void CodeWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QRcode *qrcode = QRcode_encodeString(text.data(), 7, (QRecLevel)level, (QRencodeMode)mode, casesen ? 1 : 0);
    if(0 != qrcode) {
        unsigned char *point = qrcode->data;
        painter.setPen(Qt::NoPen);
        painter.setBrush(this->background);
        painter.drawRect(0, 0, this->width(), this->height());
        double scale = (this->width () - 2.0 * margin) / qrcode->width;
        painter.setBrush(this->foreground);
        for (int y = 0; y < qrcode->width; y ++) {
            for (int x = 0; x < qrcode->width; x ++) {
                if (*point & 1) {
                    QRectF r(margin + x * scale, margin + y * scale, scale, scale);
                    painter.drawRects(&r, 1);
                }
                point ++;
            }
        }
        point = NULL;
        QRcode_free(qrcode);
        // draw icon
        // if (icon.isNull ()) {
        painter.setBrush(this->background);
        double icon_width = (this->width () - 2.0 * margin) * percent;
        double icon_height = icon_width;
        double wrap_x = (this->width () - icon_width) / 2.0;
        double wrap_y = (this->width () - icon_height) / 2.0;
        QRectF wrap(wrap_x - 5, wrap_y - 5, icon_width + 10, icon_height + 10);
        painter.drawRoundRect(wrap, 50, 50);
        QPixmap image(":/new/prefix1/code.png");
        QRectF target(wrap_x, wrap_y, icon_width, icon_height);
        QRectF source(0, 0, image.width (), image.height ());
        painter.drawPixmap (target, image, source);
    }
    qrcode = NULL;
}
 
void CodeWidget::updateCode(QByteArray &text)
{
    this->text = text;
}