historywindow moved to mainwindow. Started to get rid of Q3PtrList finally
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());
41 if (settings.value ( "/historywindow/showWithMain",false).toBool())
42 setShowWithMain(true);
44 setShowWithMain(false);
48 HistoryWindow::~HistoryWindow()
50 settings.setValue( "/historywindow/geometry/size", size() );
51 settings.setValue( "/historywindow/geometry/pos", pos() );
52 //settings.setValue( "/historywindow/showWithMain",showWithMain());
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.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
71 ui.historyTable->setItem(row, 0, item);
73 item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
74 ui.historyTable->setItem(row, 1, item);
76 item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
77 ui.historyTable->setItem(row, 2, item);
80 void HistoryWindow::update(SimpleSettings &set)
82 int undosAvail=set.readNumEntry("/history/undosAvail",0);
83 int redosAvail=set.readNumEntry("/history/redosAvail",0);
84 int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
85 int curStep=set.readNumEntry ("/history/curStep");
89 QTableWidgetItem *item;
93 ui.undoButton->setEnabled (false);
95 ui.undoButton->setEnabled (true);
98 ui.redoButton->setEnabled (false);
100 ui.redoButton->setEnabled (true);
102 // Update undos in table
103 for (i=undosAvail; i>0; i--)
108 if (s<1) s=stepsTotal;
111 // Generated the "now" row
112 QColor c(255,200,120);
117 item=new QTableWidgetItem("");
118 item->setBackgroundColor (c);
119 ui.historyTable->setItem(undosAvail, i, item);
122 item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
123 item->setBackgroundColor (c);
124 ui.historyTable->setItem(undosAvail, 1, item);
127 ui.historyTable->scrollToItem (item);
129 // Update Redos in table
131 s++; if (s>stepsTotal) s=1;
132 for (i=1;i<= redosAvail; i++)
134 updateRow (undosAvail+i,s,set);
135 s++; if (s>stepsTotal) s=1;
139 for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
142 ui.historyTable->resizeColumnsToContents();
145 void HistoryWindow::setStepsTotal (int st)
147 // Number of steps + "current" bar
148 ui.historyTable->setRowCount (st+1);
152 void HistoryWindow::undo()
154 mainWindow->editUndo();
157 void HistoryWindow::redo()
159 mainWindow->editRedo();
162 void HistoryWindow::select()
164 mainWindow->gotoHistoryStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));