1 #include "historywindow.h"
2 #include "mainwindow.h"
4 extern Settings settings;
5 extern Main *mainWindow;
7 HistoryWindow::HistoryWindow(QWidget *parent) : QDialog(parent)
10 ui.historyTable->setRowCount(
11 settings.value("/history/stepsTotal", 75).toInt());
12 ui.historyTable->setColumnCount(3);
14 QTableWidgetItem *item;
16 item = new QTableWidgetItem(tr("Action", "Table with actions"));
17 ui.historyTable->setHorizontalHeaderItem(0, item);
19 item = new QTableWidgetItem(tr("Comment", "Table with actions"));
20 ui.historyTable->setHorizontalHeaderItem(1, item);
22 item = new QTableWidgetItem(tr("Undo action", "Table with actions"));
23 ui.historyTable->setHorizontalHeaderItem(2, item);
25 ui.historyTable->setSelectionBehavior(QAbstractItemView::SelectRows);
27 ui.undoButton->setIcon(QIcon(":/undo.png"));
28 ui.redoButton->setIcon(QIcon(":/redo.png"));
30 connect(ui.undoButton, SIGNAL(clicked()), this, SLOT(undo()));
31 connect(ui.redoButton, SIGNAL(clicked()), this, SLOT(redo()));
32 connect(ui.historyTable, SIGNAL(itemSelectionChanged()), this,
39 .value("/satellite/historywindow/geometry/size", QSize(1000, 400))
41 move(settings.value("/satellite/historywindow/geometry/pos", QPoint(0, 450))
44 ui.historyTable->setColumnWidth(
46 settings.value("/satellite/historywindow/geometry/columnWidth/0", 250)
48 ui.historyTable->setColumnWidth(
50 settings.value("/satellite/historywindow/geometry/columnWidth/1", 350)
52 ui.historyTable->setColumnWidth(
54 settings.value("/satellite/historywindow/geometry/columnWidth/2", 250)
58 HistoryWindow::~HistoryWindow()
61 settings.setValue("/satellite/historywindow/geometry/size", size());
62 settings.setValue("/satellite/historywindow/geometry/pos", pos());
64 for (int i = 0; i < 3; ++i)
66 QString("/satellite/historywindow/geometry/columnWidth/%1").arg(i),
67 ui.historyTable->columnWidth(i));
70 void HistoryWindow::clearRow(int row)
73 it = ui.historyTable->item(row, 0);
76 it = ui.historyTable->item(row, 1);
79 it = ui.historyTable->item(row, 2);
84 void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
86 QTableWidgetItem *item;
88 item = new QTableWidgetItem(
89 set.value(QString("/history/step-%1/redoCommand").arg(step)));
90 ui.historyTable->setItem(row, 0, item);
92 item = new QTableWidgetItem(
93 set.value(QString("/history/step-%1/comment").arg(step)));
94 ui.historyTable->setItem(row, 1, item);
96 item = new QTableWidgetItem(
97 set.value(QString("/history/step-%1/undoCommand").arg(step)));
98 ui.historyTable->setItem(row, 2, item);
101 void HistoryWindow::update(SimpleSettings &set)
103 int undosAvail = set.numValue("/history/undosAvail", 0);
104 int redosAvail = set.numValue("/history/redosAvail", 0);
105 int stepsTotal = set.numValue("/history/stepsTotal", 1000);
106 int curStep = set.numValue("/history/curStep");
109 int r = undosAvail - 1;
110 QTableWidgetItem *item;
112 // Update number of rows
113 ui.historyTable->setRowCount(undosAvail + redosAvail + 1);
117 ui.undoButton->setEnabled(false);
119 ui.undoButton->setEnabled(true);
122 ui.redoButton->setEnabled(false);
124 ui.redoButton->setEnabled(true);
126 // Update undos in table
127 for (i = undosAvail; i > 0; i--) {
128 updateRow(r, s, set);
135 // Generated the "now" row
136 QColor c = palette().color(QPalette::Highlight);
137 for (i = 0; i <= 2; i++) {
139 item = new QTableWidgetItem("");
140 item->setBackground(QBrush(c));
141 ui.historyTable->setItem(undosAvail, i, item);
144 item = new QTableWidgetItem(
145 " - " + tr("Current state", "Current bar in history hwindow") + " - ");
146 item->setBackground(QBrush(c));
147 ui.historyTable->setItem(undosAvail, 1, item);
150 ui.historyTable->scrollToItem(item);
152 // Update Redos in table
157 for (i = 1; i <= redosAvail; i++) {
158 updateRow(undosAvail + i, s, set);
165 for (i = undosAvail + redosAvail + 1; i <= stepsTotal; i++)
168 // ui.historyTable->resizeColumnsToContents();
171 void HistoryWindow::setStepsTotal(int st)
173 // Number of steps + "current" bar
174 ui.historyTable->setRowCount(st + 1);
177 void HistoryWindow::closeEvent(QCloseEvent *ce)
181 emit(windowClosed());
184 void HistoryWindow::undo() { mainWindow->editUndo(); }
186 void HistoryWindow::redo() { mainWindow->editRedo(); }
188 void HistoryWindow::select()
190 mainWindow->gotoHistoryStep(
191 ui.historyTable->row(ui.historyTable->selectedItems().first()));