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"));
14 ui.historyTable->setHorizontalHeaderItem(0, item);
16 item= new QTableWidgetItem(tr("Comment"));
17 ui.historyTable->setHorizontalHeaderItem(1, item);
19 item= new QTableWidgetItem(tr("Undo action"));
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::updateRow(int row, int step, SimpleSettings &set)
32 QTableWidgetItem *item;
34 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
35 ui.historyTable->setItem(row, 0, item);
37 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
38 ui.historyTable->setItem(row, 1, item);
40 item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
41 ui.historyTable->setItem(row, 2, item);
44 void HistoryWindow::update(SimpleSettings &set)
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");
53 QTableWidgetItem *item;
57 ui.undoButton->setEnabled (false);
59 ui.undoButton->setEnabled (true);
62 ui.redoButton->setEnabled (false);
64 ui.redoButton->setEnabled (true);
67 for (i=undosAvail; i>0; i--)
72 if (s<1) s=stepsTotal;
75 // Generated the "now" row
76 QColor c(255,200,120);
81 item=new QTableWidgetItem("");
82 item->setBackgroundColor (c);
83 ui.historyTable->setItem(undosAvail, i, item);
86 item=new QTableWidgetItem(" - " +tr("Current state","current bar in history hwindow")+ " - ");
87 item->setBackgroundColor (c);
88 ui.historyTable->setItem(undosAvail, 1, item);
92 s++; if (s>stepsTotal) s=1;
94 for (i=1;i<= redosAvail; i++)
96 updateRow (undosAvail+i,s,set);
97 s++; if (s>stepsTotal) s=1;
100 ui.historyTable->resizeColumnsToContents();
103 void HistoryWindow::setME (MapEditor *me)
108 void HistoryWindow::setStepsTotal (int st)
110 // Number of steps + "current" bar
111 ui.historyTable->setRowCount (st+1);
115 void HistoryWindow::undo()
120 void HistoryWindow::redo()
125 void HistoryWindow::select()
127 mapEditor->gotoStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));