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