Rev 1065 | Rev 1361 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
82 | Franz | 1 | #include "cmdutil.h" |
2 | |||
3 | ScribusApp* Carrier; |
||
4 | ScribusDoc* doc; |
||
5 | |||
6 | double PointToValue(double Val) |
||
7 | { |
||
8 | double ret = 0.0; |
||
1065 | cbradney | 9 | switch (Carrier->doc->docUnitIndex) |
297 | Franz | 10 | { |
11 | case 0: |
||
12 | ret = Val; |
||
13 | break; |
||
14 | case 1: |
||
15 | ret = Val * 0.3527777; |
||
16 | break; |
||
17 | case 2: |
||
18 | ret = Val * (1.0 / 72.0); |
||
19 | break; |
||
20 | case 3: |
||
21 | ret = Val * (1.0 / 12.0); |
||
22 | break; |
||
23 | } |
||
82 | Franz | 24 | return ret; |
25 | } |
||
26 | |||
27 | double ValToPts(double Val, int ein) |
||
28 | { |
||
29 | double ret = 0.0; |
||
30 | switch (ein) |
||
297 | Franz | 31 | { |
32 | case 0: |
||
33 | ret = Val; |
||
34 | break; |
||
35 | case 1: |
||
36 | ret = Val / 0.3527777; |
||
37 | break; |
||
38 | case 2: |
||
39 | ret = Val / (1.0 / 72.0); |
||
40 | break; |
||
41 | case 3: |
||
42 | ret = Val / (1.0 / 12.0); |
||
43 | break; |
||
44 | } |
||
82 | Franz | 45 | return ret; |
46 | } |
||
47 | |||
48 | double ValueToPoint(double Val) |
||
49 | { |
||
1065 | cbradney | 50 | return ValToPts(Val, Carrier->doc->docUnitIndex); |
82 | Franz | 51 | } |
52 | |||
1283 | subik | 53 | /// Convert an X co-ordinate part in page units to a document co-ordinate |
54 | /// in system units. |
||
55 | double pageUnitXToDocX(double pageUnitX) |
||
56 | { |
||
57 | return ValueToPoint(pageUnitX) + Carrier->doc->currentPage->Xoffset; |
||
58 | } |
||
59 | |||
60 | /// Convert a Y co-ordinate part in page units to a document co-ordinate |
||
61 | /// in system units. The document co-ordinates have their origin somewere |
||
62 | /// up and left of the first page, where page co-ordinates have their |
||
63 | /// origin on the top left of the current page. |
||
64 | double pageUnitYToDocY(double pageUnitY) |
||
65 | { |
||
66 | return ValueToPoint(pageUnitY) + Carrier->doc->currentPage->Yoffset; |
||
67 | } |
||
68 | |||
82 | Franz | 69 | int GetItem(QString Name) |
70 | { |
||
297 | Franz | 71 | if (Name != "") |
72 | { |
||
662 | fschmid | 73 | for (uint a = 0; a < Carrier->doc->Items.count(); a++) |
82 | Franz | 74 | { |
662 | fschmid | 75 | if (Carrier->doc->Items.at(a)->AnName == Name) |
82 | Franz | 76 | return static_cast<int>(a); |
77 | } |
||
297 | Franz | 78 | } |
82 | Franz | 79 | else |
297 | Franz | 80 | { |
662 | fschmid | 81 | if (Carrier->view->SelItem.count() != 0) |
82 | return Carrier->view->SelItem.at(0)->ItemNr; |
||
297 | Franz | 83 | } |
82 | Franz | 84 | return -1; |
85 | } |
||
86 | |||
103 | Franz | 87 | void ReplaceColor(QString col, QString rep) |
88 | { |
||
297 | Franz | 89 | QColor tmpc; |
662 | fschmid | 90 | for (uint c = 0; c < Carrier->doc->Items.count(); c++) |
297 | Franz | 91 | { |
662 | fschmid | 92 | PageItem *ite = Carrier->doc->Items.at(c); |
93 | if (ite->PType == 4) |
||
103 | Franz | 94 | { |
1065 | cbradney | 95 | for (uint d = 0; d < ite->itemText.count(); d++) |
297 | Franz | 96 | { |
1065 | cbradney | 97 | if (col == ite->itemText.at(d)->ccolor) |
98 | ite->itemText.at(d)->ccolor = rep; |
||
99 | if (col == ite->itemText.at(d)->cstroke) |
||
100 | ite->itemText.at(d)->cstroke = rep; |
||
297 | Franz | 101 | } |
662 | fschmid | 102 | } |
103 | if (col == ite->Pcolor) |
||
104 | ite->Pcolor = rep; |
||
105 | if (col == ite->Pcolor2) |
||
106 | ite->Pcolor2 = rep; |
||
107 | QPtrVector<VColorStop> cstops = ite->fill_gradient.colorStops(); |
||
108 | for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst) |
||
109 | { |
||
110 | if (col == cstops.at(cst)->name) |
||
297 | Franz | 111 | { |
662 | fschmid | 112 | ite->SetFarbe(&tmpc, rep, cstops.at(cst)->shade); |
113 | cstops.at(cst)->color = tmpc; |
||
114 | cstops.at(cst)->name = rep; |
||
297 | Franz | 115 | } |
116 | } |
||
117 | } |
||
662 | fschmid | 118 | for (uint c = 0; c < Carrier->doc->MasterItems.count(); c++) |
297 | Franz | 119 | { |
662 | fschmid | 120 | PageItem *ite = Carrier->doc->MasterItems.at(c); |
121 | if (ite->PType == 4) |
||
297 | Franz | 122 | { |
1065 | cbradney | 123 | for (uint d = 0; d < ite->itemText.count(); d++) |
297 | Franz | 124 | { |
1065 | cbradney | 125 | if (col == ite->itemText.at(d)->ccolor) |
126 | ite->itemText.at(d)->ccolor = rep; |
||
127 | if (col == ite->itemText.at(d)->cstroke) |
||
128 | ite->itemText.at(d)->cstroke = rep; |
||
297 | Franz | 129 | } |
662 | fschmid | 130 | } |
131 | if (col == ite->Pcolor) |
||
132 | ite->Pcolor = rep; |
||
133 | if (col == ite->Pcolor2) |
||
134 | ite->Pcolor2 = rep; |
||
135 | QPtrVector<VColorStop> cstops = ite->fill_gradient.colorStops(); |
||
136 | for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst) |
||
137 | { |
||
138 | if (col == cstops.at(cst)->name) |
||
297 | Franz | 139 | { |
662 | fschmid | 140 | ite->SetFarbe(&tmpc, rep, cstops.at(cst)->shade); |
141 | cstops.at(cst)->color = tmpc; |
||
142 | cstops.at(cst)->name = rep; |
||
103 | Franz | 143 | } |
144 | } |
||
297 | Franz | 145 | } |
103 | Franz | 146 | } |
147 | |||
332 | Franz | 148 | /* 04/07/10 returns selection if is not name specified pv */ |
228 | Franz | 149 | PageItem* GetUniqueItem(QString name) |
150 | { |
||
151 | if (name.length()==0) |
||
662 | fschmid | 152 | if (Carrier->view->SelItem.count() != 0) |
153 | return Carrier->view->SelItem.at(0); |
||
720 | subik | 154 | else |
155 | { |
||
853 | subik | 156 | PyErr_SetString(NoValidObjectError, QString("Can't use empty string for object name when there is no selection")); |
720 | subik | 157 | return NULL; |
158 | } |
||
662 | fschmid | 159 | for (uint j = 0; j<Carrier->doc->Items.count(); j++) |
228 | Franz | 160 | { |
662 | fschmid | 161 | if (name==Carrier->doc->Items.at(j)->AnName) |
162 | return Carrier->doc->Items.at(j); |
||
163 | } // for items |
||
853 | subik | 164 | PyErr_SetString(NoValidObjectError, QString("Object not found")); |
228 | Franz | 165 | return NULL; |
166 | } |
||
649 | fschmid | 167 | |
720 | subik | 168 | |
649 | fschmid | 169 | /*! |
720 | subik | 170 | * Checks to see if a pageItem named 'name' exists and return true |
171 | * if it does exist. Returns false if there is no such object, or |
||
172 | * if the empty string ("") is passed. |
||
173 | */ |
||
174 | bool ItemExists(QString name) |
||
175 | { |
||
176 | if (name.length() == 0) |
||
177 | return false; |
||
178 | for (uint j = 0; j<Carrier->doc->Items.count(); j++) |
||
179 | { |
||
180 | if (name==Carrier->doc->Items.at(j)->AnName) |
||
181 | return true; |
||
182 | } // for items |
||
183 | return false; |
||
184 | } |
||
185 | |||
186 | /*! |
||
649 | fschmid | 187 | * Checks to see if there is a document open. |
188 | * If there is an open document, returns true. |
||
189 | * If there is no open document, sets a Python |
||
190 | * exception and returns false. |
||
191 | * 2004-10-27 Craig Ringer |
||
192 | */ |
||
193 | bool checkHaveDocument() |
||
194 | { |
||
195 | if (Carrier->HaveDoc) |
||
196 | return true; |
||
720 | subik | 197 | // Caller is required to check for false return from this function |
198 | // and return NULL. |
||
199 | PyErr_SetString(NoDocOpenError, QString("Command does not make sense without an open document")); |
||
649 | fschmid | 200 | return false; |
201 | } |