]> git.zarvox.org Git - shareboard.git/commitdiff
Progress toward painting images.
authorDrew Fisher <drew.m.fisher@gmail.com>
Fri, 8 Oct 2010 07:30:59 +0000 (00:30 -0700)
committerDrew Fisher <drew.m.fisher@gmail.com>
Fri, 8 Oct 2010 07:30:59 +0000 (00:30 -0700)
connectionmanager.cpp
mainwindow.cpp
shareboard.cpp
shareboard.h
shareboard.pro
shareboardcanvas.cpp
shareboardcanvas.h

index 88eee479a7479b0e2a8c812c8bd0d18df7f5a2bd..d1b86f5b3997e6044b175b52bb65a73a5b9b9112 100644 (file)
@@ -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");
index 5eca4c896fbbc9fe5371d3973553d13a76398ff3..0180e02767bff359fc203814c59c7f0f06a4263c 100644 (file)
@@ -85,7 +85,7 @@ void MainWindow::marshallAction(Action* action) {
                case Action::DrawLine: // set the action's thickness, color
                        {
                                DrawLineAction* a = static_cast<DrawLineAction*>(action);
-                               a->color == Qt::blue;
+                               a->color = Qt::blue;
                                a->width = 3;
                        }
                        break;
index 171c49055ef2216cdeeab4ec532c616cde07f7f3..8a95b2667c49831121f1a45d41fc91ccad5ae897 100644 (file)
@@ -5,12 +5,17 @@
 #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);
@@ -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<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() {
+       
+}
+*/
index f4422b09050d0e1d02444dd9f67e7abeeb5e0a34..58f79bed38bfa71aab7e7cbf681df024414b8afe 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <QWidget>
 #include <QPointF>
+#include <QDateTime>
+#include <QMap>
 
 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<int, QPointF> viewCursors;
+
+//             QPixmap renderAtTime(QDateTime time);
+//             QPixmap renderOneChange();
+       friend class ShareboardCanvas;
 };
 
 #endif // __SHAREBOARD_H__
index 6a14cc47cdb682abe77b19528f85213356afc8de..13f9b975a068416f1ecb8ce9c2a82458fe39cd8e 100644 (file)
@@ -4,7 +4,7 @@
 
 TEMPLATE = app
 TARGET = shareboard
-CONFIG += qt
+CONFIG += qt debug
 QT += network
 DEPENDPATH += .
 INCLUDEPATH += .
index cc2dae193c32db65a46773eac83cdfb8b22b3f81..84a56f11e5bcf648fa7dbe7dd37e0d9d0d4262c6 100644 (file)
@@ -4,18 +4,19 @@
 #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) {
@@ -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
 }
index c48b02606c903a13e376a710072c33b4c444d23d..3414580b03a68314080c0c7192e705884bc4a1eb 100644 (file)
@@ -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<QPointF> dragPath;
-       QMap<int, QPointF> cursors;
+       Shareboard* board;
 };
 
 #endif //__SHAREBOARDCANVAS_H__