branchpropwindow.cpp
author insilmaril
Mon, 05 May 2008 13:46:42 +0000
changeset 689 c7b1178aec77
parent 686 d6cc3365c8b8
child 721 12958f987bcf
permissions -rw-r--r--
Some code cleanup and experimental stuff to support animations later
insilmaril@421
     1
#include "branchpropwindow.h"
insilmaril@421
     2
insilmaril@440
     3
#include <QColorDialog>
insilmaril@440
     4
insilmaril@421
     5
#include "frameobj.h"
insilmaril@462
     6
#include "settings.h"
insilmaril@421
     7
insilmaril@462
     8
extern Settings settings;
insilmaril@487
     9
extern QString vymName;
insilmaril@487
    10
insilmaril@421
    11
insilmaril@480
    12
BranchPropertyWindow::BranchPropertyWindow (QWidget *parent): QDialog (parent)
insilmaril@421
    13
{
insilmaril@421
    14
	ui.setupUi (this);
insilmaril@421
    15
insilmaril@487
    16
	setCaption(vymName +" - " +tr ("Property Editor","Window caption"));
insilmaril@487
    17
insilmaril@421
    18
	branch=NULL;
insilmaril@421
    19
	mapEditor=NULL;
insilmaril@421
    20
insilmaril@440
    21
	ui.tabWidget->setEnabled(false);
insilmaril@440
    22
insilmaril@440
    23
	penColor=QColor (Qt::black);
insilmaril@440
    24
	brushColor=QColor (Qt::black);
insilmaril@440
    25
    QPixmap pix( 16,16);
insilmaril@440
    26
    pix.fill (penColor);
insilmaril@440
    27
	ui.framePenColorButton->setPixmap (pix);
insilmaril@440
    28
	ui.frameBrushColorButton->setPixmap (pix);
insilmaril@480
    29
insilmaril@672
    30
	// Create Model and View to hold attributes
insilmaril@672
    31
	attributeModel = new QStandardItemModel (1,3,this);
insilmaril@672
    32
	attributeModel->setHeaderData(0, Qt::Horizontal, tr("Name","Branchprop window: Attribute name"));
insilmaril@672
    33
	attributeModel->setHeaderData(1, Qt::Horizontal, tr("Value","Branchprop window: Attribute value"));
insilmaril@672
    34
	attributeModel->setHeaderData(2, Qt::Horizontal, tr("Type","Branchprop window: Attribute type"));
insilmaril@672
    35
	ui.attributeTableView->setModel (attributeModel);
insilmaril@672
    36
	
insilmaril@480
    37
insilmaril@480
    38
	// Load Settings
insilmaril@480
    39
	resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize());
insilmaril@480
    40
	move   (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint());
insilmaril@480
    41
	
insilmaril@480
    42
	if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool())
insilmaril@480
    43
		show();
insilmaril@480
    44
	else	
insilmaril@480
    45
		hide();
insilmaril@480
    46
insilmaril@686
    47
	// FIXME for now remove attribute tab
insilmaril@686
    48
	ui.tabWidget->removeTab (3);
insilmaril@686
    49
insilmaril@462
    50
}
insilmaril@440
    51
insilmaril@462
    52
BranchPropertyWindow::~BranchPropertyWindow ()
insilmaril@462
    53
{
insilmaril@480
    54
	settings.setValue( "/satellite/propertywindow/geometry/size", size() );
insilmaril@480
    55
	settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
insilmaril@530
    56
	settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
insilmaril@421
    57
}
insilmaril@421
    58
insilmaril@421
    59
