Skip to content

Commit a9a35c4

Browse files
authored
Merge pull request #8 from Sorok-Dva/feat/findSimilarImages
🚀 feat: find similar image
2 parents 4802860 + 9089eb1 commit a9a35c4

File tree

7 files changed

+78
-55
lines changed

7 files changed

+78
-55
lines changed

icons.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
<file>resources/icons/upload.png</file>
1313
<file>resources/icon.png</file>
1414
<file>resources/app.ico</file>
15+
<file>resources/icons/search.png</file>
1516
</qresource>
1617
</RCC>

include/editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Editor : public QWidget {
3333
void saveRequested();
3434
void copyRequested();
3535
void publishRequested();
36+
void searchRequested();
3637
void closeRequested();
3738

3839
public slots:

include/screenshotdisplay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ScreenshotDisplay : public QWidget {
4646
private slots:
4747
void onToolSelected(Editor::Tool tool);
4848
void onSaveRequested();
49-
void onPublishRequested();
49+
void onPublishRequested(bool searchImage);
5050
void onCloseRequested();
5151
void copySelectionToClipboard();
5252
void undo();

include/utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ void clearLoginInfo();
1414
void setAutoStart(bool enable);
1515

1616

17-
//const QString SCREEN_ME_HOST = "http://127.0.0.1:3001";
18-
const QString SCREEN_ME_HOST = "https://screen-me.cloud";
19-
const QString VERSION = "1.2.21";
17+
const QString SCREEN_ME_HOST = "http://127.0.0.1:3001";
18+
//const QString SCREEN_ME_HOST = "https://screen-me.cloud";
19+
const QString VERSION = "1.3.01";

resources/icons/search.png

54.3 KB
Loading

src/editor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Editor::Editor(QWidget* parent)
3030
createActionButton("Save", QIcon(":/resources/icons/save.png"), "saveRequested");
3131
createActionButton("Copy to clipboard (CTRL + C)", QIcon(":/resources/icons/copy.png"), "copyRequested");
3232
createActionButton("Upload to ScreenMe", QIcon(":/resources/icons/upload.png"), "publishRequested");
33+
createActionButton("Find similar image", QIcon(":/resources/icons/search.png"), "searchRequested");
3334
createActionButton("Close editor", QIcon(":/resources/icons/close.png"), "closeRequested");
3435
layout->addLayout(actionLayout);
3536
}

src/screenshotdisplay.cpp

Lines changed: 71 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,25 @@ ScreenshotDisplay::ScreenshotDisplay(const QPixmap& pixmap, QWidget* parent, Con
3131
setWindowIcon(QIcon("resources/icon.png"));
3232
setAttribute(Qt::WA_QuitOnClose, false);
3333

34-
QScreen* screen = QApplication::primaryScreen();
35-
QRect screenGeometry = screen->geometry();
36-
setGeometry(screenGeometry);
34+
QRect totalGeometry;
35+
const auto screens = QGuiApplication::screens();
36+
for (QScreen* scr : screens) {
37+
totalGeometry = totalGeometry.united(scr->geometry());
38+
}
39+
40+
if (totalGeometry.x() < 0 || totalGeometry.y() < 0) {
41+
totalGeometry.translate(-totalGeometry.x(), -totalGeometry.y());
42+
}
43+
44+
setGeometry(totalGeometry);
3745

3846
initializeEditor();
3947
configureShortcuts();
4048

4149
drawingPixmap.fill(Qt::transparent);
4250
QFontMetrics fm(currentFont);
4351
textBoundingRect = QRect(QPoint(100, 100), fm.size(0, text));
44-
showFullScreen();
52+
show();
4553
}
4654

4755
void ScreenshotDisplay::initializeEditor() {
@@ -56,7 +64,12 @@ void ScreenshotDisplay::initializeEditor() {
5664
});
5765
connect(editor.get(), &Editor::saveRequested, this, &ScreenshotDisplay::onSaveRequested);
5866
connect(editor.get(), &Editor::copyRequested, this, &ScreenshotDisplay::copySelectionToClipboard);
59-
connect(editor.get(), &Editor::publishRequested, this, &ScreenshotDisplay::onPublishRequested);
67+
connect(editor.get(), &Editor::publishRequested, this, [this]() {
68+
onPublishRequested(false);
69+
});
70+
connect(editor.get(), &Editor::searchRequested, this, [this]() {
71+
onPublishRequested(true);
72+
});
6073
connect(editor.get(), &Editor::closeRequested, this, &ScreenshotDisplay::onCloseRequested);
6174
}
6275

@@ -377,7 +390,7 @@ void ScreenshotDisplay::onSaveRequested() {
377390
}
378391
}
379392

