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
1=== modified file 'src/app/qml/ui/EditNoteView.qml'
2--- src/app/qml/ui/EditNoteView.qml 2015-02-24 22:49:16 +0000
3+++ src/app/qml/ui/EditNoteView.qml 2015-03-05 18:25:12 +0000
4@@ -81,6 +81,12 @@
5 }
6 }
7
8+ Binding {
9+ target: note
10+ property: "renderWidth"
11+ value: noteTextArea.width - noteTextArea.textMargin * 2
12+ }
13+
14 Column {
15 anchors { left: parent.left; top: parent.top; right: parent.right; bottom: toolbox.top }
16
17
18=== modified file 'src/libqtevernote/note.cpp'
19--- src/libqtevernote/note.cpp 2015-03-04 20:30:55 +0000
20+++ src/libqtevernote/note.cpp 2015-03-05 18:25:12 +0000
21@@ -577,6 +577,19 @@
22 NotesStore::instance()->untagNote(m_guid, tagGuid);
23 }
24
25+int Note::renderWidth() const
26+{
27+ return m_content.renderWidth();
28+}
29+
30+void Note::setRenderWidth(int renderWidth)
31+{
32+ if (m_content.renderWidth() != renderWidth) {
33+ m_content.setRenderWidth(renderWidth);
34+ emit contentChanged();
35+ }
36+}
37+
38 Note *Note::clone()
39 {
40 Note *note = new Note(m_guid, m_updateSequenceNumber);
41
42=== modified file 'src/libqtevernote/note.h'
43--- src/libqtevernote/note.h 2015-03-04 20:30:55 +0000
44+++ src/libqtevernote/note.h 2015-03-05 18:25:12 +0000
45@@ -69,6 +69,12 @@
46 Q_PROPERTY(bool synced READ synced NOTIFY syncedChanged)
47 Q_PROPERTY(bool syncError READ syncError NOTIFY syncErrorChanged)
48
49+ // When asking the note's richTextContent, usually the embedded images will have their original size.
50+ // For rendering that content in a WebView or TextEdit, that might not be appropriate as images might
51+ // be really big. Use this to restrict them to a maximum width.
52+ // Set this to -1 (the default) to keep the original size
53+ Q_PROPERTY(int renderWidth READ renderWidth WRITE setRenderWidth NOTIFY renderWidthChanged)
54+
55 public:
56 explicit Note(const QString &guid, quint32 updateSequenceNumber, QObject *parent = 0);
57 ~Note();
58@@ -160,6 +166,9 @@
59 Q_INVOKABLE void addTag(const QString &tagGuid);
60 Q_INVOKABLE void removeTag(const QString &tagGuid);
61
62+ int renderWidth() const;
63+ void setRenderWidth(int renderWidth);
64+
65 public slots:
66 void save();
67 void remove();
68@@ -186,6 +195,8 @@
69 void syncErrorChanged();
70 void conflictingChanged();
71
72+ void renderWidthChanged();
73+
74 private slots:
75 void slotNotebookGuidChanged(const QString &oldGuid, const QString &newGuid);
76 void slotTagGuidChanged(const QString &oldGuid, const QString &newGuid);
77
78=== modified file 'src/libqtevernote/utils/enmldocument.cpp'
79--- src/libqtevernote/utils/enmldocument.cpp 2015-02-28 00:45:09 +0000
80+++ src/libqtevernote/utils/enmldocument.cpp 2015-03-05 18:25:12 +0000
81@@ -49,9 +49,9 @@
82 QStringList EnmlDocument::s_argumentBlackListTags = QStringList()
83 << "ul" << "li" << "ol";
84
85-int EnmlDocument::s_richtextContentWidth = 640;
86 EnmlDocument::EnmlDocument(const QString &enml):
87- m_enml(enml)
88+ m_enml(enml),
89+ m_renderWidth(-1)
90 {
91 }
92
93@@ -156,6 +156,7 @@
94
95 writer.writeStartElement("img");
96 if (mediaType.startsWith("image")) {
97+
98 if (type == TypeRichText) {
99 writer.writeAttribute("src", composeMediaTypeUrl(mediaType, noteGuid, hash));
100 } else if (type == TypeHtml) {
101@@ -167,18 +168,17 @@
102 writer.writeAttribute("id", "en-attachment/" + hash + "/" + mediaType);
103 }
104
105- //set the width
106- if (reader.attributes().hasAttribute("width")) {
107- writer.writeAttribute("width", reader.attributes().value("width").toString());
108- } else {
109- if (type == TypeRichText) {
110- //get the size of the original image
111- QImage image = QImage::fromData(NotesStore::instance()->note(noteGuid)->resource(hash)->data());
112- if (image.width() > EnmlDocument::s_richtextContentWidth)
113- writer.writeAttribute("width", QString::number(EnmlDocument::s_richtextContentWidth));
114- } else if (type == TypeHtml) {
115- writer.writeAttribute("style", "max-width: 100%");
116- }
117+ // Set the width. We always override what's coming from Evernote and adjust it to our view.
118+ // We don't even need to take care about what sizes we write back to Evernote as other
119+ // Evernote clients ignore and override/change that too.
120+ if (type == TypeRichText) {
121+ //get the size of the original image
122+ QImage image = QImage::fromData(NotesStore::instance()->note(noteGuid)->resource(hash)->data());
123+ int originalWidthInGus = image.width() * gu(1) / 8;
124+ int imageWidth = m_renderWidth >= 0 && originalWidthInGus > m_renderWidth ? m_renderWidth : originalWidthInGus;
125+ writer.writeAttribute("width", QString::number(imageWidth));
126+ } else if (type == TypeHtml) {
127+ writer.writeAttribute("style", "max-width: 100%");
128 }
129 } else if (mediaType.startsWith("audio")) {
130 if (type == TypeRichText) {
131@@ -453,6 +453,16 @@
132 m_enml = output;
133 }
134
135+int EnmlDocument::renderWidth() const
136+{
137+ return m_renderWidth;
138+}
139+
140+void EnmlDocument::setRenderWidth(int renderWidth)
141+{
142+ m_renderWidth = renderWidth;
143+}
144+
145 void EnmlDocument::attachFile(int position, const QString &hash, const QString &type)
146 {
147 QXmlStreamReader reader(m_enml);
148
149=== modified file 'src/libqtevernote/utils/enmldocument.h'
150--- src/libqtevernote/utils/enmldocument.h 2015-02-16 19:28:02 +0000
151+++ src/libqtevernote/utils/enmldocument.h 2015-03-05 18:25:12 +0000
152@@ -43,6 +43,9 @@
153
154 void markTodo(const QString &todoId, bool checked);
155
156+ int renderWidth() const;
157+ void setRenderWidth(int renderWidth);
158+
159 private:
160 enum Type {
161 TypeRichText,
162@@ -57,10 +60,10 @@
163
164 private:
165 QString m_enml;
166+ int m_renderWidth;
167
168 static QStringList s_commonTags;
169 static QStringList s_argumentBlackListTags;
170- static int s_richtextContentWidth;
171 };
172
173 #endif // ENMLDOCUMENT_H

Subscribers

People subscribed via source and target branches