]> git.zarvox.org Git - shareboard.git/blob - shareboardcanvas.cpp
Merge branch 'master' of http://zarvox.org/~zarvox/shareboard
[shareboard.git] / shareboardcanvas.cpp
1 #include "shareboardcanvas.h"
2 #include <QMouseEvent>
3 #include <QPaintEvent>
4 #include <QPainter>
5 #include <QPixmap>
6 #include <QDebug>
7 #include "shareboard.h"
8
9 ShareboardCanvas::ShareboardCanvas(QWidget* parent) : QWidget(parent) {
10         setMinimumSize(640,480);
11         setMouseTracking(true);
12         mouseDown = false;
13 }
14
15 ShareboardCanvas::~ShareboardCanvas() {
16 }
17
18 void ShareboardCanvas::setModel(Shareboard* b) {
19         board = b;
20 }
21
22 void ShareboardCanvas::mouseMoveEvent(QMouseEvent* event) {
23         // Send mouse move event to network thread
24         emit mouseMovedTo(event->posF());
25         // If the button is down
26         if(mouseDown) {
27                 emit segmentDrawn(dragPath.last(), event->posF());
28                 dragPath.append(event->posF());
29         }
30         // Trigger a repaint
31         update();
32 }
33
34 void ShareboardCanvas::mousePressEvent(QMouseEvent* event) {
35         if(event->button() & Qt::LeftButton) {
36                 mouseDown = true;
37                 dragPath.append(event->posF()); // We're starting a new drag path
38         }
39         //
40 }
41
42 void ShareboardCanvas::mouseReleaseEvent(QMouseEvent* event) {
43         if(event->button() & Qt::LeftButton) {
44                 mouseDown = false;
45                 qDebug() << dragPath.size() << "mouse move events counted this drag";
46                 // Depending on the tool, we now dispatch different types of events
47                 dragPath.clear(); // Clear the path; we're no longer tracking a drag
48         }
49 }
50
51 void ShareboardCanvas::paintEvent(QPaintEvent* event) {
52         Q_UNUSED(event)
53         QPainter p(this);
54         // Paint the background from the saved state
55         p.drawImage(0, 0, board->view());
56         //qDebug() << "ShareboardCanvas:" << board->view().rect();
57         //qDebug() << "ShareboardCanvas:" << board->viewIndex;
58         // Now paint our local changes on top of it
59         
60         //p.set
61         // Now paint the set of mouse cursors on top of that
62 }