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