Exemplo n.º 1
1
	void Plugin::genQR ()
	{
		const auto& url = sender ()->property ("Poshuku/QRd/URL").toUrl ();

		const std::unique_ptr<QRcode, decltype (&QRcode_free)> code
		{
			QRcode_encodeString (url.toEncoded ().constData (),
					0, QR_ECLEVEL_H, QR_MODE_8, true),
			&QRcode_free
		};

		if (!code)
		{
			QMessageBox::critical (nullptr,
					"LeechCraft",
					tr ("Failed to generate QR code for the page."));
			return;
		}

		const auto width = code->width;
		QImage image { width, width, QImage::Format_Mono };
		image.setColor (0, QColor { Qt::white }.rgb ());
		image.setColor (1, QColor { Qt::black }.rgb ());
		for (int y = 0; y < width; ++y)
			for (int x = 0; x < width; ++x)
				image.setPixel (x, y, code->data [y * width + x] & 0x01);

		const auto& geom = QApplication::desktop ()->availableGeometry (QCursor::pos ());
		const auto& dim = std::min (geom.width (), geom.height ());
		if (dim < width)
		{
			QMessageBox::critical (nullptr,
					"LeechCraft",
					tr ("Sorry, but the QR code is bigger than your display."));
			return;
		}

		auto scale = (width < 2.0 * dim / 3) ? (2.0 * dim / 3 / width) : dim / width;
		if (scale > 1)
			image = image.scaled (width * scale, width * scale, Qt::KeepAspectRatio, Qt::FastTransformation);

		auto label = new QLabel;
		label->setAttribute (Qt::WA_DeleteOnClose);
		label->setPixmap (QPixmap::fromImage (image));
		label->show ();
	}
