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

tdeprint

  • tdeprint
kpmarginpage.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4 *
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License version 2 as published by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 **/
20
21#include <config.h>
22
23#include "kpmarginpage.h"
24#include "kprinter.h"
25#include "driver.h"
26#include "marginwidget.h"
27
28#include <tqgroupbox.h>
29#include <tqlayout.h>
30#include <tqprinter.h>
31#include <tqpaintdevicemetrics.h>
32
33#include <kiconloader.h>
34#include <tdelocale.h>
35#include <kdebug.h>
36#include <tdeglobal.h>
37
38KPMarginPage::KPMarginPage(KPrinter *prt, DrMain *driver, TQWidget *parent, const char *name)
39: KPrintDialogPage(0, driver, parent, name)
40{
41 m_printer = prt;
42 setTitle(i18n("Margins"));
43 m_usedriver = true;
44
45 TQGroupBox *box = new TQGroupBox(1, TQt::Vertical, i18n("Margins"), this);
46 m_margin = new MarginWidget(box, "MarginWidget", (m_printer != 0));
47 //m_margin->setSymetricMargins(true);
48 //if (m_printer)
49 // m_margin->setResolution(m_printer->resolution());
50
51 TQVBoxLayout *l0 = new TQVBoxLayout(this, 0, 10);
52 l0->addWidget(box);
53 l0->addStretch(1);
54}
55
56KPMarginPage::~KPMarginPage()
57{
58}
59
60void KPMarginPage::initPageSize(const TQString& ps, bool landscape)
61{
62 // first retrieve the Qt values for page size and margins
63 TQPrinter prt(TQPrinter::PrinterResolution);
64 prt.setFullPage(true);
65 prt.setPageSize((TQPrinter::PageSize)(ps.isEmpty() ? TDEGlobal::locale()->pageSize() : ps.toInt()));
66 TQPaintDeviceMetrics metrics(&prt);
67 float w = metrics.width();
68 float h = metrics.height();
69 unsigned int it, il, ib, ir;
70 prt.margins( &it, &il, &ib, &ir );
71 float mt = it;
72 float ml = il;
73 float mb = ib;
74 float mr = ir;
75
76 if (driver() && m_usedriver )
77 {
78 TQString pageSize(ps);
79
80 if (pageSize.isEmpty())
81 {
82 DrListOption *o = (DrListOption*)driver()->findOption("PageSize");
83 if (o)
84 pageSize = o->get("default");
85 }
86 if (!pageSize.isEmpty())
87 {
88 DrPageSize *dps = driver()->findPageSize(pageSize);
89 if (dps)
90 {
91 w = dps->pageWidth();
92 h = dps->pageHeight();
93 mt = TQMAX( mt, dps->topMargin() );
94 ml = TQMAX( ml, dps->leftMargin() );
95 mb = TQMAX( mb, dps->bottomMargin() );
96 mr = TQMAX( mr, dps->rightMargin() );
97 }
98 }
99 }
100 m_margin->setPageSize(w, h);
101 m_margin->setOrientation(landscape ? KPrinter::Landscape : KPrinter::Portrait);
102 m_margin->setDefaultMargins( mt, mb, ml, mr );
103 m_margin->setCustomEnabled(false);
104}
105
106void KPMarginPage::setOptions(const TQMap<TQString,TQString>& opts)
107{
108 TQString orient = opts["orientation-requested"];
109 bool land = (orient.isEmpty()? opts["kde-orientation"] == "Landscape" : orient == "4" || orient == "5");
110 TQString ps = opts[ "kde-printsize" ];
111 if ( ps.isEmpty() )
112 {
113 m_usedriver = true;
114 ps = opts[ "PageSize" ];
115 if (ps.isEmpty())
116 ps = opts["kde-pagesize"];
117 }
118 else
119 m_usedriver = false;
120 initPageSize(ps, land);
121
122 bool marginset(false);
123 TQString value;
124 if (!(value=opts["kde-margin-top"]).isEmpty() && value.toFloat() != m_margin->top())
125 {
126 marginset = true;
127 m_margin->setTop(value.toFloat());
128 }
129 if (!(value=opts["kde-margin-left"]).isEmpty() && value.toFloat() != m_margin->left())
130 {
131 marginset = true;
132 m_margin->setLeft(value.toFloat());
133 }
134 if (!(value=opts["kde-margin-bottom"]).isEmpty() && value.toFloat() != m_margin->bottom())
135 {
136 marginset = true;
137 m_margin->setBottom(value.toFloat());
138 }
139 if (!(value=opts["kde-margin-right"]).isEmpty() && value.toFloat() != m_margin->right())
140 {
141 marginset = true;
142 m_margin->setRight(value.toFloat());
143 }
144 m_margin->setCustomEnabled(marginset);
145}
146
147void KPMarginPage::getOptions(TQMap<TQString,TQString>& opts, bool /* incldef */)
148{
149 if (m_margin->isCustomEnabled() /*|| incldef*/)
150 {
151 opts["kde-margin-top"] = TQString::number(m_margin->top());
152 opts["kde-margin-left"] = TQString::number(m_margin->left());
153 opts["kde-margin-bottom"] = TQString::number(m_margin->bottom());
154 opts["kde-margin-right"] = TQString::number(m_margin->right());
155 }
156 else
157 {
158 opts.remove("kde-margin-top");
159 opts.remove("kde-margin-left");
160 opts.remove("kde-margin-bottom");
161 opts.remove("kde-margin-right");
162 }
163}
KPrintDialogPage
This class is intended to be used as base class for customized print dialog page.
Definition: kprintdialogpage.h:91
KPrinter
This class is the main interface to access the TDE print framework.
Definition: kprinter.h:89
KPrinter::setFullPage
void setFullPage(bool)
See TQPrinter::setFullPage().
Definition: kprinter.cpp:812
KPrinter::setPageSize
void setPageSize(PageSize, bool locking=false)
See TQPrinter::setPageSize().
Definition: kprinter.cpp:618
KPrinter::margins
TQSize margins() const
See TQPrinter::margins().
Definition: kprinter.cpp:550

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.4
This website is maintained by Timothy Pearson.