mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 18:02:13 +02:00
removed snapshot share dialog, ctrl s shouldn't leave you moving
This commit is contained in:
parent
ae54399177
commit
218b26b521
6 changed files with 6 additions and 301 deletions
|
@ -1,117 +0,0 @@
|
|||
import QtQuick 2.5
|
||||
import QtQuick.Controls 1.4
|
||||
import QtQuick.Controls.Styles 1.4
|
||||
import QtQuick.XmlListModel 2.0
|
||||
|
||||
import "../../windows"
|
||||
import "../../js/Utils.js" as Utils
|
||||
import "../models"
|
||||
|
||||
Window {
|
||||
id: root
|
||||
resizable: true
|
||||
width: 516
|
||||
height: 616
|
||||
minSize: Qt.vector2d(500, 600);
|
||||
maxSize: Qt.vector2d(1000, 800);
|
||||
|
||||
property alias source: image.source
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: "white"
|
||||
|
||||
Item {
|
||||
anchors { fill: parent; margins: 8 }
|
||||
|
||||
Image {
|
||||
id: image
|
||||
anchors { top: parent.top; left: parent.left; right: parent.right; bottom: notesLabel.top; bottomMargin: 8 }
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
|
||||
Text {
|
||||
id: notesLabel
|
||||
anchors { left: parent.left; bottom: notes.top; bottomMargin: 8; }
|
||||
text: "Notes about this image"
|
||||
font.pointSize: 14
|
||||
font.bold: true
|
||||
color: "#666"
|
||||
}
|
||||
|
||||
TextArea {
|
||||
id: notes
|
||||
anchors { left: parent.left; bottom: parent.bottom; right: shareButton.left; rightMargin: 8 }
|
||||
height: 60
|
||||
}
|
||||
|
||||
Button {
|
||||
id: shareButton
|
||||
anchors { verticalCenter: notes.verticalCenter; right: parent.right; }
|
||||
width: 120; height: 50
|
||||
text: "Share"
|
||||
|
||||
style: ButtonStyle {
|
||||
background: Rectangle {
|
||||
implicitWidth: 120
|
||||
implicitHeight: 50
|
||||
border.width: control.activeFocus ? 2 : 1
|
||||
color: "#333"
|
||||
radius: 9
|
||||
}
|
||||
label: Text {
|
||||
color: shareButton.enabled ? "white" : "gray"
|
||||
font.pixelSize: 18
|
||||
font.bold: true
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
anchors.fill: parent
|
||||
text: shareButton.text
|
||||
}
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
enabled = false;
|
||||
uploadTimer.start();
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: uploadTimer
|
||||
running: false
|
||||
interval: 5
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
var uploaded = SnapshotUploader.uploadSnapshot(root.source.toString())
|
||||
console.log("Uploaded result " + uploaded)
|
||||
if (!uploaded) {
|
||||
console.log("Upload failed ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Action {
|
||||
id: shareAction
|
||||
text: qsTr("OK")
|
||||
enabled: root.result ? true : false
|
||||
shortcut: Qt.Key_Return
|
||||
onTriggered: {
|
||||
root.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
Action {
|
||||
id: cancelAction
|
||||
text: qsTr("Cancel")
|
||||
shortcut: Qt.Key_Escape
|
||||
onTriggered: {
|
||||
root.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -1517,7 +1517,6 @@ void Application::initializeUi() {
|
|||
|
||||
// For some reason there is already an "Application" object in the QML context,
|
||||
// though I can't find it. Hence, "ApplicationInterface"
|
||||
rootContext->setContextProperty("SnapshotUploader", new SnapshotUploader());
|
||||
rootContext->setContextProperty("ApplicationInterface", this);
|
||||
rootContext->setContextProperty("Audio", &AudioScriptingInterface::getInstance());
|
||||
rootContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
|
||||
|
@ -4989,16 +4988,7 @@ void Application::takeSnapshot() {
|
|||
player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath()));
|
||||
player->play();
|
||||
|
||||
QString fileName = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot());
|
||||
|
||||
auto accountManager = DependencyManager::get<AccountManager>();
|
||||
if (!accountManager->isLoggedIn()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DependencyManager::get<OffscreenUi>()->load("hifi/dialogs/SnapshotShareDialog.qml", [=](QQmlContext*, QObject* dialog) {
|
||||
dialog->setProperty("source", QUrl::fromLocalFile(fileName));
|
||||
});
|
||||
Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot());
|
||||
}
|
||||
|
||||
float Application::getRenderResolutionScale() const {
|
||||
|
|
|
@ -133,118 +133,3 @@ QFile* Snapshot::savedFileForSnapshot(QImage & shot, bool isTemporary) {
|
|||
return imageTempFile;
|
||||
}
|
||||
}
|
||||
|
||||
const QString FORUM_URL = "https://alphas.highfidelity.io";
|
||||
const QString FORUM_UPLOADS_URL = FORUM_URL + "/uploads";
|
||||
const QString FORUM_POST_URL = FORUM_URL + "/posts";
|
||||
const QString FORUM_REPLY_TO_TOPIC = "244";
|
||||
const QString FORUM_POST_TEMPLATE = "<img src='%1'/><p>%2</p>";
|
||||
const QString SHARE_DEFAULT_ERROR = "The server isn't responding. Please try again in a few minutes.";
|
||||
const QString SUCCESS_LABEL_TEMPLATE = "Success!!! Go check out your image ...<br/><a style='color:#333;text-decoration:none' href='%1'>%1</a>";
|
||||
|
||||
|
||||
QString SnapshotUploader::uploadSnapshot(const QUrl& fileUrl) {
|
||||
auto accountManager = DependencyManager::get<AccountManager>();
|
||||
if (accountManager->getAccountInfo().getDiscourseApiKey().isEmpty()) {
|
||||
OffscreenUi::warning(nullptr, "", "Your Discourse API key is missing, you cannot share snapshots. Please try to relog.");
|
||||
return QString();
|
||||
}
|
||||
|
||||
QHttpPart apiKeyPart;
|
||||
apiKeyPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"api_key\""));
|
||||
apiKeyPart.setBody(accountManager->getAccountInfo().getDiscourseApiKey().toLatin1());
|
||||
|
||||
QString filename = fileUrl.toLocalFile();
|
||||
qDebug() << filename;
|
||||
QFile* file = new QFile(filename);
|
||||
Q_ASSERT(file->exists());
|
||||
file->open(QIODevice::ReadOnly);
|
||||
|
||||
QHttpPart imagePart;
|
||||
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
|
||||
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader,
|
||||
QVariant("form-data; name=\"file\"; filename=\"" + file->fileName() + "\""));
|
||||
imagePart.setBodyDevice(file);
|
||||
|
||||
QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
||||
file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
|
||||
multiPart->append(apiKeyPart);
|
||||
multiPart->append(imagePart);
|
||||
|
||||
QUrl url(FORUM_UPLOADS_URL);
|
||||
QNetworkRequest request(url);
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
|
||||
QString result;
|
||||
QEventLoop loop;
|
||||
|
||||
QSharedPointer<QNetworkReply> reply(NetworkAccessManager::getInstance().post(request, multiPart));
|
||||
QObject::connect(reply.data(), &QNetworkReply::finished, [&] {
|
||||
loop.quit();
|
||||
|
||||
qDebug() << reply->errorString();
|
||||
for (const auto& header : reply->rawHeaderList()) {
|
||||
qDebug() << "Header " << QString(header);
|
||||
}
|
||||
auto replyResult = reply->readAll();
|
||||
qDebug() << QString(replyResult);
|
||||
QJsonDocument jsonResponse = QJsonDocument::fromJson(replyResult);
|
||||
const QJsonObject& responseObject = jsonResponse.object();
|
||||
if (!responseObject.contains("url")) {
|
||||
OffscreenUi::warning(this, "", SHARE_DEFAULT_ERROR);
|
||||
return;
|
||||
}
|
||||
result = responseObject["url"].toString();
|
||||
});
|
||||
loop.exec();
|
||||
return result;
|
||||
}
|
||||
|
||||
QString SnapshotUploader::sendForumPost(const QString& snapshotPath, const QString& notes) {
|
||||
// post to Discourse forum
|
||||
QNetworkRequest request;
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
QUrl forumUrl(FORUM_POST_URL);
|
||||
|
||||
QUrlQuery query;
|
||||
query.addQueryItem("api_key", DependencyManager::get<AccountManager>()->getAccountInfo().getDiscourseApiKey());
|
||||
query.addQueryItem("topic_id", FORUM_REPLY_TO_TOPIC);
|
||||
query.addQueryItem("raw", FORUM_POST_TEMPLATE.arg(snapshotPath, notes));
|
||||
forumUrl.setQuery(query);
|
||||
|
||||
QByteArray postData = forumUrl.toEncoded(QUrl::RemoveFragment);
|
||||
request.setUrl(forumUrl);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
|
||||
QNetworkReply* requestReply = NetworkAccessManager::getInstance().post(request, postData);
|
||||
|
||||
QEventLoop loop;
|
||||
QString result;
|
||||
connect(requestReply, &QNetworkReply::finished, [&] {
|
||||
loop.quit();
|
||||
QJsonDocument jsonResponse = QJsonDocument::fromJson(requestReply->readAll());
|
||||
requestReply->deleteLater();
|
||||
const QJsonObject& responseObject = jsonResponse.object();
|
||||
|
||||
if (!responseObject.contains("id")) {
|
||||
QString errorMessage(SHARE_DEFAULT_ERROR);
|
||||
if (responseObject.contains("errors")) {
|
||||
QJsonArray errorArray = responseObject["errors"].toArray();
|
||||
if (!errorArray.first().toString().isEmpty()) {
|
||||
errorMessage = errorArray.first().toString();
|
||||
}
|
||||
}
|
||||
OffscreenUi::warning(this, "", errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
const QString urlTemplate = "%1/t/%2/%3/%4";
|
||||
result = urlTemplate.arg(FORUM_URL,
|
||||
responseObject["topic_slug"].toString(),
|
||||
QString::number(responseObject["topic_id"].toDouble()),
|
||||
QString::number(responseObject["post_number"].toDouble()));
|
||||
});
|
||||
loop.exec();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,12 +43,4 @@ private:
|
|||
static QFile* savedFileForSnapshot(QImage & image, bool isTemporary);
|
||||
};
|
||||
|
||||
class SnapshotUploader : public QObject{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SnapshotUploader(QObject* parent = nullptr) : QObject(parent) {}
|
||||
Q_INVOKABLE QString uploadSnapshot(const QUrl& fileUrl);
|
||||
Q_INVOKABLE QString sendForumPost(const QString& snapshotPath, const QString& notes);
|
||||
};
|
||||
|
||||
#endif // hifi_Snapshot_h
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
//
|
||||
// SnapshotShareDialog.cpp
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Stojce Slavkovski on 2/16/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#if 0
|
||||
|
||||
|
||||
#include <OffscreenUi.h>
|
||||
|
||||
const int NARROW_SNAPSHOT_DIALOG_SIZE = 500;
|
||||
const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650;
|
||||
const int SUCCESS_LABEL_HEIGHT = 140;
|
||||
|
||||
const QString SHARE_BUTTON_STYLE = "border-width:0;border-radius:9px;border-radius:9px;font-family:Arial;font-size:18px;"
|
||||
"font-weight:100;color:#FFFFFF;width: 120px;height: 50px;";
|
||||
const QString SHARE_BUTTON_ENABLED_STYLE = "background-color: #333;";
|
||||
const QString SHARE_BUTTON_DISABLED_STYLE = "background-color: #999;";
|
||||
|
||||
Q_DECLARE_METATYPE(QNetworkAccessManager::Operation)
|
||||
|
||||
SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) :
|
||||
QDialog(parent),
|
||||
_fileName(fileName)
|
||||
{
|
||||
|
||||
|
||||
_ui.snapshotWidget->setPixmap(snaphsotPixmap);
|
||||
_ui.snapshotWidget->adjustSize();
|
||||
}
|
||||
|
||||
void SnapshotShareDialog::accept() {
|
||||
// prevent multiple clicks on share button
|
||||
_ui.shareButton->setEnabled(false);
|
||||
// gray out share button
|
||||
_ui.shareButton->setStyleSheet(SHARE_BUTTON_STYLE + SHARE_BUTTON_DISABLED_STYLE);
|
||||
uploadSnapshot();
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -49,9 +49,11 @@ void KeyboardMouseDevice::InputDevice::focusOutEvent() {
|
|||
|
||||
void KeyboardMouseDevice::keyPressEvent(QKeyEvent* event) {
|
||||
auto input = _inputDevice->makeInput((Qt::Key) event->key());
|
||||
auto result = _inputDevice->_buttonPressedMap.insert(input.getChannel());
|
||||
if (!result.second) {
|
||||
// key pressed again ? without catching the release event ?
|
||||
if (!(event->modifiers() & Qt::KeyboardModifier::ControlModifier)) {
|
||||
auto result = _inputDevice->_buttonPressedMap.insert(input.getChannel());
|
||||
if (result.second) {
|
||||
// key pressed again ? without catching the release event ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue