Skip to content

Commit

Permalink
some protocol changes and preliminary layer support
Browse files Browse the repository at this point in the history
  • Loading branch information
Calle Laakkonen committed Oct 26, 2008
1 parent 341a6a6 commit a1a2112
Show file tree
Hide file tree
Showing 43 changed files with 1,308 additions and 169 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
2008-??-?? Version 0.7.0
* Protocol change: packet length is now comes first in the header
* Layer support

2008-10-20 Version 0.6.0
* Subpixel drawing
* Added pen tool (draw without antialiasing)
Expand Down
4 changes: 2 additions & 2 deletions doc/dox/protocol.dox
Expand Up @@ -14,8 +14,8 @@ for passing the packets, and the packet format is described below.

\section msg_structure Message structure

All packets are prefixed with an 8 bit packet identifier and 16 bit
packet payload length value.
All packets are prefixed with 16 bit packet length value and an 8 bit packet
identifier. The length is the length of the payload + 1 for the type field.

At minimum, the packet consists only of the packet type and nothing else.
The rest depends on the packet itself.
Expand Down
13 changes: 8 additions & 5 deletions src/client/CMakeLists.txt
Expand Up @@ -15,7 +15,8 @@ set (
localserver.h popupmessage.h userlistwidget.h userlistmodel.h chatwidget.h
mandatoryfields.h palettewidget.h palettebox.h
colorbox.h settingsdialog.h
navigator.h toolsettings.h brushslider.h viewstatus.h
navigator.h toolsettings.h brushslider.h viewstatus.h layerlistdelegate.h
layerlistwidget.h core/layerstack.h
)

# unused headers because they do not create moc_* files ()
Expand All @@ -24,7 +25,8 @@ set (
version.h user.h interfaces.h preview.h boardeditor.h boarditem.h
localpalette.h palette.h icons.h
tools.h recentfiles.h sessioninfo.h annotationitem.h
core/tile.h core/layer.h core/brush.h core/point.h core/rasterop.h
core/tile.h core/layer.h core/brush.h core/point.h
core/rasterop.h
)

set (
Expand All @@ -40,15 +42,16 @@ set (
sessioninfo.cpp icons.cpp mandatoryfields.cpp
localpalette.cpp palettewidget.cpp palettebox.cpp colorbox.cpp
settingsdialog.cpp palette.cpp navigator.cpp annotationitem.cpp
core/tile.cpp core/layer.cpp core/brush.cpp core/rasterop.cpp
brushslider.cpp viewstatus.cpp
core/tile.cpp core/layer.cpp core/layerstack.cpp core/brush.cpp
core/rasterop.cpp brushslider.cpp viewstatus.cpp layerlistdelegate.cpp
layerlistwidget.cpp
)

set ( UIs ui/brushsettings.ui ui/simplesettings.ui ui/colordialog.ui
ui/newdialog.ui ui/hostdialog.ui ui/joindialog.ui ui/logindialog.ui
ui/chatbox.ui ui/palettebox.ui ui/colorbox.ui
ui/settings.ui ui/navibox.ui ui/textsettings.ui ui/pensettings.ui
ui/erasersettings.ui )
ui/erasersettings.ui ui/layerbox.ui )

# .UI

Expand Down
4 changes: 2 additions & 2 deletions src/client/annotationitem.cpp
Expand Up @@ -206,15 +206,15 @@ dpcore::Layer *AnnotationItem::toLayer(int *x, int *y)
QPoint offset(int(pos().x() - xi*Tile::SIZE),
int(pos().y() - yi*Tile::SIZE));
QImage img(offset.x() + int(size_.width()),
int(offset.y() + size_.height()), QImage::Format_ARGB32);
int(offset.y() + size_.height()), QImage::Format_ARGB32_Premultiplied);
img.fill(0);
QPainter painter(&img);
render(&painter, QRectF(offset, size_));
if(x)
*x = xi;
if(y)
*y = yi;
return new Layer(img);
return new Layer(0, -1, "", img);
}

}
Expand Down
76 changes: 65 additions & 11 deletions src/client/board.cpp
Expand Up @@ -26,14 +26,14 @@
#include "boardeditor.h"
#include "preview.h"
#include "interfaces.h"
#include "core/layer.h"
#include "core/layerstack.h"
#include "../shared/net/annotation.h"
#include "../shared/net/message.h"

