From: Drew Fisher Date: Fri, 8 Oct 2010 07:30:59 +0000 (-0700) Subject: Progress toward painting images. X-Git-Url: http://git.zarvox.org/static/%7Bthis.props.bicon_url%7D?a=commitdiff_plain;h=c01d5f5da5d4f981e9edd409b12c9cf8642cd9bd;p=shareboard.git Progress toward painting images. --- diff --git a/connectionmanager.cpp b/connectionmanager.cpp index 88eee47..d1b86f5 100644 --- a/connectionmanager.cpp +++ b/connectionmanager.cpp @@ -47,11 +47,11 @@ void ConnectionManager::haveData() { quint16 t = 0; // Type QString timestring; textstream >> mesgID >> userID >> timestring >> t; - qDebug() << "Read line:"; + /*qDebug() << "Read line:"; qDebug() << "\tmesgID: "<< mesgID; qDebug() << "\tuserID: "<< userID; qDebug() << "\ttime : "<< timestring; - qDebug() << "\ttype : "<< t; + qDebug() << "\ttype : "<< t;*/ // Validate input QDateTime timestamp = QDateTime::fromString(timestring, "yyyy-MM-ddTHH:mm:ss.zzz"); diff --git a/mainwindow.cpp b/mainwindow.cpp index 5eca4c8..0180e02 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -85,7 +85,7 @@ void MainWindow::marshallAction(Action* action) { case Action::DrawLine: // set the action's thickness, color { DrawLineAction* a = static_cast(action); - a->color == Qt::blue; + a->color = Qt::blue; a->width = 3; } break; diff --git a/shareboard.cpp b/shareboard.cpp index 171c490..8a95b26 100644 --- a/shareboard.cpp +++ b/shareboard.cpp @@ -5,12 +5,17 @@ #include "connectwidget.h" #include "action.h" #include +#include +#include +#include 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); @@ -18,10 +23,14 @@ Shareboard::Shareboard(QWidget* parent) : QWidget(parent) { // 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() { @@ -31,12 +40,16 @@ 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) { @@ -46,7 +59,7 @@ 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) { @@ -55,6 +68,12 @@ 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) { @@ -72,3 +91,90 @@ void Shareboard::switchToPrompt() { 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(action); + viewCursors[a->userID] = a->pos; + } + break; + case Action::DrawLine: + { + DrawLineAction* a = static_cast(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() { + +} +*/ diff --git a/shareboard.h b/shareboard.h index f4422b0..58f79be 100644 --- a/shareboard.h +++ b/shareboard.h @@ -3,6 +3,8 @@ #include #include +#include +#include class QStackedLayout; class ConnectWidget; @@ -16,6 +18,7 @@ class Shareboard : public QWidget { public: Shareboard(QWidget* parent = 0); ~Shareboard(); + QImage view(); public slots: void handleMouseMoved(QPointF pos); @@ -25,6 +28,8 @@ class Shareboard : public QWidget { void switchToBoard(); void switchToPrompt(); void setUserID(int id); + void jumpToIndex(int index); + //void jumpToTime(QDateTime time); signals: void connectToServer(QString, QString); @@ -37,6 +42,15 @@ class Shareboard : public QWidget { History history; History localHistory; int userID; + // These items represent the present state of the view. + QDateTime viewTime; + QImage viewImage; + int viewIndex; // The index of the first action we haven't applied. + QMap viewCursors; + +// QPixmap renderAtTime(QDateTime time); +// QPixmap renderOneChange(); + friend class ShareboardCanvas; }; #endif // __SHAREBOARD_H__ diff --git a/shareboard.pro b/shareboard.pro index 6a14cc4..13f9b97 100644 --- a/shareboard.pro +++ b/shareboard.pro @@ -4,7 +4,7 @@ TEMPLATE = app TARGET = shareboard -CONFIG += qt +CONFIG += qt debug QT += network DEPENDPATH += . INCLUDEPATH += . diff --git a/shareboardcanvas.cpp b/shareboardcanvas.cpp index cc2dae1..84a56f1 100644 --- a/shareboardcanvas.cpp +++ b/shareboardcanvas.cpp @@ -4,18 +4,19 @@ #include #include #include +#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) { @@ -51,8 +52,12 @@ void ShareboardCanvas::paintEvent(QPaintEvent* 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 } diff --git a/shareboardcanvas.h b/shareboardcanvas.h index c48b026..3414580 100644 --- a/shareboardcanvas.h +++ b/shareboardcanvas.h @@ -8,6 +8,7 @@ class QMouseEvent; class QPaintEvent; class QPixmap; +class Shareboard; class ShareboardCanvas : public QWidget { Q_OBJECT @@ -18,14 +19,14 @@ public: void mousePressEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event); void paintEvent(QPaintEvent* event); + void setModel(Shareboard* board); signals: void mouseMovedTo(QPointF pos); void segmentDrawn(QPointF start, QPointF end); private: bool mouseDown; - QPixmap* currentScene; QVector dragPath; - QMap cursors; + Shareboard* board; }; #endif //__SHAREBOARDCANVAS_H__