From: Drew Fisher Date: Thu, 7 Oct 2010 00:41:19 +0000 (-0700) Subject: Refactor ConnectWidget into Shareboard, the primary central widget stack. X-Git-Url: http://git.zarvox.org/shortlog/year?a=commitdiff_plain;h=45d84b45a3e583ec8f1a879a84c1558fcdb2d344;p=shareboard.git Refactor ConnectWidget into Shareboard, the primary central widget stack. Begin implementing ShareboardCanvas, the actual drawing surface. --- diff --git a/mainwindow.cpp b/mainwindow.cpp index b45c8cd..d9f1848 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,18 +7,22 @@ #include #include -#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() { diff --git a/mainwindow.h b/mainwindow.h index 44cda15..e5dff43 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -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 index 0000000..902c274 --- /dev/null +++ b/shareboard.cpp @@ -0,0 +1,30 @@ +#include "shareboard.h" +#include + +#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 index 0000000..9bfa28f --- /dev/null +++ b/shareboard.h @@ -0,0 +1,29 @@ +#ifndef __SHAREBOARD_H__ +#define __SHAREBOARD_H__ + +#include + +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__ diff --git a/shareboard.pro b/shareboard.pro index 2c4c6bf..7a3909b 100644 --- a/shareboard.pro +++ b/shareboard.pro @@ -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 index 0000000..2db1b0a --- /dev/null +++ b/shareboardcanvas.cpp @@ -0,0 +1,50 @@ +#include "shareboardcanvas.h" +#include +#include +#include +#include +#include + +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 index 0000000..693485d --- /dev/null +++ b/shareboardcanvas.h @@ -0,0 +1,29 @@ +#ifndef __SHAREBOARDCANVAS_H__ +#define __SHAREBOARDCANVAS_H__ + +#include +#include +#include + +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 dragPath; + QMap cursors; +}; + +#endif //__SHAREBOARDCANVAS_H__ +