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