Rev 1084 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | paul | 1 | #include "charselect.h" |
2 | #include "charselect.moc" |
||
68 | Franz | 3 | #include "scpainter.h" |
3 | paul | 4 | #include <qtextcodec.h> |
68 | Franz | 5 | #include <qcursor.h> |
128 | Franz | 6 | |
612 | cbradney | 7 | #ifdef _MSC_VER |
8 | #if (_MSC_VER >= 1200) |
||
9 | #include "win-config.h" |
||
10 | #endif |
||
128 | Franz | 11 | #else |
12 | #include "config.h" |
||
13 | #endif |
||
14 | |||
3 | paul | 15 | #include <ft2build.h> |
16 | #include FT_FREETYPE_H |
||
17 | #include FT_OUTLINE_H |
||
18 | #include FT_GLYPH_H |
||
19 | |||
20 | extern QPixmap loadIcon(QString nam); |
||
1084 | fschmid | 21 | extern QPixmap FontSample(QString da, int s, QString ts, QColor back, bool force = false); |
22 | extern int setBestEncoding(FT_Face face); |
||
253 | Franz | 23 | |
3 | paul | 24 | QString Name() |
25 | { |
||
308 | Franz | 26 | return QObject::tr("&Insert Special"); |
3 | paul | 27 | } |
28 | |||
29 | int Type() |
||
30 | { |
||
31 | return 1; |
||
32 | } |
||
33 | |||
585 | fschmid | 34 | int ID() |
35 | { |
||
36 | return 1; |
||
37 | } |
||
38 | |||
3 | paul | 39 | void Run(QWidget *d, ScribusApp *plug) |
40 | { |
||
41 | if ((plug->HaveDoc) && (plug->doc->ActPage->SelItem.count() != 0)) |
||
188 | Franz | 42 | { |
3 | paul | 43 | PageItem *b = plug->doc->ActPage->SelItem.at(0); |
253 | Franz | 44 | if ((b->PType == 4) && ((plug->doc->AppMode == 7) || (plug->DLLinput != ""))) |
188 | Franz | 45 | { |
666 | fschmid | 46 | ZAuswahl *dia = new ZAuswahl(d, b, plug); |
253 | Franz | 47 | dia->exec(); |
48 | delete dia; |
||
49 | } |
||
50 | } |
||
3 | paul | 51 | } |
68 | Franz | 52 | |
1887 | fschmid | 53 | Zoom::Zoom(QWidget* parent, QPixmap pix, uint val) : QDialog( parent, "Edit", false, WStyle_Customize | WStyle_NoBorder) |
68 | Franz | 54 | { |
96 | Franz | 55 | QString tmp; |
56 | resize(pix.width()+2,pix.height()+20); |
||
57 | setMinimumSize(QSize(pix.width()+2,pix.height()+20)); |
||
58 | setMaximumSize(QSize(pix.width()+2,pix.height()+20)); |
||
68 | Franz | 59 | pixm = pix; |
96 | Franz | 60 | tmp.sprintf("%04X", val); |
61 | valu = "0x"+tmp; |
||
68 | Franz | 62 | } |
63 | |||
64 | void Zoom::paintEvent(QPaintEvent *) |
||
65 | { |
||
66 | QPainter p; |
||
67 | p.begin(this); |
||
68 | p.setPen(black); |
||
69 | p.setBrush(NoBrush); |
||
253 | Franz | 70 | p.drawRect(0, 0, width(), height()); |
68 | Franz | 71 | p.drawPixmap(1, 1, pixm); |
96 | Franz | 72 | p.drawText(5, height()-3, valu); |
68 | Franz | 73 | p.end(); |
74 | } |
||
75 | |||
76 | ChTable::ChTable(ZAuswahl* parent, ScribusApp *pl) : QTable(parent) |
||
77 | { |
||
78 | Mpressed = false; |
||
79 | setFocusPolicy(NoFocus); |
||
80 | ap = pl; |
||
81 | par = parent; |
||
82 | } |
||
83 | |||
84 | void ChTable::contentsMousePressEvent(QMouseEvent* e) |
||
85 | { |
||
86 | e->accept(); |
||
87 | int r = rowAt(e->pos().y()); |
||
88 | int c = columnAt(e->pos().x()); |
||
253 | Franz | 89 | QString font; |
90 | if (ap->DLLinput != "") |
||
91 | font = ap->DLLinput; |
||
92 | else |
||
93 | font = ap->doc->CurrFont; |
||
88 | Franz | 94 | if ((e->button() == RightButton) && ((r*32+c) < MaxCount)) |
188 | Franz | 95 | { |
68 | Franz | 96 | Mpressed = true; |
253 | Franz | 97 | int bh = 48 + qRound(-(*ap->doc->AllFonts)[font]->numDescender * 48) + 3; |
68 | Franz | 98 | QPixmap pixm(bh,bh); |
99 | ScPainter *p = new ScPainter(&pixm, bh, bh); |
||
100 | p->clear(); |
||
101 | pixm.fill(white); |
||
102 | QWMatrix chma; |
||
103 | chma.scale(4.8, 4.8); |
||
253 | Franz | 104 | FPointArray gly = (*ap->doc->AllFonts)[font]->GlyphArray[par->Zeich[r*32+c]].Outlines.copy(); |
105 | double ww = bh - (*ap->doc->AllFonts)[font]->CharWidth[par->Zeich[r*32+c]]*48; |
||
68 | Franz | 106 | if (gly.size() > 4) |
188 | Franz | 107 | { |
68 | Franz | 108 | gly.map(chma); |
109 | p->translate(ww / 2, 1); |
||
110 | p->setBrush(black); |
||
111 | p->setFillMode(1); |
||
112 | p->setupPolygon(&gly); |
||
113 | p->fillPath(); |
||
114 | p->end(); |
||
188 | Franz | 115 | } |
68 | Franz | 116 | delete p; |
96 | Franz | 117 | dia = new Zoom(this, pixm, par->Zeich[r*32+c]); |
68 | Franz | 118 | QPoint ps = QCursor::pos(); |
119 | dia->move(ps.x()-2, ps.y()-2); |
||
120 | dia->show(); |
||
188 | Franz | 121 | } |
68 | Franz | 122 | } |
123 | |||
124 | void ChTable::contentsMouseReleaseEvent(QMouseEvent* e) |
||
125 | { |
||
126 | e->accept(); |
||
127 | if ((e->button() == RightButton) && (Mpressed)) |
||
188 | Franz | 128 | { |
68 | Franz | 129 | Mpressed = false; |
130 | dia->close(); |
||
131 | delete dia; |
||
188 | Franz | 132 | } |
68 | Franz | 133 | if (e->button() == LeftButton) |
134 | emit SelectChar(rowAt(e->pos().y()), columnAt(e->pos().x())); |
||
135 | } |
||
253 | Franz | 136 | |
666 | fschmid | 137 | ZAuswahl::ZAuswahl( QWidget* parent, PageItem *item, ScribusApp *pl) |
253 | Franz | 138 | : QDialog( parent, "ZAuswahl", true, 0 ) |
3 | paul | 139 | { |
253 | Franz | 140 | QString font; |
141 | if (pl->DLLinput != "") |
||
142 | font = pl->DLLinput; |
||
143 | else |
||
144 | font = pl->doc->CurrFont; |
||
145 | setCaption( tr( "Select Character:" )+" "+font ); |
||
146 | ite = item; |
||
147 | ap = pl; |
||
148 | setIcon(loadIcon("AppIcon.png")); |
||
149 | ZAuswahlLayout = new QVBoxLayout( this ); |
||
150 | ZAuswahlLayout->setSpacing( 6 ); |
||
151 | ZAuswahlLayout->setMargin( 11 ); |
||
3 | paul | 152 | |
253 | Franz | 153 | ZTabelle = new ChTable( this, pl); |
154 | ZTabelle->setNumCols( 32 ); |
||
155 | ZTabelle->setLeftMargin(0); |
||
156 | ZTabelle->verticalHeader()->hide(); |
||
157 | ZTabelle->setTopMargin(0); |
||
158 | ZTabelle->horizontalHeader()->hide(); |
||
159 | ZTabelle->setSorting(false); |
||
160 | ZTabelle->setSelectionMode(QTable::NoSelection); |
||
161 | ZTabelle->setColumnMovingEnabled(false); |
||
162 | ZTabelle->setRowMovingEnabled(false); |
||
188 | Franz | 163 | int counter = 1; |
164 | FT_Face face; |
||
165 | FT_ULong charcode; |
||
166 | FT_UInt gindex; |
||
253 | Franz | 167 | face = pl->doc->FFonts[font]; |
895 | fschmid | 168 | setBestEncoding(face); |
875 | fschmid | 169 | gindex = 0; |
188 | Franz | 170 | charcode = FT_Get_First_Char(face, &gindex ); |
171 | while (gindex != 0) |
||
172 | { |
||
173 | Zeich.append(charcode); |
||
174 | counter++; |
||
175 | charcode = FT_Get_Next_Char(face, charcode, &gindex ); |
||
176 | } |
||
177 | int ab = counter / 32; |
||
178 | int ac = counter % 32; |
||
179 | int cc = 0; |
||
180 | MaxCount = counter; |
||
181 | if (ac != 0) |
||
182 | ab++; |
||
183 | ZTabelle->setNumRows( ab ); |
||
326 | Franz | 184 | int bh = 16 + qRound(-(*pl->doc->AllFonts)[font]->numDescender * 16) + 3; |
253 | Franz | 185 | QPixmap pixm(bh,bh); |
186 | for (int a = 0; a < ab; ++a) |
||
187 | { |
||
188 | for (int b = 0; b < 32; ++b) |
||
189 | { |
||
326 | Franz | 190 | ScPainter *p = new ScPainter(&pixm, bh, bh); |
188 | Franz | 191 | p->clear(); |
192 | pixm.fill(white); |
||
193 | QWMatrix chma; |
||
326 | Franz | 194 | chma.scale(1.6, 1.6); |
253 | Franz | 195 | FPointArray gly = (*pl->doc->AllFonts)[font]->GlyphArray[Zeich[cc]].Outlines.copy(); |
196 | cc++; |
||
188 | Franz | 197 | if (gly.size() > 4) |
3 | paul | 198 | { |
188 | Franz | 199 | gly.map(chma); |
326 | Franz | 200 | double ww = bh - (*ap->doc->AllFonts)[font]->CharWidth[Zeich[cc]]*16; |
201 | p->translate(ww / 2, 1); |
||
188 | Franz | 202 | p->setBrush(black); |
203 | p->setFillMode(1); |
||
204 | p->setupPolygon(&gly); |
||
205 | p->fillPath(); |
||
3 | paul | 206 | } |
326 | Franz | 207 | p->end(); |
208 | delete p; |
||
188 | Franz | 209 | QTableItem *it = new QTableItem(ZTabelle, QTableItem::Never, "", pixm); |
210 | ZTabelle->setItem(a, b, it); |
||
253 | Franz | 211 | if (cc == counter) |
188 | Franz | 212 | break; |
253 | Franz | 213 | } |
214 | } |
||
215 | for (int d = 0; d < 32; ++d) |
||
326 | Franz | 216 | ZTabelle->adjustColumn(d); |
217 | for (int d = 0; d < ZTabelle->numRows(); ++d) |
||
218 | ZTabelle->adjustRow(d); |
||
188 | Franz | 219 | ZTabelle->setMinimumSize(QSize(ZTabelle->rowHeight(0)*33, ZTabelle->rowHeight(0)*7)); |
220 | ZAuswahlLayout->addWidget( ZTabelle ); |
||
221 | ZTabelle->MaxCount = MaxCount; |
||
3 | paul | 222 | |
253 | Franz | 223 | Zeichen = new QLabel( this, "Zeichen" ); |
1029 | subik | 224 | Zeichen->setFrameShape(QFrame::Box); |
225 | Zeichen->setPaletteBackgroundColor(paletteBackgroundColor()); |
||
253 | Franz | 226 | ZAuswahlLayout->addWidget( Zeichen ); |
3 | paul | 227 | |
188 | Franz | 228 | Layout1 = new QHBoxLayout; |
229 | Layout1->setSpacing( 6 ); |
||
230 | Layout1->setMargin( 0 ); |
||
231 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
||
232 | Layout1->addItem( spacer ); |
||
3 | paul | 233 | |
340 | Franz | 234 | Einf = new QPushButton(tr( "&Insert" ), this, "Einf" ); |
188 | Franz | 235 | Layout1->addWidget( Einf ); |
340 | Franz | 236 | Delete = new QPushButton(tr("C&lear"), this, "Delete" ); |
188 | Franz | 237 | Layout1->addWidget( Delete ); |
340 | Franz | 238 | Close = new QPushButton(tr("&Close"), this, "Close" ); |
188 | Franz | 239 | Layout1->addWidget( Close ); |
240 | ZAuswahlLayout->addLayout( Layout1 ); |
||
1029 | subik | 241 | Zeichen->setMaximumSize(width(), 52); |
242 | Zeichen->setMinimumSize(width(), 52); |
||
255 | Franz | 243 | DelEdit(); |
3 | paul | 244 | |
283 | Franz | 245 | //tooltips |
246 | QToolTip::add( Einf, tr( "Insert the characters at the cursor in the text" ) ); |
||
247 | QToolTip::add( Delete, tr( "Delete the current selection(s)." ) ); |
||
248 | QToolTip::add( Close, tr( "Close this dialog and return to text editing." ) ); |
||
249 | |||
250 | |||
188 | Franz | 251 | // signals and slots connections |
252 | connect(Close, SIGNAL(clicked()), this, SLOT(accept())); |
||
253 | connect(Delete, SIGNAL(clicked()), this, SLOT(DelEdit())); |
||
254 | connect(Einf, SIGNAL(clicked()), this, SLOT(InsChar())); |
||
255 | connect(ZTabelle, SIGNAL(SelectChar(int, int)), this, SLOT(NeuesZeichen(int, int))); |
||
3 | paul | 256 | } |
257 | |||
68 | Franz | 258 | void ZAuswahl::NeuesZeichen(int r, int c) // , int b, const QPoint &pp) |
3 | paul | 259 | { |
253 | Franz | 260 | QString font; |
261 | if (ap->DLLinput != "") |
||
262 | font = ap->DLLinput; |
||
263 | else |
||
264 | font = ap->doc->CurrFont; |
||
3 | paul | 265 | if ((r*32+c) < MaxCount) |
188 | Franz | 266 | { |
95 | Franz | 267 | ChToIns += QChar(Zeich[r*32+c]); |
253 | Franz | 268 | QString da = (*ap->doc->AllFonts)[font]->Datei; |
1084 | fschmid | 269 | Zeichen->setPixmap(FontSample(da, 28, ChToIns, paletteBackgroundColor(), true)); |
255 | Franz | 270 | Einf->setEnabled(true); |
188 | Franz | 271 | } |
3 | paul | 272 | } |
273 | |||
274 | void ZAuswahl::DelEdit() |
||
275 | { |
||
95 | Franz | 276 | ChToIns = ""; |
277 | QPixmap pm(1,28); |
||
278 | pm.fill(paletteBackgroundColor()); |
||
279 | Zeichen->setPixmap(pm); |
||
255 | Franz | 280 | Einf->setEnabled(false); |
3 | paul | 281 | } |
282 | |||
283 | void ZAuswahl::InsChar() |
||
284 | { |
||
253 | Franz | 285 | if (ap->DLLinput != "") |
286 | { |
||
255 | Franz | 287 | ap->DLLReturn += ChToIns; |
288 | DelEdit(); |
||
253 | Franz | 289 | return; |
290 | } |
||
3 | paul | 291 | struct Pti *hg; |
188 | Franz | 292 | for (uint a=0; a<ChToIns.length(); ++a) |
293 | { |
||
3 | paul | 294 | hg = new Pti; |
95 | Franz | 295 | hg->ch = ChToIns.at(a); |
253 | Franz | 296 | if (hg->ch == QChar(10)) |
188 | Franz | 297 | hg->ch = QChar(13); |
253 | Franz | 298 | if (hg->ch == QChar(9)) |
188 | Franz | 299 | hg->ch = " "; |
68 | Franz | 300 | hg->cfont = ap->doc->CurrFont; |
301 | hg->csize = ap->doc->CurrFontSize; |
||
302 | hg->ccolor = ap->doc->CurrTextFill; |
||
303 | hg->cshade = ap->doc->CurrTextFillSh; |
||
304 | hg->cstroke = ap->doc->CurrTextStroke; |
||
305 | hg->cshade2 = ap->doc->CurrTextStrokeSh; |
||
306 | hg->cscale = ap->doc->CurrTextScale; |
||
307 | hg->cselect = false; |
||
308 | hg->cstyle = ap->doc->CurrentStyle; |
||
309 | hg->cab = ap->doc->CurrentABStil; |
||
310 | if (ap->doc->Vorlagen[ap->doc->CurrentABStil].Font != "") |
||
188 | Franz | 311 | { |
68 | Franz | 312 | hg->cfont = ap->doc->Vorlagen[ap->doc->CurrentABStil].Font; |
313 | hg->csize = ap->doc->Vorlagen[ap->doc->CurrentABStil].FontSize; |
||
188 | Franz | 314 | } |
3 | paul | 315 | hg->cextra = 0; |
316 | hg->cselect = false; |
||
317 | hg->xp = 0; |
||
318 | hg->yp = 0; |
||
319 | hg->PRot = 0; |
||
320 | hg->PtransX = 0; |
||
321 | hg->PtransY = 0; |
||
322 | ite->Ptext.insert(ite->CPos, hg); |
||
253 | Franz | 323 | ite->CPos += 1; |
188 | Franz | 324 | } |
68 | Franz | 325 | ap->doc->ActPage->update(); |
3 | paul | 326 | ap->slotDocCh(); |
327 | } |