Begin implementing ShareboardCanvas, the actual drawing surface.
#include <QMenuBar>
#include <QStatusBar>
-#include "connectwidget.h"
#include "connectionmanager.h"
+#include "shareboard.h"
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
createActions();
createMenus();
- prompt = new ConnectWidget();
- setCentralWidget(prompt);
-
connMan = new ConnectionManager(this);
- QObject::connect(prompt, SIGNAL(connectToServer(QString, QString)), connMan, SLOT(joinServer(QString, QString)));
+
+ board = new Shareboard(this);
+ setCentralWidget(board);
+
+ // Connect all actions
+ QObject::connect(board, SIGNAL(connectToServer(QString, QString)), connMan, SLOT(joinServer(QString, QString)));
+ QObject::connect(connMan, SIGNAL(connected()), this, SLOT(switchToBoard()));
+ QObject::connect(connMan, SIGNAL(disconnected()), this, SLOT(switchToConnect()));
statusBar()->showMessage("Ready");
}
void MainWindow::switchToBoard() {
// Here, we set the central widget to be the as-of-yet unimplemented Shareboard widget
+ board->switchToBoard();
+ statusBar()->showMessage(QString("Switched to Shareboard drawing surface"));
}
void MainWindow::switchToConnect() {
- setCentralWidget(prompt);
+ board->switchToPrompt();
+ statusBar()->showMessage(QString("Switched to connection prompt"));
}
void MainWindow::createActions() {
class QAction;
class ConnectWidget;
class ConnectionManager;
+class Shareboard;
class MainWindow : public QMainWindow {
Q_OBJECT
QAction* quitAction;
ConnectionManager* connMan;
// HistoryManager* historyManager;
-// Shareboard* board;
+ Shareboard* board;
ConnectWidget* prompt;
};
--- /dev/null
+#include "shareboard.h"
+#include <QStackedLayout>
+
+#include "shareboardcanvas.h"
+#include "connectwidget.h"
+
+Shareboard::Shareboard(QWidget* parent) : QWidget(parent) {
+ layout = new QStackedLayout(this);
+ prompt = new ConnectWidget(this);
+ canvas = new ShareboardCanvas(this);
+
+ layout->addWidget(prompt);
+ layout->addWidget(canvas);
+ setLayout(layout);
+ setMinimumSize(640,480);
+
+ QObject::connect(prompt, SIGNAL(connectToServer(QString, QString)), this, SIGNAL(connectToServer(QString, QString)));
+}
+
+Shareboard::~Shareboard() {
+
+}
+
+void Shareboard::switchToBoard() {
+ layout->setCurrentWidget(canvas);
+}
+
+void Shareboard::switchToPrompt() {
+ layout->setCurrentWidget(prompt);
+}
--- /dev/null
+#ifndef __SHAREBOARD_H__
+#define __SHAREBOARD_H__
+
+#include <QWidget>
+
+class QStackedLayout;
+class ConnectWidget;
+class ShareboardCanvas;
+
+class Shareboard : public QWidget {
+ Q_OBJECT
+ public:
+ Shareboard(QWidget* parent = 0);
+ ~Shareboard();
+
+ public slots:
+ void switchToBoard();
+ void switchToPrompt();
+
+ signals:
+ void connectToServer(QString, QString);
+
+ private:
+ QStackedLayout* layout;
+ ConnectWidget* prompt;
+ ShareboardCanvas* canvas;
+};
+
+#endif // __SHAREBOARD_H__
INCLUDEPATH += .
# Input
-HEADERS += mainwindow.h action.h connectwidget.h connectionmanager.h
-SOURCES += main.cpp mainwindow.cpp action.cpp connectwidget.cpp connectionmanager.cpp
+HEADERS += mainwindow.h action.h connectwidget.h connectionmanager.h shareboard.h shareboardcanvas.h
+SOURCES += main.cpp mainwindow.cpp action.cpp connectwidget.cpp connectionmanager.cpp shareboard.cpp shareboardcanvas.cpp
--- /dev/null
+#include "shareboardcanvas.h"
+#include <QMouseEvent>
+#include <QPaintEvent>
+#include <QPainter>
+#include <QPixmap>
+#include <QDebug>
+
+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::mouseMoveEvent(QMouseEvent* event) {
+ // Send mouse move event to network thread
+ // If the button is down
+ if(mouseDown)
+ dragPath.append(event->posF());
+ // Trigger a repaint
+ update();
+}
+
+void ShareboardCanvas::mousePressEvent(QMouseEvent* event) {
+ mouseDown = true;
+ dragPath.append(event->posF()); // We're starting a new drag path
+ //
+}
+
+void ShareboardCanvas::mouseReleaseEvent(QMouseEvent* event) {
+ mouseDown = false;
+ qDebug() << dragPath.size() << "mouse move events counted this drag";
+ // Depending on the tool, we now dispatch different types of events
+ dragPath.clear(); // Clear the path; we're no longer tracking a drag
+}
+
+void ShareboardCanvas::paintEvent(QPaintEvent* event) {
+ QPainter p(this);
+ // Paint the background from the saved state
+ p.drawPixmap(0, 0, *currentScene);
+ // Now paint our local changes on top of it
+ //p.set
+ // Now paint the set of mouse cursors on top of that
+}
--- /dev/null
+#ifndef __SHAREBOARDCANVAS_H__
+#define __SHAREBOARDCANVAS_H__
+
+#include <QWidget>
+#include <QMap>
+#include <QPointF>
+
+class QMouseEvent;
+class QPaintEvent;
+class QPixmap;
+
+class ShareboardCanvas : public QWidget {
+ Q_OBJECT
+public:
+ ShareboardCanvas(QWidget* parent = 0);
+ ~ShareboardCanvas();
+ void mouseMoveEvent(QMouseEvent* event);
+ void mousePressEvent(QMouseEvent* event);
+ void mouseReleaseEvent(QMouseEvent* event);
+ void paintEvent(QPaintEvent* event);
+private:
+ bool mouseDown;
+ QPixmap* currentScene;
+ QVector<QPointF> dragPath;
+ QMap<int, QPointF> cursors;
+};
+
+#endif //__SHAREBOARDCANVAS_H__
+