Menu

[c54480]: / historywindow.cpp  Maximize  Restore  History

Download this file

176 lines (138 with data), 5.0 kB

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