From b1ba96d51785c6ad919c4868cd5509d73e9b1e85 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 4 May 2012 15:29:22 +0900 Subject: [PATCH] add option to paste as pngs; compress pngs --- aqt/editor.py | 15 ++++++++++----- aqt/preferences.py | 2 ++ aqt/profiles.py | 1 + designer/preferences.ui | 14 +++++++++++--- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index ca92e6694..408aa46e0 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -1075,14 +1075,19 @@ class EditorWebView(AnkiWebView): def _processImage(self, mime): im = QImage(mime.imageData()) - name = namedtmp("paste-%d.png" % im.cacheKey()) + name = namedtmp("paste-%d" % im.cacheKey()) uname = unicode(name, sys.getfilesystemencoding()) - if im.hasAlphaChannel(): - im.save(uname) + if self.editor.mw.pm.profile.get("pastePNG", False): + ext = ".png" + im.save(uname+ext, None, 50) else: - im.save(uname, None, 95) + ext = ".jpg" + im.save(uname+ext, None, 80) + # invalid image? + if not os.path.exists(uname+ext): + return QMimeData() mime = QMimeData() - mime.setHtml(self.editor._addMedia(uname)) + mime.setHtml(self.editor._addMedia(uname+ext)) return mime def _retrieveURL(self, url): diff --git a/aqt/preferences.py b/aqt/preferences.py index 76a871c94..795bc3ffa 100644 --- a/aqt/preferences.py +++ b/aqt/preferences.py @@ -128,12 +128,14 @@ Not currently enabled; click the sync button in the main window to enable.""")) def setupOptions(self): self.form.stripHTML.setChecked(self.prof['stripHTML']) + self.form.pastePNG.setChecked(self.prof.get("pastePNG", False)) self.connect( self.form.profilePass, SIGNAL("clicked()"), self.onProfilePass) def updateOptions(self): self.prof['stripHTML'] = self.form.stripHTML.isChecked() + self.prof['pastePNG'] = self.form.pastePNG.isChecked() def onProfilePass(self): pw, ret = getText(_("""\ diff --git a/aqt/profiles.py b/aqt/profiles.py index a0ad36b39..cdbd6eea7 100644 --- a/aqt/profiles.py +++ b/aqt/profiles.py @@ -42,6 +42,7 @@ profileConf = dict( editFontFamily=fontForPlatform(), editFontSize=12, editLineSize=20, + pastePNG=False, # not exposed in gui deleteMedia=False, preserveKeyboard=True, diff --git a/designer/preferences.ui b/designer/preferences.ui index 753bb25b9..0f1ead375 100644 --- a/designer/preferences.ui +++ b/designer/preferences.ui @@ -44,6 +44,13 @@ + + + + Use the current deck as the default when adding notes + + + @@ -52,9 +59,9 @@ - + - Use the current deck as the default when adding notes + Paste clipboard images as PNG @@ -464,8 +471,9 @@ showEstimates showProgress - stripHTML useCurrent + stripHTML + pastePNG newSpread dayOffset lrnCutoff