historywindow.cpp
author insilmaril
Fri, 29 Dec 2006 13:52:19 +0000
changeset 416 922d7f6c4e6c
parent 404 53efc2562a7d
child 420 b7447adddc9a
permissions -rw-r--r--
Removed some FIXMEs. Added translations
     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 	resize (settings.value ( "/historywindow/geometry/size", QSize(450,600)).toSize());
    38 	move   (settings.value ( "/historywindow/geometry/pos", QPoint (250,50)).toPoint());
    39 
    40 /*
    41 	if (settings.value ( "/historywindow/showWithMain",false).toBool())
    42 		setShowWithMain(true);
    43 	else	
    44 		setShowWithMain(false);
    45 */
    46 }
    47 
    48 HistoryWindow::~HistoryWindow()
    49 {
    50 	settings.setValue( "/historywindow/geometry/size", size() );
    51 	settings.setValue( "/historywindow/geometry/pos", pos() );
    52 	//settings.setValue( "/historywindow/showWithMain",showWithMain());
    53 }
    54 
    55 void HistoryWindow::clearRow(int row)
    56 {
    57 	QTableWidgetItem *it;
    58 	it=ui.historyTable->item (row,0);
    59 	if (it) it->setText ("");
    60 	it=ui.historyTable->item (row,1);
    61 	if (it) it->setText ("");
    62 	it=ui.historyTable->item (row,2);
    63 	if (it) it->setText ("");
    64 }
    65 
    66 void HistoryWindow::updateRow(int row, int step, SimpleSettings &set)
    67 {
    68 	QTableWidgetItem *item;
    69 
    70 	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/redoCommand").arg(step)));
    71 	ui.historyTable->setItem(row, 0, item);
    72 
    73 	item= new QTableWidgetItem(set.readEntry(QString("/history/step-%1/comment").arg(step)));
    74 	ui.historyTable->setItem(row, 1, item);
    75 
    76 	item=new QTableWidgetItem(set.readEntry(QString("/history/step-%1/undoCommand").arg(step)));
    77 	ui.historyTable->setItem(row, 2, item);
    78 }
    79 
    80 void HistoryWindow::update(SimpleSettings &set)
    81 {
    82 	int undosAvail=set.readNumEntry("/history/undosAvail",0);
    83 	int redosAvail=set.readNumEntry("/history/redosAvail",0);
    84 	int stepsTotal=set.readNumEntry("/history/stepsTotal",0);
    85 	int curStep=set.readNumEntry ("/history/curStep");
    86 	int i;
    87 	int s=curStep;
    88 	int r=undosAvail-1;
    89 	QTableWidgetItem *item;
    90 
    91 	// Update buttons
    92 	if (undosAvail<1)
    93 		ui.undoButton->setEnabled (false);
    94 	else	
    95 		ui.undoButton->setEnabled (true);
    96 
    97 	if (redosAvail<1)
    98 		ui.redoButton->setEnabled (false);
    99 	else	
   100 		ui.redoButton->setEnabled (true);
   101 
   102 	// Update undos in table
   103 	for (i=undosAvail; i>0; i--)
   104 	{
   105 		updateRow (r,s,set);
   106 		r--;
   107 		s--;
   108 		if (s<1) s=stepsTotal;
   109 	}
   110 	
   111 	// Generated the "now" row
   112 	QColor c(255,200,120);
   113 	for (i=0;i<=2;i++)
   114 	{
   115 		if (i!=1)
   116 		{
   117 			item=new QTableWidgetItem("");
   118 			item->setBackgroundColor (c);
   119 			ui.historyTable->setItem(undosAvail, i, item);
   120 		}
   121 	}
   122 	item=new QTableWidgetItem(" - " +tr("Current state","Current bar in history hwindow")+ " - ");
   123 	item->setBackgroundColor (c);
   124 	ui.historyTable->setItem(undosAvail, 1, item);
   125 
   126 	// Show "now" row
   127 	ui.historyTable->scrollToItem (item);
   128 
   129 	// Update Redos in table
   130 	s=curStep;
   131 	s++; if (s>stepsTotal) s=1;
   132 	for (i=1;i<= redosAvail; i++)
   133 	{
   134 		updateRow (undosAvail+i,s,set);
   135 		s++; if (s>stepsTotal) s=1;
   136 	}
   137 
   138 	// Delete the rest
   139 	for (i=undosAvail+redosAvail+1;i<= stepsTotal; i++)
   140 		clearRow (i);
   141 
   142 	ui.historyTable->resizeColumnsToContents();
   143 }
   144 
   145 void HistoryWindow::setStepsTotal (int st)
   146 {
   147 	// Number of steps + "current" bar
   148 	ui.historyTable->setRowCount (st+1);
   149 
   150 }
   151 
   152 void HistoryWindow::undo()
   153 {
   154 	mainWindow->editUndo();
   155 }
   156 
   157 void HistoryWindow::redo()
   158 {
   159 	mainWindow->editRedo();
   160 }
   161 
   162 void HistoryWindow::select()
   163 {
   164 	mainWindow->gotoHistoryStep (ui.historyTable->row (ui.historyTable->selectedItems().first()));
   165 }