Exemplo n.º 2
0
void QRCodeDialog::genCode()
{
    QString uri = getURI();

    if (uri != "")
    {
        ui->lblQRCode->setText("");

        QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
        if (!code)
        {
            ui->lblQRCode->setText(tr("Error encoding URI into QR Code."));
            return;
        }
        myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
        myImage.fill(0xffffff);
        unsigned char *p = code->data;
        for (int y = 0; y < code->width; y++)
        {
            for (int x = 0; x < code->width; x++)
            {
                myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
                p++;
            }
        }
        QRcode_free(code);
        ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));
    }
    else
        ui->lblQRCode->setText(tr("Resulting URI too long, try to reduce the text for label / message."));
}
Exemplo n.º 3
0
void QRWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QRcode *qrcode = QRcode_encodeString(data.constData(), 1, QR_ECLEVEL_L, QR_MODE_8, 1);
    if (qrcode != NULL) {
        QColor fg(Qt::black);
        QColor bg(Qt::white);
        painter.setBrush(bg);
        painter.setPen(Qt::NoPen);
        const double w = width();
        const double h = height();
        painter.drawRect(0, 0, w, h);
        painter.setBrush(fg);
        const int s = qrcode->width > 0 ? qrcode->width : 1;
        const double aspect = w / h;
        const double scale = ((aspect > 1.0) ? h : w) / s;
        for(int y = 0; y < s; y++){
            const int yy = y * s;
            for(int x = 0; x < s; x++){
                const int xx = yy + x;
                const unsigned char b = qrcode->data[xx];
                if(b &0x01){
                    const double rx1 = x * scale, ry1 = y * scale;
                    QRectF r(rx1, ry1, scale, scale);
                    painter.drawRects(&r,1);
                }
            }
        }
        QRcode_free(qrcode);
    }
    else {
        qWarning() << tr("Generating QR code failed.");
    }
}
Exemplo n.º 4
0
QImage TcQrencode::encodeImage(const QString& s, int bulk)
{
    QImage ret;
    QRcode* qr = QRcode_encodeString(s.toUtf8(), 1, QR_ECLEVEL_Q, QR_MODE_8, 0);
    if ( qr != NULL )
    {

        int allBulk = (qr->width) * bulk;
        ret = QImage(allBulk, allBulk, QImage::Format_Mono);
        QPainter painter(&ret);
        QColor fg("black");
        QColor bg("white");
        painter.setBrush(bg);
        painter.setPen(Qt::NoPen);
        painter.drawRect(0, 0, allBulk, allBulk);

        painter.setBrush(fg);
        for( int y=0; y<qr->width; y++ )
        {
            for( int x=0; x<qr->width; x++ )
            {
                if ( qr->data[y*qr->width+x] & 1 )
                {
                    QRectF r(x*bulk, y*bulk, bulk, bulk);
                    painter.drawRects(&r, 1);
                }
            }
        }
        QRcode_free(qr);
    }
    return ret;
}
Exemplo n.º 5
0
bool qr::encode(std::istream& in, uint32_t version, error_recovery_level level,
    encode_mode mode, bool case_sensitive, std::ostream& out)
{
    std::string qr_string;
    getline(in, qr_string);

    const auto qrcode = QRcode_encodeString(qr_string.c_str(), version,
        level, mode, case_sensitive);

    if (qrcode == nullptr)
        return false;

    const auto area = qrcode->width * qrcode->width;
    if ((area == 0) || (qrcode->width > max_int32 / qrcode->width))
        return false;

    auto width_ptr = reinterpret_cast<const uint8_t*>(&qrcode->width);
    auto version_ptr = reinterpret_cast<const uint8_t*>(&qrcode->version);

    // Write out raw format of QRcode structure (defined in qrencode.h).
    // Format written is:
    // int version
    // int width
    // unsigned char* data (of width^2 length)
    ostream_writer sink(out);
    sink.write_bytes(version_ptr, sizeof(int));
    sink.write_bytes(width_ptr, sizeof(int));
    sink.write_bytes(qrcode->data, area);
    out.flush();

    return true;
}
Exemplo n.º 6
0
	/*
	 * Qrcode data encoding, implements Barcode2dBase::encode()
	 */
	bool BarcodeQrcode::encode( const std::string& cookedData, Matrix<bool>& encodedData )
	{
		QRcode *qrcode = QRcode_encodeString( cookedData.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1 );
		if ( qrcode == NULL )
		{
			return false;
		}


		int w = qrcode->width;
		encodedData.resize( w, w );
		
		
		for ( int iy = 0; iy < w; iy++ )
		{
			for ( int ix = 0; ix < w; ix++ )
			{
				encodedData[iy][ix] = qrcode->data[ iy*w + ix ] & 0x01;
			}
		}


		QRcode_free( qrcode );
		QRcode_clearCache();

		return true;
	}
