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