Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#include <QtWidgets/QInputDialog>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QTextEdit>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now unused

#include <QtWidgets/QToolTip>
#include <QtWidgets/QWhatsThis>

Expand Down
41 changes: 41 additions & 0 deletions src/mumble/RichTextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QtGui/QImageReader>
#include <QtGui/QPainter>
#include <QtWidgets/QColorDialog>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QToolTip>

Expand Down Expand Up @@ -202,6 +203,7 @@ RichTextEditor::RichTextEditor(QWidget *p) : QTabWidget(p) {

qteRichText->installEventFilter(this);
qptePlainText->installEventFilter(this);
addContextMenuToSaveImages();
}

bool RichTextEditor::isModified() const {
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRichTextEdit is now unused


void RichTextEditor::addContextMenuToSaveImages() {
qteRichText->setContextMenuPolicy(Qt::CustomContextMenu);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice, if you move the setContextMenuPolicy initialization bit into the constructor.

Then move the connect to the constructor as well, referencing your new method. Something like this:

connect(qteRichText, &QTextEdit::customContextMenuRequested, this, addContextMenuToSaveImages)

and rename addContextMenuToSaveImages to something like addCustomContextMenuActions. That way we can add more actions in this method in the future.

QString saveText = tr("Save Image As…");
Copy link
Member

Choose a reason for hiding this comment

The 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, [=]() {
Copy link
Member

Choose a reason for hiding this comment

The 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
menu->addAction(saveText, [=]() {
menu->addAction(tr("Save Image As…"), [=]() {

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ and } for single line ifs

Suggested change
if (!fileName.isEmpty()) {
if (QFileInfo(fileName).suffix().isEmpty())
fileName += ".png"; // default to PNG if no extension
image.save(fileName);
}
if (!fileName.isEmpty()) {
if (QFileInfo(fileName).suffix().isEmpty()) {
fileName += ".png"; // default to PNG if no extension
}
image.save(fileName);
}

});
}

menu->exec(qteRichText->mapToGlobal(pos));
delete menu;
});
}
2 changes: 2 additions & 0 deletions src/mumble/RichTextEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class RichTextEditor : public QTabWidget, Ui::RichTextEditor {
RichTextEditor(QWidget *p = nullptr);
QString text();
bool isModified() const;
QTextEdit *getRichTextEdit();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRichTextEdit is now unused

void addContextMenuToSaveImages();
signals:
/// The accept signal is emitted when Ctrl-Enter is pressed inside the RichTextEditor.
void accept();
Expand Down
Loading