Merge lp:~mzanetti/reminders-app/fix-image-widths into lp:reminders-app

Proposed by Michael Zanetti
Status: Merged
Approved by: Riccardo Padovani
Approved revision: 374
Merged at revision: 377
Proposed branch: lp:~mzanetti/reminders-app/fix-image-widths
Merge into: lp:reminders-app
Diff against target: 173 lines (+58/-15)
5 files modified
src/app/qml/ui/EditNoteView.qml (+6/-0)
src/libqtevernote/note.cpp (+13/-0)
src/libqtevernote/note.h (+11/-0)
src/libqtevernote/utils/enmldocument.cpp (+24/-14)
src/libqtevernote/utils/enmldocument.h (+4/-1)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/fix-image-widths
Reviewer Review Type Date Requested Status
Riccardo Padovani Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+251992@code.launchpad.net

Commit message

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

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
81 }81 }
82 }82 }
8383
84 Binding {
85 target: note
86 property: "renderWidth"
87 value: noteTextArea.width - noteTextArea.textMargin * 2
88 }
89
84 Column {90 Column {
85 anchors { left: parent.left; top: parent.top; right: parent.right; bottom: toolbox.top }91 anchors { left: parent.left; top: parent.top; right: parent.right; bottom: toolbox.top }
8692
8793
=== 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 @@
577 NotesStore::instance()->untagNote(m_guid, tagGuid);577 NotesStore::instance()->untagNote(m_guid, tagGuid);
578}578}
579579
580int Note::renderWidth() const
581{
582 return m_content.renderWidth();
583}
584
585void Note::setRenderWidth(int renderWidth)
586{
587 if (m_content.renderWidth() != renderWidth) {
588 m_content.setRenderWidth(renderWidth);
589 emit contentChanged();
590 }
591}
592
580Note *Note::clone()593Note *Note::clone()
581{594{
582 Note *note = new Note(m_guid, m_updateSequenceNumber);595 Note *note = new Note(m_guid, m_updateSequenceNumber);
583596
=== 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 @@
69 Q_PROPERTY(bool synced READ synced NOTIFY syncedChanged)69 Q_PROPERTY(bool synced READ synced NOTIFY syncedChanged)
70 Q_PROPERTY(bool syncError READ syncError NOTIFY syncErrorChanged)70 Q_PROPERTY(bool syncError READ syncError NOTIFY syncErrorChanged)
7171
72 // When asking the note's richTextContent, usually the embedded images will have their original size.
73 // For rendering that content in a WebView or TextEdit, that might not be appropriate as images might
74 // be really big. Use this to restrict them to a maximum width.
75 // Set this to -1 (the default) to keep the original size
76 Q_PROPERTY(int renderWidth READ renderWidth WRITE setRenderWidth NOTIFY renderWidthChanged)
77
72public:78public:
73 explicit Note(const QString &guid, quint32 updateSequenceNumber, QObject *parent = 0);79 explicit Note(const QString &guid, quint32 updateSequenceNumber, QObject *parent = 0);
74 ~Note();80 ~Note();
@@ -160,6 +166,9 @@
160 Q_INVOKABLE void addTag(const QString &tagGuid);166 Q_INVOKABLE void addTag(const QString &tagGuid);
161 Q_INVOKABLE void removeTag(const QString &tagGuid);167 Q_INVOKABLE void removeTag(const QString &tagGuid);
162168
169 int renderWidth() const;
170 void setRenderWidth(int renderWidth);
171
163public slots:172public slots:
164 void save();173 void save();
165 void remove();174 void remove();
@@ -186,6 +195,8 @@
186 void syncErrorChanged();195 void syncErrorChanged();
187 void conflictingChanged();196 void conflictingChanged();
188197
198 void renderWidthChanged();
199
189private slots:200private slots:
190 void slotNotebookGuidChanged(const QString &oldGuid, const QString &newGuid);201 void slotNotebookGuidChanged(const QString &oldGuid, const QString &newGuid);
191 void slotTagGuidChanged(const QString &oldGuid, const QString &newGuid);202 void slotTagGuidChanged(const QString &oldGuid, const QString &newGuid);
192203
=== 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 @@
49QStringList EnmlDocument::s_argumentBlackListTags = QStringList()49QStringList EnmlDocument::s_argumentBlackListTags = QStringList()
50 << "ul" << "li" << "ol";50 << "ul" << "li" << "ol";
5151
52int EnmlDocument::s_richtextContentWidth = 640;
53EnmlDocument::EnmlDocument(const QString &enml):52EnmlDocument::EnmlDocument(const QString &enml):
54 m_enml(enml)53 m_enml(enml),
54 m_renderWidth(-1)
55{55{
56}56}
5757
@@ -156,6 +156,7 @@
156156
157 writer.writeStartElement("img");157 writer.writeStartElement("img");
158 if (mediaType.startsWith("image")) {158 if (mediaType.startsWith("image")) {
159
159 if (type == TypeRichText) {160 if (type == TypeRichText) {
160 writer.writeAttribute("src", composeMediaTypeUrl(mediaType, noteGuid, hash));161 writer.writeAttribute("src", composeMediaTypeUrl(mediaType, noteGuid, hash));
161 } else if (type == TypeHtml) {162 } else if (type == TypeHtml) {
@@ -167,18 +168,17 @@
167 writer.writeAttribute("id", "en-attachment/" + hash + "/" + mediaType);168 writer.writeAttribute("id", "en-attachment/" + hash + "/" + mediaType);
168 }169 }
169170
170 //set the width171 // Set the width. We always override what's coming from Evernote and adjust it to our view.
171 if (reader.attributes().hasAttribute("width")) {172 // We don't even need to take care about what sizes we write back to Evernote as other
172 writer.writeAttribute("width", reader.attributes().value("width").toString());173 // Evernote clients ignore and override/change that too.
173 } else {174 if (type == TypeRichText) {
174 if (type == TypeRichText) {175 //get the size of the original image
175 //get the size of the original image176 QImage image = QImage::fromData(NotesStore::instance()->note(noteGuid)->resource(hash)->data());
176 QImage image = QImage::fromData(NotesStore::instance()->note(noteGuid)->resource(hash)->data());177 int originalWidthInGus = image.width() * gu(1) / 8;
177 if (image.width() > EnmlDocument::s_richtextContentWidth)178 int imageWidth = m_renderWidth >= 0 && originalWidthInGus > m_renderWidth ? m_renderWidth : originalWidthInGus;
178 writer.writeAttribute("width", QString::number(EnmlDocument::s_richtextContentWidth));179 writer.writeAttribute("width", QString::number(imageWidth));
179 } else if (type == TypeHtml) {180 } else if (type == TypeHtml) {
180 writer.writeAttribute("style", "max-width: 100%");181 writer.writeAttribute("style", "max-width: 100%");
181 }
182 }182 }
183 } else if (mediaType.startsWith("audio")) {183 } else if (mediaType.startsWith("audio")) {
184 if (type == TypeRichText) {184 if (type == TypeRichText) {
@@ -453,6 +453,16 @@
453 m_enml = output;453 m_enml = output;
454}454}
455455
456int EnmlDocument::renderWidth() const
457{
458 return m_renderWidth;
459}
460
461void EnmlDocument::setRenderWidth(int renderWidth)
462{
463 m_renderWidth = renderWidth;
464}
465
456void EnmlDocument::attachFile(int position, const QString &hash, const QString &type)466void EnmlDocument::attachFile(int position, const QString &hash, const QString &type)
457{467{
458 QXmlStreamReader reader(m_enml);468 QXmlStreamReader reader(m_enml);
459469
=== 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 @@
4343
44 void markTodo(const QString &todoId, bool checked);44 void markTodo(const QString &todoId, bool checked);
4545
46 int renderWidth() const;
47 void setRenderWidth(int renderWidth);
48
46private:49private:
47 enum Type {50 enum Type {
48 TypeRichText,51 TypeRichText,
@@ -57,10 +60,10 @@
5760
58private:61private:
59 QString m_enml;62 QString m_enml;
63 int m_renderWidth;
6064
61 static QStringList s_commonTags;65 static QStringList s_commonTags;
62 static QStringList s_argumentBlackListTags;66 static QStringList s_argumentBlackListTags;
63 static int s_richtextContentWidth;
64};67};
6568
66#endif // ENMLDOCUMENT_H69#endif // ENMLDOCUMENT_H

Subscribers

People subscribed via source and target branches