Skip to content
Permalink
Browse files

Add saving of images from chat log

  • Loading branch information...
bontibon authored and mkrautz committed Nov 22, 2015
1 parent 84b1bce commit b0c9521e4b5f743325380a67e6c68aa057cd635a
Showing with 43 additions and 0 deletions.
  1. +37 −0 src/mumble/MainWindow.cpp
  2. +6 −0 src/mumble/MainWindow.h
@@ -654,12 +654,49 @@ void MainWindow::on_qteLog_customContextMenuRequested(const QPoint &mpos) {

QPoint contentPosition = QPoint(QApplication::isRightToLeft() ? (qteLog->horizontalScrollBar()->maximum() - qteLog->horizontalScrollBar()->value()) : qteLog->horizontalScrollBar()->value(), qteLog->verticalScrollBar()->value());
QMenu *menu = qteLog->createStandardContextMenu(mpos + contentPosition);

QTextCursor cursor = qteLog->cursorForPosition(mpos);
QTextCharFormat fmt = cursor.charFormat();
if (fmt.objectType() == QTextFormat::NoObject) {
cursor.movePosition(QTextCursor::NextCharacter);
fmt = cursor.charFormat();
}
if (cursor.charFormat().isImageFormat()) {
menu->addSeparator();
menu->addAction(tr("Save Image As..."), this, SLOT(saveImageAs(void)));

qtcSaveImageCursor = cursor;
}

menu->addSeparator();
menu->addAction(tr("Clear"), qteLog, SLOT(clear(void)));
menu->exec(qteLog->mapToGlobal(mpos));
delete menu;
}

void MainWindow::saveImageAs() {
QDateTime now = QDateTime::currentDateTime();
QString defaultFname = QString::fromLatin1("Mumble-%1.jpg").arg(now.toString(QString::fromLatin1("yyyy-MM-dd-HHmmss")));

QString fname = QFileDialog::getSaveFileName(this, tr("Save Image File"), defaultFname, tr("Images (*.png *.jpg *.jpeg)"));
if (fname.isNull()) {
return;
}

QString resName = qtcSaveImageCursor.charFormat().toImageFormat().name();
QVariant res = qteLog->document()->resource(QTextDocument::ImageResource, resName);
QImage img = res.value<QImage>();
bool ok = img.save(fname);
if (!ok) {
// In case fname did not contain a file extension, try saving with an
// explicit format.
ok = img.save(fname, "JPG");
}
if (!ok) {
g.l->log(Log::Warning, tr("Could not save image: %1").arg(Qt::escape(fname)));
}
}

static void recreateServerHandler() {
ServerHandlerPtr sh = g.sh;
if (sh && sh->isRunning()) {
@@ -121,6 +121,10 @@ class MainWindow : public QMainWindow, public MessageHandler, public Ui::MainWin
bool restartOnQuit;
bool bAutoUnmute;

/// Contains the cursor whose position is immediately before the image to
/// save when activating the "Save Image As..." context menu item.
QTextCursor qtcSaveImageCursor;

#if QT_VERSION >= 0x050000
QPointer<Channel> cContextChannel;
QPointer<ClientUser> cuContextUser;
@@ -292,6 +296,8 @@ class MainWindow : public QMainWindow, public MessageHandler, public Ui::MainWin
void whisperReleased(QVariant scdata);
void onResetAudio();
void on_qaFilterToggle_triggered();
/// Opens a save dialog for the image referenced by qtcSaveImageCursor.
void saveImageAs();

public:
MainWindow(QWidget *parent);

0 comments on commit b0c9521

Please sign in to comment.
You can’t perform that action at this time.