void BranchPropertyWindow::setBranch (BranchObj *bo)
insilmaril@421
    60
{
insilmaril@462
    61
	disconnectSignals();
insilmaril@421
    62
	branch=bo;
insilmaril@440
    63
	if (bo) 
insilmaril@440
    64
	{
insilmaril@440
    65
		ui.tabWidget->setEnabled (true);
insilmaril@421
    66
insilmaril@440
    67
		// Frame
insilmaril@462
    68
		FrameObj::FrameType t=branch->getFrameType();
insilmaril@462
    69
		if (t==FrameObj::NoFrame)
insilmaril@440
    70
		{
insilmaril@440
    71
			ui.frameTypeCombo->setCurrentIndex (0);
insilmaril@440
    72
			penColor=Qt::white;
insilmaril@440
    73
			brushColor=Qt::white;
insilmaril@440
    74
			ui.colorGroupBox->setEnabled (false);
insilmaril@462
    75
			ui.framePaddingSpinBox->setEnabled (false);
insilmaril@462
    76
			ui.frameWidthSpinBox->setEnabled (false);
insilmaril@480
    77
			ui.framePaddingLabel->setEnabled (false);
insilmaril@480
    78
			ui.frameBorderLabel->setEnabled (false);
insilmaril@440
    79
		} else	
insilmaril@440
    80
		{
insilmaril@440
    81
			penColor=bo->getFramePenColor();
insilmaril@440
    82
			brushColor=bo->getFrameBrushColor();
insilmaril@440
    83
			QPixmap pix( 16,16);
insilmaril@440
    84
			pix.fill (penColor);
insilmaril@480
    85
			ui.framePenColorButton->setPixmap (pix);
insilmaril@440
    86
			pix.fill (brushColor);
insilmaril@440
    87
			ui.frameBrushColorButton->setPixmap (pix);
insilmaril@440
    88
			ui.colorGroupBox->setEnabled (true);
insilmaril@462
    89
			ui.framePaddingSpinBox->setEnabled (true);
insilmaril@462
    90
			ui.framePaddingSpinBox->setValue (bo->getFramePadding());
insilmaril@462
    91
			ui.frameWidthSpinBox->setEnabled (true);
insilmaril@462
    92
			ui.frameWidthSpinBox->setValue (bo->getFrameBorderWidth());
insilmaril@480
    93
			ui.framePaddingLabel->setEnabled (true);
insilmaril@480
    94
			ui.frameBorderLabel->setEnabled (true);
insilmaril@440
    95
insilmaril@440
    96
			switch (t)
insilmaril@440
    97
			{
insilmaril@462
    98
				case FrameObj::Rectangle: 
insilmaril@440
    99
					ui.frameTypeCombo->setCurrentIndex (1);
insilmaril@440
   100
					break;
insilmaril@462
   101
				case FrameObj::Ellipse: 
insilmaril@440
   102
					ui.frameTypeCombo->setCurrentIndex (2);
insilmaril@440
   103
					break;
insilmaril@440
   104
				default: 
insilmaril@440
   105
					break;
insilmaril@440
   106
			}
insilmaril@440
   107
		}	
insilmaril@440
   108
		
insilmaril@440
   109
		// Link
insilmaril@440
   110
		if (branch->getHideLinkUnselected())
insilmaril@440
   111
			ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
insilmaril@440
   112
		else	
insilmaril@440
   113
			ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
insilmaril@462
   114
insilmaril@462
   115
		// Layout
insilmaril@462
   116
		if (branch->getIncludeImagesVer())
insilmaril@462
   117
			ui.incImgVer->setCheckState (Qt::Checked);
insilmaril@462
   118
		else	
insilmaril@462
   119
			ui.incImgVer->setCheckState (Qt::Unchecked);
insilmaril@462
   120
		if (branch->getIncludeImagesHor())
insilmaril@462
   121
			ui.incImgHor->setCheckState (Qt::Checked);
insilmaril@462
   122
		else	
insilmaril@462
   123
			ui.incImgHor->setCheckState (Qt::Unchecked);
insilmaril@462
   124
insilmaril@672
   125
		// Attributes
insilmaril@672
   126
		attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
insilmaril@672
   127
insilmaril@672
   128
		// FIXME some samples for testing
insilmaril@672
   129
		QStringList attrTypes=mapEditor->attributeTable()->getTypes();
insilmaril@672
   130
		for (int i=0; i<attrTypes.count()-1;i++)
insilmaril@672
   131
		{
insilmaril@672
   132
			attributeModel->insertRow (i,QModelIndex ());
insilmaril@672
   133
			attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
insilmaril@672
   134
			attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
insilmaril@672
   135
			attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
insilmaril@672
   136
		}
insilmaril@672
   137
insilmaril@672
   138
insilmaril@672
   139
		ui.attributeTableView->resizeColumnsToContents();
insilmaril@672
   140
insilmaril@672
   141
		// Initialize Delegate
insilmaril@672
   142
		delegate.setAttributeTable (mapEditor->attributeTable());
insilmaril@672
   143
		ui.attributeTableView->setItemDelegate (&delegate);
insilmaril@672
   144
insilmaril@672
   145
insilmaril@462
   146
		// Finally activate signals
insilmaril@462
   147
		connectSignals();
insilmaril@440
   148
	} else
insilmaril@421
   149
	{
insilmaril@440
   150
		ui.tabWidget->setEnabled (false);
insilmaril@421
   151
	}
insilmaril@421
   152
}
insilmaril@421
   153
insilmaril@421
   154
void BranchPropertyWindow::setMapEditor (MapEditor *me)
insilmaril@421
   155
{
insilmaril@440
   156
	mapEditor=me;
insilmaril@440
   157
	if (mapEditor) 
insilmaril@440
   158
		setBranch (mapEditor->getSelectedBranch() );
insilmaril@440
   159
	else
insilmaril@440
   160
		ui.tabWidget->setEnabled (false);
insilmaril@440
   161
		
insilmaril@421
   162
}
insilmaril@421
   163
