1.11.2 split up of xml helper functions. started to work on attributes
1 #include "historywindow.h"
2 #include "mainwindow.h"
5 extern QString iconPath;
6 extern Settings settings;
7 extern Main *mainWindow;
9 HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
12 ui.historyTable->setRowCount (settings.value( "/mapeditor/stepsTotal",75).toInt());
13 ui.historyTable->setColumnCount (3);
16 QTableWidgetItem *item;
18 item= new QTableWidgetItem(tr("Action","Table with actions"));
19 ui.historyTable->setHorizontalHeaderItem(0, item);
21 item= new QTableWidgetItem(tr("Comment","Table with actions"));
22 ui.historyTable->setHorizontalHeaderItem(1, item);
24 item= new QTableWidgetItem(tr("Undo action","Table with actions"));
25 ui.historyTable->setHorizontalHeaderItem(2, item);
27 ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
29 ui.undoButton->setIcon (QIcon(iconPath+"/undo.png"));
30 ui.redoButton->setIcon (QIcon(iconPath+"/redo.png"));
32 connect ( ui.undoButton, SIGNAL (clicked()), this, SLOT (undo()));
33 connect ( ui.redoButton, SIGNAL (clicked()), this, SLOT (redo()));
34 connect ( ui.historyTable, SIGNAL (itemSelectionChanged()), this, SLOT (select()));
38 resize (settings.value ( "/satellite/historywindow/geometry/size", QSize(1000,400)).toSize());
39 move (settings.value ( "/satellite/historywindow/geometry/pos", QPoint (0,450)).toPoint());
41 ui.historyTable->setColumnWidth (0,settings.value("/satellite/historywindow/geometry/columnWidth/0",250).toInt());
42 ui.historyTable->setColumnWidth (1,settings.value("/satellite/historywindow/geometry/columnWidth/1",350).toInt());
43 ui.historyTable->setColumnWidth (2,settings.value("/satellite/historywindow/geometry/columnWidth/2",250).toInt());
46 HistoryWindow::~HistoryWindow()
49 settings.setValue( "/satellite/historywindow/geometry/size", size() );
50 settings.setValue( "/satellite/historywindow/geometry/pos", pos() );
52 for (int i=0; i<3; ++i)
53 settings.setValue( QString("/satellite/historywindow/geometry/columnWidth/%1").arg(i), ui.historyTable->columnWidth (i) );
56 void HistoryWindow::clearRow(int row)
59 it=ui.historyTable->item (row,0);
60 if (it) it->setText ("");
61 it=ui.historyTable->item (row,1);
62 if (it) it->setText ("");
63 it=ui.historyTable->item (row,2);
64 if (it) it->setText ("");
67 void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
69 QTableWidgetItem *item;
71 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
72 ui.historyTable->setItem(row, 0, item);
74 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
75 ui.historyTable->setItem(row, 1, item);
77 item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
78 ui.historyTable->setItem(row, 2, item);
81 void HistoryWindow::update(SimpleSettings &set)
83 int undosAvail=set.readNumEntry("/history/undosAvail",0);
84 int redosAvail=set.readNumEntry("/history/redosAvail",0);
85 int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
86 int curStep=set.readNumEntry ("/history/curStep");
90 QTableWidgetItem *item;
92 // Update number of rows
93 ui.historyTable->setRowCount (undosAvail + redosAvail +1);
97 ui.undoButton->setEnabled (false);
99 ui.undoButton->setEnabled (true);
102 ui.redoButton->setEnabled (false);
104 ui.redoButton->setEnabled (true);
106 // Update undos in table
107 for (i=undosAvail; i>0; i--)
112 if (s<1) s=stepsTotal;
115 // Generated the "now" row
116 QColor c(255,200,120);
121 item=new QTableWidgetItem("");
122 item->setBackgroundColor (c);
123 ui.historyTable->setItem(undosAvail, i, item);
126 item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
127 item->setBackgroundColor (c);
128 ui.historyTable->setItem(undosAvail, 1, item);
131 ui.historyTable->scrollToItem (item);
133 // Update Redos in table
135 s++; if (s>stepsTotal) s=1;
136 for (i=1;i<= redosAvail; i++)
138 updateRow (undosAvail+i,s,set);
139 s++; if (s>stepsTotal) s=1;
143 for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
146 //ui.historyTable->resizeColumnsToContents();
149 void HistoryWindow::setStepsTotal (int st)
151 // Number of steps + "current" bar
152 ui.historyTable->setRowCount (st+1);
156 void HistoryWindow::closeEvent (QCloseEvent *)
158 emit (windowClosed() );
161 void HistoryWindow::undo()
163 mainWindow->editUndo();
166 void HistoryWindow::redo()
168 mainWindow->editRedo();
171 void HistoryWindow::select()
173 cout <<"HW::select "<<ui.historyTable->row (ui.historyTable->selectedItems().first())<<endl;
174 mainWindow->gotoHistoryStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));