11 timestamp = QDateTime::currentDateTime();
14 Action::Action(Type t) {
18 timestamp = QDateTime::currentDateTime();
25 UserJoinAction::UserJoinAction() : Action(Action::UserJoin) {
27 UserJoinAction::~UserJoinAction() {
31 UserPartAction::UserPartAction() : Action(Action::UserPart) {
33 UserPartAction::~UserPartAction() {
37 MouseMoveAction::MouseMoveAction() : Action(Action::MouseMove) {
39 MouseMoveAction::~MouseMoveAction() {
43 DrawLineAction::DrawLineAction() : Action(Action::DrawLine) {
47 DrawLineAction::~DrawLineAction() {
50 AddImageAction::AddImageAction() : Action(Action::AddImage) {
52 AddImageAction::~AddImageAction() {
55 UserChatAction::UserChatAction() : Action(Action::UserChat) {
57 UserChatAction::~UserChatAction() {
60 ClearBoardAction::ClearBoardAction() : Action(Action::ClearBoard) {
62 ClearBoardAction::~ClearBoardAction() {
65 QTextStream& operator<<(QTextStream& out, const Action& action) {
66 out << "0 " << action.userID << " " << action.timestamp.toString("yyyy-MM-ddThh:mm:ss.zzz") << " " << static_cast<quint16>(action.type) ; // mesgID, userID, timestamp, mesgType
69 case Action::UserSynced:
71 case Action::UserJoin:
73 const UserJoinAction* a = static_cast<const UserJoinAction*>(&action);
74 out << " " << a->username;
76 case Action::UserPart:
77 break; // UserPart doesn't have any special data
78 case Action::MouseMove:
80 const MouseMoveAction* a = static_cast<const MouseMoveAction*>(&action);
81 out << " " << a->pos.x() << " " << a->pos.y();
83 case Action::DrawLine:
85 const DrawLineAction* a = static_cast<const DrawLineAction*>(&action);
86 const QColor& c = a->color;
87 out << " " << c.red() << " " << c.green() << " " << c.blue() << " " << a->width;
88 foreach(QPointF p, a->points) {
89 out << " " << p.x() << " " << p.y();
92 case Action::AddImage:
94 const AddImageAction* a = static_cast<const AddImageAction*>(&action);
95 out << " " << a->topLeft.x() << " " << a->topLeft.y();
98 buffer.open(QIODevice::WriteOnly);
99 a->image.save(&buffer, "PNG");
103 case Action::UserChat:
105 const UserChatAction* a = static_cast<const UserChatAction*>(&action);
106 out << " " << a->text;
108 case Action::ClearBoard:
109 break; // No special data for ClearBoard
115 // operator>> can't be implemented in this manner since we need to handle
116 // different types and operator>> works on a reference to the base class.
117 // Thus, I'm pushing this sort of functionality into the connection manager. - Drew