historywindow.cpp
author insilmaril
Thu Sep 14 11:38:17 2006 +0000 (2006-09-14)
changeset 385 63e28dfd877d
parent 377 5391ab620c95
child 388 3a58c9ef4a18
permissions -rw-r--r--
1.8.57 - more changes in history window, Note Editor is QT4 now
insilmaril@377
     1
#include "historywindow.h"
insilmaril@381
     2
#include "mapeditor.h"
insilmaril@377
     3
insilmaril@377
     4
HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
insilmaril@377
     5
{
insilmaril@377
     6
	ui.setupUi (this);
insilmaril@377
     7
	ui.historyTable->setRowCount (20);
insilmaril@377
     8
	ui.historyTable->setColumnCount (3);
insilmaril@377
     9
insilmaril@377
    10
	
insilmaril@377
    11
	QTableWidgetItem *item;
insilmaril@377
    12
insilmaril@377
    13
	item= new QTableWidgetItem(tr("Action"));
insilmaril@377
    14
	ui.historyTable->setHorizontalHeaderItem(0, item);
insilmaril@377
    15
	
insilmaril@377
    16
	item= new QTableWidgetItem(tr("Comment"));
insilmaril@377
    17
	ui.historyTable->setHorizontalHeaderItem(1, item);
insilmaril@377
    18
	
insilmaril@377
    19
	item= new QTableWidgetItem(tr("Undo action"));
insilmaril@377
    20
	ui.historyTable->setHorizontalHeaderItem(2, item);
insilmaril@377
    21
insilmaril@377
    22
	ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
insilmaril@381
    23
insilmaril@381
    24
	connect ( ui.undoButton, SIGNAL (clicked()), this, SLOT (undo()));
insilmaril@381
    25
	connect ( ui.redoButton, SIGNAL (clicked()), this, SLOT (redo()));
insilmaril@381
    26
	connect ( ui.historyTable, SIGNAL (itemSelectionChanged()), this, SLOT (select()));
insilmaril@377
    27
}
insilmaril@377
    28
insilmaril@377
    29
insilmaril@381
    30
void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
insilmaril@381
    31
{
insilmaril@381
    32
	QTableWidgetItem *item;
insilmaril@381
    33
insilmaril@381
    34
	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
insilmaril@381
    35
	ui.historyTable->setItem(row, 0, item);
insilmaril@381
    36
insilmaril@381
    37
	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
insilmaril@381
    38
	ui.historyTable->setItem(row, 1, item);
insilmaril@381
    39
insilmaril@381
    40
	item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
insilmaril@381
    41
	ui.historyTable->setItem(row, 2, item);
insilmaril@381
    42
}
insilmaril@381
    43
insilmaril@377
    44
void HistoryWindow::update(SimpleSettings &set)
insilmaril@377
    45
{
insilmaril@381
    46
	int undosAvail=set.readNumEntry("/history/undosAvail",0);
insilmaril@381
    47
	int redosAvail=set.readNumEntry("/history/redosAvail",0);
insilmaril@381
    48
	int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
insilmaril@381
    49
	int curStep=set.readNumEntry ("/history/curStep");
insilmaril@381
    50
	int i;
insilmaril@381
    51
	int s=curStep;
insilmaril@381
    52
	int r=undosAvail-1;
insilmaril@381
    53
	QTableWidgetItem *item;
insilmaril@377
    54
insilmaril@381
    55
	// Update buttons
insilmaril@381
    56
	if (undosAvail<1)
insilmaril@381
    57
		ui.undoButton->setEnabled (false);
insilmaril@381
    58
	else	
insilmaril@381
    59
		ui.undoButton->setEnabled (true);
insilmaril@381
    60
insilmaril@381
    61
	if (redosAvail<1)
insilmaril@381
    62
		ui.redoButton->setEnabled (false);
insilmaril@381
    63
	else	
insilmaril@381
    64
		ui.redoButton->setEnabled (true);
insilmaril@381
    65
insilmaril@381
    66
	// Update table
insilmaril@381
    67
	for (i=undosAvail; i>0; i--)
insilmaril@377
    68
	{
insilmaril@381
    69
		updateRow (r,s,set);
insilmaril@381
    70
		r--;
insilmaril@381
    71
		s--;
insilmaril@381
    72
		if (s<1) s=stepsTotal;
insilmaril@381
    73
	}
insilmaril@381
    74
	
insilmaril@381
    75
	// Generated the "now" row
insilmaril@381
    76
	QColor c(255,200,120);
insilmaril@381
    77
	for (i=0;i<=2;i++)
insilmaril@381
    78
	{
insilmaril@381
    79
		if (i!=1)
insilmaril@381
    80
		{
insilmaril@381
    81
			item=new QTableWidgetItem("");
insilmaril@381
    82
			item->setBackgroundColor (c);
insilmaril@381
    83
			ui.historyTable->setItem(undosAvail, i, item);
insilmaril@381
    84
		}
insilmaril@381
    85
	}
insilmaril@381
    86
	item=new QTableWidgetItem(" - " +tr("Current state","current bar in history hwindow")+ " - ");
insilmaril@381
    87
	item->setBackgroundColor (c);
insilmaril@381
    88
	ui.historyTable->setItem(undosAvail, 1, item);
insilmaril@377
    89
insilmaril@377
    90
insilmaril@381
    91
	s=curStep;
insilmaril@381
    92
	s++; if (s>stepsTotal) s=1;
insilmaril@377
    93
insilmaril@381
    94
	for (i=1;i<= redosAvail; i++)
insilmaril@381
    95
	{
insilmaril@381
    96
		updateRow (undosAvail+i,s,set);
insilmaril@381
    97
		s++; if (s>stepsTotal) s=1;
insilmaril@377
    98
	}
insilmaril@377
    99
insilmaril@377
   100
	ui.historyTable->resizeColumnsToContents();
insilmaril@377
   101
}
insilmaril@381
   102
insilmaril@381
   103
void HistoryWindow::setME (MapEditor *me)
insilmaril@381
   104
{
insilmaril@381
   105
	mapEditor=me;
insilmaril@381
   106
}
insilmaril@381
   107
insilmaril@381
   108
void HistoryWindow::setStepsTotal (int st)
insilmaril@381
   109
{
insilmaril@381
   110
	// Number of steps + "current" bar
insilmaril@381
   111
	ui.historyTable->setRowCount (st+1);
insilmaril@381
   112
insilmaril@381
   113
}
insilmaril@381
   114
insilmaril@381
   115
void HistoryWindow::undo()
insilmaril@381
   116
{
insilmaril@381
   117
	mapEditor->undo();
insilmaril@381
   118
}
insilmaril@381
   119
insilmaril@381
   120
void HistoryWindow::redo()
insilmaril@381
   121
{
insilmaril@381
   122
	mapEditor->redo();
insilmaril@381
   123
}
insilmaril@381
   124
insilmaril@381
   125
void HistoryWindow::select()
insilmaril@381
   126
{
insilmaril@381
   127
	mapEditor->gotoStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));
insilmaril@381
   128
}