historywindow.cpp
author insilmaril
Mon, 30 Oct 2006 12:39:37 +0000
changeset 396 445a5d5ee20b
parent 394 67cfa6e6b863
child 404 53efc2562a7d
permissions -rw-r--r--
Spanish doc is found, if LANG is set. Fixed wrong position of floatimages
insilmaril@377
     1
#include "historywindow.h"
insilmaril@381
     2
#include "mapeditor.h"
insilmaril@377
     3
insilmaril@393
     4
extern QString iconPath;
insilmaril@393
     5
insilmaril@377
     6
HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
insilmaril@377
     7
{
insilmaril@377
     8
	ui.setupUi (this);
insilmaril@377
     9
	ui.historyTable->setRowCount (20);
insilmaril@377
    10
	ui.historyTable->setColumnCount (3);
insilmaril@377
    11
insilmaril@377
    12
	
insilmaril@377
    13
	QTableWidgetItem *item;
insilmaril@377
    14
insilmaril@388
    15
	item= new QTableWidgetItem(tr("Action","Table with actions"));
insilmaril@377
    16
	ui.historyTable->setHorizontalHeaderItem(0, item);
insilmaril@377
    17
	
insilmaril@388
    18
	item= new QTableWidgetItem(tr("Comment","Table with actions"));
insilmaril@377
    19
	ui.historyTable->setHorizontalHeaderItem(1, item);
insilmaril@377
    20
	
insilmaril@388
    21
	item= new QTableWidgetItem(tr("Undo action","Table with actions"));
insilmaril@377
    22
	ui.historyTable->setHorizontalHeaderItem(2, item);
insilmaril@377
    23
insilmaril@377
    24
	ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
insilmaril@381
    25
insilmaril@393
    26
	ui.undoButton->setIcon (QIcon(iconPath+"/undo.png"));
insilmaril@393
    27
	ui.redoButton->setIcon (QIcon(iconPath+"/redo.png"));
insilmaril@393
    28
insilmaril@381
    29
	connect ( ui.undoButton, SIGNAL (clicked()), this, SLOT (undo()));
insilmaril@381
    30
	connect ( ui.redoButton, SIGNAL (clicked()), this, SLOT (redo()));
insilmaril@381
    31
	connect ( ui.historyTable, SIGNAL (itemSelectionChanged()), this, SLOT (select()));
insilmaril@377
    32
}
insilmaril@377
    33
insilmaril@377
    34
insilmaril@388
    35
void HistoryWindow::clearRow(int row)
insilmaril@388
    36
{
insilmaril@388
    37
	QTableWidgetItem *it;
insilmaril@388
    38
	it=ui.historyTable->item (row,0);
insilmaril@388
    39
	if (it) it->setText ("");
insilmaril@388
    40
	it=ui.historyTable->item (row,1);
insilmaril@388
    41
	if (it) it->setText ("");
insilmaril@388
    42
	it=ui.historyTable->item (row,2);
insilmaril@388
    43
	if (it) it->setText ("");
insilmaril@388
    44
}
insilmaril@388
    45
insilmaril@381
    46
void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
insilmaril@381
    47
{
insilmaril@381
    48
	QTableWidgetItem *item;
insilmaril@381
    49
insilmaril@381
    50
	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
insilmaril@381
    51
	ui.historyTable->setItem(row, 0, item);
insilmaril@381
    52
insilmaril@381
    53
	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
insilmaril@381
    54
	ui.historyTable->setItem(row, 1, item);
insilmaril@381
    55
insilmaril@381
    56
	item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
insilmaril@381
    57
	ui.historyTable->setItem(row, 2, item);
insilmaril@381
    58
}
insilmaril@381
    59
insilmaril@377
    60
