~ubuntu-branches/ubuntu/wily/scribus/wily-proposed

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
/*
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 <QObject>
#include <QList>
#include <QPointer>
#include "sctextstruct.h"
#include "scfonts.h"
#include "pageitem.h"
#include "scribusdoc.h"

void GlyphLayout::growWithTabLayout()
{
	if (more)
		shrink();
	more = new TabLayout();
}

struct InlineFrameData
{
	QPointer<PageItem> item;
	int refs;
	
	void reserve()  
	{ 
		++refs; 
	}
	
	bool release()
	{
		--refs;
		if (refs == 0 && item != NULL)
		{
			item->doc()->FrameItems.removeAll(item);
			item->doc()->updateFrameItems();
			delete item;
			item = NULL;
		}
		return refs == 0;
	}
};

InlineFrame::InlineFrame(PageItem* item)
{
	d = new InlineFrameData;
	d->item = item;
	d->refs = 1;
}

InlineFrame::InlineFrame(const InlineFrame& other)
{
	d = other.d;
	d->reserve();	
}

InlineFrame& InlineFrame::operator= (const InlineFrame& other)
{
	if (this != &other)
	{
		if (d->release())
			delete d;
		d = other.d;
		d->reserve();
	}
	return *this;
}

InlineFrame::~InlineFrame()
{
	if (d->release())
		delete d;
}

bool InlineFrame::hasItem() const
{
	return d->item != NULL;
}

bool InlineFrame::isShared() const
{
	return d->refs > 1;
}

PageItem* InlineFrame::getItem()
{
	return d->item;
}

QList<PageItem*> InlineFrame::getGroupedItems()
{
	QList<PageItem*> result;
//	result.setAutoDelete(false);
	if (hasItem())
	{
		PageItem* dItem = d->item;
		ScribusDoc& doc(*dItem->doc());
		result.append(d->item);
		if (dItem->Groups.count() != 0)
		{
			for (int ga=0; ga < doc.FrameItems.count(); ++ga)
			{
				if (doc.FrameItems.at(ga)->Groups.count() != 0)
				{
					if (doc.FrameItems.at(ga)->Groups.top() == dItem->Groups.top())
					{
						if (doc.FrameItems.at(ga)->ItemNr != dItem->ItemNr)
						{
							if (!result.contains(doc.FrameItems.at(ga)))
								result.append(doc.FrameItems.at(ga));
						}
					}
				}
			}
		}
	}
	return result;
}


ScText::~ScText() 
{
	// delete the linked list if present
	GlyphLayout * more = glyph.more;
	while (more) {
		glyph.more = glyph.more->more;
		delete more;
		more = glyph.more;
	}
	if (parstyle)
		delete parstyle;
	parstyle = NULL;
}

bool ScText::hasObject() const
{
	if (this->ch == SpecialChars::OBJECT)
		return this->embedded.hasItem();
	return false;
}