Merge lp:~mzanetti/reminders-app/color into lp:~notes-app-dev/reminders-app/new-design

Proposed by Michael Zanetti
Status: Merged
Approved by: Riccardo Padovani
Approved revision: 95
Merged at revision: 94
Proposed branch: lp:~mzanetti/reminders-app/color
Merge into: lp:~notes-app-dev/reminders-app/new-design
Diff against target: 237 lines (+61/-16)
9 files modified
src/app/CMakeLists.txt (+1/-1)
src/app/main.cpp (+3/-3)
src/app/preferences.cpp (+38/-5)
src/app/preferences.h (+10/-4)
src/app/qml/components/NotebooksDelegate.qml (+2/-0)
src/app/qml/components/NotesDelegate.qml (+2/-0)
src/app/qml/reminders.qml (+3/-3)
src/app/qml/ui/NotebooksPage.qml (+1/-0)
src/app/qml/ui/NotesPage.qml (+1/-0)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/color
Reviewer Review Type Date Requested Status
Riccardo Padovani Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Pending
Review via email: mp+218317@code.launchpad.net

This proposal supersedes a proposal from 2014-04-30.

Description of the change

This adds support for the colors as shown in the new design.

Changes AccountPreference to be a generic Preferences class and adds a method colorForNotebook(notebookGuid). This picks the least used color of our available ones and stores its usage into the settings. This way we can keep the same colors for the same notebooks all the time.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
lp:~mzanetti/reminders-app/color updated
94. By Michael Zanetti

added colorForNotebook() method to preferences

95. By Michael Zanetti