Exemplo n.º 7
0
void test_encode_kanji(int num)
{
	QRcode *qrcode;
	QRdata *qrdata;
	int len, ret;

	len = fill8bitString();

	qrcode = QRcode_encodeString((char *)data, 0, num % 4, QR_MODE_8, 1);
	if(qrcode == NULL) {
		if(errno == ERANGE) return;
		perror("test_encdoe_kanji aborted at QRcode_encodeString():");
		return;
	}
	qrdata = QRcode_decode(qrcode);
	if(qrdata == NULL) {
		printf("#%d: Failed to decode this code.\n", num);
		QRcode_free(qrcode);
		return;
	}
	if(qrdata->size != len) {
		printf("#%d: length mismatched (orig: %d, decoded: %d)\n", num, len, qrdata->size);
	}
	ret = memcmp(qrdata->data, data, len);
	if(ret != 0) {
		printf("#%d: data mismatched.\n", num);
	}
	QRdata_free(qrdata);
	QRcode_free(qrcode);
}
Exemplo n.º 8
0
Arquivo: qrimage.c Projeto: wxxweb/w2x
QRcode* QRimage_encode(QRimageEncodeParams* params)
{
	QRcode *code;

	if (NULL == params) {
		return NULL;
	}

	if(params->micro) {
		if(params->eightbit) {
			code = QRcode_encodeDataMQR(params->size, 
				params->data, params->version, params->level);
		} else {
			code = QRcode_encodeStringMQR((char *)params->data, params->version,
				params->level, params->hint, params->casesensitive);
		}
	} else {
		if(params->eightbit) {
			code = QRcode_encodeData(params->size, 
				params->data, params->version, params->level);
		} else {
			code = QRcode_encodeString((char *)params->data, params->version,
				params->level, params->hint, params->casesensitive);
		}
	}
	return code;
}
Exemplo n.º 9
0
lglBarcode *
gl_barcode_iec18004_new (const gchar    *id,
                         gboolean        text_flag,
                         gboolean        checksum_flag,
                         gdouble         w,
                         gdouble         h,
                         const gchar    *digits)
{
        gint             i_width, i_height;
        lglBarcode      *gbc;
        QRcode          *qrcode;

        if ( *digits == '\0' )
        {
                return NULL;
        }

        i_width  = 0;
        i_height = 0;

        qrcode = QRcode_encodeString ((const char *)digits, 0, QR_ECLEVEL_M,
                                      QR_MODE_8, 1);
        if (qrcode == NULL)
        {
                return NULL;
        }
        
        i_width = i_height = qrcode->width;
        gbc = render_iec18004 ((const gchar *)qrcode->data, i_width, i_height,
                               w, h);

        QRcode_free ( qrcode );

        return gbc;
}
char *
qrencode( UDF_INIT* initid, UDF_ARGS* args, unsigned long *length, char* is_null, char *error ) {

	struct mem_encode state;
	state.buffer = NULL;
	state.size = 0;

	QRcode *qrcode = NULL;
	qrcode = QRcode_encodeString( args->args[0], 0, QR_ECLEVEL_H, QR_MODE_8, 1);
	if ( qrcode ) {
		qrcode_to_png( &state, qrcode );
		if ( state.buffer ) {
			initid->ptr = state.buffer;
			*length = state.size;
			fprintf( stderr, "qrcode size = %lu\n", *length );
			fflush(stderr);

		} else {
			*is_null = 1;
			*error = 1;
        	initid->ptr = 0;		
		}
		QRcode_free( qrcode );
	} else {
		*is_null = 1;
		*error = 1;
        initid->ptr = 0;	
	}
	
	return initid->ptr;
}
Exemplo n.º 11
0
void printQRCode(const char *url) {

	QRcode *qrcode = QRcode_encodeString("http://localhost/btctl.apk", /*version*/0, QR_ECLEVEL_M, /*hint*/ QR_MODE_8, /*casesensitive*/ 1 );
	printf("qrcode: %p\n", qrcode);
	if(qrcode) {
		// const char *BYTES[] = {" ", /*50%oben*/ "\xE2\x96\x80", /*50%unten*/ "\xE2\x96\x84", /*100%*/ "\xE2\x96\x88"};
		const char *BYTES_INVERTED[] = {/*100%*/ "\xE2\x96\x88", /*50%unten*/ "\xE2\x96\x84", /*50%oben*/ "\xE2\x96\x80", " "};
		printf("version: %d, width: %d\n\n",qrcode->version, qrcode->width);
		for(int x=0; x < qrcode->width+2; x++) printf(BYTES_INVERTED[1]);
		printf("\n");
		for(int y=0; y < qrcode->width; y++) {
			printf(BYTES_INVERTED[0]);
			for(int x=0; x < qrcode->width; x++) {
				int val=qrcode->data[y*qrcode->width + x] & 1;
				if((y+1) < qrcode->width) {
					val|=(qrcode->data[(y+1)*qrcode->width + x] & 1) << 1; // nächste zeile 
				}
					// 1=black/0=white
				printf(BYTES_INVERTED[val]);
			}
			y++;
			printf(BYTES_INVERTED[0]);
			printf("\n");
		}
		for(int x=0; x < qrcode->width+2; x++) printf(BYTES_INVERTED[2]);
		printf("\n");
		QRcode_free(qrcode);
		printf("\n");
	} else {
		printf("error: %m\n"); // %m = strerror(errno) ohne argument
		exit(1);
	}

	return;
}
Exemplo n.º 12
0
void test_decodeVeryLong(void)
{
	char str[4000];
	int i;
	QRcode *qrcode;
	QRdata *qrdata;

	testStart("Test code words (very long string).");

	for(i=0; i<3999; i++) {
		str[i] = decodeAnTable[(int)drand(45)];
	}
	str[3999] = '\0';

	qrcode = QRcode_encodeString(str, 0, QR_ECLEVEL_L, QR_MODE_8, 0);
	qrdata = QRcode_decode(qrcode);

	assert_nonnull(qrdata, "Failed to decode.\n");
	if(qrdata != NULL) {
		assert_equal(strlen(str), qrdata->size, "Lengths of input/output mismatched.\n");
		assert_zero(strncmp(str, (char *)(qrdata->data), qrdata->size), "Decoded data %s is different from the original %s\n", qrdata->data, str);
	}
	if(qrdata != NULL) QRdata_free(qrdata);
	if(qrcode != NULL) QRcode_free(qrcode);

	testFinish();
}
Exemplo n.º 13
0
void QRcodeWidget::setUrl(const char *url)
{
    code = QRcode_encodeString(url, 0, QR_ECLEVEL_H, QR_MODE_8, 1);
    if (code != NULL) {
        this->repaint();
    }
}
Exemplo n.º 14
0
void ReceiveRequestDialog::update()
{
    if(!model)
        return;
    QString target = info.label;
    if(target.isEmpty())
        target = info.address;
    setWindowTitle(tr("Request payment to %1").arg(target));

    QString uri = GUIUtil::formatDarcoinURI(info);
    ui->btnSaveAs->setEnabled(false);
    QString html;
    html += "<html><font face='verdana, arial, helvetica, sans-serif'>";
    html += "<b>"+tr("Payment information")+"</b><br>";
    html += "<b>"+tr("URI")+"</b>: ";
    html += "<a href=\""+uri+"\">" + GUIUtil::HtmlEscape(uri) + "</a><br>";
    html += "<b>"+tr("Address")+"</b>: " + GUIUtil::HtmlEscape(info.address) + "<br>";
    if(info.amount)
        html += "<b>"+tr("Amount")+"</b>: " + DarcoinUnits::formatWithUnit(model->getDisplayUnit(), info.amount) + "<br>";
    if(!info.label.isEmpty())
        html += "<b>"+tr("Label")+"</b>: " + GUIUtil::HtmlEscape(info.label) + "<br>";
    if(!info.message.isEmpty())
        html += "<b>"+tr("Message")+"</b>: " + GUIUtil::HtmlEscape(info.message) + "<br>";
    ui->outUri->setText(html);

#ifdef USE_QRCODE
    ui->lblQRCode->setText("");
    if(!uri.isEmpty())
    {
        // limit URI length
        if (uri.length() > MAX_URI_LENGTH)
        {
            ui->lblQRCode->setText(tr("Resulting URI too long, try to reduce the text for label / message."));
        } else {
            QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
            if (!code)
            {
                ui->lblQRCode->setText(tr("Error encoding URI into QR Code."));
                return;
            }
            QImage myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
            myImage.fill(0xffffff);
            unsigned char *p = code->data;
            for (int y = 0; y < code->width; y++)
            {
                for (int x = 0; x < code->width; x++)
                {
                    myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
                    p++;
                }
            }
            QRcode_free(code);

            ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));
            ui->btnSaveAs->setEnabled(true);
        }
    }
