-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
FEAT(client): Adding Save Image Functionality to View Comment (other users) and change comment (self) #6794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
83c23d1
62c8257
2deb32a
50c0d6b
299456f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |||||||||||||||||||||||
| #include <QtGui/QImageReader> | ||||||||||||||||||||||||
| #include <QtGui/QPainter> | ||||||||||||||||||||||||
| #include <QtWidgets/QColorDialog> | ||||||||||||||||||||||||
| #include <QtWidgets/QFileDialog> | ||||||||||||||||||||||||
| #include <QtWidgets/QMessageBox> | ||||||||||||||||||||||||
| #include <QtWidgets/QToolTip> | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -202,6 +203,7 @@ RichTextEditor::RichTextEditor(QWidget *p) : QTabWidget(p) { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| qteRichText->installEventFilter(this); | ||||||||||||||||||||||||
| qptePlainText->installEventFilter(this); | ||||||||||||||||||||||||
| addContextMenuToSaveImages(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| bool RichTextEditor::isModified() const { | ||||||||||||||||||||||||
|
|
@@ -467,3 +469,42 @@ bool RichTextImage::isValidImage(const QByteArray &ba, QByteArray &fmt) { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| QTextEdit *RichTextEditor::getRichTextEdit() { | ||||||||||||||||||||||||
| return qteRichText; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+473
to
+475
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| void RichTextEditor::addContextMenuToSaveImages() { | ||||||||||||||||||||||||
| qteRichText->setContextMenuPolicy(Qt::CustomContextMenu); | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice, if you move the Then move the
and rename |
||||||||||||||||||||||||
| QString saveText = tr("Save Image As…"); | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't know what your thinking was behind this, but I would rather still have this inline with the action creation |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| connect(qteRichText, &QTextEdit::customContextMenuRequested, this, [=](const QPoint &pos) { | ||||||||||||||||||||||||
| QTextCursor cursor = qteRichText->cursorForPosition(pos); | ||||||||||||||||||||||||
| QTextCharFormat format = cursor.charFormat(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| QMenu *menu = qteRichText->createStandardContextMenu(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (format.isImageFormat()) { | ||||||||||||||||||||||||
| menu->addSeparator(); | ||||||||||||||||||||||||
| menu->addAction(saveText, [=]() { | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't know what your thinking was behind this, but I would rather still have this inline with the action creation
Suggested change
|
||||||||||||||||||||||||
| QTextImageFormat imgFmt = format.toImageFormat(); | ||||||||||||||||||||||||
| QString imgName = imgFmt.name(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| QImage image = | ||||||||||||||||||||||||
| qteRichText->document()->resource(QTextDocument::ImageResource, QUrl(imgName)).value< QImage >(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| QString fileName = QFileDialog::getSaveFileName(this, "Save Image", "", | ||||||||||||||||||||||||
| "Images (*.png *.jpg *.jpeg *.bmp *.ppm *.xbm *.xpm)"); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (!fileName.isEmpty()) { | ||||||||||||||||||||||||
| if (QFileInfo(fileName).suffix().isEmpty()) | ||||||||||||||||||||||||
| fileName += ".png"; // default to PNG if no extension | ||||||||||||||||||||||||
| image.save(fileName); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+499
to
+503
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| menu->exec(qteRichText->mapToGlobal(pos)); | ||||||||||||||||||||||||
| delete menu; | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,8 @@ class RichTextEditor : public QTabWidget, Ui::RichTextEditor { | |
| RichTextEditor(QWidget *p = nullptr); | ||
| QString text(); | ||
| bool isModified() const; | ||
| QTextEdit *getRichTextEdit(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| void addContextMenuToSaveImages(); | ||
| signals: | ||
| /// The accept signal is emitted when Ctrl-Enter is pressed inside the RichTextEditor. | ||
| void accept(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now unused