summaryrefslogtreecommitdiffstats
path: root/styles/phase2/shapes.h
diff options
context:
space:
mode:
Diffstat (limited to 'styles/phase2/shapes.h')
-rw-r--r--styles/phase2/shapes.h400
1 files changed, 400 insertions, 0 deletions
diff --git a/styles/phase2/shapes.h b/styles/phase2/shapes.h
new file mode 100644
index 00000000..b7715564
--- /dev/null
+++ b/styles/phase2/shapes.h
@@ -0,0 +1,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