#endif
}
Exemplo n.º 15
0
void test_encode2(void)
{
	QRcode *qrcode;

	testStart("Test encode (2-H) (no padding test)");
	qrcode = QRcode_encodeString("abcdefghijk123456789012", 0, QR_ECLEVEL_H, QR_MODE_8, 0);
	testEndExp(qrcode->version == 2);
	QRcode_free(qrcode);
}
Exemplo n.º 16
0
QRcode* MakeCodeA(LPSTR text)
{
	if (text == NULL)
		return NULL;

	QRcode* result = QRcode_encodeString(text, 0, QR_ECLEVEL_H, QR_MODE_8, 1);

	return result;
}
Exemplo n.º 17
0
/**
 *  功能描述: 设置生成Qrcode的字符串
 *  @param str 这里是Qrchannel的id
 *
 *  @return 无
 */
void QrCode::setString(QString str)
{
    string = str;
    if(qr != NULL) {
        QRcode_free(qr);
    }
    qr = QRcode_encodeString(string.toStdString().c_str(),
                             1, QR_ECLEVEL_L, QR_MODE_8, 1);
    return;
}
Exemplo n.º 18
0
void test_encodeEmpty(void)
{
	QRcode *qrcode;

	testStart("Test encode an empty string.");
	qrcode = QRcode_encodeString("", 0, QR_ECLEVEL_H, QR_MODE_8, 0);
	assert_null(qrcode, "QRcode_encodeString() returned something.\n");
	testFinish();
	if(qrcode != NULL) QRcode_free(qrcode);
}
Exemplo n.º 19
0
void server::toolbar_actiontriggered(QAction *tem)
{
    //工具栏按钮点击
    if(tem->text() == QString("主页")){
        ui->homepage->show();
    }else{
        ui->homepage->hide();
    }

    if(tem->text() == QString("传输中")){
        ui->transfering->show();
    }else{
        ui->transfering->hide();
    }

    if(tem->text() == QString("传输文件")){

    }
    if(tem->text() == QString("二维码")){
        QImage ret;
        int bulk = 8;
        QString str = QString("http://")+ip;
        QRcode* qr = QRcode_encodeString(str.toUtf8(), 1, QR_ECLEVEL_Q, QR_MODE_8, 0);
        if ( qr != nullptr )
        {
            int allBulk = (qr->width) * bulk;
            ret = QImage(allBulk, allBulk, QImage::Format_Mono);
            QPainter painter(&ret);
            QColor fg("black");
            QColor bg("white");
            painter.setBrush(bg);
            painter.setPen(Qt::NoPen);
            painter.drawRect(0, 0, allBulk, allBulk);

            painter.setBrush(fg);
            for( int y=0; y<qr->width; y++ )
            {
                for( int x=0; x<qr->width; x++ )
                {
                    if ( qr->data[y*qr->width+x] & 1 )
                    {
                        QRectF r(x*bulk, y*bulk, bulk, bulk);
                        painter.drawRects(&r, 1);
                    }
                }
            }
            QRcode_free(qr);
        }
        ui->qrcode_l->setPixmap(QPixmap::fromImage(ret));
        ui->qrcode->show();
    }else{
        ui->qrcode->hide();
    }
}
Exemplo n.º 20
0
static QRcode *encode(const char *intext)
{
	QRcode *code;

	if(eightbit) {
		code = QRcode_encodeString8bit(intext, version, level);
	} else {
		code = QRcode_encodeString(intext, version, level, hint, casesensitive);
	}

	return code;
}
Exemplo n.º 21
0
//http://stackoverflow.com/questions/21400254/how-to-draw-a-qr-code-with-qt-in-native-c-c
void QRWidget::paintImage()
{
    QPainter painter(image);
    //NOTE: I have hardcoded some parameters here that would make more sense as variables.
    // ECLEVEL_M is much faster recognizable by barcodescanner any any other type
    // https://fukuchi.org/works/qrencode/manual/qrencode_8h.html#a4cebc3c670efe1b8866b14c42737fc8f
    // any mode other than QR_MODE_8 or QR_MODE_KANJI results in EINVAL. First 1 is version, second is case sensitivity
    QRcode* qr = QRcode_encodeString(data.toStdString().c_str(), 1, QR_ECLEVEL_M, QR_MODE_8, 1);

    if (qr != nullptr)
    {
        QColor fg("black");
        QColor bg("white");
        painter.setBrush(bg);
        painter.setPen(Qt::NoPen);
        painter.drawRect(0, 0, size.width(), size.height());
        painter.setBrush(fg);
        const int s = qr->width > 0 ? qr->width : 1;
        const double w = width();
        const double h = height();
        const double aspect = w / h;
        const double scale = ((aspect > 1.0) ? h : w) / s;

        for (int y = 0; y < s; y++)
        {
            const int yy = y * s;
            for (int x = 0; x < s; x++)
            {
                const int xx = yy + x;
                const unsigned char b = qr->data[xx];
                if (b & 0x01)
                {
                    const double rx1 = x * scale,
                                 ry1 = y * scale;
                    QRectF r(rx1, ry1, scale, scale);
                    painter.drawRects(&r, 1);
                }
            }
        }
        QRcode_free(qr);
    }
    else
    {
        QColor error("red");
        painter.setBrush(error);
        painter.drawRect(0, 0, width(), height());
        qDebug() << "QR FAIL: " << strerror(errno);
    }

    qr = nullptr;
}
Exemplo n.º 22
0
void QRWidget::setQRData(QString data)
{
    QRData = data;
    if(qr != NULL)
    {
        QRcode_free(qr);
    }
    qr = QRcode_encodeString(QRData.toStdString().c_str(),
                             1,
                             QR_ECLEVEL_L,
                             QR_MODE_8,
                             1);
    update();
}
Exemplo n.º 23
0
void test_encode3(void)
{
	QRcode *code1, *code2;
	QRinput *input;

	testStart("Compare encodeString and encodeInput");
	code1 = QRcode_encodeString("0123456", 0, QR_ECLEVEL_L, QR_MODE_8, 0);
	input = QRinput_new2(0, QR_ECLEVEL_L);
	QRinput_append(input, QR_MODE_NUM, 7, (unsigned char *)"0123456");
	code2 = QRcode_encodeInput(input);
	testEnd(memcmp(code1->data, code2->data, code1->width * code1->width));

	QRcode_free(code1);
	QRcode_free(code2);
	QRinput_free(input);
}
Exemplo n.º 24
0
void QrWidget::setString(QString str)
{
    string = str;

    if (qr != nullptr)
    {
        QRcode_free(qr);
        qr = nullptr;
    }
    qr = QRcode_encodeString(string.toStdString().c_str(),
                             1,
                             QR_ECLEVEL_L,
                             QR_MODE_8,
                             1);
    update();
}
Exemplo n.º 25
0
void test_formatInfo(void)
{
	QRcode *qrcode;
	QRecLevel level;
	int mask;
	int ret;

	testStart("Test format info in QR code.");
	qrcode = QRcode_encodeString("AC-42", 1, QR_ECLEVEL_H, QR_MODE_8, 1);
	ret = QRcode_decodeFormat(qrcode, &level, &mask);
	assert_equal(level, QR_ECLEVEL_H, "Decoded format is wrong.\n");

	if(qrcode != NULL) QRcode_free(qrcode);

	testFinish();
}
Exemplo n.º 26
0
QRcode* MakeCode(LPWSTR text)
{
	if (text == NULL)
		return NULL;
	
	int ulen = WideCharToMultiByte(CP_UTF8, 0, text, wcslen(text), NULL, 0, NULL, NULL);
	LPSTR utfText = (LPSTR)malloc(ulen+1);
	memset(utfText, 0, ulen+1);
    WideCharToMultiByte(CP_UTF8, 0, text, wcslen(text), utfText, ulen, NULL, NULL);

	QRcode* result = QRcode_encodeString(utfText, 0, QR_ECLEVEL_H, QR_MODE_8, 1);

	free(utfText);

	return result;
}
Exemplo n.º 27
0
void QRCodeQWidget::paintEvent(QPaintEvent *event)
{
    QWidget::paintEvent (event);
    QPainter painter(this);

    QRcode *qrcode = QRcode_encodeString(m_text.constData(), 7, m_level, m_mode, m_casesen);
    if(qrcode != nullptr)
    {
        unsigned char *point = qrcode->data;
        painter.setPen(Qt::NoPen);
        painter.setBrush(m_background);
        painter.drawRect(0, 0, width(), height());
        double scale = (width () - 2.0 * m_margin) / qrcode->width;
        painter.setBrush(m_foreground);

        for(int x=0; x<qrcode->width; ++x)
        {
            for(int y =0; y<qrcode->width; ++y)
            {
                if(*point & 1)
                {
                    QRectF r(m_margin + y * scale, m_margin + x * scale, scale, scale);
                    painter.drawRects(&r, 1);
                }
                ++point;
            }
        }
        point = nullptr;
        QRcode_free(qrcode);

        /// draw icon
        painter.setBrush(m_background);
        double icon_width = (width () - 2.0 * m_margin) * m_percent;
        double icon_height = icon_width;
        double wrap_x = (width () - icon_width) / 2.0;
        double wrap_y = (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(m_iconPath);
        QRectF target(wrap_x, wrap_y, icon_width, icon_height);
        QRectF source(0, 0, image.width (), image.height ());
        painter.drawPixmap(target, image, source);
    }
    qrcode = nullptr;
    event->accept();
}
Exemplo n.º 28
0
void verifyne::QR::printAnsi(std::string data, std::ostream &out)
{
    //std::cout << "[+] QR code following ..." << std::endl << data << std::endl;

    QRcode *q = QRcode_encodeString(data.c_str(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);

    if(q == nullptr)
    {
        throw std::runtime_error("Failed to generate QR code");
    }

    //std::cout << "[+] QR code has width " << q->width << std::endl;

    writeANSI(q, out);

    free(q);
}
Exemplo n.º 29
0
void QRCodeDialog::genCode()
{
    QString uri = getURI();
    //qDebug() << "Encoding:" << uri.toUtf8().constData();
    QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
    myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
    myImage.fill(0xffffff);
    unsigned char *p = code->data;
    for(int y = 0; y < code->width; y++) {
        for(int x = 0; x < code->width; x++) {
            myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
            p++;
        }
    }
    QRcode_free(code);
    ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));
}
Exemplo n.º 30
0
void QRWidget::paint(QPainter &painter)
{    
    QRcode *qr = QRcode_encodeString(data.toStdString().c_str(), 1, QR_ECLEVEL_L, QR_MODE_8, 0);
    if (0!=qr)
    {
        QColor fg("black");
        QColor bg("white");
        painter.setBrush(bg);
        painter.setPen(Qt::NoPen);
        //painter.drawRect(0,0,width(),height());
        painter.drawRect(0,0,height(),height());
        painter.setBrush(fg);
        const int s=qr->width>0?qr->width:1;
        const double w=width();
        const double h=height();
        const double aspect=w/h;
        const double scale=((aspect>1.0)?h:w)/s;
        for(int y=0;y<s;y++)
        {
            const int yy=y*s;
            for(int x=0;x<s;x++)
            {
                const int xx=yy+x;
                const unsigned char b=qr->data[xx];
                if(b &0x01)
                {
                    const double rx1=x*scale, ry1=y*scale;
                    QRectF r(rx1, ry1, scale, scale);
                    painter.drawRects(&r,1);
                }
            }
        }
        QRcode_free(qr);
        this->setMaximumWidth(740);
        this->setMaximumHeight(740);
    }
    else
    {
        QColor error("red");

        painter.setBrush(error);
        painter.drawRect(0,0,width(),height());
    }
    qr=0;
}