summaryrefslogtreecommitdiffstats
path: root/styles/phase2/shapes.h
blob: b771556478f5f0b364c47aa75d90364c6b51c587 (plain)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#ifndef __SHAPES_H__
#define __SHAPES_H__

#include <tdestyle.h>
#include <tqcolor.h>
#include <tqimage.h>
#include "bitmaps.h"

/*
  Symbols supported by Liberation Sans:

  0x2713 - Unicode checkmark - regular
  0x2714 - Unicode checkmark = bold

  0x2206 - Unicode math operator triangle "up"
  0x2207 - Unicode math operator triangle "down"

  0x25B2 - Unicode geometric shape triangle solid "up"
  0x25BA - Unicode geometric shape triangle solid "right"
  0x25BC - Unicode geometric shape triangle solid "down"

  Symbols NOT   supported by Liberation Sans:

  0x22B2 - Unicode mathematical operator triangle "left"
  0x22B3 - Unicode mathematical operator triangle "right"

  0x25C2 - Unicode geometric shape solid "left" triangle
*/

//--- Checkmark unicode characters

#define UNICODE_CHECKMARK_REGULAR    0x2713
#define UNICODE_CHECKMARK_BOLD       0x2714
#define UNICODE_CHECKMARK_BALLOT_BOX 0x2611

static  TQChar Checkmark     = 0 ;

//--- Arrow unicode characters

#define UNICODE_TRIANGLE_OTHER       0x25BC

//--- Arrow sizes (drawn)

static int ARROW_Size1       = 16 ; // FONT_size / 2
static int ARROW_Size2       =  8 ; // FONT_size / 2
static int ARROW_Size3       =  6 ; // FONT_size / 3, made even
static int ARROW_Size4       =  4 ; // FONT_size / 4
static int ARROW_Size4x3     = 12 ; // FONT_size * (3/4)

//--- Arrow images (pre-drawn)

static TQPixmap * KPE_ListViewExpander_ArrowLeft  = 0 ;
static TQPixmap * KPE_ListViewExpander_ArrowRight = 0 ;
static TQImage * iKPE_ListViewExpander_ArrowLeft  = 0 ;
static TQImage * iKPE_ListViewExpander_ArrowRight = 0 ;

//------------------------------------------------------------------------------
//    Initialization
//------------------------------------------------------------------------------

void
Initialize_Shapes()
{
  //--- Determine checkmark

  TQChar checkmark = UNICODE_CHECKMARK_BOLD ;
  if (! CurrentFontMetrics.inFont( checkmark ) )
    checkmark = 'x' ;
  Checkmark = checkmark ;

  //--- Determine drawn arrow sizes, in terms of fractions of FONT_size

  ARROW_Size1   = FONT_Size ; if (ARROW_Size1 % 2 != 0) ARROW_Size1++ ;
  ARROW_Size1   = FONT_Size       + FONT_Size   % 2 ;
  ARROW_Size2   = ARROW_Size1 / 2 ;
  ARROW_Size3   = ARROW_Size1 / 3 + ARROW_Size1 % 3 ;
  ARROW_Size4   = ARROW_Size1 / 4 + ARROW_Size1 % 4 ;
  ARROW_Size4x3 = ARROW_Size4 * 3 ;

  //--- Create bitmaps used in legacy code:

  uarrow = TQBitmap(6, 6, uarrow_bits, true);
  uarrow.setMask(uarrow);
  darrow = TQBitmap(6, 6, darrow_bits, true);
  darrow.setMask(darrow);
  larrow = TQBitmap(6, 6, larrow_bits, true);
  larrow.setMask(larrow);
  rarrow = TQBitmap(6, 6, rarrow_bits, true);
  rarrow.setMask(rarrow);
  bplus = TQBitmap(6, 6, bplus_bits, true);
  bplus.setMask(bplus);
  bminus = TQBitmap(6, 6, bminus_bits, true);
  bminus.setMask(bminus);
  bcheck = TQBitmap(9, 9, bcheck_bits, true);
  bcheck.setMask(bcheck);
  dexpand = TQBitmap(9, 9, dexpand_bits, true);
  dexpand.setMask(dexpand);
  rexpand = TQBitmap(9, 9, rexpand_bits, true);
  rexpand.setMask(rexpand);
  doodad_mid = TQBitmap(4, 4, doodad_mid_bits, true);
  doodad_light = TQBitmap(4, 4, doodad_light_bits, true);
}

