From: Drew Fisher Date: Fri, 8 Oct 2010 15:39:04 +0000 (-0700) Subject: Make the slider change the present view of where we are in time. X-Git-Url: http://git.zarvox.org/shortlog/%7B%7B%20url_for%28%27main.login_page%27%29%20%7D%7D?a=commitdiff_plain;h=185d14a718213acb95df916ac477b4451be21d78;p=shareboard.git Make the slider change the present view of where we are in time. --- diff --git a/mainwindow.cpp b/mainwindow.cpp index fb8669e..5caf77a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -39,6 +39,11 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { QObject::connect(colorAction, SIGNAL(triggered()), this, SLOT(chooseColor())); QObject::connect(clearAction, SIGNAL(triggered()), this, SLOT(clearBoard())); + QObject::connect(board, SIGNAL(rangeChanged(int)), this, SLOT(updateSliderRange(int))); + QObject::connect(board, SIGNAL(indexChanged(int)), sliderWidget, SLOT(setValue(int))); + QObject::connect(sliderWidget, SIGNAL(valueChanged(int)), board, SLOT(jumpToIndex(int))); + + statusBar()->showMessage("Ready"); } @@ -46,6 +51,10 @@ MainWindow::~MainWindow() { } +void MainWindow::updateSliderRange(int newmax) { + sliderWidget->setRange(0, newmax); +} + void MainWindow::chooseColor() { lineColor = QColorDialog::getColor(lineColor, this, "Choose drawing color"); // update pixmap @@ -166,7 +175,7 @@ void MainWindow::createToolBars() { // Create the history UI elements. QAction* restartAction = new QAction(QIcon("icons/rewind.png"), "Replay History", this); QAction* playAction = new QAction(QIcon("icons/play.png"), "Play", this); - QSlider* sliderWidget = new QSlider(Qt::Horizontal, this); + sliderWidget = new QSlider(Qt::Horizontal, this); toolBar = addToolBar("Test"); toolBar->setMovable(false); diff --git a/mainwindow.h b/mainwindow.h index 9437980..cb82b6a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -11,6 +11,7 @@ class ConnectionManager; class Shareboard; class Action; class QSpinBox; +class QSlider; class MainWindow : public QMainWindow { Q_OBJECT @@ -28,6 +29,7 @@ public slots: void chooseColor(); void clearBoard(); void marshallAction(Action* action); + void updateSliderRange(int newmax); private: void createActions(); void createMenus(); @@ -41,6 +43,7 @@ private: QAction* colorAction; QAction* clearAction; QSpinBox* spinboxWidget; + QSlider* sliderWidget; ConnectionManager* connMan; // HistoryManager* historyManager; Shareboard* board; diff --git a/shareboard.cpp b/shareboard.cpp index 9240ea3..5ecc324 100644 --- a/shareboard.cpp +++ b/shareboard.cpp @@ -69,6 +69,7 @@ void Shareboard::postAction(Action* action) { localHistory.removeFirst(); } history.append(action); + emit rangeChanged(history.size()); jumpToIndex(history.size()); // Jump to the most recent state } @@ -153,4 +154,5 @@ void Shareboard::jumpToIndex(int index) { } p.end(); canvas->update(); + emit indexChanged(viewIndex); } diff --git a/shareboard.h b/shareboard.h index 67db295..28ab258 100644 --- a/shareboard.h +++ b/shareboard.h @@ -32,6 +32,8 @@ class Shareboard : public QWidget { //void jumpToTime(QDateTime time); signals: + void rangeChanged(int max); + void indexChanged(int index); void connectToServer(QString, QString); void actionHappened(Action* action);