• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • cups
imageposition.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "imageposition.h"
21 
22 #include <tqpainter.h>
23 #include <kstandarddirs.h>
24 
25 static void draw3DPage(TQPainter *p, TQRect r)
26 {
27  // draw white page
28  p->fillRect(r,Qt::white);
29  // draw 3D border
30  p->setPen(Qt::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(Qt::darkGray);
35  p->lineTo(r.left(),r.top());
36  p->lineTo(r.left(),r.bottom());
37  p->setPen(Qt::gray);
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);
41 }
42 
43 ImagePosition::ImagePosition(TQWidget *parent, const char *name)
44  : TQWidget(parent,name)
45 {
46  position_ = Center;
47  setMinimumSize(sizeHint());
48  setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding));
49  pix_.load(locate("data", "tdeprint/preview-mini.png"));
50 }
51 
52 ImagePosition::~ImagePosition()
53 {
54 }
55 
56 void ImagePosition::setPosition(const char *type)
57 {
58  int pos(Center);
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);
69 }
70 
71 void ImagePosition::setPosition(PositionType type)
72 {
73  if (position_ != type) {
74  position_ = type;
75  update();
76  }
77 }
78 
79 void ImagePosition::setPosition(int horiz, int vert)
80 {
81  int type = vert*3+horiz;
82  setPosition((PositionType)type);
83 }
84 
85 TQString ImagePosition::positionString() const
86 {
87  switch (position_) {
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";
97  }
98  return "center";
99 }
100 
101 void ImagePosition::paintEvent(TQPaintEvent*)
102 {
103  int horiz, vert, x, y;
104  int margin = 5;
105  int pw(width()), ph(height()), px(0), py(0);
106 
107  if (pw > ((ph * 3) / 4))
108  {
109  pw = (ph * 3) / 4;
110  px = (width() - pw) / 2;
111  }
112  else
113  {
114  ph = (pw * 4) / 3;
115  py = (height() - ph) / 2;
116  }
117  TQRect page(px, py, pw, ph), img(0, 0, pix_.width(), pix_.height());
118 
119  // compute img position
120  horiz = position_%3;
121  vert = position_/3;
122  switch (horiz) {
123  case 0: x = page.left()+margin; break;
124  default:
125  case 1: x = (page.left()+page.right()-img.width())/2; break;
126  case 2: x = page.right()-margin-img.width(); break;
127  }
128  switch (vert) {
129  case 0: y = page.top()+margin; break;
130  default:
131  case 1: y = (page.top()+page.bottom()-img.height())/2; break;
132  case 2: y = page.bottom()-margin-img.height(); break;
133  }
134  img.moveTopLeft(TQPoint(x,y));
135 
136  // draw page
137  TQPainter p(this);
138  draw3DPage(&p,page);
139 
140  // draw img
141  /*p.setPen(darkRed);
142  p.drawRect(img);
143  p.drawLine(img.topLeft(),img.bottomRight());
144  p.drawLine(img.topRight(),img.bottomLeft());*/
145  p.drawPixmap(x, y, pix_);
146 
147  p.end();
148 }
149 
150 TQSize ImagePosition::sizeHint() const
151 {
152  return TQSize(60, 80);
153 }

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.