historywindow.cpp
author insilmaril
Wed, 02 May 2007 15:31:17 +0000
changeset 482 24c7902a3e14
parent 442 dfbc371b7280
child 489 f0e482cd84f0
permissions -rw-r--r--
Mainly documentation fixes
     1 #include "historywindow.h"
     2 #include "mainwindow.h"
     3 
     4 
     5 extern QString iconPath;
     6 extern Settings settings;
     7 extern Main *mainWindow;
     8 
     9 HistoryWindow::HistoryWindow (QWidget *parent):QDialog (parent)
    10 {
    11 	ui.setupUi (this);
    12 	ui.historyTable->setRowCount (20);
    13 	ui.historyTable->setColumnCount (3);
    14 
    15 	
    16 	QTableWidgetItem *item;
    17 
    18 	item= new QTableWidgetItem(tr("Action","Table with actions"));
    19 	ui.historyTable->setHorizontalHeaderItem(0, item);
    20 	
    21 	item= new QTableWidgetItem(tr("Comment","Table with actions"));
    22 	ui.historyTable->setHorizontalHeaderItem(1, item);
    23 	
    24 	item= new QTableWidgetItem(tr("Undo action","Table with actions"));
    25 	ui.historyTable->setHorizontalHeaderItem(2, item);
    26 
    27 	ui.historyTable->setSelectionBehavior (QAbstractItemView::SelectRows);
    28 
    29 	ui.undoButton->setIcon (QIcon(iconPath+"/undo.png"));
    30 	ui.redoButton->setIcon (QIcon(iconPath+"/redo.png"));
    31 
    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()));
    35 
    36 	// Load Settings
    37 
    38 	for (int i=0; i<3; ++i)
    39 		ui.historyTable->setColumnWidth (i,settings.value( QString("/historywindow/geometry/columnWidth/%1").arg(i),150).toInt());
    40 }
    41 
    42 HistoryWindow::~HistoryWindow()
    43 {
    44 	for (int i=0; i<3; ++i)
    45 		settings.setValue( QString("/historywindow/geometry/columnWidth/%1").arg(i), ui.historyTable->columnWidth (i) );
    46 }
    47 
    48 void HistoryWindow::clearRow(int row)
    49 {
    50 	QTableWidgetItem *it;
    51 	it=ui.historyTable->item (row,0);
    52 	if (it) it->setText ("");
    53 	it=ui.historyTable->item (row,1);
    54 	if (it) it->setText ("");
    55 	it=ui.historyTable->item (row,2);
    56 	if (it) it->setText ("");
    57 }
    58 
    59 void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
    60 {
    61 	QTableWidgetItem *item;
    62 
    63 	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
    64 	ui.historyTable->setItem(row, 0, item);
    65 
    66 	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
    67 	ui.historyTable->setItem(row, 1, item);
    68 
    69 	item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
    70 	ui.historyTable->setItem(row, 2, item);
    71 }
    72 
    73 void HistoryWindow::update(SimpleSettings &set)
    74 {
    75 	int undosAvail=set.readNumEntry("/history/undosAvail",0);
    76 	int redosAvail=set.readNumEntry("/history/redosAvail",0);
    77 	int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
    78 	int curStep=set.readNumEntry ("/history/curStep");
    79 	int i;
    80 	int s=curStep;
    81 	int r=undosAvail-1;
    82 	QTableWidgetItem *item;
    83 
    84 	// Update buttons
    85 	if (undosAvail<1)
    86 		ui.undoButton->setEnabled (false);
    87 	else	
    88 		ui.undoButton->setEnabled (true);
    89 
    90 	if (redosAvail<1)
    91 		ui.redoButton->setEnabled (false);
    92 	else	
    93 		ui.redoButton->setEnabled (true);
    94 
    95 	// Update undos in table
    96 	for (i=undosAvail; i>0; i--)
    97 	{
    98 		updateRow (r,s,set);
    99 		r--;
   100 		s--;
   101 		if (s<1) s=stepsTotal;
   102 	}
   103 	
   104 	// Generated the "now" row
   105 	QColor c(255,200,120);
   106 	for (i=0;i<=2;i++)
   107 	{
   108 		if (i!=1)
   109 		{
   110 			item=new QTableWidgetItem("");
   111 			item->setBackgroundColor (c);
   112 			ui.historyTable->setItem(undosAvail, i, item);
   113 		}
   114 	}
   115 	item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
   116 	item->setBackgroundColor (c);
   117 	ui.historyTable->setItem(undosAvail, 1, item);
   118 
   119 	// Show "now" row
   120 	ui.historyTable->scrollToItem (item);
   121 
   122 	// Update Redos in table
   123 	s=curStep;
   124 	s++; if (s>stepsTotal) s=1;
   125 	for (i=1;i<= redosAvail; i++)
   126 	{
   127 		updateRow (undosAvail+i,s,set);
   128 		s++; if (s>stepsTotal) s=1;
   129 	}
   130 
   131 	// Delete the rest
   132 	for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
   133 		clearRow (i);
   134 
   135 	ui.historyTable->resizeColumnsToContents();
   136 }
   137 
   138 void HistoryWindow::setStepsTotal (int st)
   139 {
   140 	// Number of steps + "current" bar
   141 	ui.historyTable->setRowCount (st+1);
   142 
   143 }
   144 
   145 
   146 void HistoryWindow::closeEvent (QCloseEvent *ce)
   147 {
   148 	emit (windowClosed() );
   149 }
   150 
   151 void HistoryWindow::undo()
   152 {
   153 	mainWindow->editUndo();
   154 }
   155 
   156 void HistoryWindow::redo()
   157 {
   158 	mainWindow->editRedo();
   159 }
   160 
   161 void HistoryWindow::select()
   162 {
   163 	mainWindow->gotoHistoryStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));
   164 }