From 1ba6012a02c05bd077fa5cd7bbfd83473227f608 Mon Sep 17 00:00:00 2001 From: Mateusz Piekos Date: Fri, 10 Aug 2012 08:45:48 +0200 Subject: Improved whiteboard window sidebar 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 +#include + +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 + +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 #include +#include 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 #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; -- cgit v0.10.2-6-g49f6