historywindow.cpp
author insilmaril
Mon, 08 Dec 2008 16:57:33 +0000
changeset 729 7ddbe3fa34a1
parent 644 954221e01e4e
child 847 43268373032d
permissions -rw-r--r--
More fixes for selections
insilmaril@377
     1
#include "historywindow.h"
insilmaril@404
     2
#include "mainwindow.h"
insilmaril@404
     3
insilmaril@377
     4
insilmaril@393
     5
extern QString iconPath;
insilmaril@404
     6
extern Settings settings;
insilmaril@404
     7
extern Main *mainWindow;
insilmaril@393
     8
insilmaril@377
     9
HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
insilmaril@377
    10
{
insilmaril@377
    11
	ui.setupUi (this);
insilmaril@489
    12
	ui.historyTable->setRowCount (settings.value( "/mapeditor/stepsTotal",75).toInt());
insilmaril@377
    13
	ui.historyTable->setColumnCount (3);
insilmaril@377
    14
insilmaril@377
    15
	
insilmaril@377
    16
	QTableWidgetItem *item;
insilmaril@377
    17
insilmaril@388
    18
	item= new QTableWidgetItem(tr("Action","Table with actions"));
insilmaril@377
    19
	ui.historyTable->setHorizontalHeaderItem(0, item);
insilmaril@377
    20
	
insilmaril@388
    21
	item= new QTableWidgetItem(tr("Comment","Table with actions"));
insilmaril@377
    22
	ui.historyTable->setHorizontalHeaderItem(1, item);
insilmaril@377
    23
	
insilmaril@388
    24
	item= new QTableWidgetItem(tr("Undo action","Table with actions"));
insilmaril@377
    25
	ui.historyTable->setHorizontalHeaderItem(2, item);
insilmaril@377
    26
insilmaril@377
    27
	ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
insilmaril@381
    28
insilmaril@393
    29
	ui.undoButton->setIcon (QIcon(iconPath+"/undo.png"));
insilmaril@393
    30
	ui.redoButton->setIcon (QIcon(iconPath+"/redo.png"));
insilmaril@393
    31
insilmaril@381
    32
	connect ( ui.undoButton, SIGNAL (clicked()), this, SLOT (undo()));
insilmaril@381
    33
	connect ( ui.redoButton, SIGNAL (clicked()), this, SLOT (redo()));
insilmaril@381
    34
	connect ( ui.historyTable, SIGNAL (itemSelectionChanged()), this, SLOT (select()));
insilmaril@404
    35
insilmaril@404
    36
	// Load Settings
insilmaril@404
    37
insilmaril@489
    38
	resize (settings.value ( "/satellite/historywindow/geometry/size", QSize(1000,400)).toSize());
insilmaril@489
    39
	move   (settings.value ( "/satellite/historywindow/geometry/pos", QPoint (0,450)).toPoint());
insilmaril@489
    40
insilmaril@489
    41
	ui.historyTable->setColumnWidth (0,settings.value("/satellite/historywindow/geometry/columnWidth/0",250).toInt());
insilmaril@489
    42
	ui.historyTable->setColumnWidth (1,settings.value("/satellite/historywindow/geometry/columnWidth/1",350).toInt());
insilmaril@489
    43
	ui.historyTable->setColumnWidth (2,settings.value("/satellite/historywindow/geometry/columnWidth/2",250).toInt());
insilmaril@377
    44
}
insilmaril@377
    45
insilmaril@404
    46
HistoryWindow::~HistoryWindow()
insilmaril@404
    47
{
insilmaril@489
    48
	// Save settings
insilmaril@489
    49
	settings.setValue( "/satellite/historywindow/geometry/size", size() );
insilmaril@489
    50
	settings.setValue( "/satellite/historywindow/geometry/pos", pos() );
insilmaril@489
    51
insilmaril@420
    52
	for (int i=0; i<3; ++i)
insilmaril@489
    53
		settings.setValue( QString("/satellite/historywindow/geometry/columnWidth/%1").arg(i), ui.historyTable->columnWidth (i) );
insilmaril@404
    54
}
insilmaril@377
    55
insilmaril@388
    56
void HistoryWindow::clearRow(int row)
insilmaril@388
    57
{
insilmaril@388
    58
	QTableWidgetItem *it;
insilmaril@388
    59
	it=ui.historyTable->item (row,0);
insilmaril@388
    60
	if (it) it->setText ("");
insilmaril@388
    61
	it=ui.historyTable->item (row,1);
insilmaril@388
    62
	if (it) it->setText ("");
insilmaril@388
    63
	it=ui.historyTable->item (row,2);
insilmaril@388
    64
	if (it) it->setText ("");
insilmaril@388
    65
}
insilmaril@388
    66
insilmaril@381
    67
void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
insilmaril@381
    68
{
insilmaril@381
    69
	QTableWidgetItem *item;
insilmaril@381
    70
insilmaril@381
    71
	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
insilmaril@381
    72
	ui.historyTable->setItem(row, 0, item);
insilmaril@381
    73
insilmaril@381
    74
	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
insilmaril@381
    75
	ui.historyTable->setItem(row, 1, item);
insilmaril@381
    76
insilmaril@381
    77
	item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
insilmaril@381
    78
	ui.historyTable->setItem(row, 2, item);
insilmaril@381
    79
}
insilmaril@381
    80