void HistoryWindow::update(SimpleSettings &set)
insilmaril@377
    61
{
insilmaril@381
    62
	int undosAvail=set.readNumEntry("/history/undosAvail",0);
insilmaril@381
    63
	int redosAvail=set.readNumEntry("/history/redosAvail",0);
insilmaril@381
    64
	int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
insilmaril@381
    65
	int curStep=set.readNumEntry ("/history/curStep");
insilmaril@381
    66
	int i;
insilmaril@381
    67
	int s=curStep;
insilmaril@381
    68
	int r=undosAvail-1;
insilmaril@381
    69
	QTableWidgetItem *item;
insilmaril@377
    70
insilmaril@381
    71
	// Update buttons
insilmaril@381
    72
	if (undosAvail<1)
insilmaril@381
    73
		ui.undoButton->setEnabled (false);
insilmaril@381
    74
	else	
insilmaril@381
    75
		ui.undoButton->setEnabled (true);
insilmaril@381
    76
insilmaril@381
    77
	if (redosAvail<1)
insilmaril@381
    78
		ui.redoButton->setEnabled (false);
insilmaril@381
    79
	else	
insilmaril@381
    80
		ui.redoButton->setEnabled (true);
insilmaril@381
    81
insilmaril@388
    82
	// Update undos in table
insilmaril@381
    83
	for (i=undosAvail; i>0; i--)
insilmaril@377
    84
	{
insilmaril@381
    85
		updateRow (r,s,set);
insilmaril@381
    86
		r--;
insilmaril@381
    87
		s--;
insilmaril@381
    88
		if (s<1) s=stepsTotal;
insilmaril@381
    89
	}
insilmaril@381
    90
	
insilmaril@381
    91
	// Generated the "now" row
insilmaril@381
    92
	QColor c(255,200,120);
insilmaril@381
    93
	for (i=0;i<=2;i++)
insilmaril@381
    94
	{
insilmaril@381
    95
		if (i!=1)
insilmaril@381
    96
		{
insilmaril@381
    97
			item=new QTableWidgetItem("");
insilmaril@381
    98
			item->setBackgroundColor (c);
insilmaril@381
    99
			ui.historyTable->setItem(undosAvail, i, item);
insilmaril@381
   100
		}
insilmaril@381
   101
	}
insilmaril@388
   102
	item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
insilmaril@381
   103
	item->setBackgroundColor (c);
insilmaril@381
   104
	ui.historyTable->setItem(undosAvail, 1, item);
insilmaril@377
   105
insilmaril@394
   106
	// Show "now" row
insilmaril@394
   107
	ui.historyTable->scrollToItem (item);
insilmaril@377
   108
insilmaril@388
   109
	// Update Redos in table
insilmaril@381
   110
	s=curStep;
insilmaril@381
   111
	s++; if (s>stepsTotal) s=1;
insilmaril@381
   112
	for (i=1;i<= redosAvail; i++)
insilmaril@381
   113
	{
insilmaril@381
   114
		updateRow (undosAvail+i,s,set);
insilmaril@381
   115
		s++; if (s>stepsTotal) s=1;
insilmaril@377
   116
	}
insilmaril@377
   117
insilmaril@388
   118
	// Delete the rest
insilmaril@388
   119
	for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
insilmaril@388
   120
		clearRow (i);
insilmaril@388
   121
insilmaril@377
   122
	ui.historyTable->resizeColumnsToContents();
insilmaril@377
   123
}
insilmaril@381
   124
insilmaril@381
   125
void HistoryWindow::setME (MapEditor *me)
insilmaril@381
   126
{
insilmaril@381
   127
	mapEditor=me;
insilmaril@381
   128
}
insilmaril@381
   129
insilmaril@381
   130
void HistoryWindow::setStepsTotal (int st)
insilmaril@381
   131
{
insilmaril@381
   132
	// Number of steps + "current" bar
insilmaril@381
   133
	ui.historyTable->setRowCount (st+1);
insilmaril@381
   134
insilmaril@381
   135
}
insilmaril@381
   136
insilmaril@381
   137
void HistoryWindow::undo()
insilmaril@381
   138
{
insilmaril@381
   139
	mapEditor->undo();
insilmaril@381
   140
}
insilmaril@381
   141
insilmaril@381
   142
void HistoryWindow::redo()
insilmaril@381
   143
{
insilmaril@381
   144
	mapEditor->redo();
insilmaril@381
   145
}
insilmaril@381
   146
insilmaril@381
   147
void HistoryWindow::select()
insilmaril@381
   148
{
insilmaril@381
   149
	mapEditor->gotoStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));
insilmaril@381
   150
}