1 #include "historywindow.h"
4 extern QString iconPath;
6 HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
9 ui.historyTable->setRowCount (20);
10 ui.historyTable->setColumnCount (3);
13 QTableWidgetItem *item;
15 item= new QTableWidgetItem(tr("Action","Table with actions"));
16 ui.historyTable->setHorizontalHeaderItem(0, item);
18 item= new QTableWidgetItem(tr("Comment","Table with actions"));
19 ui.historyTable->setHorizontalHeaderItem(1, item);
21 item= new QTableWidgetItem(tr("Undo action","Table with actions"));
22 ui.historyTable->setHorizontalHeaderItem(2, item);
24 ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
26 ui.undoButton->setIcon (QIcon(iconPath+"/undo.png"));
27 ui.redoButton->setIcon (QIcon(iconPath+"/redo.png"));
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()));
35 void HistoryWindow::clearRow(int row)
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 ("");
46 void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
48 QTableWidgetItem *item;
50 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
51 ui.historyTable->setItem(row, 0, item);
53 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
54 ui.historyTable->setItem(row, 1, item);
56 item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
57 ui.historyTable->setItem(row, 2, item);
60 void HistoryWindow::update(SimpleSettings &set)
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");
69 QTableWidgetItem *item;
73 ui.undoButton->setEnabled (false);
75 ui.undoButton->setEnabled (true);
78 ui.redoButton->setEnabled (false);
80 ui.redoButton->setEnabled (true);
82 // Update undos in table
83 for (i=undosAvail; i>0; i--)
88 if (s<1) s=stepsTotal;
91 // Generated the "now" row
92 QColor c(255,200,120);
97 item=new QTableWidgetItem("");
98 item->setBackgroundColor (c);
99 ui.historyTable->setItem(undosAvail, i, item);
102 item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
103 item->setBackgroundColor (c);
104 ui.historyTable->setItem(undosAvail, 1, item);
107 ui.historyTable->scrollToItem (item);
109 // Update Redos in table
111 s++; if (s>stepsTotal) s=1;
112 for (i=1;i<= redosAvail; i++)
114 updateRow (undosAvail+i,s,set);
115 s++; if (s>stepsTotal) s=1;
119 for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
122 ui.historyTable->resizeColumnsToContents();
125 void HistoryWindow::setME (MapEditor *me)
130 void HistoryWindow::setStepsTotal (int st)
132 // Number of steps + "current" bar
133 ui.historyTable->setRowCount (st+1);
137 void HistoryWindow::undo()
142 void HistoryWindow::redo()
147 void HistoryWindow::select()
149 mapEditor->gotoStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));