]> git.zarvox.org Git - shareboard.git/commitdiff
Implement user-chosen line width and color.
authorDrew Fisher <drew.m.fisher@gmail.com>
Fri, 8 Oct 2010 09:21:19 +0000 (02:21 -0700)
committerDrew Fisher <drew.m.fisher@gmail.com>
Fri, 8 Oct 2010 09:21:19 +0000 (02:21 -0700)
mainwindow.cpp
mainwindow.h
shareboard.cpp
shareboardcanvas.cpp

index 2387d4daae4e8d873e18a2366add0d53bec6a0fc..cdc3b7dfa811f51a4cf4ef970768a9892e64cc01 100644 (file)
@@ -3,6 +3,7 @@
 #include <QApplication>
 #include <QFile>
 #include <QFileDialog>
+#include <QColorDialog>
 #include <QLabel>
 #include <QMenuBar>
 #include <QStatusBar>
@@ -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<DrawLineAction*>(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);
index 867bd6cb6903f84f3cb878bd622a1a77207c0998..6914f30d65dc3e8aced9e422e72e362e67b45b29 100644 (file)
@@ -2,6 +2,7 @@
 #define __MAINWINDOW_H__
 
 #include <QMainWindow>
+#include <QColor>
 
 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__
index 41f39f48ea827f848e78296d6f280fd32b9d7935..930ac3055fc65d9f3f7331d074966f02a13ccabd 100644 (file)
@@ -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() {
-       
-}
-*/
index faebffad499a803435a0d85716206f12b99e9589..af45aeb876b18d37dac2e44156707b2b1b535a0a 100644 (file)
@@ -61,7 +61,9 @@ void ShareboardCanvas::paintEvent(QPaintEvent* event) {
        // Now paint the set of mouse cursors on top of that
        QMap<int, QPointF>::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);