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