]> git.zarvox.org Git - shareboard.git/commitdiff
Refactor ConnectWidget into Shareboard, the primary central widget stack.
authorDrew Fisher <drew.m.fisher@gmail.com>
Thu, 7 Oct 2010 00:41:19 +0000 (17:41 -0700)
committerDrew Fisher <drew.m.fisher@gmail.com>
Thu, 7 Oct 2010 00:41:19 +0000 (17:41 -0700)
Begin implementing ShareboardCanvas, the actual drawing surface.

mainwindow.cpp
mainwindow.h
shareboard.cpp [new file with mode: 0644]
shareboard.h [new file with mode: 0644]
shareboard.pro
shareboardcanvas.cpp [new file with mode: 0644]
shareboardcanvas.h [new file with mode: 0644]

index b45c8cd34debb4ac49f96a533973f4481ac42ff5..d9f1848e19e0f0edbe2bd7aff834ce95b0cbe7e5 100644 (file)
@@ -7,18 +7,22 @@
 #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");
 }
@@ -60,10 +64,13 @@ void MainWindow::quit() {
 
 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() {
index 44cda1551900b83af23b6664b20b74e37e42a813..e5dff43ac5a6666ee282a10fec55b515f0cb3e44 100644 (file)
@@ -7,6 +7,7 @@ class QMenu;
 class QAction;
 class ConnectWidget;
 class ConnectionManager;
+class Shareboard;
 
 class MainWindow : public QMainWindow {
        Q_OBJECT
@@ -30,7 +31,7 @@ private:
        QAction* quitAction;
        ConnectionManager* connMan;
 //     HistoryManager* historyManager;
-//     Shareboard* board;
+       Shareboard* board;
        ConnectWidget* prompt;
 };
 
diff --git a/shareboard.cpp b/shareboard.cpp
new file mode 100644 (file)
index 0000000..902c274
--- /dev/null
@@ -0,0 +1,30 @@
+#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);
+}
diff --git a/shareboard.h b/shareboard.h
new file mode 100644 (file)
index 0000000..9bfa28f
--- /dev/null
@@ -0,0 +1,29 @@
+#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__
index 2c4c6bf504271d7c7fa679e322763b842fece289..7a3909b225fb540702e8bb96833b52c72583f3de 100644 (file)
@@ -10,5 +10,5 @@ DEPENDPATH += .
 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
diff --git a/shareboardcanvas.cpp b/shareboardcanvas.cpp
new file mode 100644 (file)
index 0000000..2db1b0a
--- /dev/null
@@ -0,0 +1,50 @@
+#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
+}
diff --git a/shareboardcanvas.h b/shareboardcanvas.h
new file mode 100644 (file)
index 0000000..693485d
--- /dev/null
@@ -0,0 +1,29 @@
+#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__
+