insilmaril@421
   164
void BranchPropertyWindow::frameTypeChanged (int i)
insilmaril@421
   165
{
insilmaril@421
   166
	if (mapEditor)
insilmaril@480
   167
	{
insilmaril@421
   168
		switch (i)
insilmaril@421
   169
		{
insilmaril@462
   170
			case 0: mapEditor->setFrameType (FrameObj::NoFrame); break;
insilmaril@672
   171
			case 1: 
insilmaril@672
   172
				mapEditor->setFrameType (FrameObj::Rectangle); 
insilmaril@672
   173
				break;
insilmaril@672
   174
			case 2: 
insilmaril@672
   175
				mapEditor->setFrameType (FrameObj::Ellipse); 
insilmaril@672
   176
				mapEditor->setFramePadding (5); 
insilmaril@672
   177
				break;
insilmaril@421
   178
		}
insilmaril@480
   179
		setBranch (branch);
insilmaril@480
   180
	}	
insilmaril@421
   181
}
insilmaril@421
   182
insilmaril@440
   183
void BranchPropertyWindow::framePenColorClicked()
insilmaril@440
   184
{
insilmaril@440
   185
	if (mapEditor) 
insilmaril@440
   186
	{	
insilmaril@440
   187
		QColor col = QColorDialog::getColor( penColor, this );
insilmaril@440
   188
		if ( col.isValid() ) 
insilmaril@440
   189
		{
insilmaril@440
   190
			penColor=col;
insilmaril@440
   191
			mapEditor->setFramePenColor (penColor);
insilmaril@440
   192
		}	
insilmaril@440
   193
	}
insilmaril@440
   194
}
insilmaril@440
   195
insilmaril@440
   196
void BranchPropertyWindow::frameBrushColorClicked()
insilmaril@440
   197
{
insilmaril@440
   198
	if (mapEditor) 
insilmaril@440
   199
	{
insilmaril@440
   200
		QColor col = QColorDialog::getColor( brushColor, this );
insilmaril@440
   201
		if ( col.isValid() ) 
insilmaril@440
   202
		{
insilmaril@440
   203
			brushColor=col;
insilmaril@440
   204
			mapEditor->setFrameBrushColor (brushColor);
insilmaril@440
   205
		}	
insilmaril@440
   206
	}	
insilmaril@440
   207
}
insilmaril@440
   208
insilmaril@462
   209
void BranchPropertyWindow::framePaddingChanged(int i)
insilmaril@462
   210
{
insilmaril@462
   211
	if (mapEditor) mapEditor->setFramePadding (i);
insilmaril@462
   212
}
insilmaril@462
   213
insilmaril@462
   214
void BranchPropertyWindow::frameBorderWidthChanged(int i)
insilmaril@462
   215
{
insilmaril@462
   216
	if (mapEditor) mapEditor->setFrameBorderWidth(i);
insilmaril@462
   217
}
insilmaril@462
   218
insilmaril@421
   219
void BranchPropertyWindow::linkHideUnselectedChanged (int i)
insilmaril@421
   220
{
insilmaril@421
   221
	if (!branch) return;
insilmaril@462
   222
	mapEditor->setHideLinkUnselected(i);
insilmaril@421
   223
}
insilmaril@421
   224
insilmaril@462
   225
void BranchPropertyWindow::incImgVerChanged (int  i)
insilmaril@462
   226
{
insilmaril@462
   227
	if (mapEditor) mapEditor->setIncludeImagesVer (i);
insilmaril@462
   228
}
insilmaril@462
   229
insilmaril@462
   230
void BranchPropertyWindow::incImgHorChanged (int  i)
insilmaril@462
   231
{
insilmaril@462
   232
	if (mapEditor) mapEditor->setIncludeImagesHor (i);
insilmaril@462
   233
}
insilmaril@462
   234
insilmaril@480
   235
void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
insilmaril@480
   236
{
insilmaril@480
   237
    ce->accept();	// can be reopened with show()
insilmaril@480
   238
	hide();
insilmaril@480
   239
	emit (windowClosed() );
insilmaril@480
   240
    return;
insilmaril@480
   241
}
insilmaril@480
   242
insilmaril@672
   243
void BranchPropertyWindow::addAttributeClicked()
insilmaril@672
   244
{
insilmaril@672
   245
	// Add empty line for adding attributes
insilmaril@672
   246
	attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
insilmaril@672
   247
	attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()),  "Add new");
insilmaril@672
   248
	attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()),  "Undefined");
insilmaril@672
   249
insilmaril@672
   250
	// Select attribute from list
insilmaril@672
   251
	ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
