diff options
37 files changed, 647 insertions, 342 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> ®ion) +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 diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp index 6f8edca..6dfdd2f 100644 --- a/metawatch/metawatch.cpp +++ b/metawatch/metawatch.cpp @@ -109,13 +109,14 @@ MetaWatch::MetaWatch(ConfigKey* settings, QObject* parent) :  	_connectTimer->setSingleShot(true);  	_connectAlignedTimer->setSingleShot(true); -	connect(_connectTimer, SIGNAL(timeout()), SLOT(retryConnect())); -	connect(_connectAlignedTimer, SIGNAL(timeout()), SLOT(retryConnect())); +	connect(_connectTimer, SIGNAL(timeout()), SLOT(timedReconnect())); +	connect(_connectAlignedTimer, SIGNAL(timeout()), SLOT(timedReconnect()));  	_sendTimer->setInterval(DelayBetweenMessages);  	connect(_sendTimer, SIGNAL(timeout()), SLOT(timedSend())); -	retryConnect(); +	// Do an initial connection attempt +	_connectTimer->start(100);  }  MetaWatch::~MetaWatch() @@ -249,7 +250,7 @@ void MetaWatch::displayNotification(Notification *notification)  		_idleTimer->stop();  	} else {  		_ringTimer->stop(); -		setVibrateMode(true, RingLength, RingLength, 2); +		// XXX setVibrateMode(true, RingLength, RingLength, 2);  		_idleTimer->start();  	}  } @@ -322,6 +323,22 @@ quint16 MetaWatch::calcCrc(const Message& msg)  	return calcCrc(data, msgSize + 4);  } +void MetaWatch::retryConnect() +{ +	delete _socket; +	_socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket); + +	connect(_socket, SIGNAL(connected()), SLOT(socketConnected())); +	connect(_socket, SIGNAL(disconnected()), SLOT(socketDisconnected())); +	connect(_socket, SIGNAL(readyRead()), SLOT(socketData())); +	connect(_socket, SIGNAL(error(QBluetoothSocket::SocketError)), +			SLOT(socketError(QBluetoothSocket::SocketError))); +	connect(_socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), +			SLOT(socketState(QBluetoothSocket::SocketState))); + +	_socket->connectToService(_address, 1, QIODevice::ReadWrite | QIODevice::Unbuffered); +} +  void MetaWatch::send(const Message &msg)  {  	_toSend.enqueue(msg); @@ -754,20 +771,9 @@ void MetaWatch::socketState(QBluetoothSocket::SocketState error)  	qDebug() << "socket is in" << error;  } -void MetaWatch::retryConnect() +void MetaWatch::timedReconnect()  { -	delete _socket; -	_socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket); - -	connect(_socket, SIGNAL(connected()), SLOT(socketConnected())); -	connect(_socket, SIGNAL(disconnected()), SLOT(socketDisconnected())); -	connect(_socket, SIGNAL(readyRead()), SLOT(socketData())); -	connect(_socket, SIGNAL(error(QBluetoothSocket::SocketError)), -			SLOT(socketError(QBluetoothSocket::SocketError))); -	connect(_socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), -			SLOT(socketState(QBluetoothSocket::SocketState))); - -	_socket->connectToService(_address, 1, QIODevice::ReadWrite | QIODevice::Unbuffered); +	retryConnect();  }  void MetaWatch::timedSend() diff --git a/metawatch/metawatch.h b/metawatch/metawatch.h index 760752b..b25b14d 100644 --- a/metawatch/metawatch.h +++ b/metawatch/metawatch.h @@ -198,8 +198,11 @@ protected:  	static quint16 calcCrc(const QByteArray& data, int size);  	static quint16 calcCrc(const Message& msg); +	/** Attempt a connection to the watch. */ +	virtual void retryConnect(); +  	/** Sends a message to the watch. Does not block. */ -	void send(const Message& msg); +	virtual void send(const Message& msg);  	/** Sends a message to the watch if a message of the same type is not  	 *  already queued. Does not block.  	 */ @@ -237,7 +240,7 @@ private slots:  	void socketData();  	void socketError(QBluetoothSocket::SocketError error);  	void socketState(QBluetoothSocket::SocketState error); -	void retryConnect(); +	void timedReconnect();  	void timedSend();  	void timedRing(); diff --git a/metawatch/metawatch.pro b/metawatch/metawatch.pro index 721380d..536ccee 100644 --- a/metawatch/metawatch.pro +++ b/metawatch/metawatch.pro @@ -12,25 +12,25 @@ maemo5 {  MOBILITY += connectivity systeminfo  SOURCES += metawatchplugin.cpp \ -    metawatchsimulatorform.cpp \ -    metawatchsimulator.cpp \      metawatchpaintengine.cpp \      metawatch.cpp \      metawatchdigital.cpp \      metawatchanalog.cpp \ -    metawatchscanner.cpp +    metawatchscanner.cpp \ +    metawatchdigitalsimulator.cpp \ +    metawatchdigitalsimulatorform.cpp  HEADERS += metawatchplugin.h \ -    metawatchsimulatorform.h \ -    metawatchsimulator.h \      metawatchpaintengine.h \      metawatch.h \      metawatchdigital.h \      metawatchanalog.h \ -    metawatchscanner.h +    metawatchscanner.h \ +    metawatchdigitalsimulator.h \ +    metawatchdigitalsimulatorform.h  FORMS += \ -	metawatchsimulatorform.ui +    metawatchdigitalsimulatorform.ui  res_files.files += res/graphics res/fonts  qml_files.files += qml/com qml/metawatch-digital-config.qml diff --git a/metawatch/metawatchdigitalsimulator.cpp b/metawatch/metawatchdigitalsimulator.cpp new file mode 100644 index 0000000..f12e987 --- /dev/null +++ b/metawatch/metawatchdigitalsimulator.cpp @@ -0,0 +1,119 @@ +#include <QtCore/QDebug> +#include <QtGui/QPainter> + +#include "metawatchdigitalsimulator.h" + +#define SIMULATE_DAMAGES 1 +#define SIMULATE_FRAMERATE 1 + +using namespace sowatch; + +MetaWatchDigitalSimulator::MetaWatchDigitalSimulator(ConfigKey *config, QObject *parent) : +	MetaWatchDigital(config, parent), +	_form(new MetaWatchDigitalSimulatorForm), +	_nextFrame(QTime::currentTime()) +{ +	_pixmap[IdleMode] = QPixmap(screenWidth, screenHeight); +	_pixmap[ApplicationMode] = QPixmap(screenWidth, screenHeight); +	_pixmap[NotificationMode] = QPixmap(screenWidth, screenHeight); +	_form->showNormal(); +	connect(_form, SIGNAL(buttonPressed(int)), SIGNAL(buttonPressed(int))); +	connect(_form, SIGNAL(buttonReleased(int)), SIGNAL(buttonReleased(int))); +} + +MetaWatchDigitalSimulator::~MetaWatchDigitalSimulator() +{ +	delete _form; +} + +bool MetaWatchDigitalSimulator::busy() const +{ +#if SIMULATE_FRAMERATE +	return _nextFrame > QTime::currentTime(); +#else +	return false; +#endif +} + +void MetaWatchDigitalSimulator::displayIdleScreen() +{ +	MetaWatchDigital::displayIdleScreen(); +	_form->refreshScreen(_pixmap[_currentMode]); +} + +void MetaWatchDigitalSimulator::displayNotification(Notification *notification) +{ +	MetaWatchDigital::displayNotification(notification); +	_form->refreshScreen(_pixmap[_currentMode]); +} + +void MetaWatchDigitalSimulator::displayApplication() +{ +	MetaWatchDigital::displayApplication(); +	// No need to refresh. +} + +void MetaWatchDigitalSimulator::clear(Mode mode, bool black) +{ +	_pixmap[mode].fill(black ? Qt::black : Qt::white); +	if (mode == _currentMode) { +		_form->refreshScreen(_pixmap[mode]); +	} +} + +void MetaWatchDigitalSimulator::update(Mode mode, const QList<QRect> &rects) +{ +#if SIMULATE_DAMAGES +	const QRect imageRect = _image[mode].rect(); +	QPainter p; +	QVector<bool> rows(96, false); + +	p.begin(&_pixmap[mode]); +	foreach (const QRect& rect, rects) { +		QRect r = rect.intersect(imageRect); +		for (int i = r.top(); i <= r.bottom(); i++) { +			rows[i] = true; +		} + +		p.drawImage(r, _image[mode], r); +	} +	p.end(); + +	int totalRows = rows.count(true); + +	qDebug() << "updated" << totalRows << "lines"; +	_nextFrame = QTime::currentTime().addMSecs(((totalRows / 2) + 1) * DelayBetweenMessages); +#else +	Q_UNUSED(rects); +	_pixmap[mode] = QPixmap::fromImage(_image[mode]); +	_nextFrame = QTime::currentTime().addMSecs(DelayBetweenMessages); +#endif +	if (mode == _currentMode) { +		_form->refreshScreen(_pixmap[mode]); +	} +} + +void MetaWatchDigitalSimulator::vibrate(bool on) +{ +	qDebug() << "vibrate" << on; +} + +void MetaWatchDigitalSimulator::retryConnect() +{ +	if (!_connected && _form) { +		qDebug() << "connected"; + +		_connected = true; +		_currentMode = IdleMode; +		_paintMode = IdleMode; + +		handleWatchConnected(); + +		emit connected(); +	} +} + +void MetaWatchDigitalSimulator::send(const Message &msg) +{ +	// Do not send messages +} diff --git a/metawatch/metawatchdigitalsimulator.h b/metawatch/metawatchdigitalsimulator.h new file mode 100644 index 0000000..6f5c130 --- /dev/null +++ b/metawatch/metawatchdigitalsimulator.h @@ -0,0 +1,40 @@ +#ifndef METAWATCHSIMULATOR_H +#define METAWATCHSIMULATOR_H + +#include <QtCore/QTime> +#include <QtGui/QPixmap> +#include "metawatchdigital.h" +#include "metawatchdigitalsimulatorform.h" + +namespace sowatch { + +class MetaWatchDigitalSimulator : public MetaWatchDigital +{ +    Q_OBJECT +public: +    explicit MetaWatchDigitalSimulator(ConfigKey *settings, QObject *parent = 0); +	~MetaWatchDigitalSimulator(); + +	bool busy() const; + +	void displayIdleScreen(); +	void displayNotification(Notification *notification); +	void displayApplication(); + +	void clear(Mode mode, bool black); +	void update(Mode mode, const QList<QRect> &rects); + +	void vibrate(bool on); + +	void retryConnect(); +	void send(const Message& msg); + +private: +	MetaWatchDigitalSimulatorForm* _form; +	QPixmap _pixmap[3]; +	QTime _nextFrame; +}; + +} + +#endif // METAWATCHSIMULATOR_H diff --git a/metawatch/metawatchdigitalsimulatorform.cpp b/metawatch/metawatchdigitalsimulatorform.cpp new file mode 100644 index 0000000..fc3c890 --- /dev/null +++ b/metawatch/metawatchdigitalsimulatorform.cpp @@ -0,0 +1,82 @@ +#include "metawatchdigitalsimulatorform.h" +#include "ui_metawatchdigitalsimulatorform.h" + +using namespace sowatch; + +MetaWatchDigitalSimulatorForm::MetaWatchDigitalSimulatorForm(QWidget* parent) : +    QWidget(parent), +    ui(new Ui::MetaWatchDigitalSimulatorForm) +{ +    ui->setupUi(this); +} + +MetaWatchDigitalSimulatorForm::~MetaWatchDigitalSimulatorForm() +{ +    delete ui; +} + +void MetaWatchDigitalSimulatorForm::refreshScreen(const QPixmap& pixmap) +{ +	ui->lblDisplay->setPixmap(pixmap); +	ui->lblDisplay->update(); +} + +void MetaWatchDigitalSimulatorForm::btnAPressed() +{ +	emit buttonPressed(0); +} + +void MetaWatchDigitalSimulatorForm::btnAReleased() +{ +	emit buttonReleased(0); +} + +void MetaWatchDigitalSimulatorForm::btnBPressed() +{ +	emit buttonPressed(1); +} + +void MetaWatchDigitalSimulatorForm::btnBReleased() +{ +	emit buttonReleased(1); +} + +void MetaWatchDigitalSimulatorForm::btnCPressed() +{ +	emit buttonPressed(2); +} + +void MetaWatchDigitalSimulatorForm::btnCReleased() +{ +	emit buttonReleased(2); +} + +void MetaWatchDigitalSimulatorForm::btnDPressed() +{ +	emit buttonPressed(3); +} + +void MetaWatchDigitalSimulatorForm::btnDReleased() +{ +	emit buttonReleased(3); +} + +void MetaWatchDigitalSimulatorForm::btnEPressed() +{ +	emit buttonPressed(4); +} + +void MetaWatchDigitalSimulatorForm::btnEReleased() +{ +	emit buttonReleased(4); +} + +void MetaWatchDigitalSimulatorForm::btnFPressed() +{ +	emit buttonPressed(5); +} + +void MetaWatchDigitalSimulatorForm::btnFReleased() +{ +	emit buttonReleased(5); +} diff --git a/metawatch/metawatchsimulatorform.h b/metawatch/metawatchdigitalsimulatorform.h index 0b45746..054a1a8 100644 --- a/metawatch/metawatchsimulatorform.h +++ b/metawatch/metawatchdigitalsimulatorform.h @@ -4,18 +4,18 @@  #include <QWidget>  namespace Ui { -	class MetaWatchSimulatorForm; +	class MetaWatchDigitalSimulatorForm;  }  namespace sowatch { -class MetaWatchSimulatorForm : public QWidget +class MetaWatchDigitalSimulatorForm : public QWidget  {      Q_OBJECT  public: -    explicit MetaWatchSimulatorForm(QWidget *parent = 0); -    ~MetaWatchSimulatorForm(); +    explicit MetaWatchDigitalSimulatorForm(QWidget *parent = 0); +    ~MetaWatchDigitalSimulatorForm();  	void refreshScreen(const QPixmap& screen); @@ -38,7 +38,7 @@ protected slots:  	void btnFReleased();  private: -    Ui::MetaWatchSimulatorForm *ui; +    Ui::MetaWatchDigitalSimulatorForm *ui;  };  } diff --git a/metawatch/metawatchsimulatorform.ui b/metawatch/metawatchdigitalsimulatorform.ui index 39280b3..239c342 100644 --- a/metawatch/metawatchsimulatorform.ui +++ b/metawatch/metawatchdigitalsimulatorform.ui @@ -1,7 +1,7 @@  <?xml version="1.0" encoding="UTF-8"?>  <ui version="4.0"> - <class>MetaWatchSimulatorForm</class> - <widget class="QWidget" name="MetaWatchSimulatorForm"> + <class>MetaWatchDigitalSimulatorForm</class> + <widget class="QWidget" name="MetaWatchDigitalSimulatorForm">    <property name="geometry">     <rect>      <x>0</x> @@ -11,29 +11,47 @@     </rect>    </property>    <property name="windowTitle"> -   <string>MetaWatch-Digital Simulator</string> +   <string>MetaWatch Digital Simulator</string>    </property>    <layout class="QHBoxLayout" name="horizontalLayout">     <item>      <layout class="QVBoxLayout" name="btnsLeft">       <item> -      <widget class="QPushButton" name="btnA"> +      <widget class="QPushButton" name="btnF"> +       <property name="maximumSize"> +        <size> +         <width>50</width> +         <height>16777215</height> +        </size> +       </property>         <property name="text"> -        <string>A</string> +        <string>F</string>         </property>        </widget>       </item>       <item> -      <widget class="QPushButton" name="btnB"> +      <widget class="QPushButton" name="btnE"> +       <property name="maximumSize"> +        <size> +         <width>50</width> +         <height>16777215</height> +        </size> +       </property>         <property name="text"> -        <string>B</string> +        <string>E</string>         </property>        </widget>       </item>       <item> -      <widget class="QPushButton" name="btnC"> +      <widget class="QPushButton" name="btnD"> +       <property name="maximumSize"> +        <size> +         <width>50</width> +         <height>16777215</height> +        </size> +       </property>         <property name="text"> -        <string>C</string> +        <string>D</string>         </property>        </widget>       </item> @@ -58,23 +76,41 @@     <item>      <layout class="QVBoxLayout" name="btnsRight">       <item> -      <widget class="QPushButton" name="btnD"> +      <widget class="QPushButton" name="btnA"> +       <property name="maximumSize"> +        <size> +         <width>50</width> +         <height>16777215</height> +        </size> +       </property>         <property name="text"> -        <string>D</string> +        <string>A</string>         </property>        </widget>       </item>       <item> -      <widget class="QPushButton" name="btnE"> +      <widget class="QPushButton" name="btnB"> +       <property name="maximumSize"> +        <size> +         <width>50</width> +         <height>16777215</height> +        </size> +       </property>         <property name="text"> -        <string>E</string> +        <string>B</string>         </property>        </widget>       </item>       <item> -      <widget class="QPushButton" name="btnF"> +      <widget class="QPushButton" name="btnC"> +       <property name="maximumSize"> +        <size> +         <width>50</width> +         <height>16777215</height> +        </size> +       </property>         <property name="text"> -        <string>F</string> +        <string>C</string>         </property>        </widget>       </item> @@ -87,7 +123,7 @@    <connection>     <sender>btnA</sender>     <signal>pressed()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnAPressed()</slot>     <hints>      <hint type="sourcelabel"> @@ -103,7 +139,7 @@    <connection>     <sender>btnA</sender>     <signal>released()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnAReleased()</slot>     <hints>      <hint type="sourcelabel"> @@ -119,7 +155,7 @@    <connection>     <sender>btnB</sender>     <signal>pressed()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnBPressed()</slot>     <hints>      <hint type="sourcelabel"> @@ -135,7 +171,7 @@    <connection>     <sender>btnB</sender>     <signal>released()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnBReleased()</slot>     <hints>      <hint type="sourcelabel"> @@ -151,7 +187,7 @@    <connection>     <sender>btnC</sender>     <signal>pressed()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnCPressed()</slot>     <hints>      <hint type="sourcelabel"> @@ -167,7 +203,7 @@    <connection>     <sender>btnC</sender>     <signal>released()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnCReleased()</slot>     <hints>      <hint type="sourcelabel"> @@ -183,7 +219,7 @@    <connection>     <sender>btnD</sender>     <signal>pressed()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnDPressed()</slot>     <hints>      <hint type="sourcelabel"> @@ -199,7 +235,7 @@    <connection>     <sender>btnD</sender>     <signal>released()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnDReleased()</slot>     <hints>      <hint type="sourcelabel"> @@ -215,7 +251,7 @@    <connection>     <sender>btnE</sender>     <signal>pressed()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnEPressed()</slot>     <hints>      <hint type="sourcelabel"> @@ -231,7 +267,7 @@    <connection>     <sender>btnE</sender>     <signal>released()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnEReleased()</slot>     <hints>      <hint type="sourcelabel"> @@ -247,7 +283,7 @@    <connection>     <sender>btnF</sender>     <signal>pressed()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnFPressed()</slot>     <hints>      <hint type="sourcelabel"> @@ -263,7 +299,7 @@    <connection>     <sender>btnF</sender>     <signal>released()</signal> -   <receiver>MetaWatchSimulatorForm</receiver> +   <receiver>MetaWatchDigitalSimulatorForm</receiver>     <slot>btnFReleased()</slot>     <hints>      <hint type="sourcelabel"> diff --git a/metawatch/metawatchplugin.cpp b/metawatch/metawatchplugin.cpp index f73c127..0969ddf 100644 --- a/metawatch/metawatchplugin.cpp +++ b/metawatch/metawatchplugin.cpp @@ -1,8 +1,8 @@  #include <QtGui/QFontDatabase>  #include <QtConnectivity/QBluetoothAddress> -#include "metawatchdigital.h"  #include "metawatchanalog.h" -#include "metawatchsimulator.h" +#include "metawatchdigital.h" +#include "metawatchdigitalsimulator.h"  #include "metawatchscanner.h"  #include "metawatchplugin.h" @@ -30,7 +30,7 @@ MetaWatchPlugin::~MetaWatchPlugin()  QStringList MetaWatchPlugin::drivers()  {  	QStringList d; -	d << "metawatch-digital" << "metawatch-analog"; +	d << "metawatch-analog" << "metawatch-digital" << "metawatch-digital-simulator";  	return d;  } @@ -54,6 +54,8 @@ Watch* MetaWatchPlugin::getWatch(const QString& driver, ConfigKey* settings, QOb  		return new MetaWatchDigital(settings, parent);  	} else if (driver == "metawatch-analog") {  		return new MetaWatchAnalog(settings, parent); +	} else if (driver == "metawatch-digital-simulator") { +		return new MetaWatchDigitalSimulator(settings, parent);  	} else {  		return 0;  	} diff --git a/metawatch/metawatchsimulator.cpp b/metawatch/metawatchsimulator.cpp deleted file mode 100644 index 57a4f0c..0000000 --- a/metawatch/metawatchsimulator.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include <QtCore/QDebug> -#include <QtGui/QPainter> - -#include "metawatchsimulator.h" - -#define SIMULATE_DAMAGES 1 -#define SIMULATE_FRAMERATE 1 - -using namespace sowatch; - -MetaWatchSimulator::MetaWatchSimulator(QObject *parent) : -	WatchSimulator(parent), -	_image(96, 96, QImage::Format_Mono), -	_screen(96, 96), -	_form(new MetaWatchSimulatorForm), -	_nextFrame(QTime::currentTime()) -{ -	_form->showNormal(); -	connect(_form, SIGNAL(destroyed()), SIGNAL(disconnected())); -	connect(_form, SIGNAL(buttonPressed(int)), SIGNAL(buttonPressed(int))); -	connect(_form, SIGNAL(buttonReleased(int)), SIGNAL(buttonReleased(int))); -} - -MetaWatchSimulator::~MetaWatchSimulator() -{ -	delete _form; -} - -QString MetaWatchSimulator::model() const -{ -	return "metawatch-digital"; -} - -bool MetaWatchSimulator::isConnected() const -{ -	return true; -} - -bool MetaWatchSimulator::busy() const -{ -#if SIMULATE_FRAMERATE -	return _nextFrame > QTime::currentTime(); -#else -	return false; -#endif -} - -void MetaWatchSimulator::update(const QList<QRect> &rects) -{ -#if SIMULATE_DAMAGES -	const QRect imageRect = _image.rect(); -	QPainter p; -	QVector<bool> rows(96, false); -	unsigned total = 0, totalRows; - -	p.begin(&_screen); -	foreach (const QRect& rect, rects) { -		QRect r = rect.intersect(imageRect); -		for (int i = r.top(); i <= r.bottom(); i++) { -			rows[i] = true; -		} -		total += r.width() * r.height(); - -		p.drawImage(r, _image, r); -	} -	p.end(); - -	totalRows = rows.count(true); - -	_form->refreshScreen(_screen); - -	qDebug() << "updated " << total << " pixels " << totalRows << " lines"; -	_nextFrame = QTime::currentTime().addMSecs(((totalRows / 2) + 1) * 30); -#else -	_form->refreshScreen(QPixmap::fromImage(_image)); -	_nextFrame = QTime::currentTime().addMSecs(30); -#endif -} - -void MetaWatchSimulator::vibrate(bool on) -{ -	qDebug() << "vibrate" << on; -} diff --git a/metawatch/metawatchsimulator.h b/metawatch/metawatchsimulator.h deleted file mode 100644 index 38391d0..0000000 --- a/metawatch/metawatchsimulator.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef METAWATCHSIMULATOR_H -#define METAWATCHSIMULATOR_H - -#include <QtCore/QTime> -#include "watchsimulator.h" -#include "metawatchsimulatorform.h" - -namespace sowatch { - -class MetaWatchSimulator : public WatchSimulator -{ -    Q_OBJECT -public: -    explicit MetaWatchSimulator(QObject *parent = 0); -	~MetaWatchSimulator(); - -	QString model() const; -	bool isConnected() const; -	bool busy() const; - -	void update(const QList<QRect> &rects); -	void vibrate(bool on); - -protected: -	QImage _image; -	QPixmap _screen; -	MetaWatchSimulatorForm* _form; -	QTime _nextFrame; -}; - -} - -#endif // METAWATCHSIMULATOR_H diff --git a/metawatch/metawatchsimulatorform.cpp b/metawatch/metawatchsimulatorform.cpp deleted file mode 100644 index f2323bd..0000000 --- a/metawatch/metawatchsimulatorform.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "metawatchsimulatorform.h" -#include "ui_metawatchsimulatorform.h" - -using namespace sowatch; - -MetaWatchSimulatorForm::MetaWatchSimulatorForm(QWidget* parent) : -    QWidget(parent), -    ui(new Ui::MetaWatchSimulatorForm) -{ -    ui->setupUi(this); -} - -MetaWatchSimulatorForm::~MetaWatchSimulatorForm() -{ -    delete ui; -} - -void MetaWatchSimulatorForm::refreshScreen(const QPixmap& pixmap) -{ -	ui->lblDisplay->setPixmap(pixmap); -	ui->lblDisplay->update(); -} - -void MetaWatchSimulatorForm::btnAPressed() -{ -	emit buttonPressed(0); -} - -void MetaWatchSimulatorForm::btnAReleased() -{ -	emit buttonReleased(0); -} - -void MetaWatchSimulatorForm::btnBPressed() -{ -	emit buttonPressed(1); -} - -void MetaWatchSimulatorForm::btnBReleased() -{ -	emit buttonReleased(1); -} - -void MetaWatchSimulatorForm::btnCPressed() -{ -	emit buttonPressed(2); -} - -void MetaWatchSimulatorForm::btnCReleased() -{ -	emit buttonReleased(2); -} - -void MetaWatchSimulatorForm::btnDPressed() -{ -	emit buttonPressed(3); -} - -void MetaWatchSimulatorForm::btnDReleased() -{ -	emit buttonReleased(3); -} - -void MetaWatchSimulatorForm::btnEPressed() -{ -	emit buttonPressed(4); -} - -void MetaWatchSimulatorForm::btnEReleased() -{ -	emit buttonReleased(4); -} - -void MetaWatchSimulatorForm::btnFPressed() -{ -	emit buttonPressed(5); -} - -void MetaWatchSimulatorForm::btnFReleased() -{ -	emit buttonReleased(5); -} diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/MWLabel.qml b/metawatch/qml/com/javispedro/sowatch/metawatch/MWLabel.qml index d1fe507..3ce64ca 100644 --- a/metawatch/qml/com/javispedro/sowatch/metawatch/MWLabel.qml +++ b/metawatch/qml/com/javispedro/sowatch/metawatch/MWLabel.qml @@ -2,5 +2,5 @@ import Qt 4.7  Text {  	font.family: "MetaWatch Large 16pt" -	font.pixelSize: 16 +	font.pointSize: 10.5  } diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml b/metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml index b6764b7..37b9093 100644 --- a/metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml +++ b/metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml @@ -4,10 +4,13 @@ ListView {  	id: list  	property bool selectable: true +	property bool indicator: true  	interactive: false  	highlightFollowsCurrentItem: false +	keyNavigationWraps: false  	boundsBehavior: Flickable.StopAtBounds +	flickableDirection: Flickable.VerticalFlick  	property real currentItemTop: currentItem !== null ? currentItem.y - contentY : 0  	property real currentItemBottom: currentItem !== null ? currentItemTop + currentItem.height : 0 @@ -44,8 +47,12 @@ ListView {  				return;  			}  			if (currentIndex >= 0 && currentItemTop > 0) { +				var prevContentY = contentY;  				// If the previous item is visible, highlight it  				decrementCurrentIndex(); +				// ListView will "smoothtly scroll the list" even if hightlightFollowsCurrentItem is false, +				// so we have to add the following ugly workaround: +				contentY = prevContentY;  			}  			if (currentItemTop <= 0) {  				// If the previous item now is still not visible, scroll @@ -59,4 +66,30 @@ ListView {  			}  		}  	} + +	Rectangle { +		id: indicatorContainer +		visible: list.indicator && (list.contentHeight > list.height) +		anchors.top: parent.top +		anchors.right: parent.right +		anchors.bottom: parent.bottom +		width: 4 + +		color: "white" + +		Rectangle { +			id: indicatorRect + +			property int minHeight: 10 + +			anchors.right: parent.right +			anchors.left: parent.left +			anchors.leftMargin: 1 + +			y: (list.contentY / list.contentHeight) * indicatorContainer.height +			height: Math.max(minHeight, (list.height / list.contentHeight) * indicatorContainer.height) + +			color: "black" +		} +	}  } diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/MWSmallLabel.qml b/metawatch/qml/com/javispedro/sowatch/metawatch/MWSmallLabel.qml deleted file mode 100644 index d26e058..0000000 --- a/metawatch/qml/com/javispedro/sowatch/metawatch/MWSmallLabel.qml +++ /dev/null @@ -1,6 +0,0 @@ -import Qt 4.7 - -Text { -	font.family: "MetaWatch Large caps 8pt" -	font.pixelSize: 8 -} diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml b/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml index 017d6a1..b87d535 100644 --- a/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml +++ b/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml @@ -5,6 +5,7 @@ Rectangle {  	height: 16  	property alias text: label.text +	property alias font: label.font  	property alias icon: image  	Image { @@ -18,5 +19,6 @@ Rectangle {  		anchors.left: image.right  		anchors.leftMargin: 2  		anchors.verticalCenter: parent.verticalCenter +		font.pointSize: 12  	}  } diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir b/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir index c6b0714..10ca498 100644 --- a/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir +++ b/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir @@ -1,5 +1,4 @@  MWPage 1.0 MWPage.qml  MWLabel 1.0 MWLabel.qml -MWSmallLabel 1.0 MWSmallLabel.qml  MWTitle 1.0 MWTitle.qml  MWListView 1.0 MWListView.qml diff --git a/notificationswatchlet/metawatch-digital.qml b/notificationswatchlet/metawatch-digital.qml index 71c52a8..57a6176 100644 --- a/notificationswatchlet/metawatch-digital.qml +++ b/notificationswatchlet/metawatch-digital.qml @@ -1,12 +1,7 @@  import Qt 4.7  import com.javispedro.sowatch.metawatch 1.0 -Rectangle { -	width: 96 -	height: 96 - -	color: "white" - +MWPage {  	MWTitle {  		id: title  		anchors.top: parent.top @@ -22,7 +17,9 @@ Rectangle {  		anchors.left: parent.left  		anchors.right: parent.right  		anchors.bottom: parent.bottom +		clip: true  		model: watch.notifications +  		delegate: Rectangle {  			id: notifDelegate  			property bool selected: ListView.isCurrentItem @@ -30,14 +27,16 @@ Rectangle {  			height: childrenRect.height  			color: ListView.isCurrentItem ? "black" : "white"  			Column { +				width: parent.width  				MWLabel { -					width: notifs.width +					width: parent.width  					text: model.modelData.title  					wrapMode: Text.WrapAtWordBoundaryOrAnywhere  					color: notifDelegate.selected ? "white" : "black" +					font.pointSize: 12  				} -				MWSmallLabel { -					width: notifs.width +				MWLabel { +					width: parent.width  					text: model.modelData.body  					wrapMode: Text.WrapAtWordBoundaryOrAnywhere  					color: notifDelegate.selected ? "white" : "black" diff --git a/sowatch.pro b/sowatch.pro index b5eabdc..460fcfb 100644 --- a/sowatch.pro +++ b/sowatch.pro @@ -9,7 +9,7 @@ metawatch.depends = libsowatch  # Some watchlets  SUBDIRS += notificationswatchlet sysinfowatchlet -SUBDIRS += qmsgwatchlet +#SUBDIRS += qmsgwatchlet  SUBDIRS += qmapwatchlet  notificationswatchlet.depends = libsowatch  sysinfowatchlet.depends = libsowatch diff --git a/sowatchd/main.cpp b/sowatchd/main.cpp index 7853cde..67ed7ac 100644 --- a/sowatchd/main.cpp +++ b/sowatchd/main.cpp @@ -21,6 +21,7 @@ int main(int argc, char *argv[])  	QApplication::setOrganizationDomain("com.javispedro.sowatch");  	QApplication::setOrganizationName("sowatch");  	QApplication::setApplicationName("sowatchd"); +	QApplication::setQuitOnLastWindowClosed(false);  	sowatch::daemon = new Daemon(&app);  	new DaemonAdaptor(sowatch::daemon); diff --git a/sysinfowatchlet/metawatch-digital.qml b/sysinfowatchlet/metawatch-digital.qml index e94ad27..6e26174 100644 --- a/sysinfowatchlet/metawatch-digital.qml +++ b/sysinfowatchlet/metawatch-digital.qml @@ -17,7 +17,7 @@ Rectangle {  			icon.source: "icon.png"  		} -		MWSmallLabel { +		MWLabel {  			text: "Battery: " + batteryLevel + "%"  		} @@ -38,7 +38,7 @@ Rectangle {  			}  		} -		MWSmallLabel { +		MWLabel {  			width: parent.width  			text: "Connected to:"  		} diff --git a/testnotification/testnotificationprovider.cpp b/testnotification/testnotificationprovider.cpp index 960f450..f66ae89 100644 --- a/testnotification/testnotificationprovider.cpp +++ b/testnotification/testnotificationprovider.cpp @@ -3,14 +3,19 @@  using namespace sowatch; +int TestNotificationProvider::_counter = 1; +  TestNotificationProvider::TestNotificationProvider(QObject *parent) :      NotificationProvider(parent),      _timer(new QTimer(this))  { -	QTimer::singleShot(15000, this, SLOT(generateInitialNotification())); +	QTimer::singleShot(1000, this, SLOT(generateInitialNotification())); +	QTimer::singleShot(1200, this, SLOT(generateNotification())); +	QTimer::singleShot(1400, this, SLOT(generateNotification())); +	QTimer::singleShot(1600, this, SLOT(generateNotification()));  	connect(_timer, SIGNAL(timeout()), SLOT(generateNotification()));  	_timer->setInterval(60000); -	_timer->start(); +	//_timer->start();  }  TestNotificationProvider::~TestNotificationProvider() @@ -28,7 +33,9 @@ void TestNotificationProvider::generateInitialNotification()  void TestNotificationProvider::generateNotification()  {  	TestNotification *n = new TestNotification(Notification::ImNotification, -	                                           "A friend", -	                                           "I will keep talking to you"); +	                                           QString("Friend %1").arg(_counter++), +	                                           "Lorem ipsum dolor sit amet. " +	                                           "Consectetur adipiscing elit. " +	                                           "Donec non congue augue.");  	emit incomingNotification(n);  } diff --git a/testnotification/testnotificationprovider.h b/testnotification/testnotificationprovider.h index 9931ea0..7bca1f3 100644 --- a/testnotification/testnotificationprovider.h +++ b/testnotification/testnotificationprovider.h @@ -21,6 +21,7 @@ private slots:  	void generateNotification();  private: +	static int _counter;  	QTimer *_timer;  }; | 
