diff -r 5391ab620c95 -r 142e0f1e61d5 historywindow.cpp --- a/historywindow.cpp Wed Sep 06 12:47:06 2006 +0000 +++ b/historywindow.cpp Thu Sep 14 11:38:17 2006 +0000 @@ -1,4 +1,5 @@ #include "historywindow.h" +#include "mapeditor.h" HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent) { @@ -19,28 +20,109 @@ ui.historyTable->setHorizontalHeaderItem(2, item); ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows); + + connect ( ui.undoButton, SIGNAL (clicked()), this, SLOT (undo())); + connect ( ui.redoButton, SIGNAL (clicked()), this, SLOT (redo())); + connect ( ui.historyTable, SIGNAL (itemSelectionChanged()), this, SLOT (select())); } +void HistoryWindow::updateRow(int row, int step, SimpleSettings &set) +{ + QTableWidgetItem *item; + + item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step))); + ui.historyTable->setItem(row, 0, item); + + item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step))); + ui.historyTable->setItem(row, 1, item); + + item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step))); + ui.historyTable->setItem(row, 2, item); +} + void HistoryWindow::update(SimpleSettings &set) { - //int rows=set.readNumEntry("/history/undosTotal"); - //ui.historyTable->setRowCount (rows); + int undosAvail=set.readNumEntry("/history/undosAvail",0); + int redosAvail=set.readNumEntry("/history/redosAvail",0); + int stepsTotal=set.readNumEntry("/history/stepsTotal",0); + int curStep=set.readNumEntry ("/history/curStep"); + int i; + int s=curStep; + int r=undosAvail-1; + QTableWidgetItem *item; - int i; - for (i=0;i<= set.readNumEntry("/history/undosAvail",0); i++) + // Update buttons + if (undosAvail<1) + ui.undoButton->setEnabled (false); + else + ui.undoButton->setEnabled (true); + + if (redosAvail<1) + ui.redoButton->setEnabled (false); + else + ui.redoButton->setEnabled (true); + + // Update table + for (i=undosAvail; i>0; i--) { - QTableWidgetItem *item; + updateRow (r,s,set); + r--; + s--; + if (s<1) s=stepsTotal; + } + + // Generated the "now" row + QColor c(255,200,120); + for (i=0;i<=2;i++) + { + if (i!=1) + { + item=new QTableWidgetItem(""); + item->setBackgroundColor (c); + ui.historyTable->setItem(undosAvail, i, item); + } + } + item=new QTableWidgetItem(" - " +tr("Current state","current bar in history hwindow")+ " - "); + item->setBackgroundColor (c); + ui.historyTable->setItem(undosAvail, 1, item); - item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(i))); - ui.historyTable->setItem(i, 0, item); - item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(i))); - ui.historyTable->setItem(i, 1, item); + s=curStep; + s++; if (s>stepsTotal) s=1; - item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(i))); - ui.historyTable->setItem(i, 2, item); + for (i=1;i<= redosAvail; i++) + { + updateRow (undosAvail+i,s,set); + s++; if (s>stepsTotal) s=1; } ui.historyTable->resizeColumnsToContents(); } + +void HistoryWindow::setME (MapEditor *me) +{ + mapEditor=me; +} + +void HistoryWindow::setStepsTotal (int st) +{ + // Number of steps + "current" bar + ui.historyTable->setRowCount (st+1); + +} + +void HistoryWindow::undo() +{ + mapEditor->undo(); +} + +void HistoryWindow::redo() +{ + mapEditor->redo(); +} + +void HistoryWindow::select() +{ + mapEditor->gotoStep (ui.historyTable->row (ui.historyTable->selectedItems().first())); +}