namespace drawingboard {

Board::Board(QObject *parent, interface::BrushSource *brush, interface::ColorSource *color)
: QGraphicsScene(parent), image_(0),localuser_(-1), toolpreview_(0), brushsrc_(brush), colorsrc_(color), hla_(false)
: QGraphicsScene(parent), image_(0),localuser_(-1), toolpreview_(0), brushsrc_(brush), colorsrc_(color), hla_(false), layerwidget_(0)
{
setItemIndexMethod(NoIndex);
}
Expand Down Expand Up @@ -69,7 +69,7 @@ void Board::initBoard(QImage image)
image_ = new BoardItem(image.convertToFormat(QImage::Format_RGB32));
addItem(image_);
foreach(User *u, users_)
u->setLayer(image_);
u->setBoard(image_);
QList<QRectF> regions;
regions.append(sceneRect());
emit changed(regions);
Expand Down Expand Up @@ -156,8 +156,7 @@ void Board::addUser(int id)
qDebug() << "Reusing board user" << id;
delete users_.take(id);
}
User *user = new User(id);
user->setLayer(image_);
User *user = new User(image_, id);
users_[id] = user;
}

Expand All @@ -170,6 +169,20 @@ void Board::setLocalUser(int id)
{
Q_ASSERT(users_.contains(id));
localuser_ = id;
// Set the layer list if we know it already
if(layerwidget_)
users_[localuser_]->setLayerList(layerwidget_);
}

/**
* @param llist layer list widget
*/
void Board::setLayerList(widgets::LayerList *llist)
{
layerwidget_ = llist;
// Update local user if it exists
if(localuser_ != -1)
users_[localuser_]->setLayerList(layerwidget_);
}

/**
Expand All @@ -178,7 +191,7 @@ void Board::setLocalUser(int id)
QImage Board::image() const
{
if(image_)
return image_->image()->toImage();
return image_->image()->toFlatImage();
else
return QImage();
}
Expand Down Expand Up @@ -219,6 +232,16 @@ int Board::height() const {
return -1;
}

/**
* @return layer stack
*/
dpcore::LayerStack *Board::layers()
{
if(image_)
return image_->image();
return 0;
}

/**
* Returns a BoardEditor for modifying the drawing board either
* directly or over the network.
Expand Down Expand Up @@ -248,7 +271,7 @@ void Board::addPreview(const dpcore::Point& point)

Preview *pre;
if(previewcache_.isEmpty()) {
pre = new StrokePreview(user->layer());
pre = new StrokePreview(user->board());
} else
pre = previewcache_.dequeue();
if(previewstarted_) {
Expand Down Expand Up @@ -278,10 +301,10 @@ void Board::commitPreviews()
while(previews_.isEmpty()==false) {
qreal distance;
Preview *p = previews_.dequeue();
if(p->from() != lastpoint)
image_->drawPoint(p->from(), p->brush());
else
image_->drawLine(p->from(), p->to(), p->brush(), distance);
if(p->from() != lastpoint) // TODO
image_->drawPoint(0, p->from(), p->brush());
else // TODO
image_->drawLine(0, p->from(), p->to(), p->brush(), distance);
lastpoint = p->to();
delete p;
}
Expand Down Expand Up @@ -389,6 +412,37 @@ void Board::unannotate(int id)
}
}

void Board::addLayer(const QString& name)
{
layers()->addLayer(name, layers()->size());
}

/**
* The layer is removed and all users active layers are changed to point
* to something else.
* @param layer id
*/
void Board::deleteLayer(int id)
{
const int index = layers()->id2index(id);
if(index<0) {
qWarning() << "Tried to delete nonexistent layer";
}

// Fix user layers
foreach(User *u, users_) {
if(u->layer() == index) {
if(index==0)
u->setLayerId(1);
else
u->setLayerId(index-1);
}
}

// Delete the layer
layers()->deleteLayer(id);
update();
}

}

