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 (20);
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 for (int i=0; i<3; ++i)
39 ui.historyTable->setColumnWidth (i,settings.value( QString("/historywindow/geometry/columnWidth/%1").arg(i),150).toInt());
42 HistoryWindow::~HistoryWindow()
44 for (int i=0; i<3; ++i)
45 settings.setValue( QString("/historywindow/geometry/columnWidth/%1").arg(i), ui.historyTable->columnWidth (i) );
48 void HistoryWindow::clearRow(int row)
51 it=ui.historyTable->item (row,0);
52 if (it) it->setText ("");
53 it=ui.historyTable->item (row,1);
54 if (it) it->setText ("");
55 it=ui.historyTable->item (row,2);
56 if (it) it->setText ("");
59 void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
61 QTableWidgetItem *item;
63 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
64 ui.historyTable->setItem(row, 0, item);
66 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
67 ui.historyTable->setItem(row, 1, item);
69 item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
70 ui.historyTable->setItem(row, 2, item);
73 void HistoryWindow::update(SimpleSettings &set)
75 int undosAvail=set.readNumEntry("/history/undosAvail",0);
76 int redosAvail=set.readNumEntry("/history/redosAvail",0);
77 int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
78 int curStep=set.readNumEntry ("/history/curStep");
82 QTableWidgetItem *item;
86 ui.undoButton->setEnabled (false);
88 ui.undoButton->setEnabled (true);
91 ui.redoButton->setEnabled (false);
93 ui.redoButton->setEnabled (true);
95 // Update undos in table
96 for (i=undosAvail; i>0; i--)
101 if (s<1) s=stepsTotal;
104 // Generated the "now" row
105 QColor c(255,200,120);
110 item=new QTableWidgetItem("");
111 item->setBackgroundColor (c);
112 ui.historyTable->setItem(undosAvail, i, item);
115 item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
116 item->setBackgroundColor (c);
117 ui.historyTable->setItem(undosAvail, 1, item);
120 ui.historyTable->scrollToItem (item);
122 // Update Redos in table
124 s++; if (s>stepsTotal) s=1;
125 for (i=1;i<= redosAvail; i++)
127 updateRow (undosAvail+i,s,set);
128 s++; if (s>stepsTotal) s=1;
132 for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
135 ui.historyTable->resizeColumnsToContents();
138 void HistoryWindow::setStepsTotal (int st)
140 // Number of steps + "current" bar
141 ui.historyTable->setRowCount (st+1);
146 void HistoryWindow::closeEvent (QCloseEvent *ce)
148 emit (windowClosed() );
151 void HistoryWindow::undo()
153 mainWindow->editUndo();
156 void HistoryWindow::redo()
158 mainWindow->editRedo();
161 void HistoryWindow::select()
163 mainWindow->gotoHistoryStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));