diff --git a/icons.qrc b/icons.qrc index 7ec5613..5a86713 100644 --- a/icons.qrc +++ b/icons.qrc @@ -12,5 +12,6 @@ resources/icons/upload.png resources/icon.png resources/app.ico + resources/icons/search.png diff --git a/include/editor.h b/include/editor.h index 8557262..94fe969 100644 --- a/include/editor.h +++ b/include/editor.h @@ -33,6 +33,7 @@ class Editor : public QWidget { void saveRequested(); void copyRequested(); void publishRequested(); + void searchRequested(); void closeRequested(); public slots: diff --git a/include/screenshotdisplay.h b/include/screenshotdisplay.h index ee864a8..3c42e82 100644 --- a/include/screenshotdisplay.h +++ b/include/screenshotdisplay.h @@ -46,7 +46,7 @@ class ScreenshotDisplay : public QWidget { private slots: void onToolSelected(Editor::Tool tool); void onSaveRequested(); - void onPublishRequested(); + void onPublishRequested(bool searchImage); void onCloseRequested(); void copySelectionToClipboard(); void undo(); diff --git a/include/utils.h b/include/utils.h index 9be46bd..4e7f50b 100644 --- a/include/utils.h +++ b/include/utils.h @@ -14,6 +14,6 @@ void clearLoginInfo(); void setAutoStart(bool enable); -//const QString SCREEN_ME_HOST = "http://127.0.0.1:3001"; -const QString SCREEN_ME_HOST = "https://screen-me.cloud"; -const QString VERSION = "1.2.21"; \ No newline at end of file +const QString SCREEN_ME_HOST = "http://127.0.0.1:3001"; +//const QString SCREEN_ME_HOST = "https://screen-me.cloud"; +const QString VERSION = "1.3.01"; \ No newline at end of file diff --git a/resources/icons/search.png b/resources/icons/search.png new file mode 100644 index 0000000..86f8d1a Binary files /dev/null and b/resources/icons/search.png differ diff --git a/src/editor.cpp b/src/editor.cpp index 9c991c2..d8c02c7 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -30,6 +30,7 @@ Editor::Editor(QWidget* parent) createActionButton("Save", QIcon(":/resources/icons/save.png"), "saveRequested"); createActionButton("Copy to clipboard (CTRL + C)", QIcon(":/resources/icons/copy.png"), "copyRequested"); createActionButton("Upload to ScreenMe", QIcon(":/resources/icons/upload.png"), "publishRequested"); + createActionButton("Find similar image", QIcon(":/resources/icons/search.png"), "searchRequested"); createActionButton("Close editor", QIcon(":/resources/icons/close.png"), "closeRequested"); layout->addLayout(actionLayout); } diff --git a/src/screenshotdisplay.cpp b/src/screenshotdisplay.cpp index b693546..af3f1e9 100644 --- a/src/screenshotdisplay.cpp +++ b/src/screenshotdisplay.cpp @@ -31,9 +31,17 @@ ScreenshotDisplay::ScreenshotDisplay(const QPixmap& pixmap, QWidget* parent, Con setWindowIcon(QIcon("resources/icon.png")); setAttribute(Qt::WA_QuitOnClose, false); - QScreen* screen = QApplication::primaryScreen(); - QRect screenGeometry = screen->geometry(); - setGeometry(screenGeometry); + QRect totalGeometry; + const auto screens = QGuiApplication::screens(); + for (QScreen* scr : screens) { + totalGeometry = totalGeometry.united(scr->geometry()); + } + + if (totalGeometry.x() < 0 || totalGeometry.y() < 0) { + totalGeometry.translate(-totalGeometry.x(), -totalGeometry.y()); + } + + setGeometry(totalGeometry); initializeEditor(); configureShortcuts(); @@ -41,7 +49,7 @@ ScreenshotDisplay::ScreenshotDisplay(const QPixmap& pixmap, QWidget* parent, Con drawingPixmap.fill(Qt::transparent); QFontMetrics fm(currentFont); textBoundingRect = QRect(QPoint(100, 100), fm.size(0, text)); - showFullScreen(); + show(); } void ScreenshotDisplay::initializeEditor() { @@ -56,7 +64,12 @@ void ScreenshotDisplay::initializeEditor() { }); connect(editor.get(), &Editor::saveRequested, this, &ScreenshotDisplay::onSaveRequested); connect(editor.get(), &Editor::copyRequested, this, &ScreenshotDisplay::copySelectionToClipboard); - connect(editor.get(), &Editor::publishRequested, this, &ScreenshotDisplay::onPublishRequested); + connect(editor.get(), &Editor::publishRequested, this, [this]() { + onPublishRequested(false); + }); + connect(editor.get(), &Editor::searchRequested, this, [this]() { + onPublishRequested(true); + }); connect(editor.get(), &Editor::closeRequested, this, &ScreenshotDisplay::onCloseRequested); } @@ -377,7 +390,7 @@ void ScreenshotDisplay::onSaveRequested() { } } -void ScreenshotDisplay::onPublishRequested() { +void ScreenshotDisplay::onPublishRequested(bool searchImage) { if (textEdit) { finalizeTextEdit(); } @@ -459,7 +472,7 @@ void ScreenshotDisplay::onPublishRequested() { qDebug() << "Network Error:" << reply->errorString(); }); - connect(reply, &QNetworkReply::finished, this, [reply, file, tempFilePath, this, progressDialog, screenGeometry, loginInfo]() { + connect(reply, &QNetworkReply::finished, this, [reply, file, tempFilePath, this, progressDialog, searchImage, screenGeometry, loginInfo]() { progressDialog->close(); if (reply->error() == QNetworkReply::NoError) { @@ -469,51 +482,58 @@ void ScreenshotDisplay::onPublishRequested() { QString url = jsonObject["url"].toString(); QString id = QString::number(jsonObject["id"].toInt()); QString link = SCREEN_ME_HOST + "/" + url; - - QMessageBox msgBox(this); - msgBox.setWindowTitle("Screenshot Uploaded"); - msgBox.setText("Screenshot uploaded successfully ! Link: " + link); - QPushButton* copyButton = msgBox.addButton(tr("Copy"), QMessageBox::ActionRole); - QPushButton* openButton = msgBox.addButton(tr("Open"), QMessageBox::ActionRole); - msgBox.addButton(QMessageBox::Ok); - - QCheckBox* privateCheckBox = nullptr; - if (!loginInfo["token"].toString().isEmpty()) { - privateCheckBox = new QCheckBox("Private", &msgBox); - msgBox.setCheckBox(privateCheckBox); - - connect(privateCheckBox, &QCheckBox::toggled, this, [id, loginInfo](bool checked) { - QNetworkAccessManager* manager = new QNetworkAccessManager(); - QUrl url(SCREEN_ME_HOST + "/api/screenshot/" + id); - QNetworkRequest request(url); - - request.setRawHeader("Authorization", "Bearer " + loginInfo["token"].toString().toUtf8()); - request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - - QJsonObject json; - json["privacy"] = checked ? "private" : "public"; - QJsonDocument doc(json); - QByteArray data = doc.toJson(); - - QNetworkReply* reply = manager->sendCustomRequest(request, "PATCH", data); - connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); - }); + QString imageUrl = jsonObject["imageUrl"].toString(); + + if (!searchImage) { + QMessageBox msgBox(this); + msgBox.setWindowTitle("Screenshot Uploaded"); + msgBox.setText("Screenshot uploaded successfully ! Link: " + link); + QPushButton* copyButton = msgBox.addButton(tr("Copy"), QMessageBox::ActionRole); + QPushButton* openButton = msgBox.addButton(tr("Open"), QMessageBox::ActionRole); + msgBox.addButton(QMessageBox::Ok); + + QCheckBox* privateCheckBox = nullptr; + if (!loginInfo["token"].toString().isEmpty()) { + privateCheckBox = new QCheckBox("Private", &msgBox); + msgBox.setCheckBox(privateCheckBox); + + connect(privateCheckBox, &QCheckBox::toggled, this, [id, loginInfo](bool checked) { + QNetworkAccessManager* manager = new QNetworkAccessManager(); + QUrl url(SCREEN_ME_HOST + "/api/screenshot/" + id); + QNetworkRequest request(url); + + request.setRawHeader("Authorization", "Bearer " + loginInfo["token"].toString().toUtf8()); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + + QJsonObject json; + json["privacy"] = checked ? "private" : "public"; + QJsonDocument doc(json); + QByteArray data = doc.toJson(); + + QNetworkReply* reply = manager->sendCustomRequest(request, "PATCH", data); + connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); + }); + } + + connect(copyButton, &QPushButton::clicked, [link]() { + QClipboard* clipboard = QGuiApplication::clipboard(); + clipboard->setText(link); + }); + + connect(openButton, &QPushButton::clicked, [link]() { + QDesktopServices::openUrl(QUrl(link)); + }); + + // Position the message box at the bottom right of the screen + msgBox.show(); + QSize msgBoxSize = msgBox.sizeHint(); + msgBox.move(screenGeometry.bottomRight() - QPoint(msgBoxSize.width() + 10, msgBoxSize.height() + 100)); + msgBox.exec(); } - - connect(copyButton, &QPushButton::clicked, [link]() { - QClipboard* clipboard = QGuiApplication::clipboard(); - clipboard->setText(link); - }); - - connect(openButton, &QPushButton::clicked, [link]() { - QDesktopServices::openUrl(QUrl(link)); - }); - - // Position the message box at the bottom right of the screen - msgBox.show(); - QSize msgBoxSize = msgBox.sizeHint(); - msgBox.move(screenGeometry.bottomRight() - QPoint(msgBoxSize.width() + 10, msgBoxSize.height() + 100)); - msgBox.exec(); + else { + QDesktopServices::openUrl(QUrl("https://tineye.com/search?url=" + imageUrl)); + } + } else { QString errorString = reply->errorString();