X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=src%2Fhistorywindow.cpp;fp=src%2Fhistorywindow.cpp;h=a61f2d9a4b8be1bb5f265bbb60fa92d3bf230f73;hb=d483bd8e6523c23c6f1d8908a2e0611c2bc9ff4f;hp=0000000000000000000000000000000000000000;hpb=7dfa3fe589d1722d49681f42cdb0bf1e6efb5223;p=sven%2Fvym.git diff --git a/src/historywindow.cpp b/src/historywindow.cpp new file mode 100644 index 0000000..a61f2d9 --- /dev/null +++ b/src/historywindow.cpp @@ -0,0 +1,192 @@ +#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.numValue("/history/undosAvail", 0); + int redosAvail = set.numValue("/history/redosAvail", 0); + int stepsTotal = set.numValue("/history/stepsTotal", 1000); + int curStep = set.numValue("/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 = palette().color(QPalette::Highlight); + for (i = 0; i <= 2; i++) { + if (i != 1) { + item = new QTableWidgetItem(""); + item->setBackground(QBrush(c)); + ui.historyTable->setItem(undosAvail, i, item); + } + } + item = new QTableWidgetItem( + " - " + tr("Current state", "Current bar in history hwindow") + " - "); + item->setBackground(QBrush(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())); +}