20 #include "imageposition.h"
22 #include <tqpainter.h>
23 #include <kstandarddirs.h>
25 static void draw3DPage(TQPainter *p, TQRect r)
28 p->fillRect(r,TQt::white);
30 p->setPen(TQt::black);
31 p->moveTo(r.left(),r.bottom());
32 p->lineTo(r.right(),r.bottom());
33 p->lineTo(r.right(),r.top());
34 p->setPen(TQt::darkGray);
35 p->lineTo(r.left(),r.top());
36 p->lineTo(r.left(),r.bottom());
38 p->moveTo(r.left()+1,r.bottom()-1);
39 p->lineTo(r.right()-1,r.bottom()-1);
40 p->lineTo(r.right()-1,r.top()+1);
43 ImagePosition::ImagePosition(TQWidget *parent,
const char *name)
44 : TQWidget(parent,name)
47 setMinimumSize(sizeHint());
48 setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding));
49 pix_.load(locate(
"data",
"tdeprint/preview-mini.png"));
52 ImagePosition::~ImagePosition()
56 void ImagePosition::setPosition(
const char *type)
59 if (strcmp(type,
"top-left") == 0) pos = TopLeft;
60 else if (strcmp(type,
"top") == 0) pos = Top;
61 else if (strcmp(type,
"top-right") == 0) pos = TopRight;
62 else if (strcmp(type,
"left") == 0) pos = Left;
63 else if (strcmp(type,
"center") == 0) pos = Center;
64 else if (strcmp(type,
"right") == 0) pos = Right;
65 else if (strcmp(type,
"bottom-left") == 0) pos = BottomLeft;
66 else if (strcmp(type,
"bottom") == 0) pos = Bottom;
67 else if (strcmp(type,
"bottom-right") == 0) pos = BottomRight;
68 setPosition((PositionType)pos);
71 void ImagePosition::setPosition(PositionType type)
73 if (position_ != type) {
79 void ImagePosition::setPosition(
int horiz,
int vert)
81 int type = vert*3+horiz;
82 setPosition((PositionType)type);
85 TQString ImagePosition::positionString()
const
88 case TopLeft:
return "top-left";
89 case Top:
return "top";
90 case TopRight:
return "top-right";
91 case Left:
return "left";
92 case Center:
return "center";
93 case Right:
return "right";
94 case BottomLeft:
return "bottom-left";
95 case Bottom:
return "bottom";
96 case BottomRight:
return "bottom-right";
101 void ImagePosition::paintEvent(TQPaintEvent*)
103 int horiz, vert, x, y;
105 int pw(width()), ph(height()), px(0), py(0);
107 if (pw > ((ph * 3) / 4))
110 px = (width() - pw) / 2;
115 py = (height() - ph) / 2;
117 TQRect page(px, py, pw, ph), img(0, 0, pix_.width(), pix_.height());
123 case 0: x = page.left()+margin;
break;
125 case 1: x = (page.left()+page.right()-img.width())/2;
break;
126 case 2: x = page.right()-margin-img.width();
break;
129 case 0: y = page.top()+margin;
break;
131 case 1: y = (page.top()+page.bottom()-img.height())/2;
break;
132 case 2: y = page.bottom()-margin-img.height();
break;
134 img.moveTopLeft(TQPoint(x,y));
145 p.drawPixmap(x, y, pix_);
150 TQSize ImagePosition::sizeHint()
const
152 return TQSize(60, 80);