historywindow.cpp
changeset 386 142e0f1e61d5
parent 377 5391ab620c95
child 388 3a58c9ef4a18
     1.1 --- a/historywindow.cpp	Wed Sep 06 12:47:06 2006 +0000
     1.2 +++ b/historywindow.cpp	Thu Sep 14 11:38:17 2006 +0000
     1.3 @@ -1,4 +1,5 @@
     1.4  #include "historywindow.h"
     1.5 +#include "mapeditor.h"
     1.6  
     1.7  HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
     1.8  {
     1.9 @@ -19,28 +20,109 @@
    1.10  	ui.historyTable->setHorizontalHeaderItem(2, item);
    1.11  
    1.12  	ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
    1.13 +
    1.14 +	connect ( ui.undoButton, SIGNAL (clicked()), this, SLOT (undo()));
    1.15 +	connect ( ui.redoButton, SIGNAL (clicked()), this, SLOT (redo()));
    1.16 +	connect ( ui.historyTable, SIGNAL (itemSelectionChanged()), this, SLOT (select()));
    1.17  }
    1.18  
    1.19  
    1.20 +void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
    1.21 +{
    1.22 +	QTableWidgetItem *item;
    1.23 +
    1.24 +	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
    1.25 +	ui.historyTable->setItem(row, 0, item);
    1.26 +
    1.27 +	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
    1.28 +	ui.historyTable->setItem(row, 1, item);
    1.29 +
    1.30 +	item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
    1.31 +	ui.historyTable->setItem(row, 2, item);
    1.32 +}
    1.33 +
    1.34  void HistoryWindow::update(SimpleSettings &set)
    1.35  {
    1.36 -	//int rows=set.readNumEntry("/history/undosTotal");
    1.37 -	//ui.historyTable->setRowCount (rows);
    1.38 +	int undosAvail=set.readNumEntry("/history/undosAvail",0);
    1.39 +	int redosAvail=set.readNumEntry("/history/redosAvail",0);
    1.40 +	int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
    1.41 +	int curStep=set.readNumEntry ("/history/curStep");
    1.42 +	int i;
    1.43 +	int s=curStep;
    1.44 +	int r=undosAvail-1;
    1.45 +	QTableWidgetItem *item;
    1.46  
    1.47 -	int i;
    1.48 -	for (i=0;i<= set.readNumEntry("/history/undosAvail",0); i++)
    1.49 +	// Update buttons
    1.50 +	if (undosAvail<1)
    1.51 +		ui.undoButton->setEnabled (false);
    1.52 +	else	
    1.53 +		ui.undoButton->setEnabled (true);
    1.54 +
    1.55 +	if (redosAvail<1)
    1.56 +		ui.redoButton->setEnabled (false);
    1.57 +	else	
    1.58 +		ui.redoButton->setEnabled (true);
    1.59 +
    1.60 +	// Update table
    1.61 +	for (i=undosAvail; i>0; i--)
    1.62  	{
    1.63 -		QTableWidgetItem *item;
    1.64 +		updateRow (r,s,set);
    1.65 +		r--;
    1.66 +		s--;
    1.67 +		if (s<1) s=stepsTotal;
    1.68 +	}
    1.69 +	
    1.70 +	// Generated the "now" row
    1.71 +	QColor c(255,200,120);
    1.72 +	for (i=0;i<=2;i++)
    1.73 +	{
    1.74 +		if (i!=1)
    1.75 +		{
    1.76 +			item=new QTableWidgetItem("");
    1.77 +			item->setBackgroundColor (c);
    1.78 +			ui.historyTable->setItem(undosAvail, i, item);
    1.79 +		}
    1.80 +	}
    1.81 +	item=new QTableWidgetItem(" - " +tr("Current state","current bar in history hwindow")+ " - ");
    1.82 +	item->setBackgroundColor (c);
    1.83 +	ui.historyTable->setItem(undosAvail, 1, item);
    1.84  
    1.85 -		item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(i)));
    1.86 -		ui.historyTable->setItem(i, 0, item);
    1.87  
    1.88 -		item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(i)));
    1.89 -		ui.historyTable->setItem(i, 1, item);
    1.90 +	s=curStep;
    1.91 +	s++; if (s>stepsTotal) s=1;
    1.92  
    1.93 -		item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(i)));
    1.94 -		ui.historyTable->setItem(i, 2, item);
    1.95 +	for (i=1;i<= redosAvail; i++)
    1.96 +	{
    1.97 +		updateRow (undosAvail+i,s,set);
    1.98 +		s++; if (s>stepsTotal) s=1;
    1.99  	}
   1.100  
   1.101  	ui.historyTable->resizeColumnsToContents();
   1.102  }
   1.103 +
   1.104 +void HistoryWindow::setME (MapEditor *me)
   1.105 +{
   1.106 +	mapEditor=me;
   1.107 +}
   1.108 +
   1.109 +void HistoryWindow::setStepsTotal (int st)
   1.110 +{
   1.111 +	// Number of steps + "current" bar
   1.112 +	ui.historyTable->setRowCount (st+1);
   1.113 +
   1.114 +}
   1.115 +
   1.116 +void HistoryWindow::undo()
   1.117 +{
   1.118 +	mapEditor->undo();
   1.119 +}
   1.120 +
   1.121 +void HistoryWindow::redo()
   1.122 +{
   1.123 +	mapEditor->redo();
   1.124 +}
   1.125 +
   1.126 +void HistoryWindow::select()
   1.127 +{
   1.128 +	mapEditor->gotoStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));
   1.129 +}