branchpropwindow.cpp
author insilmaril
Tue, 15 Dec 2009 09:14:59 +0000
changeset 818 25ee6b988b73
parent 804 14f2b1b15242
permissions -rw-r--r--
Fixed A&O report to show subitems
     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 	model=m;
   173 	if (model) 
   174 		setItem (model->getSelectedItem() );
   175 	else
   176 		ui.tabWidget->setEnabled (false);
   177 		
   178 }
   179 
   180 void BranchPropertyWindow::frameTypeChanged (int i)
   181 {
   182 	if (model)
   183 	{
   184 		switch (i)
   185 		{
   186 			case 0: model->setFrameType (FrameObj::NoFrame); break;
   187 			case 1: 
   188 				model->setFrameType (FrameObj::Rectangle); 
   189 				break;
   190 			case 2: 
   191 				model->setFrameType (FrameObj::Ellipse); 
   192 				model->setFramePadding (5); 
   193 				break;
   194 		}
   195 		setItem (branchItem);
   196 	}	
   197 }
   198 
   199 void BranchPropertyWindow::framePenColorClicked()
   200 {
   201 	if (model) 
   202 	{	
   203 		QColor col = QColorDialog::getColor( penColor, this );
   204 		if ( col.isValid() ) 
   205 		{
   206 			penColor=col;
   207 			model->setFramePenColor (penColor);
   208 		}	
   209 	}
   210 }
   211 
   212 void BranchPropertyWindow::frameBrushColorClicked()
   213 {
   214 	if (model) 
   215 	{
   216 		QColor col = QColorDialog::getColor( brushColor, this );
   217 		if ( col.isValid() ) 
   218 		{
   219 			brushColor=col;
   220 			model->setFrameBrushColor (brushColor);
   221 		}	
   222 	}	
   223 }
   224 
   225 void BranchPropertyWindow::framePaddingChanged(int i)
   226 {
   227 	if (model) model->setFramePadding (i);
   228 }
   229 
   230 void BranchPropertyWindow::frameBorderWidthChanged(int i)
   231 {
   232 	if (model) model->setFrameBorderWidth(i);
   233 }
   234 
   235 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
   236 {
   237 	if (!branchItem) return;
   238 	model->setHideLinkUnselected(i);
   239 }
   240 
   241 void BranchPropertyWindow::incImgVerChanged (int  i)
   242 {
   243 	if (model) model->setIncludeImagesVer (i);
   244 }
   245 
   246 void BranchPropertyWindow::incImgHorChanged (int  i)
   247 {
   248 	if (model) model->setIncludeImagesHor (i);
   249 }
   250 
   251 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
   252 {
   253     ce->accept();	// can be reopened with show()
   254 	hide();
   255 	emit (windowClosed() );
   256     return;
   257 }
   258 
   259 /*
   260 void BranchPropertyWindow::addAttributeClicked()
   261 {
   262 	// Add empty line for adding attributes
   263 	attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
   264 	attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()),  "Add new");
   265 	attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()),  "Undefined");
   266 
   267 	// Select attribute from list
   268 	ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
   269 	ui.attributeTableView->resizeColumnsToContents();
   270 
   271 //	QString attname=attributeModel->in
   272 //	attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()),  );
   273 
   274 
   275 
   276 	ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
   277 
   278 }
   279 
   280 void BranchPropertyWindow::deleteAttributeClicked()
   281 {
   282 	//FIXME-3 cout << "BPW::delete\n";
   283 }
   284 */
   285 
   286 void BranchPropertyWindow::connectSignals()
   287 {
   288 	// Frame
   289 	connect ( 
   290 		ui.framePenColorButton, SIGNAL (clicked()), 
   291 		this, SLOT (framePenColorClicked()));
   292 	connect ( 
   293 		ui.framePaddingSpinBox, SIGNAL (valueChanged( int)), 
   294 		this, SLOT (framePaddingChanged (int)));
   295 	connect ( 
   296 		ui.frameWidthSpinBox, SIGNAL (valueChanged( int)), 
   297 		this, SLOT (frameBorderWidthChanged (int)));
   298 	connect ( 
   299 		ui.frameBrushColorButton, SIGNAL (clicked()), 
   300 		this, SLOT (frameBrushColorClicked()));
   301 	connect ( 
   302 		ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)), 
   303 		this, SLOT (frameTypeChanged (int)));
   304 
   305 
   306 	// Link	
   307 	connect ( 
   308 		ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)), 
   309 		this, SLOT (linkHideUnselectedChanged (int)));
   310 
   311 	// Layout	
   312 	connect ( 
   313 		ui.incImgVer, SIGNAL (stateChanged( int)), 
   314 		this, SLOT (incImgVerChanged (int)));
   315 	connect ( 
   316 		ui.incImgHor, SIGNAL (stateChanged( int)), 
   317 		this, SLOT (incImgHorChanged (int)));
   318 
   319 /*
   320 	// Attributes	
   321 	connect ( 
   322 		ui.addAttributeButton, SIGNAL (clicked()), 
   323 		this, SLOT (addAttributeClicked()));
   324 	connect ( 
   325 		ui.deleteAttributeButton, SIGNAL (clicked()), 
   326 		this, SLOT (deleteAttributeClicked()));
   327 */		
   328 }
   329 
   330 
   331 void BranchPropertyWindow::disconnectSignals()
   332 {
   333 	// Frame 
   334 	disconnect ( ui.frameTypeCombo, 0,0,0);
   335 	disconnect ( ui.framePenColorButton, 0,0,0);
   336 	disconnect ( ui.framePaddingSpinBox, 0,0,0);
   337 	disconnect ( ui.frameWidthSpinBox, 0,0,0);
   338 	disconnect ( ui.frameBrushColorButton, 0,0,0);
   339 
   340 	// Link	
   341 	disconnect ( ui.hideLinkIfUnselected, 0,0,0);
   342 
   343 	// Layout	
   344 	disconnect ( ui.incImgVer, 0,0,0);
   345 	disconnect ( ui.incImgHor, 0,0,0);
   346 
   347 	// Attributes
   348 	/*
   349 	disconnect ( ui.addAttributeButton, 0,0,0);
   350 	disconnect ( ui.deleteAttributeButton, 0,0,0);
   351 	*/
   352 }
   353 
   354