insilmaril@377
|
1 |
#include "historywindow.h"
|
insilmaril@404
|
2 |
#include "mainwindow.h"
|
insilmaril@404
|
3 |
|
insilmaril@377
|
4 |
|
insilmaril@393
|
5 |
extern QString iconPath;
|
insilmaril@404
|
6 |
extern Settings settings;
|
insilmaril@404
|
7 |
extern Main *mainWindow;
|
insilmaril@393
|
8 |
|
insilmaril@377
|
9 |
HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
|
insilmaril@377
|
10 |
{
|
insilmaril@377
|
11 |
ui.setupUi (this);
|
insilmaril@377
|
12 |
ui.historyTable->setRowCount (20);
|
insilmaril@377
|
13 |
ui.historyTable->setColumnCount (3);
|
insilmaril@377
|
14 |
|
insilmaril@377
|
15 |
|
insilmaril@377
|
16 |
QTableWidgetItem *item;
|
insilmaril@377
|
17 |
|
insilmaril@388
|
18 |
item= new QTableWidgetItem(tr("Action","Table with actions"));
|
insilmaril@377
|
19 |
ui.historyTable->setHorizontalHeaderItem(0, item);
|
insilmaril@377
|
20 |
|
insilmaril@388
|
21 |
item= new QTableWidgetItem(tr("Comment","Table with actions"));
|
insilmaril@377
|
22 |
ui.historyTable->setHorizontalHeaderItem(1, item);
|
insilmaril@377
|
23 |
|
insilmaril@388
|
24 |
item= new QTableWidgetItem(tr("Undo action","Table with actions"));
|
insilmaril@377
|
25 |
ui.historyTable->setHorizontalHeaderItem(2, item);
|
insilmaril@377
|
26 |
|
insilmaril@377
|
27 |
ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
|
insilmaril@381
|
28 |
|
insilmaril@393
|
29 |
ui.undoButton->setIcon (QIcon(iconPath+"/undo.png"));
|
insilmaril@393
|
30 |
ui.redoButton->setIcon (QIcon(iconPath+"/redo.png"));
|
insilmaril@393
|
31 |
|
insilmaril@381
|
32 |
connect ( ui.undoButton, SIGNAL (clicked()), this, SLOT (undo()));
|
insilmaril@381
|
33 |
connect ( ui.redoButton, SIGNAL (clicked()), this, SLOT (redo()));
|
insilmaril@381
|
34 |
connect ( ui.historyTable, SIGNAL (itemSelectionChanged()), this, SLOT (select()));
|
insilmaril@404
|
35 |
|
insilmaril@404
|
36 |
// Load Settings
|
insilmaril@404
|
37 |
resize (settings.value ( "/historywindow/geometry/size", QSize(450,600)).toSize());
|
insilmaril@404
|
38 |
move (settings.value ( "/historywindow/geometry/pos", QPoint (250,50)).toPoint());
|
insilmaril@404
|
39 |
|
insilmaril@420
|
40 |
for (int i=0; i<3; ++i)
|
insilmaril@420
|
41 |
ui.historyTable->setColumnWidth (i,settings.value( QString("/historywindow/geometry/columnWidth/%1").arg(i),150).toInt());
|
insilmaril@421
|
42 |
|
insilmaril@404
|
43 |
if (settings.value ( "/historywindow/showWithMain",false).toBool())
|
insilmaril@404
|
44 |
setShowWithMain(true);
|
insilmaril@404
|
45 |
else
|
insilmaril@404
|
46 |
setShowWithMain(false);
|
insilmaril@421
|
47 |
|
insilmaril@377
|
48 |
}
|
insilmaril@377
|
49 |
|
insilmaril@404
|
50 |
HistoryWindow::~HistoryWindow()
|
insilmaril@404
|
51 |
{
|
insilmaril@404
|
52 |
settings.setValue( "/historywindow/geometry/size", size() );
|
insilmaril@404
|
53 |
settings.setValue( "/historywindow/geometry/pos", pos() );
|
insilmaril@421
|
54 |
settings.setValue( "/historywindow/showWithMain",showWithMain());
|
insilmaril@420
|
55 |
for (int i=0; i<3; ++i)
|
insilmaril@420
|
56 |
settings.setValue( QString("/historywindow/geometry/columnWidth/%1").arg(i), ui.historyTable->columnWidth (i) );
|
insilmaril@404
|
57 |
}
|
insilmaril@377
|
58 |
|
insilmaril@388
|
59 |
void HistoryWindow::clearRow(int row)
|
insilmaril@388
|
60 |
{
|
insilmaril@388
|
61 |
QTableWidgetItem *it;
|
insilmaril@388
|
62 |
it=ui.historyTable->item (row,0);
|
insilmaril@388
|
63 |
if (it) it->setText ("");
|
insilmaril@388
|
64 |
it=ui.historyTable->item (row,1);
|
insilmaril@388
|
65 |
if (it) it->setText ("");
|
insilmaril@388
|
66 |
it=ui.historyTable->item (row,2);
|
insilmaril@388
|
67 |
if (it) it->setText ("");
|
insilmaril@388
|
68 |
}
|
insilmaril@388
|
69 |
|
insilmaril@381
|
70 |
void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
|
insilmaril@381
|
71 |
{
|
insilmaril@381
|
72 |
QTableWidgetItem *item;
|
insilmaril@381
|
73 |
|
insilmaril@381
|
74 |
item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
|
insilmaril@381
|
75 |
ui.historyTable->setItem(row, 0, item);
|
insilmaril@381
|
76 |
|
insilmaril@381
|
77 |
item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
|
insilmaril@381
|
78 |
ui.historyTable->setItem(row, 1, item);
|
insilmaril@381
|
79 |
|
insilmaril@381
|
80 |
item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
|
insilmaril@381
|
81 |
ui.historyTable->setItem(row, 2, item);
|
insilmaril@381
|
82 |
}
|
insilmaril@381
|
83 |
|
insilmaril@377
|
84 |
void HistoryWindow::update(SimpleSettings &set)
|
insilmaril@377
|
85 |
{
|
insilmaril@381
|
86 |
int undosAvail=set.readNumEntry("/history/undosAvail",0);
|
insilmaril@381
|
87 |
int redosAvail=set.readNumEntry("/history/redosAvail",0);
|
insilmaril@381
|
88 |
int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
|
insilmaril@381
|
89 |
int curStep=set.readNumEntry ("/history/curStep");
|
insilmaril@381
|
90 |
int i;
|
insilmaril@381
|
91 |
int s=curStep;
|
insilmaril@381
|
92 |
int r=undosAvail-1;
|
insilmaril@381
|
93 |
QTableWidgetItem *item;
|
insilmaril@377
|
94 |
|
insilmaril@381
|
95 |
// Update buttons
|
insilmaril@381
|
96 |
if (undosAvail<1)
|
insilmaril@381
|
97 |
ui.undoButton->setEnabled (false);
|
insilmaril@381
|
98 |
else
|
insilmaril@381
|
99 |
ui.undoButton->setEnabled (true);
|
insilmaril@381
|
100 |
|
insilmaril@381
|
101 |
if (redosAvail<1)
|
insilmaril@381
|
102 |
ui.redoButton->setEnabled (false);
|
insilmaril@381
|
103 |
else
|
insilmaril@381
|
104 |
ui.redoButton->setEnabled (true);
|
insilmaril@381
|
105 |
|
insilmaril@388
|
106 |
// Update undos in table
|
insilmaril@381
|
107 |
for (i=undosAvail; i>0; i--)
|
insilmaril@377
|
108 |
{
|
insilmaril@381
|
109 |
updateRow (r,s,set);
|
insilmaril@381
|
110 |
r--;
|
insilmaril@381
|
111 |
s--;
|
insilmaril@381
|
112 |
if (s<1) s=stepsTotal;
|
insilmaril@381
|
113 |
}
|
insilmaril@381
|
114 |
|
insilmaril@381
|
115 |
// Generated the "now" row
|
insilmaril@381
|
116 |
QColor c(255,200,120);
|
insilmaril@381
|
117 |
for (i=0;i<=2;i++)
|
insilmaril@381
|
118 |
{
|
insilmaril@381
|
119 |
if (i!=1)
|
insilmaril@381
|
120 |
{
|
insilmaril@381
|
121 |
item=new QTableWidgetItem("");
|
insilmaril@381
|
122 |
item->setBackgroundColor (c);
|
insilmaril@381
|
123 |
ui.historyTable->setItem(undosAvail, i, item);
|
insilmaril@381
|
124 |
}
|
insilmaril@381
|
125 |
}
|
insilmaril@388
|
126 |
item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
|
insilmaril@381
|
127 |
item->setBackgroundColor (c);
|
insilmaril@381
|
128 |
ui.historyTable->setItem(undosAvail, 1, item);
|
insilmaril@377
|
129 |
|
insilmaril@394
|
130 |
// Show "now" row
|
insilmaril@394
|
131 |
ui.historyTable->scrollToItem (item);
|
insilmaril@377
|
132 |
|
insilmaril@388
|
133 |
// Update Redos in table
|
insilmaril@381
|
134 |
s=curStep;
|
insilmaril@381
|
135 |
s++; if (s>stepsTotal) s=1;
|
insilmaril@381
|
136 |
for (i=1;i<= redosAvail; i++)
|
insilmaril@381
|
137 |
{
|
insilmaril@381
|
138 |
updateRow (undosAvail+i,s,set);
|
insilmaril@381
|
139 |
s++; if (s>stepsTotal) s=1;
|
insilmaril@377
|
140 |
}
|
insilmaril@377
|
141 |
|
insilmaril@388
|
142 |
// Delete the rest
|
insilmaril@388
|
143 |
for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
|
insilmaril@388
|
144 |
clearRow (i);
|
insilmaril@388
|
145 |
|
insilmaril@377
|
146 |
ui.historyTable->resizeColumnsToContents();
|
insilmaril@377
|
147 |
}
|
insilmaril@381
|
148 |
|
insilmaril@381
|
149 |
void HistoryWindow::setStepsTotal (int st)
|
insilmaril@381
|
150 |
{
|
insilmaril@381
|
151 |
// Number of steps + "current" bar
|
insilmaril@381
|
152 |
ui.historyTable->setRowCount (st+1);
|
insilmaril@381
|
153 |
|
insilmaril@381
|
154 |
}
|
insilmaril@381
|
155 |
|
insilmaril@421
|
156 |
void HistoryWindow::setShowWithMain (bool v)
|
insilmaril@421
|
157 |
{
|
insilmaril@421
|
158 |
showwithmain=v;
|
insilmaril@421
|
159 |
}
|
insilmaril@421
|
160 |
|
insilmaril@421
|
161 |
bool HistoryWindow::showWithMain()
|
insilmaril@421
|
162 |
{
|
insilmaril@421
|
163 |
return showwithmain;
|
insilmaril@421
|
164 |
}
|
insilmaril@421
|
165 |
|
insilmaril@381
|
166 |
void HistoryWindow::undo()
|
insilmaril@381
|
167 |
{
|
insilmaril@404
|
168 |
mainWindow->editUndo();
|
insilmaril@381
|
169 |
}
|
insilmaril@381
|
170 |
|
insilmaril@381
|
171 |
void HistoryWindow::redo()
|
insilmaril@381
|
172 |
{
|
insilmaril@404
|
173 |
mainWindow->editRedo();
|
insilmaril@381
|
174 |
}
|
insilmaril@381
|
175 |
|
insilmaril@381
|
176 |
void HistoryWindow::select()
|
insilmaril@381
|
177 |
{
|
insilmaril@404
|
178 |
mainWindow->gotoHistoryStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));
|
insilmaril@381
|
179 |
}
|