~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

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
172
173
174
175
/*
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.
*/
/***************************************************************************
                          dynamictip.cpp  -  description
                             -------------------
    begin                : Wed Aug 31 2005
    copyright            : (C) 2005 by Franz Schmid
    email                : Franz.Schmid@altmuehlnet.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "dynamictip.h"
#include "seiten.h"
#include "tree.h"
#include "pageitem.h"

DynamicTip::DynamicTip( QListBox* parent, ColorList* pale ) : QToolTip( parent )
{
	colorList = pale;
	listB = parent;
	kind = ColorListBox;
}

DynamicTip::DynamicTip( QTable* parent ) : QToolTip( parent->viewport() )
{
	table = parent;
	kind = Table;
}

DynamicTip::DynamicTip( QHeader *parent ) : QToolTip( parent )
{
	header = parent;
	kind = TableHeader;
}

DynamicTip::DynamicTip( QListView* parent ) : QToolTip( parent->viewport() )
{
	listV = parent;
	kind = TreeView;
}

void DynamicTip::maybeTip( const QPoint &pos )
{
	if (kind == ColorListBox)
	{
		QListBoxItem* it = listB->itemAt(pos);
		if (it != 0)
		{
			if (!colorList->contains(it->text()))
				return;
			QString tipText = "";
			ScColor col = (*colorList)[it->text()];
			if (col.getColorModel() == colorModelCMYK)
			{
				int c, m, y, k;
				col.getCMYK(&c, &m, &y, &k);
				tipText = QString("C:%1% M:%2% Y:%3% K:%4%").arg(qRound(c / 2.55)).arg(qRound(m / 2.55)).arg(qRound(y / 2.55)).arg(qRound(k / 2.55));
			}
			else
			{
				int r, g, b;
				col.getRawRGBColor(&r, &g, &b);
				tipText = QString("R:%1 G:%2 B:%3").arg(r).arg(g).arg(b);
			}
			tip(listB->itemRect(it), tipText);
		}
	}
	else if (kind == Table)
	{
		QPoint cp = table->viewportToContents( pos );
		int row = table->rowAt( cp.y() );
		int col = table->columnAt( cp.x() );
		QTableItem* ite = table->item(row, col);
		if (ite == 0)
			return;
		QRect cr = table->cellGeometry( row, col );
		cr.moveTopLeft( table->contentsToViewport( cr.topLeft() ) );
		SeItem* it = (SeItem*)ite;
		QString tipString = it->getPageName();
		tip( cr, tipString );
	}
	else if (kind == TableHeader)
	{
		int col = header->sectionAt(pos.x());
		tip( header->sectionRect(col), headerTips[col] );
	}
	else if (kind == TreeView)
	{
		QListViewItem* it = listV->itemAt(pos);
		if (it != 0)
		{
			TreeItem *item = (TreeItem*)it;
			if (item != NULL)
			{
				QString tipText = "";
				if ((item->type == 1) || (item->type == 3) || (item->type == 4))
				{
					PageItem *pgItem = item->PageItemObject;
					switch (pgItem->itemType())
					{
						case PageItem::ImageFrame:
							tipText = QObject::tr("Image");
							break;
						case PageItem::TextFrame:
							switch (pgItem->annotation().Type())
							{
								case 2:
									tipText = QObject::tr("PDF Push Button");
									break;
								case 3:
									tipText = QObject::tr("PDF Text Field");
									break;
								case 4:
									tipText = QObject::tr("PDF Check Box");
									break;
								case 5:
									tipText = QObject::tr("PDF Combo Box");
									break;
								case 6:
									tipText = QObject::tr("PDF List Box");
									break;
								case 10:
									tipText = QObject::tr("PDF Text Annotation");
									break;
								case 11:
									tipText = QObject::tr("PDF Link Annotation");
									break;
								default:
									tipText = QObject::tr("Text");
									break;
							}
							break;
						case PageItem::Line:
							tipText = QObject::tr("Line");
							break;
						case PageItem::Polygon:
							tipText = QObject::tr("Polygon");
							break;
						case PageItem::PolyLine:
							tipText = QObject::tr("Polyline");
							break;
						case PageItem::PathText:
							tipText = QObject::tr("PathText");
							break;
						default:
							break;
					}
					tip(listV->itemRect(it), tipText);
				}
			}
		}
	}
}

void DynamicTip::addHeaderTip( QString tip )
{
	headerTips.append(tip);
}

void DynamicTip::clearHeaderTips()
{
	headerTips.clear();
}