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