mirror of
https://github.com/x-tools-author/x-tools.git
synced 2025-09-15 15:28:40 +08:00
add QR code window
This commit is contained in:
parent
576e316d50
commit
434f2b767b
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2020 wuuhii. All rights reserved.
|
||||
* Copyright (C) 2020 wuuhii. All rights reserved.
|
||||
*
|
||||
* The file is encoding with utf-8 (with BOM). It is a part of QtSwissArmyKnife
|
||||
* project. The project is a open source project, you can get the source from:
|
||||
@ -9,69 +9,34 @@
|
||||
* For more information about the project, please join our QQ group(952218522).
|
||||
* In addition, the email address of the project author is wuuhii@outlook.com.
|
||||
*/
|
||||
#include <QTimer>
|
||||
#include <QSettings>
|
||||
#include <QTextCursor>
|
||||
#include <QTranslator>
|
||||
#include <QImage>
|
||||
|
||||
#include "SAKSettings.hh"
|
||||
#include "SAKMainWindow.hh"
|
||||
#include "SAKApplication.hh"
|
||||
#include "SAKApplicationInformation.hh"
|
||||
#include "SAKQRCodeWidget.hh"
|
||||
#include "SAKQRCodeDialog.hh"
|
||||
|
||||
SAKApplication::SAKApplication(int argc, char **argv)
|
||||
: QApplication (argc, argv)
|
||||
, mainWindow (Q_NULLPTR)
|
||||
#include "ui_SAKQRCodeDialog.h"
|
||||
|
||||
SAKQRCodeDialog::SAKQRCodeDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::SAKQRCodeDialog)
|
||||
{
|
||||
installLanguage();
|
||||
setApplicationVersion(SAKApplicationInformation::instance()->version());
|
||||
ui->setupUi(this);
|
||||
setModal(true);
|
||||
resize(350, 580);
|
||||
|
||||
/// 注册表选项
|
||||
setOrganizationName(QString("Qter"));
|
||||
setOrganizationDomain(QString("IT"));
|
||||
setApplicationName(QString("QtSwissArmyKnife"));
|
||||
tabWidget = ui->tabWidget;
|
||||
tabWidget->clear();
|
||||
|
||||
QTimer::singleShot(5*1000, [=](){
|
||||
if (SAKSettings::instance()->enableAutoCheckForUpdate()){
|
||||
emit this->checkForUpdate();
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow = new SAKMainWindow;
|
||||
mainWindow->show();
|
||||
addQRCode(tr("用户交流"), QString(":/resources/images/QSAKQQ.jpg"));
|
||||
addQRCode(tr("技术交流"), QString(":/resources/images/QtQQ.jpg"));
|
||||
}
|
||||
|
||||
SAKApplication::~SAKApplication()
|
||||
SAKQRCodeDialog::~SAKQRCodeDialog()
|
||||
{
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SAKApplication::installLanguage()
|
||||
void SAKQRCodeDialog::addQRCode(QString name, QString image)
|
||||
{
|
||||
QString language = SAKSettings::instance()->language();
|
||||
QString qmName;
|
||||
if (language.isEmpty()){
|
||||
if (QLocale().country() == QLocale::China){
|
||||
qmName = QString("zh_CN");
|
||||
}else{
|
||||
qmName = QString("en");
|
||||
}
|
||||
}else{
|
||||
qmName = language.split('-').first();
|
||||
}
|
||||
|
||||
qtBaeTranslator.load(QString(":/translations/qt/qtbase_%1.qm").arg(qmName));
|
||||
qApp->installTranslator(&qtBaeTranslator);
|
||||
|
||||
qtTranslator.load(QString(":/translations/qt/qt_%1.qm").arg(qmName));
|
||||
qApp->installTranslator(&qtTranslator);
|
||||
|
||||
sakTranslator.load(QString(":/translations/sak/SAK_%1.qm").arg(qmName));
|
||||
qApp->installTranslator(&sakTranslator);
|
||||
|
||||
if (sender() && inherits("QAction")){
|
||||
QAction *action = reinterpret_cast<QAction*>(sender());
|
||||
action->setChecked(true);
|
||||
QString title = action->data().toString();
|
||||
}
|
||||
tabWidget->addTab(new SAKQRCodeWidget(size(), image, this), name);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2019 wuuhii. All rights reserved.
|
||||
* Copyright (C) 2020 wuuhii. All rights reserved.
|
||||
*
|
||||
* The file is encoding with utf-8 (with BOM). It is a part of QtSwissArmyKnife
|
||||
* project. The project is a open source project, you can get the source from:
|
||||
@ -9,33 +9,27 @@
|
||||
* For more information about the project, please join our QQ group(952218522).
|
||||
* In addition, the email address of the project author is wuuhii@outlook.com.
|
||||
*/
|
||||
#ifndef SAKAPPLICATION_HH
|
||||
#define SAKAPPLICATION_HH
|
||||
#ifndef SAKQRCODEDIALOG_HH
|
||||
#define SAKQRCODEDIALOG_HH
|
||||
|
||||
#include <QTranslator>
|
||||
#include <QApplication>
|
||||
#include <QStyleFactory>
|
||||
#include <QDialog>
|
||||
#include <QTabWidget>
|
||||
|
||||
class SAKMainWindow;
|
||||
class SAKApplication:public QApplication
|
||||
namespace Ui {
|
||||
class SAKQRCodeDialog;
|
||||
}
|
||||
class SAKQRCodeDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SAKApplication(int argc, char **argv);
|
||||
~SAKApplication();
|
||||
|
||||
/**
|
||||
* @brief installLanguage 安装语言包
|
||||
*/
|
||||
void installLanguage();
|
||||
SAKQRCodeDialog(QWidget *parent = Q_NULLPTR);
|
||||
~SAKQRCodeDialog();
|
||||
private:
|
||||
SAKMainWindow *mainWindow;
|
||||
|
||||
QTranslator qtTranslator;
|
||||
QTranslator qtBaeTranslator;
|
||||
QTranslator sakTranslator;
|
||||
signals:
|
||||
void checkForUpdate();
|
||||
Ui::SAKQRCodeDialog *ui;
|
||||
QTabWidget *tabWidget;
|
||||
private:
|
||||
/// @brief 添加二维码
|
||||
void addQRCode(QString name, QString image);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SAKQRCode</class>
|
||||
<widget class="QDialog" name="SAKQRCode">
|
||||
<class>SAKQRCodeDialog</class>
|
||||
<widget class="QDialog" name="SAKQRCodeDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>510</width>
|
||||
<height>548</height>
|
||||
<width>545</width>
|
||||
<height>633</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
<string>二维码</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
|
||||
@ -9,28 +9,35 @@
|
||||
* For more information about the project, please join our QQ group(952218522).
|
||||
* In addition, the email address of the project author is wuuhii@outlook.com.
|
||||
*/
|
||||
#include <QImage>
|
||||
#include <QRectF>
|
||||
#include <QPainter>
|
||||
#include "SAKQRCodeWidget.hh"
|
||||
|
||||
#include "SAKQRCodeDialog.hh"
|
||||
#include "ui_SAKQRCodeDialog.h"
|
||||
|
||||
SAKQRCodeDialog::SAKQRCodeDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::SAKQRCodeDialog)
|
||||
SAKQRCodeWidget::SAKQRCodeWidget(QSize size, QString image, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, size(size)
|
||||
, image(image)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setModal(true);
|
||||
|
||||
tabWidget = ui->tabWidget;
|
||||
tabWidget->clear();
|
||||
resize(size.width(), size.height());
|
||||
}
|
||||
|
||||
SAKQRCodeDialog::~SAKQRCodeDialog()
|
||||
SAKQRCodeWidget::~SAKQRCodeWidget()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SAKQRCodeDialog::addQRCode(QString qrcode)
|
||||
void SAKQRCodeWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QImage iamge(qrcode);
|
||||
Q_UNUSED(event);
|
||||
|
||||
QPixmap qrCode(image);
|
||||
qrCode = qrCode.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
int w = qrCode.width();
|
||||
int h = qrCode.height();
|
||||
|
||||
QRectF target((width()-w)/2, (height()-h)/2, w, h);
|
||||
QRectF source(0, 0, w, h);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(target, qrCode, source);
|
||||
}
|
||||
|
||||
@ -9,27 +9,23 @@
|
||||
* For more information about the project, please join our QQ group(952218522).
|
||||
* In addition, the email address of the project author is wuuhii@outlook.com.
|
||||
*/
|
||||
#ifndef SAKQRCODEDIALOG_HH
|
||||
#define SAKQRCODEDIALOG_HH
|
||||
#ifndef SAKQRCODEWIDGET_HH
|
||||
#define SAKQRCODEWIDGET_HH
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTabWidget>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class SAKQRCodeDialog;
|
||||
}
|
||||
class SAKQRCodeDialog : public QDialog
|
||||
/// @brief 显示一张二维码图片
|
||||
class SAKQRCodeWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SAKQRCodeDialog(QWidget *parent = Q_NULLPTR);
|
||||
~SAKQRCodeDialog();
|
||||
SAKQRCodeWidget(QSize size, QString image, QWidget *parent = Q_NULLPTR);
|
||||
~SAKQRCodeWidget();
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
private:
|
||||
Ui::SAKQRCodeDialog *ui;
|
||||
QTabWidget *tabWidget;
|
||||
private:
|
||||
/// @brief 添加二维码,参数为二维码图片路径,如":/resources/images/QSAKQQ.jpg"
|
||||
void addQRCode(QString qrcode);
|
||||
QSize size;
|
||||
QString image;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user