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