rename preferences

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Working as expected, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/CMakeLists.txt'
2--- src/app/CMakeLists.txt 2014-02-15 17:05:32 +0000
3+++ src/app/CMakeLists.txt 2014-05-05 18:01:04 +0000
4@@ -3,7 +3,7 @@
5 set(reminders_SRCS
6 main.cpp
7 camerahelper.cpp
8- accountpreference.cpp
9+ preferences.cpp
10 ${QML_SRCS}
11 )
12
13
14=== modified file 'src/app/main.cpp'
15--- src/app/main.cpp 2014-03-17 22:26:42 +0000
16+++ src/app/main.cpp 2014-05-05 18:01:04 +0000
17@@ -21,7 +21,7 @@
18 */
19
20 #include "camerahelper.h"
21-#include "accountpreference.h"
22+#include "preferences.h"
23
24 #include <QtGui/QGuiApplication>
25 #include <QtQuick/QQuickView>
26@@ -100,8 +100,8 @@
27 view.engine()->rootContext()->setContextProperty("cameraHelper", &helper);
28
29 // Set up account preferences
30- AccountPreference preferences;
31- view.engine()->rootContext()->setContextProperty("accountPreference", &preferences);
32+ Preferences preferences;
33+ view.engine()->rootContext()->setContextProperty("preferences", &preferences);
34
35 // load the qml file
36 if (qmlfile.isEmpty()) {
37
38=== renamed file 'src/app/accountpreference.cpp' => 'src/app/preferences.cpp'
39--- src/app/accountpreference.cpp 2014-02-08 18:43:27 +0000
40+++ src/app/preferences.cpp 2014-05-05 18:01:04 +0000
41@@ -19,21 +19,54 @@
42 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
43 * Riccardo Padovani <rpadovani@ubuntu.com>
44 */
45-#include "accountpreference.h"
46+#include "preferences.h"
47
48-AccountPreference::AccountPreference(QObject *parent): QObject(parent),
49+Preferences::Preferences(QObject *parent): QObject(parent),
50 m_settings(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/com.ubuntu.reminders/reminders.conf", QSettings::IniFormat)
51 {
52-
53+ m_notebookColors.append("#35af44");
54+ m_notebookColors.append("#298bd6");
55+ m_notebookColors.append("#d33781");
56+ m_notebookColors.append("#b68b01");
57+ m_notebookColors.append("#db3131");
58+ m_notebookColors.append("#2ba098");
59 }
60
61-QString AccountPreference::accountName() const
62+QString Preferences::accountName() const
63 {
64 return m_settings.value("accountName").toString();
65 }
66
67-void AccountPreference::setAccountName(const QString &accountName)
68+void Preferences::setAccountName(const QString &accountName)
69 {
70 m_settings.setValue("accountName", accountName);
71 emit accountNameChanged();
72 }
73+
74+
75+QString Preferences::colorForNotebook(const QString &notebookGuid)
76+{
77+ m_settings.beginGroup("notebookColors");
78+ QString colorName = m_settings.value(notebookGuid).toString();
79+
80+ if (colorName.isEmpty()) {
81+ QHash<QString, int> usedColors;
82+ foreach (const QString &tmp, m_settings.allKeys()) {
83+ usedColors[m_settings.value(tmp).toString()]++;
84+ }
85+
86+ while (colorName.isEmpty()) {
87+ foreach (const QString &c, m_notebookColors) {
88+ if (usedColors[c] == 0) {
89+ colorName = c;
90+ break;
91+ }
92+ usedColors[c]--;
93+ }
94+ }
95+
96+ m_settings.setValue(notebookGuid, colorName);
97+ }
98+ m_settings.endGroup();
99+ return colorName;
100+}
101
102=== renamed file 'src/app/accountpreference.h' => 'src/app/preferences.h'
103--- src/app/accountpreference.h 2014-02-08 18:43:27 +0000
104+++ src/app/preferences.h 2014-05-05 18:01:04 +0000
105@@ -20,28 +20,34 @@
106 * Riccardo Padovani <rpadovani@ubuntu.com>
107 */
108
109-#ifndef ACCOUNTPREFERENCE_H
110-#define ACCOUNTPREFERENCE_H
111+#ifndef PREFERENCE_H
112+#define PREFERENCE_H
113
114 #include <QSettings>
115 #include <QStandardPaths>
116 #include <QObject>
117 #include <QDebug>
118+#include <QList>
119+#include <QColor>
120
121-class AccountPreference: public QObject
122+class Preferences: public QObject
123 {
124 Q_OBJECT
125 Q_PROPERTY(QString accountName READ accountName WRITE setAccountName NOTIFY accountNameChanged)
126+
127 public:
128- AccountPreference(QObject *parent = 0);
129+ Preferences(QObject *parent = 0);
130 QString accountName() const;
131 void setAccountName(const QString &accountName);
132
133+ Q_INVOKABLE QString colorForNotebook(const QString &notebookGuid);
134+
135 signals:
136 void accountNameChanged();
137
138 private:
139 QSettings m_settings;
140+ QList<QString> m_notebookColors;
141 };
142
143 #endif
144
145=== modified file 'src/app/qml/components/NotebooksDelegate.qml'
146--- src/app/qml/components/NotebooksDelegate.qml 2014-01-28 08:31:37 +0000
147+++ src/app/qml/components/NotebooksDelegate.qml 2014-05-05 18:01:04 +0000
148@@ -27,6 +27,7 @@
149 property string name
150 property int noteCount
151 property string shareStatus
152+ property color notebookColor
153
154 Column {
155 id: contentColumn
156@@ -43,6 +44,7 @@
157 text: root.name
158 font.bold: true
159 elide: Text.ElideRight
160+ color: root.notebookColor
161 }
162 Label {
163 anchors { left: parent.left; right: parent.right }
164
165=== modified file 'src/app/qml/components/NotesDelegate.qml'
166--- src/app/qml/components/NotesDelegate.qml 2014-01-27 13:00:41 +0000
167+++ src/app/qml/components/NotesDelegate.qml 2014-05-05 18:01:04 +0000
168@@ -28,6 +28,7 @@
169 property date creationDate
170 property string content
171 property string resource
172+ property color notebookColor
173
174 Column {
175 id: contentColumn
176@@ -45,6 +46,7 @@
177 text: root.title
178 font.bold: true
179 elide: Text.ElideRight
180+ color: root.notebookColor
181 }
182 Label {
183 anchors { left: parent.left; right: parent.right }
184
185=== modified file 'src/app/qml/reminders.qml'
186--- src/app/qml/reminders.qml 2014-03-13 18:12:25 +0000
187+++ src/app/qml/reminders.qml 2014-05-05 18:01:04 +0000
188@@ -123,7 +123,7 @@
189
190 pagestack.push(rootTabs)
191 print("got accounts:", accounts.count)
192- var accountName = accountPreference.accountName;
193+ var accountName = preferences.accountName;
194 if (accountName) {
195 var i;
196 for (i = 0; i < accounts.count; i++) {
197@@ -151,7 +151,7 @@
198 target: UserStore
199 onUsernameChanged: {
200 print("Logged in as user:", UserStore.username);
201- accountPreference.accountName = UserStore.username;
202+ preferences.accountName = UserStore.username;
203 }
204 }
205
206@@ -219,7 +219,7 @@
207 var component = Qt.createComponent(Qt.resolvedUrl("ui/NotesPage.qml"))
208 var page = component.createObject();
209 print("opening note page for notebook", notebookGuid)
210- pagestack.push(page, {title: title/*, filter: notebookGuid*/});
211+ pagestack.push(page, {title: title, filter: notebookGuid});
212 page.selectedNoteChanged.connect(function() {
213 print("foo", page.selectedNote);
214 if (page.selectedNote) {
215
216=== modified file 'src/app/qml/ui/NotebooksPage.qml'
217--- src/app/qml/ui/NotebooksPage.qml 2014-03-19 16:26:36 +0000
218+++ src/app/qml/ui/NotebooksPage.qml 2014-05-05 18:01:04 +0000
219@@ -113,6 +113,7 @@
220 name: model.name
221 noteCount: model.noteCount
222 shareStatus: model.publised ? i18n.tr("Shared") : i18n.tr("Private")
223+ notebookColor: preferences.colorForNotebook(model.guid)
224
225 onClicked: {
226 print("selected notebook:", model.guid)
227
228=== modified file 'src/app/qml/ui/NotesPage.qml'
229--- src/app/qml/ui/NotesPage.qml 2014-03-13 18:11:32 +0000
230+++ src/app/qml/ui/NotesPage.qml 2014-05-05 18:01:04 +0000
231@@ -110,6 +110,7 @@
232 creationDate: model.created
233 content: model.plaintextContent
234 resource: model.resourceUrls.length > 0 ? model.resourceUrls[0] : ""
235+ notebookColor: preferences.colorForNotebook(model.notebookGuid)
236
237 Component.onCompleted: NotesStore.refreshNoteContent(model.guid)
238

Subscribers

People subscribed via source and target branches