summaryrefslogtreecommitdiffstats
path: root/scribus/smlinestylewidget.cpp
blob: d21cca26f244a909931bfe3e94d59ce0d4b3e185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/

#include <QEvent>
#include <QToolTip>

#include "smlinestylewidget.h"
#include "colorcombo.h"
#include "linecombo.h"
#include "sccolorengine.h"
#include "scrspinbox.h"
#include "util_color.h"
#include "util_icon.h"
#include "util.h"


SMLineStyleWidget::SMLineStyleWidget() : QWidget()
{
	setupUi(this);
	addButton->setIcon(QIcon(loadIcon("penciladd.png")));
	removeButton->setIcon(QIcon(loadIcon("pencilsub.png")));

	dashCombo = new LineCombo(this);
	gridLayout->addWidget(dashCombo, 0, 0);

	lineWidth = new ScrSpinBox( 0, 300, this, 0 );
	gridLayout1->addWidget(lineWidth, 0, 1);
	
	colorCombo = new ColorCombo(this);
	gridLayout1->addWidget(colorCombo, 1, 0);

	endCombo->addItem(loadIcon("ButtCap.png"), tr( "Flat Cap" ) );
	endCombo->addItem(loadIcon("SquareCap.png"), tr( "Square Cap" ) );
	endCombo->addItem(loadIcon("RoundCap.png"), tr( "Round Cap" ) );

	joinCombo->addItem(loadIcon("MiterJoin.png"), tr( "Miter Join" ) );
	joinCombo->addItem(loadIcon("BevelJoin.png"), tr( "Bevel Join" ) );
	joinCombo->addItem(loadIcon("RoundJoin.png"), tr( "Round Join" ) );

	languageChange();
}

void SMLineStyleWidget::changeEvent(QEvent *e)
{
	if (e->type() == QEvent::LanguageChange)
	{
		languageChange();
	}
}

void SMLineStyleWidget::languageChange()
{
/***********************************/
/*      Begin Tooltips             */
/***********************************/
// These are for the line style page

	addButton->setToolTip(    tr("Add a new line"));
	removeButton->setToolTip( tr("Remove a line"));
	dashCombo->setToolTip(    tr("Line style"));
	lineWidth->setToolTip(    tr("Line width"));
	endCombo->setToolTip(     tr("End style"));
	joinCombo->setToolTip(    tr("Join style"));
	colorCombo->setToolTip(   tr("Line color"));
	shadeBox->setToolTip(     tr("Line shade"));

/***********************************/
/*      End Tooltips               */
/***********************************/
}


void SMLineStyleWidget::unitChange(double oldRatio, double newRatio, int unitIndex)
{
	lineWidth->setNewUnit(unitIndex);
}

void SMLineStyleWidget::showStyle(const multiLine &lineStyle, ColorList &colorList, int subLine)
{
// 	disconnect(lineStyles, SIGNAL(highlighted(int)), this, SLOT(slotEditNewLine(int)));
	disconnect(lineStyles, SIGNAL(currentRowChanged(int)), this, SLOT(slotEditNewLine(int)));
	currentStyle = lineStyle;
	colorCombo->clear();
	colorCombo->updateBox(colorList, ColorCombo::fancyPixmaps, false);
	colors = colorList;
	updateLineList();
	slotEditNewLine(subLine);
	connect(lineStyles, SIGNAL(currentRowChanged(int)), this, SLOT(slotEditNewLine(int)));
}

void SMLineStyleWidget::slotEditNewLine(int i)
{
	lineStyles->setCurrentRow(i);
// 	lineStyles->setSelected(i, true);
	//currentLine_ = i;

	// JG #5876 protect against broken line styles 
	// JG #6099 no current item selected
	if (currentStyle.count() <= i || (i < 0))
		return;

	lineWidth->setValue(currentStyle[i].Width);
	setCurrentComboItem(colorCombo, currentStyle[i].Color);
	shadeBox->setValue(currentStyle[i].Shade);
	
	dashCombo->setCurrentIndex(currentStyle[i].Dash - 1);
	switch (static_cast<Qt::PenCapStyle>(currentStyle[i].LineEnd))
	{
	case Qt::FlatCap:
		endCombo->setCurrentIndex(0);
		break;
	case Qt::SquareCap:
		endCombo->setCurrentIndex(1);
		break;
	case Qt::RoundCap:
		endCombo->setCurrentIndex(2);
		break;
	default:
		endCombo->setCurrentIndex(0);
		break;
	}

	switch (static_cast<Qt::PenJoinStyle>(currentStyle[i].LineJoin))
	{
	case Qt::MiterJoin:
		joinCombo->setCurrentIndex(0);
		break;
	case Qt::BevelJoin:
		joinCombo->setCurrentIndex(1);
		break;
	case Qt::RoundJoin:
		joinCombo->setCurrentIndex(2);
		break;
	default:
		joinCombo->setCurrentIndex(0);
		break;
	}
}

void SMLineStyleWidget::updateLineList()
{
	QString tmp, tmp2;
	lineStyles->clear();
	QPixmap * pm2;
	for (multiLine::iterator it = currentStyle.begin(); it != currentStyle.end(); ++it)
	{
		pm2 = getWidePixmap(getColor((*it).Color, (*it).Shade));
		tmp2 = " "+tmp.setNum((*it).Width)+ lineWidth->suffix()+" ";
		if ((*it).Dash < 6)
			tmp2 += CommonStrings::translatePenStyleName(static_cast<Qt::PenStyle>((*it).Dash));
		tmp2 += " ";
		// lineStyles->insertItem( ...)
		lineStyles->addItem(new QListWidgetItem(*pm2, tmp2, lineStyles));
	}
}

QColor SMLineStyleWidget::getColor(const QString &name, int shade)
{
	const ScColor& color = colors[name];
	QColor tmpf = ScColorEngine::getDisplayColor(color, colors.document(), shade);
	return tmpf;
}

SMLineStyleWidget::~SMLineStyleWidget()
{
	
}