19 changes: 19 additions & 0 deletions src/client/board.h
Expand Up @@ -41,6 +41,11 @@ namespace interface {

namespace dpcore {
class Brush;
class LayerStack;
}

namespace widgets {
class LayerList;
}

//! Drawing board related classes
Expand Down Expand Up @@ -73,12 +78,18 @@ class Board : public QGraphicsScene
//! Initialize the board using an existing image as base
void initBoard(QImage image);

//! Set the layer list widget to update when local user's layer changes
void setLayerList(widgets::LayerList *llist);

//! Get board width
int width() const;

//! Get board height
int height() const;

//! Get the layers
dpcore::LayerStack *layers();

//! Get board contents as an image
QImage image() const;

Expand Down Expand Up @@ -137,6 +148,12 @@ class Board : public QGraphicsScene
//! Remove an annotation
void unannotate(int id);

//! Create a new layer
void addLayer(const QString& name);

//! Delete a layer
void deleteLayer(int id);

signals:
//! The local user just created a new annotation
void newLocalAnnotation(drawingboard::AnnotationItem *item);
Expand Down Expand Up @@ -180,6 +197,8 @@ class Board : public QGraphicsScene
interface::ColorSource *colorsrc_;

bool hla_;

widgets::LayerList *layerwidget_;
};

}
Expand Down
54 changes: 51 additions & 3 deletions src/client/boardeditor.cpp
Expand Up @@ -30,6 +30,7 @@
#include "preview.h"
#include "annotationitem.h"
#include "core/layer.h"
#include "core/layerstack.h"
#include "../shared/net/annotation.h"

namespace drawingboard {
Expand Down Expand Up @@ -111,9 +112,9 @@ void BoardEditor::startPreview(tools::Type tool, const dpcore::Point& point, con
Q_ASSERT(board_->toolpreview_ == 0);
Q_ASSERT(tool == tools::LINE || tool == tools::RECTANGLE || tool == tools::ANNOTATION);
if(tool == tools::LINE)
board_->toolpreview_ = new StrokePreview(user_->layer());
board_->toolpreview_ = new StrokePreview(user_->board());
else
board_->toolpreview_ = new RectanglePreview(user_->layer());
board_->toolpreview_ = new RectanglePreview(user_->board());
board_->toolpreview_->preview(point,point, brush);
}

Expand All @@ -138,7 +139,7 @@ void BoardEditor::endPreview()
*/
void BoardEditor::mergeLayer(int x, int y, const dpcore::Layer *layer)
{
board_->image_->image()->merge(x, y, layer);
board_->image_->image()->getLayer(user_->layer())->merge(x, y, layer);
}

/**
Expand All @@ -158,6 +159,31 @@ void LocalBoardEditor::setTool(const dpcore::Brush& brush)
user_->setBrush(brush);
}

/**
* @param id layer id
*/
void LocalBoardEditor::setLayer(int id)
{
user_->setLayerId(id);
}

/**
* A new empty layer is created on top of the layer stack
* @param name layer name
*/
void LocalBoardEditor::createLayer(const QString& name)
{
board_->addLayer(name);
}

/**
* @param id layer ID
*/
void LocalBoardEditor::deleteLayer(int id)
{
board_->deleteLayer(id);
}

/**
* @param point point to add
*/
Expand Down Expand Up @@ -223,6 +249,28 @@ void RemoteBoardEditor::setTool(const dpcore::Brush& brush)
session_->sendToolSelect(brush);
}

/**
* @param id layer id
*/
void RemoteBoardEditor::setLayer(int id)
{
session_->sendLayerSelect(id);
}

void RemoteBoardEditor::createLayer(const QString& name)
{
// TODO
}

/**
* Layer deletion is not supported while in a network session.
* @param id layer ID
*/
void RemoteBoardEditor::deleteLayer(int id)
{
qWarning() << "BUG: Tried to delete layer ID" << id << "while in a network session!";
}

/**
* In atomic mode, all strokes until strokeEnd are sent in a single long
* message. This is slightly more efficient and ensures no brush strokes
Expand Down

0 comments on commit a1a2112

Please sign in to comment.