summaryrefslogtreecommitdiff
path: root/metawatch/metawatchdigital.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-10-17 00:08:17 +0200
committerJavier S. Pedro <maemo@javispedro.com>2011-10-17 00:08:17 +0200
commit5db79919b3140673f66c9da5965b54671e8f4b6a (patch)
tree6ac03eba5721027e0a46182412b608236b070760 /metawatch/metawatchdigital.cpp
parente86bf7a875ed3decda48fc146598a19685a4a27d (diff)
downloadsowatch-5db79919b3140673f66c9da5965b54671e8f4b6a.tar.gz
sowatch-5db79919b3140673f66c9da5965b54671e8f4b6a.zip
Simplify notification rendering code usign QTextOption
Diffstat (limited to 'metawatch/metawatchdigital.cpp')
-rw-r--r--metawatch/metawatchdigital.cpp44
1 files changed, 19 insertions, 25 deletions
diff --git a/metawatch/metawatchdigital.cpp b/metawatch/metawatchdigital.cpp
index df7d015..8a81f97 100644
--- a/metawatch/metawatchdigital.cpp
+++ b/metawatch/metawatchdigital.cpp
@@ -260,7 +260,8 @@ void MetaWatchDigital::renderNotification(Notification *n)
const int iconY = margin;
const int titleY = margin*2 + iconH;
const int dateX = x + iconW + margin;
- int textFlags;
+ QTextOption option;
+ QRect rect, titleRect;
QString text;
p.begin(this);
@@ -269,40 +270,33 @@ void MetaWatchDigital::renderNotification(Notification *n)
p.drawImage(x, iconY, icon);
p.setPen(Qt::black);
+ option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
+ option.setAlignment(Qt::AlignRight | Qt::AlignVCenter);
+ // Render "N minutes ago"
p.setFont(sf);
- textFlags = Qt::AlignRight | Qt::AlignVCenter | Qt::TextWordWrap;
+ rect.setRect(dateX, iconY, (screenWidth - dateX) - margin, iconH);
text = n->displayTime();
- QRect dateRect(dateX, iconY, (screenWidth - dateX) - margin, iconH);
- p.drawText(dateRect, textFlags, text);
+ p.drawText(rect, text, option);
+ option.setAlignment(Qt::AlignLeft | Qt::AlignTop);
+
+ // Render title
p.setFont(lf);
- textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap;
+ rect.setRect(x, titleY, screenWidth - x*2, screenHeight - titleY);
text = n->title();
+ titleRect = p.boundingRect(rect, text, option).toRect();
+ p.drawText(rect, text, option);
- QRect titleMaxRect(x, titleY, screenWidth - x*2, screenHeight - titleY);
- QRect titleRect = p.boundingRect(titleMaxRect, textFlags, text);
- if (titleRect.width() > titleMaxRect.width()) {
- textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere;
- titleRect = p.boundingRect(titleMaxRect, textFlags, text);
- }
-
- p.drawText(titleMaxRect, textFlags, text);
-
- p.setFont(mf);
- textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap;
- text = n->body();
-
+ // Do not try to draw body if title was large
int bodyY = titleRect.y() + titleRect.height();
if (bodyY >= screenHeight) return;
- QRect bodyMaxRect(x, bodyY, titleMaxRect.width(), screenHeight - bodyY);
- QRect bodyRect = p.boundingRect(bodyMaxRect, textFlags, text);
- if (bodyRect.width() > bodyMaxRect.width()) {
- textFlags = Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere;
- }
-
- p.drawText(bodyMaxRect, textFlags, text);
+ // Render body
+ p.setFont(mf);
+ rect.setRect(x, bodyY, screenWidth - x*2, screenHeight - bodyY);
+ text = n->body();
+ p.drawText(rect, text, option);
p.end();
_paintMode = _currentMode;