#include <QPaintEvent>
#include <QPainter>
#include <QPixmap>
+#include <QPen>
+#include <QColor>
#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) {
// Send mouse move event to network thread
- // If the button is down
- if(mouseDown)
+ emit mouseMovedTo(event->posF());
+ lastPos = event->posF();
+ // If the button is down
+ if(mouseDown) {
+ emit segmentDrawn(dragPath.last(), event->posF());
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
+ if(event->button() & Qt::LeftButton) {
+ if(board->drawState == 0) {
+ emit insertImage(event->posF());
+ return;
+ }
+ 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
+ if(event->button() & Qt::LeftButton) {
+ 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) {
+ Q_UNUSED(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
+ p.drawImage(0, 0, board->view());
+ // Now paint our local changes on top of it (optional, will make things look snappier)
+
// Now paint the set of mouse cursors on top of that
+ QMap<int, QPointF>::const_iterator i;
+ for (i = board->viewCursors.constBegin(); i!=board->viewCursors.constEnd(); ++i) {
+ if(i.key() == board->userID) {
+ if( board->drawState < 0) {// Eraser mode
+ p.setPen(QColor(Qt::black));
+ p.setBrush(QColor(Qt::white));
+ p.drawEllipse(lastPos, qAbs(board->drawState), qAbs(board->drawState));
+ //p.drawEllipse(i.value(), qAbs(board->drawState), qAbs(board->drawState));
+ }
+ if( board->drawState == 0) { // Image mode
+ p.drawImage(lastPos, board->insertImage);
+ }
+ continue;
+ }
+ QPen pen(QColor(255,0,0,50));
+ pen.setCapStyle(Qt::RoundCap);
+ p.setPen(pen);
+ p.setBrush(QBrush(QColor(255,0,0,50)));
+ p.drawEllipse(i.value(),4,4);
+ p.setPen(Qt::black);
+ p.setBrush(Qt::black);
+ p.drawText(i.value(),board->viewUsers[i.key()]);
+ }
}