#include "connectwidget.h"
#include "action.h"
#include <QDebug>
+#include <QPainter>
+#include <QPen>
+#include <QImage>
Shareboard::Shareboard(QWidget* parent) : QWidget(parent) {
layout = new QStackedLayout(this);
prompt = new ConnectWidget(this);
canvas = new ShareboardCanvas(this);
+ canvas->setModel(this);
+
layout->addWidget(prompt);
layout->addWidget(canvas);
setLayout(layout);
// All real userIDs are positive, so we won't trigger the delete in postAction until setUserID is called
userID = -1;
+ viewIndex = 0;
+ viewImage = QImage(1024,768,QImage::Format_ARGB32_Premultiplied);
+ viewImage.fill(Qt::white);
QObject::connect(prompt, SIGNAL(connectToServer(QString, QString)), this, SIGNAL(connectToServer(QString, QString)));
QObject::connect(canvas, SIGNAL(mouseMovedTo(QPointF)), this, SLOT(handleMouseMoved(QPointF)));
QObject::connect(canvas, SIGNAL(segmentDrawn(QPointF,QPointF)), this, SLOT(handleSegmentDrawn(QPointF,QPointF)));
+ qDebug() << viewImage.rect();
}
Shareboard::~Shareboard() {
delete localHistory[i];
}
+QImage Shareboard::view() {
+ return viewImage;
+}
+
void Shareboard::handleMouseMoved(QPointF pos) {
MouseMoveAction* action = new MouseMoveAction();
action->userID = userID;
action->pos = pos;
emit actionHappened(action);
- qDebug() << "shareboard.cpp: mouse moved to" << pos;
+ //qDebug() << "shareboard.cpp: mouse moved to" << pos;
}
void Shareboard::handleSegmentDrawn(QPointF start, QPointF end) {
action->points.append(start);
action->points.append(end);
emit actionHappened(action);
- qDebug() << "shareboard.cpp: segment drawn from" << start << "to" << end;
+ //qDebug() << "shareboard.cpp: segment drawn from" << start << "to" << end;
}
void Shareboard::postAction(Action* action) {
localHistory.removeFirst();
}
history.append(action);
+ if(viewIndex+1 == history.size()) {
+ jumpToIndex(viewIndex+1);
+ } else {
+ qDebug() << "viewIndex = "<< viewIndex;
+ qDebug() << "history.size = "<< history.size();
+ }
}
void Shareboard::postLocalAction(Action* action) {
void Shareboard::setUserID(int id) {
userID = id;
}
+
+void Shareboard::jumpToIndex(int index) {
+ int i = 0;
+ if(index < viewIndex) {
+ viewImage = QImage(1024,768,QImage::Format_ARGB32_Premultiplied);
+ viewImage.fill(Qt::white);
+ viewCursors.clear();
+ } else {
+ i = viewIndex;
+ }
+ QPainter p;
+ qDebug() << "\t\tjumpToIndex():" << viewImage.valid(0,0) << viewImage.rect();
+ p.begin(&viewImage);
+ while(i < history.size() && i < index) {
+ viewTime = history[i]->timestamp;
+ Action* action = history[i];
+ // Apply action to pixmap
+ switch(action->type) {
+ case Action::INVALID:
+ case Action::UserJoin:
+ break;
+ case Action::UserPart:
+ {
+ viewCursors.remove(action->userID);
+ }
+ break;
+ case Action::MouseMove:
+ {
+ MouseMoveAction* a = static_cast<MouseMoveAction*>(action);
+ viewCursors[a->userID] = a->pos;
+ }
+ break;
+ case Action::DrawLine:
+ {
+ DrawLineAction* a = static_cast<DrawLineAction*>(action);
+ QPen pen(a->color);
+ pen.setWidth(a->width);
+ p.setPen(pen);
+ qDebug() << "Painting line\tcolor: " << a->color << "\twidth:" << a->width;
+ p.drawPolyline(a->points.data(), a->points.size());
+ }
+ break;
+ case Action::AddImage:
+ //TODO Implement this
+ case Action::UserChat:
+ case Action::UserSynced:
+ break;
+ }
+ i++;
+ }
+ p.end();
+}
+/*
+void Shareboard::jumpToTime(QDateTime time) {
+ int i = 0;
+ if(time < viewTime) {
+ // Start from a blank pixmap, trace through all changes up until time
+ viewImage = QImage(1024,768,QImage::Format_ARGB32_Premultiplied);
+ viewImage.fill(Qt::white);
+ viewCursors.clear();
+ } else {
+ while(i < history.size() && history[i]->timestamp <= viewTime)
+ i++;
+ }
+ QPainter p;
+ p.begin(&viewImage);
+ // Now, i matches either the beginning of time or the entry for the currently-rendered pixmap,
+ // whichever is more useful
+ // Now, apply all actions from i until time
+ while(i < history.size() && history[i]->timestamp <= time) {
+ }
+ qDebug() << "i is at" << i << "of" << history.size();
+ p.end();
+ qDebug() << "cursors:" << viewCursors;
+}
+*/
+
+/*
+QPixmap renderAtTime(QDateTime time) {
+ QPixmap pixmap;
+ return pixmap;
+}
+
+QPixmap renderOneChange() {
+
+}
+*/
#include <QPainter>
#include <QPixmap>
#include <QDebug>
+#include "shareboard.h"
ShareboardCanvas::ShareboardCanvas(QWidget* parent) : QWidget(parent) {
setMinimumSize(640,480);
setMouseTracking(true);
- currentScene = new QPixmap(size());
- currentScene->fill();
mouseDown = false;
}
ShareboardCanvas::~ShareboardCanvas() {
- if (currentScene)
- delete currentScene;
+}
+
+void ShareboardCanvas::setModel(Shareboard* b) {
+ board = b;
}
void ShareboardCanvas::mouseMoveEvent(QMouseEvent* event) {
Q_UNUSED(event)
QPainter p(this);
// Paint the background from the saved state
- p.drawPixmap(0, 0, *currentScene);
+ p.drawImage(0, 0, board->view());
+ qDebug() << "ShareboardCanvas:" << board->view().rect();
+ qDebug() << "ShareboardCanvas:" << board->viewIndex;
+ p.drawEllipse(0,0,100,100);
// Now paint our local changes on top of it
+
//p.set
// Now paint the set of mouse cursors on top of that
}