File indexing completed on 2025-07-13 04:09:58

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2005 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005 *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 
0013 
0014 #include "painter.h"
0015 
0016 namespace Kst {
0017 
0018 Painter::Painter(PaintType t)
0019 : QPainter(), _type(t), _drawInlineUI(false), _makingMask(false) {
0020 }
0021 
0022 
0023 Painter::~Painter() {
0024 }
0025 
0026 
0027 void Painter::setType(PaintType t) {
0028   _type = t;
0029 }
0030 
0031 
0032 Painter::PaintType Painter::type() const {
0033   return _type;
0034 }
0035 
0036 
0037 bool Painter::drawInlineUI() const {
0038   return _drawInlineUI;
0039 }
0040 
0041 
0042 void Painter::setDrawInlineUI(bool draw) {
0043   _drawInlineUI = draw;
0044 }
0045 
0046 
0047 bool Painter::makingMask() const {
0048   return _makingMask;
0049 }
0050 
0051 
0052 void Painter::setMakingMask(bool making) {
0053   _makingMask = making;
0054 }
0055 
0056 
0057 int Painter::lineWidthAdjustmentFactor() const {
0058   int factor = 1;
0059   
0060   if (type() == P_PRINT || type() == P_EXPORT) {
0061     const QRect& w(window());
0062     
0063     //
0064     // we want a line width of 1 to give a width of approximately 1 pt (where 1 pt = 1/72 
0065     //  inch) when printing on letter sized paper. Assuming a margin of 0.25 inch in one 
0066     //  direction (on both sides) and 0.5 inch in the other direction (again on both sides)
0067     //  and a printer resolution of 600 dpi:
0068     //
0069     //  w.width() + w.height() = ( 8 + 11 - ( 2 * 0.5 ) - ( 2 * 0.25 ) ) * 600 = 10500
0070     //
0071     //  we want a scale factor of 600/72 = 8.333 in the line width, so our magic number simply 
0072     //  becomes:
0073     //
0074     //  w.width() + w.height() / scale factor = 10200 / 8.333 ~ 1300
0075     //
0076     
0077     factor = (w.width() + w.height()) / 1300;
0078   }
0079   
0080   return factor > 0 ? factor : 1;
0081 }
0082 
0083 }
0084 // vim: ts=2 sw=2 et