1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

qrcode always visible, button to save

This commit is contained in:
agilob 2015-03-15 15:45:28 +00:00
parent a501620d92
commit 9d99007e2c
No known key found for this signature in database
GPG Key ID: 34568050DBCCB997
3 changed files with 95 additions and 16 deletions

View File

@ -27,8 +27,6 @@
#include "src/widget/gui.h"
#include "src/historykeeper.h"
#include "src/misc/style.h"
#include "src/misc/qrwidget.h"
#include "qrencode.h"
#include <QLabel>
#include <QLineEdit>
#include <QGroupBox>
@ -38,7 +36,6 @@
#include <QFileDialog>
#include <QBuffer>
void ProfileForm::refreshProfiles()
{
bodyUI->profiles->clear();
@ -78,9 +75,11 @@ ProfileForm::ProfileForm(QWidget *parent) :
toxId->setReadOnly(true);
toxId->setFrame(false);
toxId->setFont(Style::getFont(Style::Small));
QVBoxLayout *toxIdGroup = qobject_cast<QVBoxLayout*>(bodyUI->toxGroup->layout());
toxIdGroup->replaceWidget(bodyUI->toxId, toxId);
bodyUI->toxId->hide();
bodyUI->toxGroup->layout()->addWidget(toxId);
profilePicture = new MaskablePixmapWidget(this, QSize(64, 64), ":/img/avatar_mask.png");
profilePicture->setPixmap(QPixmap(":/img/contact_dark.png"));
profilePicture->setClickable(true);
@ -172,10 +171,10 @@ void ProfileForm::setToxId(const QString& id)
toxId->setText(id);
toxId->setCursorPosition(0);
QRWidget *qrcode = new QRWidget();
qrcode->setQRData(id);
toxId->setToolTip(qrcode->getImageAsText());
qr = new QRWidget();
qr->setQRData(id);
bodyUI->qrCode->setPixmap(QPixmap::fromImage(qr->getImage()->scaledToWidth(150)));
bodyUI->qrCode->setToolTip(qr->getImageAsText());
}
void ProfileForm::onAvatarClicked()
@ -376,3 +375,32 @@ void ProfileForm::showEvent(QShowEvent *event)
refreshProfiles();
QWidget::showEvent(event);
}
void ProfileForm::on_copyQr_clicked()
{
}
void ProfileForm::on_saveQr_clicked()
{
QString current = bodyUI->profiles->currentText() + ".png";
QString path = QFileDialog::getSaveFileName(0, tr("Save", "save qr image"),
QDir::home().filePath(current),
tr("Save QrCode (*.png)", "save dialog filter"));
if (!path.isEmpty())
{
bool success;
if (QFile::exists(path))
{
success = QFile::remove(path);
if (!success)
{
QMessageBox::warning(this, tr("Failed to remove file"), tr("The file you chose to overwrite could not be removed first."));
return;
}
}
success = qr->saveImage(path);
if (!success)
QMessageBox::warning(this, tr("Failed to copy file"), tr("The file you chose could not be written to."));
}
}

View File

@ -22,6 +22,7 @@
#include <QTimer>
#include <QVBoxLayout>
#include "src/core.h"
#include "src/misc/qrwidget.h"
class CroppingLabel;
class Core;
@ -36,7 +37,7 @@ class ClickableTE : public QLineEdit
{
Q_OBJECT
public:
signals:
void clicked();
protected:
@ -73,7 +74,10 @@ private slots:
void onNewClicked();
void disableSwitching();
void enableSwitching();
void on_copyQr_clicked();
void on_saveQr_clicked();
protected:
virtual void showEvent(QShowEvent *);
@ -85,6 +89,7 @@ private:
Core* core;
QTimer timer;
bool hasCheck = false;
QRWidget *qr;
ClickableTE* toxId;
};

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>439</width>
<height>472</height>
<width>442</width>
<height>659</height>
</rect>
</property>
<property name="windowTitle">
@ -39,8 +39,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>419</width>
<height>452</height>
<width>422</width>
<height>639</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,1">
@ -97,6 +97,52 @@ Share it with your friends to communicate.</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="toxId"/>
</item>
<item>
<widget class="QFrame" name="verticalFrame">
<layout class="QHBoxLayout" name="qrGroup">
<item>
<widget class="QLabel" name="qrCode">
<property name="text">
<string>QRCODE</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="horizontalFrame">
<layout class="QVBoxLayout" name="qrButtons">
<item alignment="Qt::AlignTop">
<widget class="QLabel" name="label">
<property name="text">
<string>Share this code, so friends can add you</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignVCenter">
<widget class="QPushButton" name="saveQr">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignVCenter">
<widget class="QPushButton" name="copyQr">
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
@ -212,7 +258,7 @@ Profile does not contain your history.</string>
<customwidget>
<class>CroppingLabel</class>
<extends>QLabel</extends>
<header>src/widget/croppinglabel.h</header>
<header location="global">src/widget/croppinglabel.h</header>
</customwidget>
</customwidgets>
<resources/>