Skip to content

Commit

Permalink
Merge pull request #8 from Sorok-Dva/feat/findSimilarImages
Browse files Browse the repository at this point in the history
🚀 feat: find similar image
  • Loading branch information
Sorok-Dva authored Dec 8, 2024
2 parents 4802860 + 9089eb1 commit a9a35c4
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 55 deletions.
1 change: 1 addition & 0 deletions icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<file>resources/icons/upload.png</file>
<file>resources/icon.png</file>
<file>resources/app.ico</file>
<file>resources/icons/search.png</file>
</qresource>
</RCC>
1 change: 1 addition & 0 deletions include/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Editor : public QWidget {
void saveRequested();
void copyRequested();
void publishRequested();
void searchRequested();
void closeRequested();

public slots:
Expand Down
2 changes: 1 addition & 1 deletion include/screenshotdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
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";
Binary file added resources/icons/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
122 changes: 71 additions & 51 deletions src/screenshotdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@ 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();

drawingPixmap.fill(Qt::transparent);
QFontMetrics fm(currentFont);
textBoundingRect = QRect(QPoint(100, 100), fm.size(0, text));
showFullScreen();
show();
}

void ScreenshotDisplay::initializeEditor() {
Expand All @@ -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);
}

Expand Down Expand Up @@ -377,7 +390,7 @@ void ScreenshotDisplay::onSaveRequested() {
}
}

void ScreenshotDisplay::onPublishRequested() {
void ScreenshotDisplay::onPublishRequested(bool searchImage) {
if (textEdit) {
finalizeTextEdit();
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down

0 comments on commit a9a35c4

Please sign in to comment.