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