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