branchpropwindow.cpp
author insilmaril
Wed, 25 Apr 2007 16:02:54 +0000
changeset 465 8e6b95a0efa0
parent 462 494a5b8c131e
child 480 4e2c9394c7da
permissions -rw-r--r--
started doxygen documentation
     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 BranchPropertyWindow::~BranchPropertyWindow ()
    28 {
    29 	settings.setValue( "/branchpropertywindow/geometry/size", size() );
    30 	settings.setValue( "/branchpropertywindow/geometry/pos", pos() );
    31 	//settings.setValue( "/branchpropertywindow/showWithMain",showWithMain());	//FIXME add this!
    32 }
    33 
    34 void BranchPropertyWindow::setBranch (BranchObj *bo)
    35 {
    36 	disconnectSignals();
    37 	branch=bo;
    38 	if (bo) 
    39 	{
    40 		ui.tabWidget->setEnabled (true);
    41 
    42 		// Frame
    43 		FrameObj::FrameType t=branch->getFrameType();
    44 		if (t==FrameObj::NoFrame)
    45 		{
    46 			ui.frameTypeCombo->setCurrentIndex (0);
    47 			penColor=Qt::white;
    48 			brushColor=Qt::white;
    49 			ui.colorGroupBox->setEnabled (false);
    50 			ui.framePaddingSpinBox->setEnabled (false);
    51 			ui.frameWidthSpinBox->setEnabled (false);
    52 		} else	
    53 		{
    54 			penColor=bo->getFramePenColor();
    55 			brushColor=bo->getFrameBrushColor();
    56 			QPixmap pix( 16,16);
    57 			pix.fill (penColor);
    58 			ui.frameBrushColorButton->setPixmap (pix);
    59 			pix.fill (brushColor);
    60 			ui.frameBrushColorButton->setPixmap (pix);
    61 			ui.colorGroupBox->setEnabled (true);
    62 			ui.framePaddingSpinBox->setEnabled (true);
    63 			ui.framePaddingSpinBox->setValue (bo->getFramePadding());
    64 			ui.frameWidthSpinBox->setEnabled (true);
    65 			ui.frameWidthSpinBox->setValue (bo->getFrameBorderWidth());
    66 
    67 			switch (t)
    68 			{
    69 				case FrameObj::Rectangle: 
    70 					ui.frameTypeCombo->setCurrentIndex (1);
    71 					break;
    72 				case FrameObj::Ellipse: 
    73 					ui.frameTypeCombo->setCurrentIndex (2);
    74 					break;
    75 				default: 
    76 					break;
    77 			}
    78 		}	
    79 		
    80 		// Link
    81 		if (branch->getHideLinkUnselected())
    82 			ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
    83 		else	
    84 			ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
    85 
    86 		// Layout
    87 		if (branch->getIncludeImagesVer())
    88 			ui.incImgVer->setCheckState (Qt::Checked);
    89 		else	
    90 			ui.incImgVer->setCheckState (Qt::Unchecked);
    91 		if (branch->getIncludeImagesHor())
    92 			ui.incImgHor->setCheckState (Qt::Checked);
    93 		else	
    94 			ui.incImgHor->setCheckState (Qt::Unchecked);
    95 
    96 		// Finally activate signals
    97 		connectSignals();
    98 	} else
    99 	{
   100 		ui.tabWidget->setEnabled (false);
   101 	}
   102 }
   103 
   104 void BranchPropertyWindow::setMapEditor (MapEditor *me)
   105 {
   106 	mapEditor=me;
   107 	if (mapEditor) 
   108 		setBranch (mapEditor->getSelectedBranch() );
   109 	else
   110 		ui.tabWidget->setEnabled (false);
   111 		
   112 }
   113 
   114 void BranchPropertyWindow::frameTypeChanged (int i)
   115 {
   116 	if (mapEditor)
   117 		switch (i)
   118 		{
   119 			case 0: mapEditor->setFrameType (FrameObj::NoFrame); break;
   120 			case 1: mapEditor->setFrameType (FrameObj::Rectangle); break;
   121 			case 2: mapEditor->setFrameType (FrameObj::Ellipse); break;
   122 		}
   123 }
   124 
   125 void BranchPropertyWindow::framePenColorClicked()
   126 {
   127 	if (mapEditor) 
   128 	{	
   129 		QColor col = QColorDialog::getColor( penColor, this );
   130 		if ( col.isValid() ) 
   131 		{
   132 			penColor=col;
   133 			mapEditor->setFramePenColor (penColor);
   134 		}	
   135 	}
   136 }
   137 
   138 void BranchPropertyWindow::frameBrushColorClicked()
   139 {
   140 	if (mapEditor) 
   141 	{
   142 		QColor col = QColorDialog::getColor( brushColor, this );
   143 		if ( col.isValid() ) 
   144 		{
   145 			brushColor=col;
   146 			mapEditor->setFrameBrushColor (brushColor);
   147 		}	
   148 	}	
   149 }
   150 
   151 void BranchPropertyWindow::framePaddingChanged(int i)
   152 {
   153 	if (mapEditor) mapEditor->setFramePadding (i);
   154 }
   155 
   156 void BranchPropertyWindow::frameBorderWidthChanged(int i)
   157 {
   158 	if (mapEditor) mapEditor->setFrameBorderWidth(i);
   159 }
   160 
   161 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
   162 {
   163 	if (!branch) return;
   164 	mapEditor->setHideLinkUnselected(i);
   165 }
   166 
   167 void BranchPropertyWindow::incImgVerChanged (int  i)
   168 {
   169 	if (mapEditor) mapEditor->setIncludeImagesVer (i);
   170 }
   171 
   172 void BranchPropertyWindow::incImgHorChanged (int  i)
   173 {
   174 	if (mapEditor) mapEditor->setIncludeImagesHor (i);
   175 }
   176 
   177 void BranchPropertyWindow::connectSignals()
   178 {
   179 	// Frame
   180 	connect ( 
   181 		ui.framePenColorButton, SIGNAL (clicked()), 
   182 		this, SLOT (framePenColorClicked()));
   183 	connect ( 
   184 		ui.framePaddingSpinBox, SIGNAL (valueChanged( int)), 
   185 		this, SLOT (framePaddingChanged (int)));
   186 	connect ( 
   187 		ui.frameWidthSpinBox, SIGNAL (valueChanged( int)), 
   188 		this, SLOT (frameBorderWidthChanged (int)));
   189 	connect ( 
   190 		ui.frameBrushColorButton, SIGNAL (clicked()), 
   191 		this, SLOT (frameBrushColorClicked()));
   192 	connect ( 
   193 		ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)), 
   194 		this, SLOT (frameTypeChanged (int)));
   195 
   196 
   197 	// Link	
   198 	connect ( 
   199 		ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)), 
   200 		this, SLOT (linkHideUnselectedChanged (int)));
   201 
   202 	// Layout	
   203 	connect ( 
   204 		ui.incImgVer, SIGNAL (stateChanged( int)), 
   205 		this, SLOT (incImgVerChanged (int)));
   206 	connect ( 
   207 		ui.incImgHor, SIGNAL (stateChanged( int)), 
   208 		this, SLOT (incImgHorChanged (int)));
   209 }
   210 
   211 
   212 void BranchPropertyWindow::disconnectSignals()
   213 {
   214 	// Frame
   215 	disconnect ( ui.frameTypeCombo, 0,0,0);
   216 	disconnect ( ui.framePenColorButton, 0,0,0);
   217 	disconnect ( ui.framePaddingSpinBox, 0,0,0);
   218 	disconnect ( ui.frameWidthSpinBox, 0,0,0);
   219 	disconnect ( ui.frameBrushColorButton, 0,0,0);
   220 
   221 	// Link	
   222 	disconnect ( ui.hideLinkIfUnselected, 0,0,0);
   223 
   224 	// Layout	
   225 	disconnect ( ui.incImgVer, 0,0,0);
   226 	disconnect ( ui.incImgHor, 0,0,0);
   227 }
   228 
   229