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