//------------------------------------------------------------------------------
//    Low-level image drawing functions
//------------------------------------------------------------------------------

//--- Taken from Highcontrast style:

void
addOffset(
  TQRect* r,
  int     offset,
  int     lineWidth = 0
)
{
  int offset1 = offset;
  int offset2 = offset;

  *r = r->normalize();

  if (lineWidth > 0)
  {
    offset1 += lineWidth/2;
    offset2 += lineWidth - lineWidth/2 - 1;
  }

  if (offset1 + offset2 > r->width())
    r->addCoords (r->width()/2, 0, - (r->width() - r->width()/2), 0);
  else
    r->addCoords (offset1, 0, -offset2, 0);

  if (offset1 + offset2 > r->height())
    r->addCoords (0, r->height()/2, 0, - (r->height() - r->height()/2));
  else
    r->addCoords (0, offset1, 0, -offset2);
}

//------------------------------------------------------------------------------

void
Phase2Style::drawRect(
  TQPainter* p,
  TQRect     r,
  int  offset,
  bool       filled
) const
{
  addOffset (&r, offset, p->pen().width());
  if (filled)
    p->fillRect (r, p->backgroundColor());

  p->drawRect (r);
}

void
Phase2Style::drawRoundRect(
  TQPainter* p,
  TQRect     r,
  int  offset,
  bool       filled
) const
{
  int lineWidth = p->pen().width();
  if ((r.width() >= 5*lineWidth + 2*offset) && (r.height() >= 5*lineWidth + 2*offset))
  {
    TQRect r2 (r);
    addOffset (&r2, offset, lineWidth);

    addOffset (&r, offset);
    TQRect r3 (r);
    addOffset (&r3, lineWidth);

    p->save();
    p->setPen (Qt::NoPen);
    if (filled)
      p->fillRect (r3, p->backgroundColor());
    p->drawRect (r3);
    p->restore();

    p->drawLine (r.left()+lineWidth, r2.top(), r.right()+1-lineWidth, r2.top());
    p->fillRect (r.left()+1, r.top()+1, lineWidth, lineWidth, p->pen().color());
    p->drawLine (r2.left(), r.top()+lineWidth, r2.left(), r.bottom()+1-lineWidth);
    p->fillRect (r.left()+1, r.bottom()-lineWidth, lineWidth, lineWidth, p->pen().color());
    p->drawLine (r.left()+lineWidth, r2.bottom(), r.right()+1-lineWidth, r2.bottom());
    p->fillRect (r.right()-lineWidth, r.bottom()-lineWidth, lineWidth, lineWidth, p->pen().color());
    p->drawLine (r2.right(), r.top()+lineWidth, r2.right(), r.bottom()+1-lineWidth);
    p->fillRect (r.right()-lineWidth, r.top()+1, lineWidth, lineWidth, p->pen().color());
  }
  else
    drawRect (p, r, offset, filled);
}

void
Phase2Style::drawEllipse(
  TQPainter* p,
  TQRect     r,
  int  offset,
  bool       filled
) const
{
  addOffset (&r, offset, p->pen().width());

  if (filled) {
    p->save();
    p->setBrush (p->backgroundColor());
    p->drawRoundRect (r, 99, 99);
    p->restore();
  }

  p->drawRoundRect (r, 99, 99);
}

//------------------------------------------------------------------------------

void
Phase2Style::drawArrow(
  TQPainter*    p,
  TQRect        r,
  TQ_PrimitiveElement arrow,
  int offset
) const
{
  p->save();
  addOffset (&r, offset);

  TQPoint center = r.center();
  if (r.height() < r.width())
    r.setWidth (r.height());
  if (r.width() % 2 != 0)
    r.setWidth (r.width() - 1);
  r.setHeight (r.width());
  r.moveCenter (center);

  TQPointArray points (3);
  switch (arrow) {
    case PE_ArrowUp:
    case PE_SpinWidgetUp:
    case PE_SpinWidgetPlus: {
      points.setPoint (0, r.bottomLeft());
      points.setPoint (1, r.bottomRight());
      points.setPoint (2, r.center().x(), r.top() + r.height()/7);
      break;
    }
    case PE_ArrowDown:
    case PE_SpinWidgetDown:
    case PE_SpinWidgetMinus: {
      points.setPoint (0, r.topLeft());
      points.setPoint (1, r.topRight());
      points.setPoint (2, r.center().x(), r.bottom() - r.height()/7);
      break;
    }
    case PE_ArrowLeft: {
      points.setPoint (0, r.topRight());
      points.setPoint (1, r.bottomRight());
      points.setPoint (2, r.left() + r.width()/7, r.center().y());
      break;
    }
    default: {
      points.setPoint (0, r.topLeft());
      points.setPoint (1, r.bottomLeft());
      points.setPoint (2, r.right() - r.width()/7, r.center().y());
    }
  }

  p->setPen (p->pen().color());
  p->setBrush (p->pen().color());
  p->drawPolygon (points);
  p->restore();
}