insilmaril@672
   252
	ui.attributeTableView->resizeColumnsToContents();
insilmaril@672
   253
insilmaril@672
   254
//	QString attname=attributeModel->in
insilmaril@672
   255
//	attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()),  );
insilmaril@672
   256
insilmaril@672
   257
insilmaril@672
   258
insilmaril@672
   259
	ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
insilmaril@672
   260
insilmaril@672
   261
}
insilmaril@672
   262
insilmaril@672
   263
void BranchPropertyWindow::deleteAttributeClicked()
insilmaril@672
   264
{
insilmaril@672
   265
	cout << "BPW::delete\n";
insilmaril@672
   266
}
insilmaril@480
   267
insilmaril@462
   268
void BranchPropertyWindow::connectSignals()
insilmaril@462
   269
{
insilmaril@462
   270
	// Frame
insilmaril@462
   271
	connect ( 
insilmaril@462
   272
		ui.framePenColorButton, SIGNAL (clicked()), 
insilmaril@462
   273
		this, SLOT (framePenColorClicked()));
insilmaril@462
   274
	connect ( 
insilmaril@462
   275
		ui.framePaddingSpinBox, SIGNAL (valueChanged( int)), 
insilmaril@462
   276
		this, SLOT (framePaddingChanged (int)));
insilmaril@462
   277
	connect ( 
insilmaril@462
   278
		ui.frameWidthSpinBox, SIGNAL (valueChanged( int)), 
insilmaril@462
   279
		this, SLOT (frameBorderWidthChanged (int)));
insilmaril@462
   280
	connect ( 
insilmaril@462
   281
		ui.frameBrushColorButton, SIGNAL (clicked()), 
insilmaril@462
   282
		this, SLOT (frameBrushColorClicked()));
insilmaril@462
   283
	connect ( 
insilmaril@462
   284
		ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)), 
insilmaril@462
   285
		this, SLOT (frameTypeChanged (int)));
insilmaril@462
   286
insilmaril@462
   287
insilmaril@462
   288
	// Link	
insilmaril@462
   289
	connect ( 
insilmaril@462
   290
		ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)), 
insilmaril@462
   291
		this, SLOT (linkHideUnselectedChanged (int)));
insilmaril@462
   292
insilmaril@462
   293
	// Layout	
insilmaril@462
   294
	connect ( 
insilmaril@462
   295
		ui.incImgVer, SIGNAL (stateChanged( int)), 
insilmaril@462
   296
		this, SLOT (incImgVerChanged (int)));
insilmaril@462
   297
	connect ( 
insilmaril@462
   298
		ui.incImgHor, SIGNAL (stateChanged( int)), 
insilmaril@462
   299
		this, SLOT (incImgHorChanged (int)));
insilmaril@672
   300
insilmaril@672
   301
	// Attributes	
insilmaril@672
   302
	connect ( 
insilmaril@672
   303
		ui.addAttributeButton, SIGNAL (clicked()), 
insilmaril@672
   304
		this, SLOT (addAttributeClicked()));
insilmaril@672
   305
	connect ( 
insilmaril@672
   306
		ui.deleteAttributeButton, SIGNAL (clicked()), 
insilmaril@672
   307
		this, SLOT (deleteAttributeClicked()));
insilmaril@462
   308
}
insilmaril@462
   309
insilmaril@462
   310
insilmaril@462
   311
void BranchPropertyWindow::disconnectSignals()
insilmaril@462
   312
{
insilmaril@480
   313
	// Frame 
insilmaril@462
   314
	disconnect ( ui.frameTypeCombo, 0,0,0);
insilmaril@462
   315
	disconnect ( ui.framePenColorButton, 0,0,0);
insilmaril@462
   316
	disconnect ( ui.framePaddingSpinBox, 0,0,0);
insilmaril@462
   317
	disconnect ( ui.frameWidthSpinBox, 0,0,0);
insilmaril@462
   318
	disconnect ( ui.frameBrushColorButton, 0,0,0);
insilmaril@462
   319
insilmaril@462
   320
	// Link	
insilmaril@462
   321
	disconnect ( ui.hideLinkIfUnselected, 0,0,0);
insilmaril@462
   322
insilmaril@462
   323
	// Layout	
insilmaril@462
   324
	disconnect ( ui.incImgVer, 0,0,0);
insilmaril@462
   325
	disconnect ( ui.incImgHor, 0,0,0);
insilmaril@672
   326
insilmaril@672
   327
	// Attributes
insilmaril@672
   328
	disconnect ( ui.addAttributeButton, 0,0,0);
insilmaril@672
   329
	disconnect ( ui.deleteAttributeButton, 0,0,0);
insilmaril@462
   330
}
insilmaril@462
   331
insilmaril@462
   332