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()));
37 resize (settings.value ( "/historywindow/geometry/size", QSize(450,600)).toSize());
38 move (settings.value ( "/historywindow/geometry/pos", QPoint (250,50)).toPoint());
40 for (int i=0; i<3; ++i)
41 ui.historyTable->setColumnWidth (i,settings.value( QString("/historywindow/geometry/columnWidth/%1").arg(i),150).toInt());
43 if (settings.value ( "/historywindow/showWithMain",false).toBool())
44 setShowWithMain(true);
46 setShowWithMain(false);
50 HistoryWindow::~HistoryWindow()
52 settings.setValue( "/historywindow/geometry/size", size() );
53 settings.setValue( "/historywindow/geometry/pos", pos() );
54 settings.setValue( "/historywindow/showWithMain",showWithMain());
55 for (int i=0; i<3; ++i)
56 settings.setValue( QString("/historywindow/geometry/columnWidth/%1").arg(i), ui.historyTable->columnWidth (i) );
59 void HistoryWindow::clearRow(int row)
62 it=ui.historyTable->item (row,0);
63 if (it) it->setText ("");
64 it=ui.historyTable->item (row,1);
65 if (it) it->setText ("");
66 it=ui.historyTable->item (row,2);
67 if (it) it->setText ("");
70 void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
72 QTableWidgetItem *item;
74 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
75 ui.historyTable->setItem(row, 0, item);
77 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
78 ui.historyTable->setItem(row, 1, item);
80 item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
81 ui.historyTable->setItem(row, 2, item);
84 void HistoryWindow::update(SimpleSettings &set)
86 int undosAvail=set.readNumEntry("/history/undosAvail",0);
87 int redosAvail=set.readNumEntry("/history/redosAvail",0);
88 int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
89 int curStep=set.readNumEntry ("/history/curStep");
93 QTableWidgetItem *item;
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::setShowWithMain (bool v)
161 void HistoryWindow::closeEvent( QCloseEvent* ce )
163 ce->accept(); // TextEditor can be reopened with show()
165 emit (windowClosed() );
170 bool HistoryWindow::showWithMain()
175 void HistoryWindow::undo()
177 mainWindow->editUndo();
180 void HistoryWindow::redo()
182 mainWindow->editRedo();
185 void HistoryWindow::select()
187 mainWindow->gotoHistoryStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));