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