/*
 *  Called from phasestyle.cpp:
 *    drawPrimitive()
 *      PE_HeaderArrow    ARROW_Size2   (scaling =  0)
 *      PE_ScrollBar(Add,Sub)Line     ARROW_Size2   (scaling =  0)
 *      PE_SpinWidget(Up,Down)  ARROW_Size2   (scaling =  1)
 *      PE_Arrow(Up,Down,Left,Right)  ARROW_Size4   (scaling = -1)
 *    drawTDEStylePrimitive()
 *      KPE_ListViewExpander    ARROW_Size2   (scaling =  1)
 *    drawControl()
 *      CE_PopupMenuItem        ARROW_Size2 (offset=0)
 *      CE_PushButtonLabel drawArrow called directly, offset 3 # FIXME
 *
 */

//------------------------------------------------------------------------------


//--- Taken from legacy code:

void
Phase2Style::drawArrowBitmap(
  TQPainter*    painter,
  TQRect        rect,
  TQ_PrimitiveElement arrow
) const
{
  int x, y, w, h, x2, y2 ;
  rect.rect(&x, &y, &w, &h)   ;

  TQBitmap arrowBitmap ;
  switch (arrow) {
    case PE_ArrowUp:    { arrowBitmap = uarrow ; break ; }
    case PE_ArrowDown:  { arrowBitmap = darrow ; break ; }
    case PE_ArrowLeft:  { arrowBitmap = larrow ; break ; }
    case PE_ArrowRight: { arrowBitmap = rarrow ; break ; }
  }

  painter->drawPixmap(x+w/2-3, y+h/2-3, arrowBitmap);
}

//--- New code:

void
Phase2Style::drawCheckmark(
  TQPainter* p,
  TQRect     r,
  int        offset
) const
{
  p->save();
  p->setPen( p->pen().black );

  if ( ! Checkmark.isNull() )
    //--- "Draw" the unicode checkmark character
    p->drawText( r, TQt::AlignCenter, Checkmark );

  else {

    //--- Draw a crude-looking checkmark

    p->setPen( p->pen().SolidLine );

    TQPen pen = p->pen();
    pen.setWidth( 2 );
    p->setPen( pen );

    addOffset (&r, 2);

    TQPoint center = r.center();
    if (r.height() < r.width())
      r.setWidth (r.height());
    if (r.width() % 2 != 0)
      r.setWidth (r.width() - 1);
    r.setHeight (r.width());

    TQPointArray points (3);
    points.setPoint (0, r.topRight());
    points.setPoint (1, r.center().x(), r.bottom() - r.height()/7);
    points.setPoint (2, r.left() + r.width()/7, r.center().y());

    p->drawPolyline (points);
  }

  p->restore();
}

//------------------------------------------------------------------------------
//    Image generation functions
//------------------------------------------------------------------------------

TQPixmap *
Phase2Style::Create_Arrow_Pix(
  TQ_PrimitiveElement shape,
  int     size,
  int     scaling
) const
{
  TQRect     frame = TQRect(0, 0, size, size) ;
  TQPainter  canvas ;
  TQPixmap * picture = new TQPixmap(size, size, 1) ;
  canvas.begin(picture) ;
  canvas.fillRect(frame, color0) ;
  drawArrow( &canvas, frame, shape, scaling ) ;
  canvas.end() ;

  // TQImage image = picture->convertToImage() ;

  // TQImage * image = new TQImage() ;
  // *image = picture->convertToImage() ;

  return picture;
}

TQImage *
Phase2Style::Create_Arrow_Image(
  TQ_PrimitiveElement shape,
  int     size,
  int     scaling
) const
{
  TQPixmap * pixmap = Create_Arrow_Pix( shape, size, scaling) ;
  if (! pixmap ) return NULL ;
  TQImage  * image  = new TQImage()  ;
  *image = pixmap->convertToImage() ;
  return image ;
}

#endif