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