insilmaril@377
    81
void HistoryWindow::update(SimpleSettings &set)
insilmaril@377
    82
{
insilmaril@381
    83
	int undosAvail=set.readNumEntry("/history/undosAvail",0);
insilmaril@381
    84
	int redosAvail=set.readNumEntry("/history/redosAvail",0);
insilmaril@381
    85
	int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
insilmaril@381
    86
	int curStep=set.readNumEntry ("/history/curStep");
insilmaril@381
    87
	int i;
insilmaril@381
    88
	int s=curStep;
insilmaril@381
    89
	int r=undosAvail-1;
insilmaril@381
    90
	QTableWidgetItem *item;
insilmaril@377
    91
insilmaril@489
    92
	// Update number of rows
insilmaril@489
    93
	ui.historyTable->setRowCount (undosAvail + redosAvail +1);
insilmaril@489
    94
insilmaril@381
    95
	// Update buttons
insilmaril@381
    96
	if (undosAvail<1)
insilmaril@381
    97
		ui.undoButton->setEnabled (false);
insilmaril@381
    98
	else	
insilmaril@381
    99
		ui.undoButton->setEnabled (true);
insilmaril@381
   100
insilmaril@381
   101
	if (redosAvail<1)
insilmaril@381
   102
		ui.redoButton->setEnabled (false);
insilmaril@381
   103
	else	
insilmaril@381
   104
		ui.redoButton->setEnabled (true);
insilmaril@381
   105
insilmaril@388
   106
	// Update undos in table
insilmaril@381
   107
	for (i=undosAvail; i>0; i--)
insilmaril@377
   108
	{
insilmaril@381
   109
		updateRow (r,s,set);
insilmaril@381
   110
		r--;
insilmaril@381
   111
		s--;
insilmaril@381
   112
		if (s<1) s=stepsTotal;
insilmaril@381
   113
	}
insilmaril@381
   114
	
insilmaril@381
   115
	// Generated the "now" row
insilmaril@381
   116
	QColor c(255,200,120);
insilmaril@381
   117
	for (i=0;i<=2;i++)
insilmaril@381
   118
	{
insilmaril@381
   119
		if (i!=1)
insilmaril@381
   120
		{
insilmaril@381
   121
			item=new QTableWidgetItem("");
insilmaril@381
   122
			item->setBackgroundColor (c);
insilmaril@381
   123
			ui.historyTable->setItem(undosAvail, i, item);
insilmaril@381
   124
		}
insilmaril@381
   125
	}
insilmaril@388
   126
	item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
insilmaril@381
   127
	item->setBackgroundColor (c);
insilmaril@381
   128
	ui.historyTable->setItem(undosAvail, 1, item);
insilmaril@377
   129
insilmaril@394
   130
	// Show "now" row
insilmaril@394
   131
	ui.historyTable->scrollToItem (item);
insilmaril@377
   132
insilmaril@388
   133
	// Update Redos in table
insilmaril@381
   134
	s=curStep;
insilmaril@381
   135
	s++; if (s>stepsTotal) s=1;
insilmaril@381
   136
	for (i=1;i<= redosAvail; i++)
insilmaril@381
   137
	{
insilmaril@381
   138
		updateRow (undosAvail+i,s,set);
insilmaril@381
   139
		s++; if (s>stepsTotal) s=1;
insilmaril@377
   140
	}
insilmaril@377
   141
insilmaril@388
   142
	// Delete the rest
insilmaril@388
   143
	for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
insilmaril@388
   144
		clearRow (i);
insilmaril@388
   145
insilmaril@489
   146
	//ui.historyTable->resizeColumnsToContents();
insilmaril@377
   147
}
insilmaril@381
   148
insilmaril@381
   149
void HistoryWindow::setStepsTotal (int st)
insilmaril@381
   150
{
insilmaril@381
   151
	// Number of steps + "current" bar
insilmaril@381
   152
	ui.historyTable->setRowCount (st+1);
insilmaril@381
   153
}
insilmaril@381
   154
insilmaril@482
   155
insilmaril@489
   156
void HistoryWindow::closeEvent (QCloseEvent *)
insilmaril@421
   157
{
insilmaril@442
   158
	emit (windowClosed() );
insilmaril@421
   159
}
insilmaril@421
   160
insilmaril@381
   161
void HistoryWindow::undo()
insilmaril@381
   162
{
insilmaril@404
   163
	mainWindow->editUndo();
insilmaril@381
   164
}
insilmaril@381
   165
insilmaril@381
   166
void HistoryWindow::redo()
insilmaril@381
   167
{
insilmaril@404
   168
	mainWindow->editRedo();
insilmaril@381
   169
}
insilmaril@381
   170
insilmaril@381
   171
void HistoryWindow::select()
insilmaril@381
   172
{
insilmaril@404
   173
	mainWindow->gotoHistoryStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));
insilmaril@381
   174
}