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