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