1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "nsPrintSettingsQt.h"
11 #include "nsCRTGlue.h"
13 NS_IMPL_ISUPPORTS_INHERITED(nsPrintSettingsQt
,
17 nsPrintSettingsQt::nsPrintSettingsQt():
18 mQPrinter(new QPrinter())
22 nsPrintSettingsQt::~nsPrintSettingsQt()
24 //smart pointer should take care of cleanup
27 nsPrintSettingsQt::nsPrintSettingsQt(const nsPrintSettingsQt
& aPS
):
28 mQPrinter(aPS
.mQPrinter
)
33 nsPrintSettingsQt::operator=(const nsPrintSettingsQt
& rhs
)
39 nsPrintSettings::operator=(rhs
);
40 mQPrinter
= rhs
.mQPrinter
;
45 nsPrintSettingsQt::_Clone(nsIPrintSettings
** _retval
)
47 NS_ENSURE_ARG_POINTER(_retval
);
49 nsPrintSettingsQt
* newSettings
= new nsPrintSettingsQt(*this);
50 *_retval
= newSettings
;
56 nsPrintSettingsQt::_Assign(nsIPrintSettings
* aPS
)
58 nsPrintSettingsQt
* printSettingsQt
= static_cast<nsPrintSettingsQt
*>(aPS
);
60 return NS_ERROR_UNEXPECTED
;
61 *this = *printSettingsQt
;
66 nsPrintSettingsQt::GetPrintRange(int16_t* aPrintRange
)
68 NS_ENSURE_ARG_POINTER(aPrintRange
);
70 QPrinter::PrintRange range
= mQPrinter
->printRange();
71 if (range
== QPrinter::PageRange
) {
72 *aPrintRange
= kRangeSpecifiedPageRange
;
73 } else if (range
== QPrinter::Selection
) {
74 *aPrintRange
= kRangeSelection
;
76 *aPrintRange
= kRangeAllPages
;
83 nsPrintSettingsQt::SetPrintRange(int16_t aPrintRange
)
85 if (aPrintRange
== kRangeSelection
) {
86 mQPrinter
->setPrintRange(QPrinter::Selection
);
87 } else if (aPrintRange
== kRangeSpecifiedPageRange
) {
88 mQPrinter
->setPrintRange(QPrinter::PageRange
);
90 mQPrinter
->setPrintRange(QPrinter::AllPages
);
96 nsPrintSettingsQt::GetStartPageRange(int32_t* aStartPageRange
)
98 NS_ENSURE_ARG_POINTER(aStartPageRange
);
99 int32_t start
= mQPrinter
->fromPage();
100 *aStartPageRange
= start
;
105 nsPrintSettingsQt::SetStartPageRange(int32_t aStartPageRange
)
107 int32_t endRange
= mQPrinter
->toPage();
108 mQPrinter
->setFromTo(aStartPageRange
, endRange
);
113 nsPrintSettingsQt::GetEndPageRange(int32_t* aEndPageRange
)
115 NS_ENSURE_ARG_POINTER(aEndPageRange
);
116 int32_t end
= mQPrinter
->toPage();
117 *aEndPageRange
= end
;
122 nsPrintSettingsQt::SetEndPageRange(int32_t aEndPageRange
)
124 int32_t startRange
= mQPrinter
->fromPage();
125 mQPrinter
->setFromTo(startRange
, aEndPageRange
);
130 nsPrintSettingsQt::GetPrintReversed(bool* aPrintReversed
)
132 NS_ENSURE_ARG_POINTER(aPrintReversed
);
133 if (mQPrinter
->pageOrder() == QPrinter::LastPageFirst
) {
134 *aPrintReversed
= true;
136 *aPrintReversed
= false;
142 nsPrintSettingsQt::SetPrintReversed(bool aPrintReversed
)
144 if (aPrintReversed
) {
145 mQPrinter
->setPageOrder(QPrinter::LastPageFirst
);
147 mQPrinter
->setPageOrder(QPrinter::FirstPageFirst
);
153 nsPrintSettingsQt::GetPrintInColor(bool* aPrintInColor
)
155 NS_ENSURE_ARG_POINTER(aPrintInColor
);
156 if (mQPrinter
->colorMode() == QPrinter::Color
) {
157 *aPrintInColor
= true;
159 *aPrintInColor
= false;
164 nsPrintSettingsQt::SetPrintInColor(bool aPrintInColor
)
167 mQPrinter
->setColorMode(QPrinter::Color
);
169 mQPrinter
->setColorMode(QPrinter::GrayScale
);
175 nsPrintSettingsQt::GetOrientation(int32_t* aOrientation
)
177 NS_ENSURE_ARG_POINTER(aOrientation
);
178 QPrinter::Orientation orientation
= mQPrinter
->orientation();
179 if (orientation
== QPrinter::Landscape
) {
180 *aOrientation
= kLandscapeOrientation
;
182 *aOrientation
= kPortraitOrientation
;
188 nsPrintSettingsQt::SetOrientation(int32_t aOrientation
)
190 if (aOrientation
== kLandscapeOrientation
) {
191 mQPrinter
->setOrientation(QPrinter::Landscape
);
193 mQPrinter
->setOrientation(QPrinter::Portrait
);
199 nsPrintSettingsQt::GetToFileName(char16_t
** aToFileName
)
201 NS_ENSURE_ARG_POINTER(aToFileName
);
203 filename
= mQPrinter
->outputFileName();
204 *aToFileName
= ToNewUnicode(
205 nsDependentString((char16_t
*)filename
.data()));
210 nsPrintSettingsQt::SetToFileName(const char16_t
* aToFileName
)
212 nsCOMPtr
<nsIFile
> file
;
213 nsresult rv
= NS_NewLocalFile(nsDependentString(aToFileName
), true,
214 getter_AddRefs(file
));
215 NS_ENSURE_SUCCESS(rv
, rv
);
217 QString
filename((const QChar
*)aToFileName
, NS_strlen(aToFileName
));
218 mQPrinter
->setOutputFileName(filename
);
224 nsPrintSettingsQt::GetPrinterName(char16_t
** aPrinter
)
226 NS_ENSURE_ARG_POINTER(aPrinter
);
227 *aPrinter
= ToNewUnicode(nsDependentString(
228 (const char16_t
*)mQPrinter
->printerName().constData()));
233 nsPrintSettingsQt::SetPrinterName(const char16_t
* aPrinter
)
235 QString
printername((const QChar
*)aPrinter
, NS_strlen(aPrinter
));
236 mQPrinter
->setPrinterName(printername
);
241 nsPrintSettingsQt::GetNumCopies(int32_t* aNumCopies
)
243 NS_ENSURE_ARG_POINTER(aNumCopies
);
244 *aNumCopies
= mQPrinter
->numCopies();
249 nsPrintSettingsQt::SetNumCopies(int32_t aNumCopies
)
251 mQPrinter
->setNumCopies(aNumCopies
);
256 nsPrintSettingsQt::GetScaling(double* aScaling
)
258 NS_ENSURE_ARG_POINTER(aScaling
);
259 qDebug()<<Q_FUNC_INFO
;
260 qDebug()<<"Scaling not implemented in Qt port";
261 *aScaling
= 1.0; //FIXME
262 return NS_ERROR_NOT_IMPLEMENTED
;
266 nsPrintSettingsQt::SetScaling(double aScaling
)
268 qDebug()<<Q_FUNC_INFO
;
269 qDebug()<<"Scaling not implemented in Qt port"; //FIXME
270 return NS_ERROR_NOT_IMPLEMENTED
;
273 static const char* const indexToPaperName
[] =
274 { "A4", "B5", "Letter", "Legal", "Executive",
275 "A0", "A1", "A2", "A3", "A5", "A6", "A7", "A8", "A9",
276 "B0", "B1", "B10", "B2", "B3", "B4", "B6", "B7", "B8", "B9",
277 "C5E", "Comm10E", "DLE", "Folio", "Ledger", "Tabloid"
280 static const QPrinter::PageSize indexToQtPaperEnum
[] =
282 QPrinter::A4
, QPrinter::B5
, QPrinter::Letter
, QPrinter::Legal
,
283 QPrinter::Executive
, QPrinter::A0
, QPrinter::A1
, QPrinter::A2
, QPrinter::A3
,
284 QPrinter::A5
, QPrinter::A6
, QPrinter::A7
, QPrinter::A8
, QPrinter::A9
,
285 QPrinter::B0
, QPrinter::B1
, QPrinter::B10
, QPrinter::B2
, QPrinter::B3
,
286 QPrinter::B4
, QPrinter::B6
, QPrinter::B7
, QPrinter::B8
, QPrinter::B9
,
287 QPrinter::C5E
, QPrinter::Comm10E
, QPrinter::DLE
, QPrinter::Folio
,
288 QPrinter::Ledger
, QPrinter::Tabloid
292 nsPrintSettingsQt::GetPaperName(char16_t
** aPaperName
)
294 QPrinter::PaperSize size
= mQPrinter
->paperSize();
295 QString
name(indexToPaperName
[size
]);
296 *aPaperName
= ToNewUnicode(nsDependentString((const char16_t
*)name
.constData()));
301 nsPrintSettingsQt::SetPaperName(const char16_t
* aPaperName
)
303 QString
ref((QChar
*)aPaperName
, NS_strlen(aPaperName
));
304 for (uint32_t i
= 0; i
< sizeof(indexToPaperName
)/sizeof(char*); i
++)
306 if (ref
== QString(indexToPaperName
[i
])) {
307 mQPrinter
->setPageSize(indexToQtPaperEnum
[i
]);
311 return NS_ERROR_FAILURE
;
314 QPrinter::Unit
GetQtUnit(int16_t aGeckoUnit
)
316 if (aGeckoUnit
== nsIPrintSettings::kPaperSizeMillimeters
) {
317 return QPrinter::Millimeter
;
319 return QPrinter::Inch
;
323 #define SETUNWRITEABLEMARGIN\
324 mQPrinter->setPageMargins(\
325 NS_TWIPS_TO_INCHES(mUnwriteableMargin.left),\
326 NS_TWIPS_TO_INCHES(mUnwriteableMargin.top),\
327 NS_TWIPS_TO_INCHES(mUnwriteableMargin.right),\
328 NS_TWIPS_TO_INCHES(mUnwriteableMargin.bottom),\
332 nsPrintSettingsQt::SetUnwriteableMarginInTwips(nsIntMargin
& aUnwriteableMargin
)
334 nsPrintSettings::SetUnwriteableMarginInTwips(aUnwriteableMargin
);
340 nsPrintSettingsQt::SetUnwriteableMarginTop(double aUnwriteableMarginTop
)
342 nsPrintSettings::SetUnwriteableMarginTop(aUnwriteableMarginTop
);
348 nsPrintSettingsQt::SetUnwriteableMarginLeft(double aUnwriteableMarginLeft
)
350 nsPrintSettings::SetUnwriteableMarginLeft(aUnwriteableMarginLeft
);
356 nsPrintSettingsQt::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom
)
358 nsPrintSettings::SetUnwriteableMarginBottom(aUnwriteableMarginBottom
);
364 nsPrintSettingsQt::SetUnwriteableMarginRight(double aUnwriteableMarginRight
)
366 nsPrintSettings::SetUnwriteableMarginRight(aUnwriteableMarginRight
);
372 nsPrintSettingsQt::GetPaperWidth(double* aPaperWidth
)
374 NS_ENSURE_ARG_POINTER(aPaperWidth
);
375 QSizeF papersize
= mQPrinter
->paperSize(GetQtUnit(mPaperSizeUnit
));
376 *aPaperWidth
= papersize
.width();
381 nsPrintSettingsQt::SetPaperWidth(double aPaperWidth
)
383 QSizeF papersize
= mQPrinter
->paperSize(GetQtUnit(mPaperSizeUnit
));
384 papersize
.setWidth(aPaperWidth
);
385 mQPrinter
->setPaperSize(papersize
, GetQtUnit(mPaperSizeUnit
));
390 nsPrintSettingsQt::GetPaperHeight(double* aPaperHeight
)
392 NS_ENSURE_ARG_POINTER(aPaperHeight
);
393 QSizeF papersize
= mQPrinter
->paperSize(GetQtUnit(mPaperSizeUnit
));
394 *aPaperHeight
= papersize
.height();
399 nsPrintSettingsQt::SetPaperHeight(double aPaperHeight
)
401 QSizeF papersize
= mQPrinter
->paperSize(GetQtUnit(mPaperSizeUnit
));
402 papersize
.setHeight(aPaperHeight
);
403 mQPrinter
->setPaperSize(papersize
, GetQtUnit(mPaperSizeUnit
));
408 nsPrintSettingsQt::SetPaperSizeUnit(int16_t aPaperSizeUnit
)
410 mPaperSizeUnit
= aPaperSizeUnit
;
415 nsPrintSettingsQt::GetEffectivePageSize(double* aWidth
, double* aHeight
)
417 QSizeF papersize
= mQPrinter
->paperSize(QPrinter::Inch
);
418 if (mQPrinter
->orientation() == QPrinter::Landscape
) {
419 *aWidth
= NS_INCHES_TO_INT_TWIPS(papersize
.height());
420 *aHeight
= NS_INCHES_TO_INT_TWIPS(papersize
.width());
422 *aWidth
= NS_INCHES_TO_INT_TWIPS(papersize
.width());
423 *aHeight
= NS_INCHES_TO_INT_TWIPS(papersize
.height());