QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
To copy to clipboard, switch view to plain text mode
#include "minecraftskindownloader.h"
#include "ui_minecraftskindownloader.h"
#include "nouser.h"
#include <QWidget>
#include <QObject>
#include <QtNetwork/QNetworkAccessManager>
#include <QFileDialog>
#include <QtNetwork/QNetworkRequest>
#include <QDebug>
#include <QUrl>
#include <QFile>
#include <QPixmap>
#include <QMessageBox>
MinecraftSkinDownloader
::MinecraftSkinDownloader(QWidget *parent
) : ui(new Ui::MinecraftSkinDownloader)
{
ui->setupUi(this);
this->setWindowTitle("Minecraft Skin Downloader");
setFixedSize(400, 200);
setStyleSheet("QMainWindow { background-image: url(:/bg.png); } ");
connect(ui->save, SIGNAL(clicked()), this, SLOT(onsaveAs_clicked()));
}
MinecraftSkinDownloader::~MinecraftSkinDownloader()
{
delete ui;
}
//http://s3.amazonaws.com/MinecraftSkins/USERNAMEHERE.png
void MinecraftSkinDownloader::on_pushButton_clicked()
{
QString prefix
= "http://s3.amazonaws.com/MinecraftSkins/";
QString usrl
= prefix
+= ui
->lineEdit
->text
() += ".png";
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slot_netwManagerFinished(QNetworkReply*)));
QNetworkRequest request(url);
manager->get(request);
}
void MinecraftSkinDownloader::slot_netwManagerFinished(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError)
{
qDebug() << "Error in" << reply->url() << ":" << reply->errorString();
NoUser mDiag;
mDiag.setModal(true);
mDiag.exec();
return;
}
MinecraftSkinDownloader::pngData = reply->readAll();
pixmap.loadFromData(MinecraftSkinDownloader::pngData);
QPixmap scaled
= pixmap.
scaled(128,
64,Qt
::IgnoreAspectRatio, Qt
::FastTransformation);
ui->preview->show();
ui->preview->setStyleSheet("QLabel { background-color: white; }");
ui->preview->setPixmap(scaled);
reply->deleteLater();
}
void MinecraftSkinDownloader::onsaveAs_clicked()
{
QString filename
= QFileDialog::getSaveFileName(this, tr
("Save Skin"),
"C:/Users/",
("PNG Image (*.png)"));
file.write(MinecraftSkinDownloader::pngData);
file.close();
}
void MinecraftSkinDownloader::on_pushButton_2_clicked()
{
ui->lineEdit->clear();
ui->preview->hide();
}
#include "minecraftskindownloader.h"
#include "ui_minecraftskindownloader.h"
#include "nouser.h"
#include <QWidget>
#include <QObject>
#include <QtNetwork/QNetworkAccessManager>
#include <QFileDialog>
#include <QtNetwork/QNetworkRequest>
#include <QDebug>
#include <QUrl>
#include <QFile>
#include <QPixmap>
#include <QMessageBox>
MinecraftSkinDownloader::MinecraftSkinDownloader(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MinecraftSkinDownloader)
{
ui->setupUi(this);
this->setWindowTitle("Minecraft Skin Downloader");
setFixedSize(400, 200);
setStyleSheet("QMainWindow { background-image: url(:/bg.png); } ");
connect(ui->save, SIGNAL(clicked()), this, SLOT(onsaveAs_clicked()));
}
MinecraftSkinDownloader::~MinecraftSkinDownloader()
{
delete ui;
}
//http://s3.amazonaws.com/MinecraftSkins/USERNAMEHERE.png
void MinecraftSkinDownloader::on_pushButton_clicked()
{
QString prefix = "http://s3.amazonaws.com/MinecraftSkins/";
QString usrl = prefix += ui->lineEdit->text() += ".png";
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slot_netwManagerFinished(QNetworkReply*)));
QUrl url(usrl);
QNetworkRequest request(url);
manager->get(request);
}
void MinecraftSkinDownloader::slot_netwManagerFinished(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError)
{
qDebug() << "Error in" << reply->url() << ":" << reply->errorString();
NoUser mDiag;
mDiag.setModal(true);
mDiag.exec();
return;
}
MinecraftSkinDownloader::pngData = reply->readAll();
QPixmap pixmap;
pixmap.loadFromData(MinecraftSkinDownloader::pngData);
QPixmap scaled = pixmap.scaled(128,64,Qt::IgnoreAspectRatio, Qt::FastTransformation);
ui->preview->show();
ui->preview->setStyleSheet("QLabel { background-color: white; }");
ui->preview->setPixmap(scaled);
reply->deleteLater();
}
void MinecraftSkinDownloader::onsaveAs_clicked()
{
QString filename = QFileDialog::getSaveFileName(this, tr("Save Skin"), "C:/Users/", ("PNG Image (*.png)"));
QFile file(filename);
file.open(QIODevice::WriteOnly);
file.write(MinecraftSkinDownloader::pngData);
file.close();
}
void MinecraftSkinDownloader::on_pushButton_2_clicked()
{
ui->lineEdit->clear();
ui->preview->hide();
}
To copy to clipboard, switch view to plain text mode
Bookmarks