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