Permalink
Browse files

some protocol changes and preliminary layer support

  • Loading branch information...
1 parent 341a6a6 commit a1a21123f9391f29e869c13801eca07c4d280e3c Calle Laakkonen committed Oct 26, 2008
Showing with 1,308 additions and 169 deletions.
  1. +4 −0 ChangeLog
  2. +2 −2 doc/dox/protocol.dox
  3. +8 −5 src/client/CMakeLists.txt
  4. +2 −2 src/client/annotationitem.cpp
  5. +65 −11 src/client/board.cpp
  6. +19 −0 src/client/board.h
  7. +51 −3 src/client/boardeditor.cpp
  8. +16 −1 src/client/boardeditor.h
  9. +11 −6 src/client/boarditem.cpp
  10. +10 −9 src/client/boarditem.h
  11. +13 −9 src/client/brushpreview.cpp
  12. +2 −2 src/client/brushpreview.h
  13. +17 −0 src/client/controller.cpp
  14. +8 −0 src/client/controller.h
  15. +15 −15 src/client/core/brush.cpp
  16. +12 −12 src/client/core/brush.h
  17. +62 −38 src/client/core/layer.cpp
  18. +28 −8 src/client/core/layer.h
  19. +251 −0 src/client/core/layerstack.cpp
  20. +110 −0 src/client/core/layerstack.h
  21. +5 −5 src/client/core/rasterop.cpp
  22. +6 −14 src/client/core/tile.cpp
  23. +7 −4 src/client/core/tile.h
  24. +97 −0 src/client/layerlistdelegate.cpp
  25. +49 −0 src/client/layerlistdelegate.h
  26. +115 −0 src/client/layerlistwidget.cpp
  27. +71 −0 src/client/layerlistwidget.h
  28. +24 −2 src/client/mainwindow.cpp
  29. +4 −0 src/client/mainwindow.h
  30. +22 −0 src/client/sessionstate.cpp
  31. +10 −0 src/client/sessionstate.h
  32. +68 −0 src/client/ui/layerbox.ui
  33. +22 −6 src/client/user.cpp
  34. +20 −5 src/client/user.h
  35. +1 −1 src/client/version.h
  36. +1 −1 src/shared/net/constants.h
  37. +10 −6 src/shared/net/protocol.cpp
  38. +2 −1 src/shared/net/protocol.h
  39. +12 −0 src/shared/net/toolselect.cpp
  40. +44 −0 src/shared/net/toolselect.h
  41. +5 −1 src/shared/server/client.cpp
  42. +4 −0 src/shared/server/client.h
  43. +3 −0 src/shared/server/server.cpp
View
@@ -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)
View
@@ -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.
View
@@ -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 ()
@@ -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 (
@@ -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
@@ -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);
}
}
View
@@ -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);
}
@@ -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);
@@ -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;
}
@@ -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_);
}
/**
@@ -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();
}
@@ -220,6 +233,16 @@ int Board::height() const {
}
/**
+ * @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.
* @param session which network session the editor works over. If 0, a local editor is returned
@@ -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_) {
@@ -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;
}
@@ -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();
+}
}
View
@@ -41,6 +41,11 @@ namespace interface {
namespace dpcore {
class Brush;
+ class LayerStack;
+}
+
+namespace widgets {
+ class LayerList;
}
//! Drawing board related classes
@@ -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;
@@ -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);
@@ -180,6 +197,8 @@ class Board : public QGraphicsScene
interface::ColorSource *colorsrc_;
bool hla_;
+
+ widgets::LayerList *layerwidget_;
};
}
View
@@ -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 {
@@ -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);
}
@@ -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);
}
/**
@@ -159,6 +160,31 @@ void LocalBoardEditor::setTool(const dpcore::Brush& 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
*/
void LocalBoardEditor::addStroke(const dpcore::Point& point)
@@ -224,6 +250,28 @@ void RemoteBoardEditor::setTool(const dpcore::Brush& 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
* from other users can be interleaved with the components of this stroke.
Oops, something went wrong.

0 comments on commit a1a2112

Please sign in to comment.