1 #include "historywindow.h"
2 #include "mainwindow.h"
5 extern Settings settings;
6 extern Main *mainWindow;
8 HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
11 ui.historyTable->setRowCount (settings.value( "/history/stepsTotal",75).toInt());
12 ui.historyTable->setColumnCount (3);
15 QTableWidgetItem *item;
17 item= new QTableWidgetItem(tr("Action","Table with actions"));
18 ui.historyTable->setHorizontalHeaderItem(0, item);
20 item= new QTableWidgetItem(tr("Comment","Table with actions"));
21 ui.historyTable->setHorizontalHeaderItem(1, item);
23 item= new QTableWidgetItem(tr("Undo action","Table with actions"));
24 ui.historyTable->setHorizontalHeaderItem(2, item);
26 ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
28 ui.undoButton->setIcon (QIcon(":/undo.png"));
29 ui.redoButton->setIcon (QIcon(":/redo.png"));
31 connect ( ui.undoButton, SIGNAL (clicked()), this, SLOT (undo()));
32 connect ( ui.redoButton, SIGNAL (clicked()), this, SLOT (redo()));
33 connect ( ui.historyTable, SIGNAL (itemSelectionChanged()), this, SLOT (select()));
37 resize (settings.value ( "/satellite/historywindow/geometry/size", QSize(1000,400)).toSize());
38 move (settings.value ( "/satellite/historywindow/geometry/pos", QPoint (0,450)).toPoint());
40 ui.historyTable->setColumnWidth (0,settings.value("/satellite/historywindow/geometry/columnWidth/0",250).toInt());
41 ui.historyTable->setColumnWidth (1,settings.value("/satellite/historywindow/geometry/columnWidth/1",350).toInt());
42 ui.historyTable->setColumnWidth (2,settings.value("/satellite/historywindow/geometry/columnWidth/2",250).toInt());
45 HistoryWindow::~HistoryWindow()
48 settings.setValue( "/satellite/historywindow/geometry/size", size() );
49 settings.setValue( "/satellite/historywindow/geometry/pos", pos() );
51 for (int i=0; i<3; ++i)
52 settings.setValue( QString("/satellite/historywindow/geometry/columnWidth/%1").arg(i), ui.historyTable->columnWidth (i) );
55 void HistoryWindow::clearRow(int row)
58 it=ui.historyTable->item (row,0);
59 if (it) it->setText ("");
60 it=ui.historyTable->item (row,1);
61 if (it) it->setText ("");
62 it=ui.historyTable->item (row,2);
63 if (it) it->setText ("");
66 void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
68 QTableWidgetItem *item;
70 item= new QTableWidgetItem(set.value(QString("/history/step-%1/redoCommand").arg(step)));
71 ui.historyTable->setItem(row, 0, item);
73 item= new QTableWidgetItem(set.value(QString("/history/step-%1/comment").arg(step)));
74 ui.historyTable->setItem(row, 1, item);
76 item=new QTableWidgetItem(set.value(QString("/history/step-%1/undoCommand").arg(step)));
77 ui.historyTable->setItem(row, 2, item);
80 void HistoryWindow::update(SimpleSettings &set)
82 int undosAvail=set.readNumValue("/history/undosAvail",0);
83 int redosAvail=set.readNumValue("/history/redosAvail",0);
84 int stepsTotal=set.readNumValue("/history/stepsTotal",1000);
85 int curStep=set.readNumValue ("/history/curStep");
89 QTableWidgetItem *item;
91 // Update number of rows
92 ui.historyTable->setRowCount (undosAvail + redosAvail +1);
96 ui.undoButton->setEnabled (false);
98 ui.undoButton->setEnabled (true);
101 ui.redoButton->setEnabled (false);
103 ui.redoButton->setEnabled (true);
105 // Update undos in table
106 for (i=undosAvail; i>0; i--)
111 if (s<1) s=stepsTotal;
114 // Generated the "now" row
115 QColor c(255,200,120);
120 item=new QTableWidgetItem("");
121 item->setBackgroundColor (c);
122 ui.historyTable->setItem(undosAvail, i, item);
125 item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
126 item->setBackgroundColor (c);
127 ui.historyTable->setItem(undosAvail, 1, item);
130 ui.historyTable->scrollToItem (item);
132 // Update Redos in table
134 s++; if (s>stepsTotal) s=1;
135 for (i=1;i<= redosAvail; i++)
137 updateRow (undosAvail+i,s,set);
138 s++; if (s>stepsTotal) s=1;
142 for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
145 //ui.historyTable->resizeColumnsToContents();
148 void HistoryWindow::setStepsTotal (int st)
150 // Number of steps + "current" bar
151 ui.historyTable->setRowCount (st+1);
155 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 mainWindow->gotoHistoryStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));