1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 
8 
9 #include "propertiespalette_utils.h"
10 
11 #include <QCloseEvent>
12 #include <QEvent>
13 #include <QFocusEvent>
14 #include <QHBoxLayout>
15 #include <QImage>
16 #include <QKeyEvent>
17 #include <QLabel>
18 #include <QListView>
19 #include <QMenu>
20 #include <QObject>
21 #include <QRegExp>
22 #include <QToolTip>
23 #include <QValidator>
24 #include <QWidget>
25 
26 #if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
27 #define _USE_MATH_DEFINES
28 #endif
29 #include <cmath>
30 #include "commonstrings.h"
31 #include "sccolorengine.h"
32 #include "scraction.h"
33 #include "scribusdoc.h"
34 #include "selection.h"
35 #include "units.h"
36 #include "util.h"
37 #include "util_math.h"
38 
39 //using namespace std;
40 
41 
LineStyleValue()42 LineStyleValue::LineStyleValue() : m_doc(nullptr), m_name() {};
43 
LineStyleValue(const multiLine & line,ScribusDoc * doc,const QString & name)44 LineStyleValue::LineStyleValue(const multiLine& line, ScribusDoc* doc, const QString& name) :
45 	m_Line(line),
46 	m_doc(doc),
47 	m_name(name)
48 {};
49 
LineStyleValue(const LineStyleValue & other)50 LineStyleValue::LineStyleValue(const LineStyleValue& other)
51 {
52 	m_name = other.m_name;
53 	m_Line = other.m_Line;
54 	m_doc = other.m_doc;
55 }
56 
operator =(const LineStyleValue & other)57 LineStyleValue& LineStyleValue::operator= (const LineStyleValue& other)
58 {
59 	m_name = other.m_name;
60 	m_Line = other.m_Line;
61 	m_doc = other.m_doc;
62 	return *this;
63 }
64 
65 
redraw(const QVariant & data) const66 void LineStyleItemDelegate::redraw(const QVariant& data) const
67 {
68 	const LineStyleValue& item(data.value<LineStyleValue>());
69 	pmap->fill(Qt::white);
70 	QPainter p;
71 	p.begin(pmap.data());
72 	for (int i = item.m_Line.size() - 1; i > -1; i--)
73 	{
74 		const SingleLine& sLine = item.m_Line.at(i);
75 		const ScColor& col = item.m_doc->PageColors[sLine.Color];
76 		QColor tmpf = ScColorEngine::getDisplayColor(col, item.m_doc, sLine.Shade);
77 		QPen pen;
78 		QVector<double> m_array;
79 		if (sLine.Dash == 1)
80 			pen.setStyle(Qt::SolidLine);
81 		else
82 		{
83 			getDashArray(sLine.Dash, 1, m_array);
84 			pen.setDashPattern(m_array);
85 		}
86 		pen.setColor(tmpf);
87 		pen.setWidth(qMax(static_cast<int>(sLine.Width), 1));
88 		pen.setCapStyle(static_cast<Qt::PenCapStyle>(sLine.LineEnd));
89 		pen.setJoinStyle(static_cast<Qt::PenJoinStyle>(sLine.LineJoin));
90 		p.setPen(pen);
91 		p.drawLine(0, 18, 37, 18);
92 	}
93 	p.end();
94 }
95 
text(const QVariant & data) const96 QString LineStyleItemDelegate::text(const QVariant& data) const
97 {
98 	return data.toString();
99 }
100 
NameWidget(QWidget * parent)101 NameWidget::NameWidget(QWidget* parent) : QLineEdit(parent)
102 {
103 	setObjectName("namewidget");
104 	QRegExp rx( "[\\w()]+" );
105 	QValidator* validator = new QRegExpValidator( rx, this );
106 	setValidator( validator );
107 }
108 
focusOutEvent(QFocusEvent * e)109 void NameWidget::focusOutEvent(QFocusEvent *e)
110 {
111 	emit Leaved();
112 	QLineEdit::focusOutEvent(e);
113 }
114 
UserActionSniffer(QObject * parent)115 UserActionSniffer::UserActionSniffer(QObject* parent) : QObject (parent)
116 {
117 
118 }
119 
eventFilter(QObject *,QEvent * e)120 bool UserActionSniffer::eventFilter(QObject*, QEvent *e)
121 {
122 	if (e->type() == QEvent::MouseButtonPress)
123 		emit actionStart();
124 	else if (e->type() == QEvent::MouseButtonRelease)
125 		emit actionEnd();
126 	else if (e->type() == QEvent::KeyPress)
127 	{
128 		QKeyEvent *k = dynamic_cast<QKeyEvent*>(e);
129 		if (k && !k->isAutoRepeat() && (k->key() == Qt::Key_Up || k->key() == Qt::Key_Down))
130 			emit actionStart();
131 	}
132 	else if (e->type() == QEvent::KeyRelease)
133 	{
134 		QKeyEvent *k = dynamic_cast<QKeyEvent*>(e);
135 		if (k && !k->isAutoRepeat() && (k->key() == Qt::Key_Up || k->key() == Qt::Key_Down))
136 			emit actionEnd();
137 	}
138 	return false;
139 }
140 
141 
142