1 #include "historywindow.h"
4 HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
7 ui.historyTable->setRowCount (20);
8 ui.historyTable->setColumnCount (3);
11 QTableWidgetItem *item;
13 item= new QTableWidgetItem(tr("Action","Table with actions"));
14 ui.historyTable->setHorizontalHeaderItem(0, item);
16 item= new QTableWidgetItem(tr("Comment","Table with actions"));
17 ui.historyTable->setHorizontalHeaderItem(1, item);
19 item= new QTableWidgetItem(tr("Undo action","Table with actions"));
20 ui.historyTable->setHorizontalHeaderItem(2, item);
22 ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
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()));
30 void HistoryWindow::clearRow(int row)
33 it=ui.historyTable->item (row,0);
34 if (it) it->setText ("");
35 it=ui.historyTable->item (row,1);
36 if (it) it->setText ("");
37 it=ui.historyTable->item (row,2);
38 if (it) it->setText ("");
41 void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
43 QTableWidgetItem *item;
45 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
46 ui.historyTable->setItem(row, 0, item);
48 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
49 ui.historyTable->setItem(row, 1, item);
51 item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
52 ui.historyTable->setItem(row, 2, item);
55 void HistoryWindow::update(SimpleSettings &set)
57 int undosAvail=set.readNumEntry("/history/undosAvail",0);
58 int redosAvail=set.readNumEntry("/history/redosAvail",0);
59 int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
60 int curStep=set.readNumEntry ("/history/curStep");
64 QTableWidgetItem *item;
68 ui.undoButton->setEnabled (false);
70 ui.undoButton->setEnabled (true);
73 ui.redoButton->setEnabled (false);
75 ui.redoButton->setEnabled (true);
77 // Update undos in table
78 for (i=undosAvail; i>0; i--)
83 if (s<1) s=stepsTotal;
86 // Generated the "now" row
87 QColor c(255,200,120);
92 item=new QTableWidgetItem("");
93 item->setBackgroundColor (c);
94 ui.historyTable->setItem(undosAvail, i, item);
97 item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
98 item->setBackgroundColor (c);
99 ui.historyTable->setItem(undosAvail, 1, item);
102 // Update Redos in table
104 s++; if (s>stepsTotal) s=1;
105 for (i=1;i<= redosAvail; i++)
107 updateRow (undosAvail+i,s,set);
108 s++; if (s>stepsTotal) s=1;
112 for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
115 ui.historyTable->resizeColumnsToContents();
118 void HistoryWindow::setME (MapEditor *me)
123 void HistoryWindow::setStepsTotal (int st)
125 // Number of steps + "current" bar
126 ui.historyTable->setRowCount (st+1);
130 void HistoryWindow::undo()
135 void HistoryWindow::redo()
140 void HistoryWindow::select()
142 mapEditor->gotoStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));