Michael Zanetti has proposed merging 
lp:~mzanetti/reminders-app/fix-image-widths into lp:reminders-app.

Commit message:
Always override image's widths to make it look good on our screen

Requested reviews:
  Ubuntu Reminders app developers (reminders-app-dev)

For more details, see:
https://code.launchpad.net/~mzanetti/reminders-app/fix-image-widths/+merge/251992
-- 
Your team Ubuntu Reminders app developers is requested to review the proposed 
merge of lp:~mzanetti/reminders-app/fix-image-widths into lp:reminders-app.
=== modified file 'src/app/qml/ui/EditNoteView.qml'
--- src/app/qml/ui/EditNoteView.qml	2015-02-24 22:49:16 +0000
+++ src/app/qml/ui/EditNoteView.qml	2015-03-05 18:25:12 +0000
@@ -81,6 +81,12 @@
          }
      }
 
+    Binding {
+        target: note
+        property: "renderWidth"
+        value: noteTextArea.width - noteTextArea.textMargin * 2
+    }
+
     Column {
         anchors { left: parent.left; top: parent.top; right: parent.right; bottom: toolbox.top }
 

=== modified file 'src/libqtevernote/note.cpp'
--- src/libqtevernote/note.cpp	2015-03-04 20:30:55 +0000
+++ src/libqtevernote/note.cpp	2015-03-05 18:25:12 +0000
@@ -577,6 +577,19 @@
     NotesStore::instance()->untagNote(m_guid, tagGuid);
 }
 
+int Note::renderWidth() const
+{
+    return m_content.renderWidth();
+}
+
+void Note::setRenderWidth(int renderWidth)
+{
+    if (m_content.renderWidth() != renderWidth) {
+        m_content.setRenderWidth(renderWidth);
+        emit contentChanged();
+    }
+}
+
 Note *Note::clone()
 {
     Note *note = new Note(m_guid, m_updateSequenceNumber);

=== modified file 'src/libqtevernote/note.h'
--- src/libqtevernote/note.h	2015-03-04 20:30:55 +0000
+++ src/libqtevernote/note.h	2015-03-05 18:25:12 +0000
@@ -69,6 +69,12 @@
     Q_PROPERTY(bool synced READ synced NOTIFY syncedChanged)
     Q_PROPERTY(bool syncError READ syncError NOTIFY syncErrorChanged)
 
+    // When asking the note's richTextContent, usually the embedded images will have their original size.
+    // For rendering that content in a WebView or TextEdit, that might not be appropriate as images might
+    // be really big. Use this to restrict them to a maximum width.
+    // Set this to -1 (the default) to keep the original size
+    Q_PROPERTY(int renderWidth READ renderWidth WRITE setRenderWidth NOTIFY renderWidthChanged)
+
 public:
     explicit Note(const QString &guid, quint32 updateSequenceNumber, QObject *parent = 0);
     ~Note();
@@ -160,6 +166,9 @@
     Q_INVOKABLE void addTag(const QString &tagGuid);
     Q_INVOKABLE void removeTag(const QString &tagGuid);
 
+    int renderWidth() const;
+    void setRenderWidth(int renderWidth);
+
 public slots:
     void save();
     void remove();
@@ -186,6 +195,8 @@
     void syncErrorChanged();
     void conflictingChanged();
 
+    void renderWidthChanged();
+
 private slots:
     void slotNotebookGuidChanged(const QString &oldGuid, const QString &newGuid);
     void slotTagGuidChanged(const QString &oldGuid, const QString &newGuid);

=== modified file 'src/libqtevernote/utils/enmldocument.cpp'
--- src/libqtevernote/utils/enmldocument.cpp	2015-02-28 00:45:09 +0000
+++ src/libqtevernote/utils/enmldocument.cpp	2015-03-05 18:25:12 +0000
@@ -49,9 +49,9 @@
 QStringList EnmlDocument::s_argumentBlackListTags = QStringList()
         << "ul" << "li" << "ol";
 
-int EnmlDocument::s_richtextContentWidth = 640;
 EnmlDocument::EnmlDocument(const QString &enml):
-    m_enml(enml)
+    m_enml(enml),
+    m_renderWidth(-1)
 {
 }
 
@@ -156,6 +156,7 @@
 
                 writer.writeStartElement("img");
                 if (mediaType.startsWith("image")) {
+
                     if (type == TypeRichText) {
                         writer.writeAttribute("src", composeMediaTypeUrl(mediaType, noteGuid, hash));
                     } else if (type  == TypeHtml) {
@@ -167,18 +168,17 @@
                         writer.writeAttribute("id", "en-attachment/" + hash + "/" + mediaType);
                     }
 
-                    //set the width
-                    if (reader.attributes().hasAttribute("width")) {
-                        writer.writeAttribute("width", reader.attributes().value("width").toString());
-                    } else {
-                        if (type == TypeRichText) {
-                            //get the size of the original image
-                            QImage image = QImage::fromData(NotesStore::instance()->note(noteGuid)->resource(hash)->data());
-                            if (image.width() > EnmlDocument::s_richtextContentWidth)
-                                writer.writeAttribute("width", QString::number(EnmlDocument::s_richtextContentWidth));
-                        } else if (type == TypeHtml) {
-                            writer.writeAttribute("style", "max-width: 100%");
-                        }
+                    // Set the width. We always override what's coming from Evernote and adjust it to our view.
+                    // We don't even need to take care about what sizes we write back to Evernote as other
+                    // Evernote clients ignore and override/change that too.
+                    if (type == TypeRichText) {
+                        //get the size of the original image
+                        QImage image = QImage::fromData(NotesStore::instance()->note(noteGuid)->resource(hash)->data());
+                        int originalWidthInGus = image.width() * gu(1) / 8;
+                        int imageWidth = m_renderWidth >= 0 && originalWidthInGus > m_renderWidth ? m_renderWidth : originalWidthInGus;
+                        writer.writeAttribute("width", QString::number(imageWidth));
+                    } else if (type == TypeHtml) {
+                        writer.writeAttribute("style", "max-width: 100%");
                     }
                 } else if (mediaType.startsWith("audio")) {
                     if (type == TypeRichText) {
@@ -453,6 +453,16 @@
     m_enml = output;
 }
 
+int EnmlDocument::renderWidth() const
+{
+    return m_renderWidth;
+}
+
+void EnmlDocument::setRenderWidth(int renderWidth)
+{
+    m_renderWidth = renderWidth;
+}
+
 void EnmlDocument::attachFile(int position, const QString &hash, const QString &type)
 {
     QXmlStreamReader reader(m_enml);

=== modified file 'src/libqtevernote/utils/enmldocument.h'
--- src/libqtevernote/utils/enmldocument.h	2015-02-16 19:28:02 +0000
+++ src/libqtevernote/utils/enmldocument.h	2015-03-05 18:25:12 +0000
@@ -43,6 +43,9 @@
 
     void markTodo(const QString &todoId, bool checked);
 
+    int renderWidth() const;
+    void setRenderWidth(int renderWidth);
+
 private:
     enum Type {
         TypeRichText,
@@ -57,10 +60,10 @@
 
 private:
     QString m_enml;
+    int m_renderWidth;
 
     static QStringList s_commonTags;
     static QStringList s_argumentBlackListTags;
-    static int s_richtextContentWidth;
 };
 
 #endif // ENMLDOCUMENT_H

-- 
Mailing list: https://launchpad.net/~ubuntu-touch-coreapps-reviewers
Post to     : ubuntu-touch-coreapps-reviewers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~ubuntu-touch-coreapps-reviewers
More help   : https://help.launchpad.net/ListHelp

Reply via email to