summaryrefslogtreecommitdiff
path: root/libsowatch
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2012-08-13 21:31:52 +0200
committerJavier S. Pedro <maemo@javispedro.com>2012-08-13 21:31:52 +0200
commitabdf3b1eaba8151f1b8e862750c38cb7a5411d2a (patch)
tree69e314d80a332295dd5475fc91f45c2078eaead5 /libsowatch
parent51701e30d710ad016ddf2d306cdd7be122ddf25b (diff)
downloadsowatch-abdf3b1eaba8151f1b8e862750c38cb7a5411d2a.tar.gz
sowatch-abdf3b1eaba8151f1b8e862750c38cb7a5411d2a.zip
make watchsimulator work again
Diffstat (limited to 'libsowatch')
-rw-r--r--libsowatch/declarativewatchlet.cpp23
-rw-r--r--libsowatch/graphicswatchlet.cpp56
-rw-r--r--libsowatch/graphicswatchlet.h7
-rw-r--r--libsowatch/libsowatch.pro8
-rw-r--r--libsowatch/notificationsmodel.cpp70
-rw-r--r--libsowatch/notificationsmodel.h37
-rw-r--r--libsowatch/sowatch.h1
-rw-r--r--libsowatch/watchlet.cpp10
-rw-r--r--libsowatch/watchlet.h3
-rw-r--r--libsowatch/watchpaintengine.cpp46
-rw-r--r--libsowatch/watchserver.cpp5
-rw-r--r--libsowatch/watchserver.h1
-rw-r--r--libsowatch/watchsimulator.cpp11
-rw-r--r--libsowatch/watchsimulator.h19
14 files changed, 238 insertions, 59 deletions
diff --git a/libsowatch/declarativewatchlet.cpp b/libsowatch/declarativewatchlet.cpp
index 68d6c28..510a68f 100644
--- a/libsowatch/declarativewatchlet.cpp
+++ b/libsowatch/declarativewatchlet.cpp
@@ -1,6 +1,7 @@
#include <QtCore/QDebug>
#include <QtDeclarative/QtDeclarative>
#include "watchserver.h"
+#include "watch.h"
#include "gconfkey.h"
#include "declarativewatchwrapper.h"
#include "declarativewatchlet.h"
@@ -17,6 +18,8 @@ DeclarativeWatchlet::DeclarativeWatchlet(WatchServer* server, const QString& id)
_wrapper(0)
{
setScene(new QGraphicsScene(this));
+ scene()->setItemIndexMethod(QGraphicsScene::NoIndex);
+ scene()->setStickyFocus(true);
if (!_registered) {
qmlRegisterUncreatableType<DeclarativeWatchWrapper>("com.javispedro.sowatch", 1, 0,
@@ -27,7 +30,13 @@ DeclarativeWatchlet::DeclarativeWatchlet(WatchServer* server, const QString& id)
}
_engine = new QDeclarativeEngine(this);
+#if !defined(QT_NO_DEBUG)
+ QString qmlDir = QDir::current().absoluteFilePath(SOWATCH_QML_DIR);
+ qDebug() << "Using debug QML import path: " << qmlDir;
_engine->addImportPath(SOWATCH_QML_DIR);
+#else
+ _engine->addImportPath(SOWATCH_QML_DIR);
+#endif
_wrapper = new DeclarativeWatchWrapper(server, server->watch(), this);
_engine->rootContext()->setContextProperty("watch", _wrapper);
@@ -80,6 +89,19 @@ QDeclarativeItem* DeclarativeWatchlet::rootObject()
void DeclarativeWatchlet::activate()
{
+ // Now we certainly know the watch's area, so it is a good moment to
+ // resize the root object if needed.
+ if (_item) {
+ Watch *watch = this->watch();
+ if (!qFuzzyCompare(watch->width(), _item->width())) {
+ qDebug() << "Resizing root object to width" << watch->width();
+ _item->setWidth(watch->width());
+ }
+ if (!qFuzzyCompare(watch->height(), _item->height())) {
+ qDebug() << "Resizing root object to height" << watch->width();
+ _item->setHeight(watch->height());
+ }
+ }
GraphicsWatchlet::activate();
_wrapper->activate();
}
@@ -99,7 +121,6 @@ void DeclarativeWatchlet::setRootObject(QDeclarativeItem *item)
}
_item = item;
- // TODO Resize _item
scene()->addItem(_item);
}
diff --git a/libsowatch/graphicswatchlet.cpp b/libsowatch/graphicswatchlet.cpp
index e11d5cc..2d58ff6 100644
--- a/libsowatch/graphicswatchlet.cpp
+++ b/libsowatch/graphicswatchlet.cpp
@@ -16,7 +16,6 @@ GraphicsWatchlet::GraphicsWatchlet(WatchServer* server, const QString& id) :
GraphicsWatchlet::~GraphicsWatchlet()
{
-
}
QGraphicsScene* GraphicsWatchlet::scene()
@@ -36,27 +35,55 @@ void GraphicsWatchlet::setScene(QGraphicsScene *scene)
}
}
-void GraphicsWatchlet::sceneChanged(const QList<QRectF> &region)
+QRectF GraphicsWatchlet::sceneRect() const
{
- foreach(const QRectF& r, region) {
- _damaged += r.toRect();
+ if (_scene) {
+ return _scene->sceneRect();
+ } else {
+ return QRectF();
}
- if (!_damaged.isEmpty()) {
- _frameTimer.start(frameDelay);
+}
+
+QRect GraphicsWatchlet::viewportRect() const
+{
+ if (_active) {
+ const Watch *watch = this->watch();
+ return QRect(0, 0, watch->width(), watch->height());
+ } else {
+ return QRect();
+ }
+}
+
+void GraphicsWatchlet::sceneChanged(const QList<QRectF> &rects)
+{
+ if (_active) {
+ // Only consider scene updates if the watchlet is active
+ QRect viewport = viewportRect();
+ foreach(const QRectF& frect, rects) {
+ QRect rect = frect.toAlignedRect() & viewport;
+ _damaged += rect;
+ }
+
+ // Start frame timer if we got new data
+ if (!_damaged.isEmpty() && !_frameTimer.isActive()) {
+ _frameTimer.start(frameDelay);
+ }
}
}
void GraphicsWatchlet::frameTimeout()
{
- if (!_active) return; // Watchlet was ejected, do not draw.
+ // Do not draw if watchlet is not active
+ if (!_active) return;
+
if (watch()->busy()) {
+ // Watch is busy, delay this frame.
_frameTimer.start(busyFrameDelay);
return;
}
const QVector<QRect> rects = _damaged.rects();
QPainter p(watch());
-
foreach(const QRect& r, rects) {
_scene->render(&p, r, r, Qt::IgnoreAspectRatio);
}
@@ -66,14 +93,19 @@ void GraphicsWatchlet::frameTimeout()
void GraphicsWatchlet::activate()
{
Watchlet::activate();
- // We have to assume that the watch has completely forgot about everything.
- QRect area(0, 0, watch()->width(), watch()->height());
- _damaged += area;
- _scene->update(area);
+ // We have to assume that the watch has completely forgot about everything
+ // So assume the entire viewport is damaged
+ QRect viewport = viewportRect();
+ _damaged += viewport;
+ // This will emit sceneChanged and start the frame timer.
+ _scene->update(viewport);
}
void GraphicsWatchlet::deactivate()
{
+ // Stop updates
_frameTimer.stop();
+ _damaged = QRegion();
+
Watchlet::deactivate();
}
diff --git a/libsowatch/graphicswatchlet.h b/libsowatch/graphicswatchlet.h
index 6456a18..34f69cb 100644
--- a/libsowatch/graphicswatchlet.h
+++ b/libsowatch/graphicswatchlet.h
@@ -20,13 +20,16 @@ public:
QGraphicsScene* scene();
void setScene(QGraphicsScene* scene);
- static const int frameDelay = 25;
- static const int busyFrameDelay = 50;
+ QRectF sceneRect() const;
+ QRect viewportRect() const;
protected:
void activate();
void deactivate();
+ static const int frameDelay = 25;
+ static const int busyFrameDelay = 50;
+
QGraphicsScene* _scene;
QTimer _frameTimer;
diff --git a/libsowatch/libsowatch.pro b/libsowatch/libsowatch.pro
index 1057a87..59f2eee 100644
--- a/libsowatch/libsowatch.pro
+++ b/libsowatch/libsowatch.pro
@@ -16,7 +16,6 @@ VERSION = 1.0.0
DEFINES += SOWATCH_LIBRARY
SOURCES += \
- watchsimulator.cpp \
watchserver.cpp \
watchpaintengine.cpp \
watchlet.cpp \
@@ -34,10 +33,10 @@ SOURCES += \
watchscanner.cpp \
allwatchscanner.cpp \
configkey.cpp \
- gconfkey.cpp
+ gconfkey.cpp \
+ notificationsmodel.cpp
HEADERS += \
- watchsimulator.h \
watchserver.h \
watchpaintengine.h \
watchlet.h \
@@ -57,7 +56,8 @@ HEADERS += \
watchscanner.h \
allwatchscanner.h \
configkey.h \
- gconfkey.h
+ gconfkey.h \
+ notificationsmodel.h
install_headers.files = $$HEADERS
diff --git a/libsowatch/notificationsmodel.cpp b/libsowatch/notificationsmodel.cpp
new file mode 100644
index 0000000..2eba9a0
--- /dev/null
+++ b/libsowatch/notificationsmodel.cpp
@@ -0,0 +1,70 @@
+#include "notificationsmodel.h"
+
+using namespace sowatch;
+
+#define FOREACH_TYPE_FROM_TO(x, from, to) \
+ for(Notification::Type x = from; x < to; x = static_cast<Notification::Type>(x + 1))
+
+#define FOREACH_TYPE_UNTIL(x, to) FOREACH_TYPE_FROM_TO(x, Notification::OtherNotification, to)
+
+#define FOREACH_TYPE(x) FOREACH_TYPE_FROM_TO(x, Notification::OtherNotification, Notification::TypeCount)
+
+NotificationsModel::NotificationsModel(QObject *parent) :
+ QAbstractListModel(parent)
+{
+}
+
+int NotificationsModel::rowCount(const QModelIndex &parent) const
+{
+ int count = 0;
+ Q_UNUSED(parent);
+ FOREACH_TYPE(type) {
+ count += _list[type].count();
+ }
+ return count;
+}
+
+QVariant NotificationsModel::data(const QModelIndex &index, int role) const
+{
+}
+
+void NotificationsModel::add(Notification *n)
+{
+}
+
+void NotificationsModel::remove(Notification *n)
+{
+
+}
+
+int NotificationsModel::fullCount() const
+{
+ int count = 0;
+ FOREACH_TYPE(type) {
+ count += fullCountByType(type);
+ }
+ return count;
+}
+
+int NotificationsModel::fullCountByType(Notification::Type type) const
+{
+ int count = 0;
+ Q_FOREACH(const Notification *n, _list[type]) {
+ count += n->count();
+ }
+ return count;
+}
+
+bool NotificationsModel::removeDeletedNotification(Notification *n)
+{
+ // Can't call any methods of 'n'
+}
+
+int NotificationsModel::getOffsetForType(Notification::Type type)
+{
+ int count = 0;
+ FOREACH_TYPE_UNTIL(t, type) {
+ count += _list[type].count();
+ }
+ return count;
+}
diff --git a/libsowatch/notificationsmodel.h b/libsowatch/notificationsmodel.h
new file mode 100644
index 0000000..5e7e029
--- /dev/null
+++ b/libsowatch/notificationsmodel.h
@@ -0,0 +1,37 @@
+#ifndef SOWATCH_NOTIFICATIONSMODEL_H
+#define SOWATCH_NOTIFICATIONSMODEL_H
+
+#include <QtCore/QAbstractListModel>
+
+#include "notification.h"
+
+namespace sowatch
+{
+
+class NotificationsModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ explicit NotificationsModel(QObject *parent = 0);
+
+ int rowCount(const QModelIndex &parent) const;
+ QVariant data(const QModelIndex &index, int role) const;
+
+ void add(Notification *n);
+ void remove(Notification *n);
+
+ int fullCount() const;
+ int fullCountByType(Notification::Type type) const;
+
+ bool removeDeletedNotification(Notification *n);
+
+private:
+ int getOffsetForType(Notification::Type type);
+
+private:
+ QList<Notification*> _list[Notification::TypeCount];
+};
+
+}
+
+#endif // SOWATCH_NOTIFICATIONSMODEL_H
diff --git a/libsowatch/sowatch.h b/libsowatch/sowatch.h
index 921e69c..e0ace02 100644
--- a/libsowatch/sowatch.h
+++ b/libsowatch/sowatch.h
@@ -8,7 +8,6 @@
#include "watch.h"
#include "watchserver.h"
-#include "watchsimulator.h"
#include "watchscanner.h"
#include "watchplugininterface.h"
diff --git a/libsowatch/watchlet.cpp b/libsowatch/watchlet.cpp
index 9b3567e..555443f 100644
--- a/libsowatch/watchlet.cpp
+++ b/libsowatch/watchlet.cpp
@@ -24,6 +24,16 @@ Watch* Watchlet::watch()
return _server->watch();
}
+const WatchServer* Watchlet::server() const
+{
+ return _server;
+}
+
+const Watch* Watchlet::watch() const
+{
+ return _server->watch();
+}
+
QString Watchlet::id() const
{
return _id;
diff --git a/libsowatch/watchlet.h b/libsowatch/watchlet.h
index dad1ddc..f442086 100644
--- a/libsowatch/watchlet.h
+++ b/libsowatch/watchlet.h
@@ -23,6 +23,9 @@ public:
WatchServer* server();
Watch* watch();
+ const WatchServer* server() const;
+ const Watch* watch() const;
+
Q_INVOKABLE QString id() const;
bool isActive() const;
diff --git a/libsowatch/watchpaintengine.cpp b/libsowatch/watchpaintengine.cpp
index 90ad8bf..78e6dfd 100644
--- a/libsowatch/watchpaintengine.cpp
+++ b/libsowatch/watchpaintengine.cpp
@@ -5,6 +5,9 @@
using namespace sowatch;
+#define TRACE(x)
+//#define TRACE(x) x
+
WatchPaintEngine::WatchPaintEngine()
: QPaintEngine(QPaintEngine::AllFeatures),
_painter()
@@ -26,6 +29,7 @@ bool WatchPaintEngine::begin(QPaintDevice *pdev)
_hasBrush = false;
_clipEnabled = false;
_clipRegion = _area;
+ _transform = QTransform();
return _painter.begin(pdev);
}
@@ -75,46 +79,51 @@ void WatchPaintEngine::damagePenStroke(const QLineF &line)
void WatchPaintEngine::updateClipRegion(const QRegion& region, Qt::ClipOperation op)
{
- switch(op) {
+ QRegion mapped = _transform.map(region);
+ switch (op) {
case Qt::NoClip:
_clipEnabled = false;
_clipRegion = _area;
break;
case Qt::ReplaceClip:
_clipEnabled = true;
- _clipRegion = region;
+ _clipRegion = mapped;
break;
case Qt::IntersectClip:
_clipEnabled = true;
- _clipRegion &= region;
+ _clipRegion &= mapped;
break;
case Qt::UniteClip:
_clipEnabled = true;
- _clipRegion |= region;
+ _clipRegion |= mapped;
break;
}
}
void WatchPaintEngine::drawEllipse(const QRectF &r)
{
+ TRACE(qDebug() << __func__ << r);
damageRect(r);
_painter.drawEllipse(r);
}
void WatchPaintEngine::drawEllipse(const QRect &r)
{
+ TRACE(qDebug() << __func__ << r);
damageRect(r);
_painter.drawEllipse(r);
}
void WatchPaintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
{
+ TRACE(qDebug() << __func__ << r);
damageRect(r);
_painter.drawImage(r, pm, sr, flags);
}
void WatchPaintEngine::drawLines(const QLineF *lines, int lineCount)
{
+ TRACE(qDebug() << __func__ << lines << lineCount);
int i;
for (i = 0; i < lineCount; i++) {
const QLineF& line = lines[i];
@@ -125,6 +134,7 @@ void WatchPaintEngine::drawLines(const QLineF *lines, int lineCount)
void WatchPaintEngine::drawLines(const QLine *lines, int lineCount)
{
+ TRACE(qDebug() << __func__ << lines << lineCount);
int i;
for (i = 0; i < lineCount; i++) {
const QLine& line = lines[i];
@@ -135,6 +145,7 @@ void WatchPaintEngine::drawLines(const QLine *lines, int lineCount)
void WatchPaintEngine::drawPath(const QPainterPath &path)
{
+ TRACE(qDebug() << __func__ << path);
damageRect(path.boundingRect());
_painter.drawPath(path);
}
@@ -193,6 +204,7 @@ void WatchPaintEngine::drawPolygon(const QPoint *points, int pointCount, Polygon
void WatchPaintEngine::drawRects(const QRectF *rects, int rectCount)
{
+ TRACE(qDebug() << __func__ << rects << rectCount);
int i;
for (i = 0; i < rectCount; i++) {
const QRectF& r = rects[i];
@@ -211,6 +223,7 @@ void WatchPaintEngine::drawRects(const QRectF *rects, int rectCount)
void WatchPaintEngine::drawRects(const QRect *rects, int rectCount)
{
+ TRACE(qDebug() << __func__ << rects << rectCount);
int i;
for (i = 0; i < rectCount; i++) {
const QRect& r = rects[i];
@@ -230,6 +243,7 @@ void WatchPaintEngine::drawRects(const QRect *rects, int rectCount)
void WatchPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
{
+ TRACE(qDebug() << __func__ << p << textItem.text());
const qreal ascent = textItem.ascent();
const qreal descent = textItem.descent();
const qreal w = textItem.width();
@@ -239,6 +253,7 @@ void WatchPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
void WatchPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
{
+ TRACE(qDebug() << __func__ << r << pixmap << s);
damageRect(r);
_painter.drawTiledPixmap(r, pixmap, s);
}
@@ -251,14 +266,26 @@ QPaintEngine::Type WatchPaintEngine::type() const
void WatchPaintEngine::updateState(const QPaintEngineState &state)
{
const QPaintEngine::DirtyFlags flags = state.state();
+
+ TRACE(qDebug() << __func__ << flags);
+
+ if (flags & QPaintEngine::DirtyTransform)
+ {
+ TRACE(qDebug() << " " << "DirtyTransform" << state.transform());
+ _transform = state.transform();
+ _painter.setTransform(_transform);
+ }
+
if (flags & QPaintEngine::DirtyBackground)
{
_painter.setBackground(state.backgroundBrush());
}
+
if (flags & QPaintEngine::DirtyBackgroundMode)
{
_painter.setBackgroundMode(state.backgroundMode());
}
+
if (flags & QPaintEngine::DirtyBrush)
{
QBrush brush = state.brush();
@@ -271,22 +298,26 @@ void WatchPaintEngine::updateState(const QPaintEngineState &state)
}
if (flags & QPaintEngine::DirtyClipEnabled)
{
+ TRACE(qDebug() << " " << "DirtyClipEnabled" << state.isClipEnabled());
_clipEnabled = state.isClipEnabled();
_painter.setClipping(_clipEnabled);
}
if (flags & QPaintEngine::DirtyClipPath)
{
+ TRACE(qDebug() << " " << "DirtyClipPath" << state.clipPath().boundingRect());
QRegion region = state.clipPath().boundingRect().toAlignedRect();
updateClipRegion(region, state.clipOperation());
_painter.setClipPath(state.clipPath(), state.clipOperation());
}
if (flags & QPaintEngine::DirtyClipRegion)
{
+ TRACE(qDebug() << " " << "DirtyClipRegion" << state.clipRegion());
updateClipRegion(state.clipRegion(), state.clipOperation());
_painter.setClipRegion(state.clipRegion(), state.clipOperation());
}
if (flags & QPaintEngine::DirtyCompositionMode)
{
+ TRACE(qDebug() << " " << "DirtyCompositionMode" << state.compositionMode());
_painter.setCompositionMode(state.compositionMode());
}
if (flags & QPaintEngine::DirtyFont)
@@ -304,9 +335,6 @@ void WatchPaintEngine::updateState(const QPaintEngineState &state)
_penWidth = pen.widthF();
_painter.setPen(pen);
}
- if (flags & QPaintEngine::DirtyTransform)
- {
- _transform = state.transform();
- _painter.setTransform(_transform);
- }
+
+ TRACE(qDebug() << __func__ << "end");
}
diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp
index 35d2429..a6b5886 100644
--- a/libsowatch/watchserver.cpp
+++ b/libsowatch/watchserver.cpp
@@ -29,6 +29,11 @@ Watch* WatchServer::watch()
return _watch;
}
+const Watch* WatchServer::watch() const
+{
+ return _watch;
+}
+
QString WatchServer::nextWatchletButton() const
{
if (_nextWatchletButton >= 0) {
diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h
index edb4e1a..af2a8de 100644
--- a/libsowatch/watchserver.h
+++ b/libsowatch/watchserver.h
@@ -28,6 +28,7 @@ public:
explicit WatchServer(Watch *watch, QObject *parent = 0);
Watch* watch();
+ const Watch* watch() const;
QString nextWatchletButton() const;
void setNextWatchletButton(const QString& value);
diff --git a/libsowatch/watchsimulator.cpp b/libsowatch/watchsimulator.cpp
deleted file mode 100644
index 47496f2..0000000
--- a/libsowatch/watchsimulator.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <QtGui/QPainter>
-
-#include "watchsimulator.h"
-
-using namespace sowatch;
-
-WatchSimulator::WatchSimulator(QObject* parent) :
- Watch(parent)
-{
-
-}
diff --git a/libsowatch/watchsimulator.h b/libsowatch/watchsimulator.h
deleted file mode 100644
index 8189dfe..0000000
--- a/libsowatch/watchsimulator.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef SOWATCH_WATCHSIMULATOR_H
-#define SOWATCH_WATCHSIMULATOR_H
-
-#include "watch.h"
-#include "sowatch_global.h"
-
-namespace sowatch
-{
-
-class SOWATCH_EXPORT WatchSimulator : public Watch
-{
- Q_OBJECT
-public:
- explicit WatchSimulator(QObject *parent = 0);
-};
-
-}
-
-#endif // SOWATCH_WATCHSIMULATOR_H