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