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