From: Drew Fisher Date: Fri, 8 Oct 2010 09:21:19 +0000 (-0700) Subject: Implement user-chosen line width and color. X-Git-Url: https://git.zarvox.org/shortlog/month?a=commitdiff_plain;h=04cae22e1d71963759eac783d936bd65db082254;p=shareboard.git Implement user-chosen line width and color. --- diff --git a/mainwindow.cpp b/mainwindow.cpp index 2387d4d..cdc3b7d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -19,6 +20,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { createActions(); createMenus(); + lineColor = Qt::blue; createToolBars(); board = new Shareboard(this); @@ -34,6 +36,8 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { QObject::connect(connMan, SIGNAL(error(QString)), this, SLOT(showError(QString))); QObject::connect(board, SIGNAL(actionHappened(Action*)), this, SLOT(marshallAction(Action*))); + QObject::connect(colorAction, SIGNAL(triggered()), this, SLOT(chooseColor())); + statusBar()->showMessage("Ready"); } @@ -41,6 +45,14 @@ MainWindow::~MainWindow() { } +void MainWindow::chooseColor() { + lineColor = QColorDialog::getColor(lineColor, this, "Choose drawing color"); + // update pixmap + QPixmap pixmap(16, 16); + pixmap.fill(lineColor); + colorAction->setIcon(QIcon(pixmap)); +} + void MainWindow::load() { QString fileName = QFileDialog::getOpenFileName(this, "Load saved board:", ".", "Shareboards (*.board)"); if(fileName.isEmpty()) { @@ -91,8 +103,8 @@ void MainWindow::marshallAction(Action* action) { case Action::DrawLine: // set the action's thickness, color { DrawLineAction* a = static_cast(action); - a->color = Qt::blue; - a->width = 3; + a->color = lineColor; + a->width = spinboxWidget->value(); } break; default: break; @@ -136,14 +148,14 @@ void MainWindow::createToolBars() { QAction* clearAction = new QAction(QIcon("icons/clear.png"), "Clear", this); // Style - QSpinBox* spinboxWidget = new QSpinBox(this); + spinboxWidget = new QSpinBox(this); spinboxWidget->setMinimum(4); spinboxWidget->setMaximum(40); QPixmap pixmap(16, 16); - pixmap.fill(QColor(0, 0, 255)); - QAction* colorAction = new QAction(QIcon(pixmap), "Select Color", this); + pixmap.fill(lineColor); + colorAction = new QAction(QIcon(pixmap), "Select Color", this); // Create the history UI elements. QAction* restartAction = new QAction(QIcon("icons/rewind.png"), "Replay History", this); diff --git a/mainwindow.h b/mainwindow.h index 867bd6c..6914f30 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,6 +2,7 @@ #define __MAINWINDOW_H__ #include +#include class QMenu; class QAction; @@ -9,6 +10,7 @@ class ConnectWidget; class ConnectionManager; class Shareboard; class Action; +class QSpinBox; class MainWindow : public QMainWindow { Q_OBJECT @@ -23,6 +25,7 @@ public slots: void switchToBoard(); void switchToConnect(); void showError(QString error); + void chooseColor(); void marshallAction(Action* action); private: void createActions(); @@ -34,10 +37,13 @@ private: QAction* loadPastAction; QAction* saveAction; QAction* quitAction; + QAction* colorAction; + QSpinBox* spinboxWidget; ConnectionManager* connMan; // HistoryManager* historyManager; Shareboard* board; ConnectWidget* prompt; + QColor lineColor; }; #endif // __MAINWINDOW_H__ diff --git a/shareboard.cpp b/shareboard.cpp index 41f39f4..930ac30 100644 --- a/shareboard.cpp +++ b/shareboard.cpp @@ -25,7 +25,7 @@ Shareboard::Shareboard(QWidget* parent) : QWidget(parent) { userID = -1; viewIndex = 0; viewImage = QImage(1024,768,QImage::Format_ARGB32_Premultiplied); - viewImage.fill(Qt::white); + viewImage.fill(QColor(Qt::white).rgb()); QObject::connect(prompt, SIGNAL(connectToServer(QString, QString)), this, SIGNAL(connectToServer(QString, QString))); QObject::connect(canvas, SIGNAL(mouseMovedTo(QPointF)), this, SLOT(handleMouseMoved(QPointF))); @@ -93,7 +93,7 @@ void Shareboard::jumpToIndex(int index) { int i = 0; if(index < viewIndex) { viewImage = QImage(1024,768,QImage::Format_ARGB32_Premultiplied); - viewImage.fill(Qt::white); + viewImage.fill(QColor(Qt::white).rgb()); viewCursors.clear(); viewUsers.clear(); } else { @@ -149,38 +149,3 @@ void Shareboard::jumpToIndex(int index) { p.end(); canvas->update(); } -/* -void Shareboard::jumpToTime(QDateTime time) { - int i = 0; - if(time < viewTime) { - // Start from a blank pixmap, trace through all changes up until time - viewImage = QImage(1024,768,QImage::Format_ARGB32_Premultiplied); - viewImage.fill(Qt::white); - viewCursors.clear(); - } else { - while(i < history.size() && history[i]->timestamp <= viewTime) - i++; - } - QPainter p; - p.begin(&viewImage); - // Now, i matches either the beginning of time or the entry for the currently-rendered pixmap, - // whichever is more useful - // Now, apply all actions from i until time - while(i < history.size() && history[i]->timestamp <= time) { - } - qDebug() << "i is at" << i << "of" << history.size(); - p.end(); - qDebug() << "cursors:" << viewCursors; -} -*/ - -/* -QPixmap renderAtTime(QDateTime time) { - QPixmap pixmap; - return pixmap; -} - -QPixmap renderOneChange() { - -} -*/ diff --git a/shareboardcanvas.cpp b/shareboardcanvas.cpp index faebffa..af45aeb 100644 --- a/shareboardcanvas.cpp +++ b/shareboardcanvas.cpp @@ -61,7 +61,9 @@ void ShareboardCanvas::paintEvent(QPaintEvent* event) { // Now paint the set of mouse cursors on top of that QMap::const_iterator i; for (i = board->viewCursors.constBegin(); i!=board->viewCursors.constEnd(); ++i) { - p.setPen(QPen(QColor(255,0,0,50))); + QPen pen(QColor(255,0,0,50)); + pen.setCapStyle(Qt::RoundCap); + p.setPen(pen); p.setBrush(QBrush(QColor(255,0,0,50))); p.drawEllipse(i.value(),4,4); p.setPen(Qt::black);