380-
void ScreenshotDisplay::onPublishRequested() {
393+
void ScreenshotDisplay::onPublishRequested(bool searchImage) {
381394
if (textEdit) {
382395
finalizeTextEdit();
383396
}
@@ -459,7 +472,7 @@ void ScreenshotDisplay::onPublishRequested() {
459472
qDebug() << "Network Error:" << reply->errorString();
460473
});
461474

462-
connect(reply, &QNetworkReply::finished, this, [reply, file, tempFilePath, this, progressDialog, screenGeometry, loginInfo]() {
475+
connect(reply, &QNetworkReply::finished, this, [reply, file, tempFilePath, this, progressDialog, searchImage, screenGeometry, loginInfo]() {
463476
progressDialog->close();
464477

465478
if (reply->error() == QNetworkReply::NoError) {
@@ -469,51 +482,58 @@ void ScreenshotDisplay::onPublishRequested() {
469482
QString url = jsonObject["url"].toString();
470483
QString id = QString::number(jsonObject["id"].toInt());
471484
QString link = SCREEN_ME_HOST + "/" + url;
472-
473-
QMessageBox msgBox(this);
474-
msgBox.setWindowTitle("Screenshot Uploaded");
475-
msgBox.setText("Screenshot uploaded successfully ! Link: " + link);
476-
QPushButton* copyButton = msgBox.addButton(tr("Copy"), QMessageBox::ActionRole);
477-
QPushButton* openButton = msgBox.addButton(tr("Open"), QMessageBox::ActionRole);
478-
msgBox.addButton(QMessageBox::Ok);
479-
480-
QCheckBox* privateCheckBox = nullptr;
481-
if (!loginInfo["token"].toString().isEmpty()) {
482-
privateCheckBox = new QCheckBox("Private", &msgBox);
483-
msgBox.setCheckBox(privateCheckBox);
484-
485-
connect(privateCheckBox, &QCheckBox::toggled, this, [id, loginInfo](bool checked) {
486-
QNetworkAccessManager* manager = new QNetworkAccessManager();
487-
QUrl url(SCREEN_ME_HOST + "/api/screenshot/" + id);
488-
QNetworkRequest request(url);
489-
490-
request.setRawHeader("Authorization", "Bearer " + loginInfo["token"].toString().toUtf8());
491-
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
492-
493-
QJsonObject json;
494-
json["privacy"] = checked ? "private" : "public";
495-
QJsonDocument doc(json);
496-
QByteArray data = doc.toJson();
497-
498-
QNetworkReply* reply = manager->sendCustomRequest(request, "PATCH", data);
499-
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
500-
});
485+
QString imageUrl = jsonObject["imageUrl"].toString();
486+
487+
if (!searchImage) {
488+
QMessageBox msgBox(this);
489+
msgBox.setWindowTitle("Screenshot Uploaded");
490+
msgBox.setText("Screenshot uploaded successfully ! Link: " + link);
491+
QPushButton* copyButton = msgBox.addButton(tr("Copy"), QMessageBox::ActionRole);
492+
QPushButton* openButton = msgBox.addButton(tr("Open"), QMessageBox::ActionRole);
493+
msgBox.addButton(QMessageBox::Ok);
494+
495+
QCheckBox* privateCheckBox = nullptr;
496+
if (!loginInfo["token"].toString().isEmpty()) {
497+
privateCheckBox = new QCheckBox("Private", &msgBox);
498+
msgBox.setCheckBox(privateCheckBox);
499+
500+
connect(privateCheckBox, &QCheckBox::toggled, this, [id, loginInfo](bool checked) {
501+
QNetworkAccessManager* manager = new QNetworkAccessManager();
502+
QUrl url(SCREEN_ME_HOST + "/api/screenshot/" + id);
503+
QNetworkRequest request(url);
504+
505+
request.setRawHeader("Authorization", "Bearer " + loginInfo["token"].toString().toUtf8());
506+
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
507+
508+
QJsonObject json;
509+
json["privacy"] = checked ? "private" : "public";
510+
QJsonDocument doc(json);
511+
QByteArray data = doc.toJson();
512+
513+
QNetworkReply* reply = manager->sendCustomRequest(request, "PATCH", data);
514+
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
515+
});
516+
}
517+
518+
connect(copyButton, &QPushButton::clicked, [link]() {
519+
QClipboard* clipboard = QGuiApplication::clipboard();
520+
clipboard->setText(link);
521+
});
522+
523+
connect(openButton, &QPushButton::clicked, [link]() {
524+
QDesktopServices::openUrl(QUrl(link));
525+
});
526+
527+
// Position the message box at the bottom right of the screen
528+
msgBox.show();
529+
QSize msgBoxSize = msgBox.sizeHint();
530+
msgBox.move(screenGeometry.bottomRight() - QPoint(msgBoxSize.width() + 10, msgBoxSize.height() + 100));
531+
msgBox.exec();
501532
}
502-
503-
connect(copyButton, &QPushButton::clicked, [link]() {
504-
QClipboard* clipboard = QGuiApplication::clipboard();
505-
clipboard->setText(link);
506-
});
507-
508-
connect(openButton, &QPushButton::clicked, [link]() {
509-
QDesktopServices::openUrl(QUrl(link));
510-
});
511-
512-
// Position the message box at the bottom right of the screen
513-
msgBox.show();
514-
QSize msgBoxSize = msgBox.sizeHint();
515-
msgBox.move(screenGeometry.bottomRight() - QPoint(msgBoxSize.width() + 10, msgBoxSize.height() + 100));
516-
msgBox.exec();
533+
else {
534+
QDesktopServices::openUrl(QUrl("https://tineye.com/search?url=" + imageUrl));
535+
}
536+
517537
}
518538
else {
519539
QString errorString = reply->errorString();

0 commit comments

Comments
 (0)