branchpropwindow.cpp
author insilmaril
Thu May 03 14:40:13 2007 +0000 (2007-05-03)
changeset 487 8fca3a710dc4
parent 480 4e2c9394c7da
child 488 bd28847feede
permissions -rw-r--r--
Fixed window captions
     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 
    31 	// Load Settings
    32 	//FIXME setSatelliteName ( "propertyWindow" );
    33 	resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize());
    34 	move   (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint());
    35 	
    36 	if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool())
    37 		show();
    38 	else	
    39 		hide();
    40 
    41 }
    42 
    43 BranchPropertyWindow::~BranchPropertyWindow ()
    44 {
    45 	settings.setValue( "/satellite/propertywindow/geometry/size", size() );
    46 	settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
    47 
    48 }
    49 
    50 void BranchPropertyWindow::setBranch (BranchObj *bo)
    51 {
    52 	disconnectSignals();
    53 	branch=bo;
    54 	if (bo) 
    55 	{
    56 		ui.tabWidget->setEnabled (true);
    57 
    58 		// Frame
    59 		FrameObj::FrameType t=branch->getFrameType();
    60 		if (t==FrameObj::NoFrame)
    61 		{
    62 			ui.frameTypeCombo->setCurrentIndex (0);
    63 			penColor=Qt::white;
    64 			brushColor=Qt::white;
    65 			ui.colorGroupBox->setEnabled (false);
    66 			ui.framePaddingSpinBox->setEnabled (false);
    67 			ui.frameWidthSpinBox->setEnabled (false);
    68 			ui.framePaddingLabel->setEnabled (false);
    69 			ui.frameBorderLabel->setEnabled (false);
    70 		} else	
    71 		{
    72 			penColor=bo->getFramePenColor();
    73 			brushColor=bo->getFrameBrushColor();
    74 			QPixmap pix( 16,16);
    75 			pix.fill (penColor);
    76 			ui.framePenColorButton->setPixmap (pix);
    77 			pix.fill (brushColor);
    78 			ui.frameBrushColorButton->setPixmap (pix);
    79 			ui.colorGroupBox->setEnabled (true);
    80 			ui.framePaddingSpinBox->setEnabled (true);
    81 			ui.framePaddingSpinBox->setValue (bo->getFramePadding());
    82 			ui.frameWidthSpinBox->setEnabled (true);
    83 			ui.frameWidthSpinBox->setValue (bo->getFrameBorderWidth());
    84 			ui.framePaddingLabel->setEnabled (true);
    85 			ui.frameBorderLabel->setEnabled (true);
    86 
    87 			switch (t)
    88 			{
    89 				case FrameObj::Rectangle: 
    90 					ui.frameTypeCombo->setCurrentIndex (1);
    91 					break;
    92 				case FrameObj::Ellipse: 
    93 					ui.frameTypeCombo->setCurrentIndex (2);
    94 					break;
    95 				default: 
    96 					break;
    97 			}
    98 		}	
    99 		
   100 		// Link
   101 		if (branch->getHideLinkUnselected())
   102 			ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
   103 		else	
   104 			ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
   105 
   106 		// Layout
   107 		if (branch->getIncludeImagesVer())
   108 			ui.incImgVer->setCheckState (Qt::Checked);
   109 		else	
   110 			ui.incImgVer->setCheckState (Qt::Unchecked);
   111 		if (branch->getIncludeImagesHor())
   112 			ui.incImgHor->setCheckState (Qt::Checked);
   113 		else	
   114 			ui.incImgHor->setCheckState (Qt::Unchecked);
   115 
   116 		// Finally activate signals
   117 		connectSignals();
   118 	} else
   119 	{
   120 		ui.tabWidget->setEnabled (false);
   121 	}
   122 }
   123 
   124 void BranchPropertyWindow::setMapEditor (MapEditor *me)
   125 {
   126 	mapEditor=me;
   127 	if (mapEditor) 
   128 		setBranch (mapEditor->getSelectedBranch() );
   129 	else
   130 		ui.tabWidget->setEnabled (false);
   131 		
   132 }
   133 
   134 void BranchPropertyWindow::frameTypeChanged (int i)
   135 {
   136 	if (mapEditor)
   137 	{
   138 		switch (i)
   139 		{
   140 			case 0: mapEditor->setFrameType (FrameObj::NoFrame); break;
   141 			case 1: mapEditor->setFrameType (FrameObj::Rectangle); break;
   142 			case 2: mapEditor->setFrameType (FrameObj::Ellipse); break;
   143 		}
   144 		setBranch (branch);
   145 	}	
   146 }
   147 
   148 void BranchPropertyWindow::framePenColorClicked()
   149 {
   150 	if (mapEditor) 
   151 	{	
   152 		QColor col = QColorDialog::getColor( penColor, this );
   153 		if ( col.isValid() ) 
   154 		{
   155 			penColor=col;
   156 			mapEditor->setFramePenColor (penColor);
   157 		}	
   158 	}
   159 }
   160 
   161 void BranchPropertyWindow::frameBrushColorClicked()
   162 {
   163 	if (mapEditor) 
   164 	{
   165 		QColor col = QColorDialog::getColor( brushColor, this );
   166 		if ( col.isValid() ) 
   167 		{
   168 			brushColor=col;
   169 			mapEditor->setFrameBrushColor (brushColor);
   170 		}	
   171 	}	
   172 }
   173 
   174 void BranchPropertyWindow::framePaddingChanged(int i)
   175 {
   176 	if (mapEditor) mapEditor->setFramePadding (i);
   177 }
   178 
   179 void BranchPropertyWindow::frameBorderWidthChanged(int i)
   180 {
   181 	if (mapEditor) mapEditor->setFrameBorderWidth(i);
   182 }
   183 
   184 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
   185 {
   186 	if (!branch) return;
   187 	mapEditor->setHideLinkUnselected(i);
   188 }
   189 
   190 void BranchPropertyWindow::incImgVerChanged (int  i)
   191 {
   192 	if (mapEditor) mapEditor->setIncludeImagesVer (i);
   193 }
   194 
   195 void BranchPropertyWindow::incImgHorChanged (int  i)
   196 {
   197 	if (mapEditor) mapEditor->setIncludeImagesHor (i);
   198 }
   199 
   200 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
   201 {
   202     ce->accept();	// can be reopened with show()
   203 	hide();
   204 	emit (windowClosed() );
   205     return;
   206 }
   207 
   208 
   209 void BranchPropertyWindow::connectSignals()
   210 {
   211 	// Frame
   212 	connect ( 
   213 		ui.framePenColorButton, SIGNAL (clicked()), 
   214 		this, SLOT (framePenColorClicked()));
   215 	connect ( 
   216 		ui.framePaddingSpinBox, SIGNAL (valueChanged( int)), 
   217 		this, SLOT (framePaddingChanged (int)));
   218 	connect ( 
   219 		ui.frameWidthSpinBox, SIGNAL (valueChanged( int)), 
   220 		this, SLOT (frameBorderWidthChanged (int)));
   221 	connect ( 
   222 		ui.frameBrushColorButton, SIGNAL (clicked()), 
   223 		this, SLOT (frameBrushColorClicked()));
   224 	connect ( 
   225 		ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)), 
   226 		this, SLOT (frameTypeChanged (int)));
   227 
   228 
   229 	// Link	
   230 	connect ( 
   231 		ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)), 
   232 		this, SLOT (linkHideUnselectedChanged (int)));
   233 
   234 	// Layout	
   235 	connect ( 
   236 		ui.incImgVer, SIGNAL (stateChanged( int)), 
   237 		this, SLOT (incImgVerChanged (int)));
   238 	connect ( 
   239 		ui.incImgHor, SIGNAL (stateChanged( int)), 
   240 		this, SLOT (incImgHorChanged (int)));
   241 }
   242 
   243 
   244 void BranchPropertyWindow::disconnectSignals()
   245 {
   246 	// Frame 
   247 	disconnect ( ui.frameTypeCombo, 0,0,0);
   248 	disconnect ( ui.framePenColorButton, 0,0,0);
   249 	disconnect ( ui.framePaddingSpinBox, 0,0,0);
   250 	disconnect ( ui.frameWidthSpinBox, 0,0,0);
   251 	disconnect ( ui.frameBrushColorButton, 0,0,0);
   252 
   253 	// Link	
   254 	disconnect ( ui.hideLinkIfUnselected, 0,0,0);
   255 
   256 	// Layout	
   257 	disconnect ( ui.incImgVer, 0,0,0);
   258 	disconnect ( ui.incImgHor, 0,0,0);
   259 }
   260 
   261