summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-08-10 06:45:48 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-08-10 06:45:48 (GMT)
commit1ba6012a02c05bd077fa5cd7bbfd83473227f608 (patch)
treed2bc58d93d21591e3cf284385d2f787a20575df8
parent7316162e0d809816b276512b50a1d6585265f959 (diff)
downloadswift-contrib-1ba6012a02c05bd077fa5cd7bbfd83473227f608.zip
swift-contrib-1ba6012a02c05bd077fa5cd7bbfd83473227f608.tar.bz2
Improved whiteboard window sidebar
-rw-r--r--Swift/QtUI/SConscript1
-rw-r--r--Swift/QtUI/Whiteboard/ColorWidget.cpp37
-rw-r--r--Swift/QtUI/Whiteboard/ColorWidget.h33
-rw-r--r--Swift/QtUI/Whiteboard/GView.cpp14
-rw-r--r--Swift/QtUI/Whiteboard/GView.h2
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp25
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.h7
7 files changed, 108 insertions, 11 deletions
diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript
index 0ffe2fe..8d95dc4 100644
--- a/Swift/QtUI/SConscript
+++ b/Swift/QtUI/SConscript
@@ -144,6 +144,7 @@ sources = [
"Whiteboard/GView.cpp",
"Whiteboard/TextDialog.cpp",
"Whiteboard/QtWhiteboardWindow.cpp",
+ "Whiteboard/ColorWidget.cpp",
"QtSubscriptionRequestWindow.cpp",
"QtRosterHeader.cpp",
"QtWebView.cpp",
diff --git a/Swift/QtUI/Whiteboard/ColorWidget.cpp b/Swift/QtUI/Whiteboard/ColorWidget.cpp
new file mode 100644
index 0000000..e96b760
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/ColorWidget.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+
+#include "ColorWidget.h"
+#include <QPainter>
+#include <QMouseEvent>
+
+namespace Swift {
+ ColorWidget::ColorWidget(QWidget* parent) : QWidget(parent) {
+ setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
+ }
+
+ QSize ColorWidget::sizeHint() const {
+ return QSize(20, 20);
+ }
+
+ void ColorWidget::setColor(QColor color) {
+ this->color = color;
+ update();
+ }
+
+ void ColorWidget::paintEvent(QPaintEvent* /*event*/) {
+ QPainter painter(this);
+ painter.fillRect(0, 0, 20, 20, color);
+ }
+
+ void ColorWidget::mouseReleaseEvent(QMouseEvent* event) {
+ if (event->button() == Qt::LeftButton) {
+ emit clicked();
+ }
+ }
+}
+
diff --git a/Swift/QtUI/Whiteboard/ColorWidget.h b/Swift/QtUI/Whiteboard/ColorWidget.h
new file mode 100644
index 0000000..6abdf00
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/ColorWidget.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QWidget>
+
+namespace Swift {
+ class ColorWidget : public QWidget {
+ Q_OBJECT;
+ public:
+ ColorWidget(QWidget* parent = 0);
+ QSize sizeHint() const;
+
+ public slots:
+ void setColor(QColor color);
+
+ private:
+ QColor color;
+
+ protected:
+ void paintEvent(QPaintEvent* /*event*/);
+ void mouseReleaseEvent(QMouseEvent* event);
+
+ signals:
+ void clicked();
+
+ };
+}
+
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp
index b26f0bb..2c2f849 100644
--- a/Swift/QtUI/Whiteboard/GView.cpp
+++ b/Swift/QtUI/Whiteboard/GView.cpp
@@ -34,6 +34,7 @@ namespace Swift {
} else {
defaultPen.setColor(color);
}
+ lineColorChanged(color);
}
QColor GView::getLineColor() {
@@ -49,8 +50,7 @@ namespace Swift {
} else {
defaultBrush.setColor(color);
}
-
-// brush.setStyle(Qt::SolidPattern);
+ brushColorChanged(color);
}
QColor GView::getBrushColor() {
@@ -99,6 +99,8 @@ namespace Swift {
pen.setWidth(1);
defaultPen = pen;
lineWidthChanged(1);
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
}
QGraphicsItem* GView::getItem(QString id) {
@@ -438,6 +440,8 @@ namespace Swift {
ellipseItem->setPen(pen);
ellipseItem->setBrush(brush);
}
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
}
void GView::setActualPenAndBrushFromItem(QGraphicsItem* item) {
@@ -474,6 +478,8 @@ namespace Swift {
brush = ellipseItem->brush();
}
lineWidthChanged(pen.width());
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
}
void GView::deselect() {
@@ -484,6 +490,8 @@ namespace Swift {
delete selectionRect;
selectionRect = 0;
lineWidthChanged(pen.width());
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
}
}
@@ -497,6 +505,8 @@ namespace Swift {
delete selectionRect;
selectionRect = 0;
lineWidthChanged(pen.width());
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
}
}
}
diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h
index 71c865c..bc3b3fc 100644
--- a/Swift/QtUI/Whiteboard/GView.h
+++ b/Swift/QtUI/Whiteboard/GView.h
@@ -71,5 +71,7 @@ namespace Swift {
void lastItemChanged(QGraphicsItem* item, int pos, GView::Type type);
void itemDeleted(QString id, int pos);
void lineWidthChanged(int i);
+ void lineColorChanged(QColor color);
+ void brushColorChanged(QColor color);
};
}
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
index 74c5a5f..82744f8 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
@@ -21,6 +21,7 @@
#include <Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h>
#include <QMessageBox>
+#include <QLabel>
namespace Swift {
QtWhiteboardWindow::QtWhiteboardWindow(WhiteboardSession::ref whiteboardSession) : QWidget() {
@@ -51,11 +52,19 @@ namespace Swift {
moveDownButton = new QPushButton("Move Down", this);
connect(moveDownButton, SIGNAL(clicked()), graphicsView, SLOT(moveDownSelectedItem()));
- colorDialogButton = new QPushButton("Color", this);
- connect(colorDialogButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
+ strokeLayout = new QHBoxLayout;
+ strokeColor = new ColorWidget;
+ strokeLayout->addWidget(new QLabel("Stroke:"));
+ strokeLayout->addWidget(strokeColor);
+ connect(strokeColor, SIGNAL(clicked()), this, SLOT(showColorDialog()));
+ connect(graphicsView, SIGNAL(lineColorChanged(QColor)), strokeColor, SLOT(setColor(QColor)));
- brushColorDialogButton = new QPushButton("Brush", this);
- connect(brushColorDialogButton, SIGNAL(clicked()), this, SLOT(showBrushColorDialog()));
+ fillLayout = new QHBoxLayout;
+ fillColor = new ColorWidget;
+ fillLayout->addWidget(new QLabel("Fill:"));
+ fillLayout->addWidget(fillColor);
+ connect(fillColor, SIGNAL(clicked()), this, SLOT(showBrushColorDialog()));
+ connect(graphicsView, SIGNAL(brushColorChanged(QColor)), fillColor, SLOT(setColor(QColor)));
rubberButton = new QToolButton(this);
rubberButton->setIcon(QIcon(":/icons/eraser.png"));
@@ -115,13 +124,15 @@ namespace Swift {
toolboxLayout->addWidget(textButton, 2, 0);
toolboxLayout->addWidget(polygonButton, 2, 1);
-
sidebarLayout->addLayout(toolboxLayout);
+ sidebarLayout->addSpacing(30);
sidebarLayout->addWidget(moveUpButton);
sidebarLayout->addWidget(moveDownButton);
+ sidebarLayout->addSpacing(40);
sidebarLayout->addWidget(widthBox);
- sidebarLayout->addWidget(colorDialogButton);
- sidebarLayout->addWidget(brushColorDialogButton);
+ sidebarLayout->addLayout(strokeLayout);
+ sidebarLayout->addLayout(fillLayout);
+ sidebarLayout->addStretch();
hLayout->addWidget(graphicsView);
hLayout->addLayout(sidebarLayout);
layout->addLayout(hLayout);
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
index 1462981..1f531e5 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
@@ -25,6 +25,7 @@
#include <QCloseEvent>
#include "GView.h"
+#include "ColorWidget.h"
namespace Swift {
class QtWhiteboardWindow : public QWidget, public WhiteboardWindow
@@ -64,11 +65,13 @@ namespace Swift {
QVBoxLayout* sidebarLayout;
QHBoxLayout* hLayout;
QGridLayout* toolboxLayout;
+ QHBoxLayout* strokeLayout;
+ QHBoxLayout* fillLayout;
+ ColorWidget* strokeColor;
+ ColorWidget* fillColor;
QWidget* widget;
QPushButton* moveUpButton;
QPushButton* moveDownButton;
- QPushButton* colorDialogButton;
- QPushButton* brushColorDialogButton;
QSpinBox* widthBox;
QToolButton* rubberButton;
QToolButton* lineButton;