00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "marginwidget.h"
00021 #include "marginpreview.h"
00022 #include "marginvaluewidget.h"
00023 #include "kprinter.h"
00024
00025 #include <qcombobox.h>
00026 #include <qcheckbox.h>
00027 #include <qlayout.h>
00028 #include <qlabel.h>
00029 #include <qwhatsthis.h>
00030 #include <klocale.h>
00031 #include <kglobal.h>
00032
00033 MarginWidget::MarginWidget(QWidget *parent, const char* name, bool allowMetricUnit)
00034 : QWidget(parent, name), m_default(4, 0), m_pagesize( 2 )
00035 {
00036
00037 QString whatsThisTopMarginWidget = i18n( " <qt> "
00038 " <p><b>Top Margin</b></p>. "
00039 " <p>This spinbox/text edit field lets you control the top margin of your printout if the printing "
00040 " application does not define its margins internally. </p> "
00041 " <p>The setting works for instance for ASCII text file printing, or for printing from KMail and "
00042 " and Konqueror.. </p>"
00043 " <p><b>Note:</b></p>This margin setting is not intended for KOffice or OpenOffice.org printing, "
00044 " because these applications (or rather their users) are expected to do it by themselves. "
00045 " It also does not work for PostScript or PDF file, which in most cases have their margins hardcoded "
00046 " internally.</p> "
00047 " <br> "
00048 " <hr> "
00049 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00050 " with the CUPS commandline job option parameter:</em> "
00051 " <pre>"
00052 " -o page-top=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
00053 " </pre>"
00054 " </p> "
00055 " </qt>" );
00056
00057 QString whatsThisBottomMarginWidget = i18n( " <qt> "
00058 " <p><b>Bottom Margin</b></p>. "
00059 " <p>This spinbox/text edit field lets you control the bottom margin of your printout if the printing "
00060 " application does not define its margins internally. </p> "
00061 " <p>The setting works for instance for ASCII text file printing, or for printing from KMail and "
00062 " and Konqueror. </p>"
00063 " <p><b>Note:</b></p>This margin setting is not intended for KOffice or OpenOffice.org printing, "
00064 " because these applications (or rather their users) are expected to do it by themselves. "
00065 " It also does not work for PostScript or PDF file, which in most cases have their margins hardcoded "
00066 " internally.</p> "
00067 " <br> "
00068 " <hr> "
00069 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00070 " with the CUPS commandline job option parameter:</em> "
00071 " <pre>"
00072 " -o page-bottom=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
00073 " </pre>"
00074 " </qt>" );
00075
00076 QString whatsThisLeftMarginWidget = i18n( " <qt> "
00077 " <p><b>Left Margin</b></p>. "
00078 " <p>This spinbox/text edit field lets you control the left margin of your printout if the printing "
00079 " application does not define its margins internally. </p> "
00080 " <p>The setting works for instance for ASCII text file printing, or for printing from KMail and "
00081 " and Konqueror. </p>"
00082 " <p><b>Note:</b></p>This margin setting is not intended for KOffice or OpenOffice.org printing, "
00083 " because these applications (or rather their users) are expected to do it by themselves. "
00084 " It also does not work for PostScript or PDF file, which in most cases have their margins hardcoded "
00085 " internally.</p> "
00086 " <br> "
00087 " <hr> "
00088 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00089 " with the CUPS commandline job option parameter:</em> "
00090 " <pre>"
00091 " -o page-left=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
00092 " </pre>"
00093 " </qt>" );
00094
00095 QString whatsThisRightMarginWidget = i18n( " <qt> "
00096 " <p><b>Right Margin</b></p>. "
00097 " <p>This spinbox/text edit field lets you control the right margin of your printout if the printing "
00098 " application does not define its margins internally. </p> "
00099 " <p>The setting works for instance for ASCII text file printing, or for printing from KMail and "
00100 " and Konqueror. </p>"
00101 " <p><b>Note:</b></p>This margin setting is not intended for KOffice or OpenOffice.org printing, "
00102 " because these applications (or rather their users) are expected to do it by themselves. "
00103 " It also does not work for PostScript or PDF file, which in most cases have their margins hardcoded "
00104 " internally.</p> "
00105 " <br> "
00106 " <hr> "
00107 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00108 " with the CUPS commandline job option parameter:</em> "
00109 " <pre>"
00110 " -o page-right=... # use values from \"0\" or higher. \"72\" is equal to 1 inch. "
00111 " </pre>"
00112 " </qt>" );
00113
00114 QString whatsThisMeasurementUnitMarginWidget = i18n( " <qt> "
00115 " <p><b>Change Measurement Unit<b></p>. "
00116 " <p>You can change the units of measurement for the page"
00117 " margins here. Select from Millimeter, Centimeter, Inch or Pixels (1 pixel == 1/72 inch). "
00118 " </p> "
00119 " </qt>" );
00120
00121 QString whatsThisCheckboxMarginWidget = i18n( " <qt> "
00122 " <p><b>Custom Margins Checkbox</b></p>. "
00123 " <p>Enable this checkbox if you want to modify the margins of your printouts "
00124 " <p>You can change margin settings in 4 ways: "
00125 " <ul> "
00126 " <li>Edit the text fields. </li> "
00127 " <li>Click spinbox arrows. </li> "
00128 " <li>Scroll wheel of wheelmouses. </li> "
00129 " <li>Drag margins in preview frame with mouse. </li> "
00130 " </ul> "
00131 " <b>Note:</b> The margin setting does not work if you load such files directly into "
00132 " kprinter, which have their print margins hardcoded internally, like as most "
00133 " PDF or PostScript files. It works for all ASCII text files however. It also may not "
00134 " work with non-KDE applications which fail to "
00135 " fully utilize the KDEPrint framework, such as OpenOffice.org. </p> "
00136 " </qt>" );
00137
00138 QString whatsThisDragAndPreviewMarginWidget = i18n( " <qt> "
00139 " <p><b>\"Drag-your-Margins\" </p>. "
00140 " <p>Use your mouse to drag and set each margin on this little preview window. </p> "
00141 " </qt>" );
00142
00143 m_symetric = m_block = false;
00144 m_pagesize[ 0 ] = 595;
00145 m_pagesize[ 1 ] = 842;
00146 m_landscape = false;
00147
00148 m_custom = new QCheckBox(i18n("&Use custom margins"), this);
00149 QWhatsThis::add(m_custom, whatsThisCheckboxMarginWidget);
00150 m_top = new MarginValueWidget(0, 0.0, this);
00151 QWhatsThis::add(m_top, whatsThisTopMarginWidget);
00152 m_bottom = new MarginValueWidget(m_top, 0.0, this);
00153 QWhatsThis::add(m_bottom, whatsThisBottomMarginWidget);
00154 m_left = new MarginValueWidget(m_bottom, 0.0, this);
00155 QWhatsThis::add(m_left, whatsThisLeftMarginWidget);
00156 m_right = new MarginValueWidget(m_left, 0.0, this);
00157 QWhatsThis::add(m_right, whatsThisRightMarginWidget);
00158 m_top->setLabel(i18n("&Top:"), Qt::AlignLeft|Qt::AlignVCenter);
00159 m_bottom->setLabel(i18n("&Bottom:"), Qt::AlignLeft|Qt::AlignVCenter);
00160 m_left->setLabel(i18n("Le&ft:"), Qt::AlignLeft|Qt::AlignVCenter);
00161 m_right->setLabel(i18n("&Right:"), Qt::AlignLeft|Qt::AlignVCenter);
00162 m_units = new QComboBox(this);
00163 QWhatsThis::add(m_units, whatsThisMeasurementUnitMarginWidget);
00164 m_units->insertItem(i18n("Pixels (1/72nd in)"));
00165 if ( allowMetricUnit )
00166 {
00167 m_units->insertItem(i18n("Inches (in)"));
00168 m_units->insertItem(i18n("Centimeters (cm)"));
00169 m_units->insertItem( i18n( "Millimeters (mm)" ) );
00170 }
00171 m_units->setCurrentItem(0);
00172 connect(m_units, SIGNAL(activated(int)), m_top, SLOT(setMode(int)));
00173 connect(m_units, SIGNAL(activated(int)), m_bottom, SLOT(setMode(int)));
00174 connect(m_units, SIGNAL(activated(int)), m_left, SLOT(setMode(int)));
00175 connect(m_units, SIGNAL(activated(int)), m_right, SLOT(setMode(int)));
00176 m_preview = new MarginPreview(this);
00177 QWhatsThis::add(m_preview, whatsThisDragAndPreviewMarginWidget);
00178 m_preview->setMinimumSize(60, 80);
00179 m_preview->setPageSize(m_pagesize[ 0 ], m_pagesize[ 1 ]);
00180 connect(m_preview, SIGNAL(marginChanged(int,float)), SLOT(slotMarginPreviewChanged(int,float)));
00181 connect(m_top, SIGNAL(marginChanged(float)), SLOT(slotMarginValueChanged()));
00182 connect(m_bottom, SIGNAL(marginChanged(float)), SLOT(slotMarginValueChanged()));
00183 connect(m_left, SIGNAL(marginChanged(float)), SLOT(slotMarginValueChanged()));
00184 connect(m_right, SIGNAL(marginChanged(float)), SLOT(slotMarginValueChanged()));
00185 slotMarginValueChanged();
00186 connect(m_custom, SIGNAL(toggled(bool)), m_top, SLOT(setEnabled(bool)));
00187 connect(m_custom, SIGNAL(toggled(bool)), m_left, SLOT(setEnabled(bool)));
00188
00189 connect(m_custom, SIGNAL(toggled(bool)), SLOT(slotCustomMarginsToggled(bool)));
00190 connect(m_custom, SIGNAL(toggled(bool)), m_preview, SLOT(enableRubberBand(bool)));
00191 m_top->setEnabled(false);
00192 m_bottom->setEnabled(false);
00193 m_left->setEnabled(false);
00194 m_right->setEnabled(false);
00195
00196
00197 QGridLayout *l3 = new QGridLayout(this, 7, 2, 0, 10);
00198 l3->addWidget(m_custom, 0, 0);
00199 l3->addWidget(m_top, 1, 0);
00200 l3->addWidget(m_bottom, 2, 0);
00201 l3->addWidget(m_left, 3, 0);
00202 l3->addWidget(m_right, 4, 0);
00203 l3->addRowSpacing(5, 10);
00204 l3->addWidget(m_units, 6, 0);
00205 l3->addMultiCellWidget(m_preview, 0, 6, 1, 1);
00206
00207 if ( allowMetricUnit )
00208 {
00209 int mode = (KGlobal::locale()->measureSystem() == KLocale::Metric ? 2 : 1);
00210 m_top->setMode(mode);
00211 m_bottom->setMode(mode);
00212 m_left->setMode(mode);
00213 m_right->setMode(mode);
00214 m_units->setCurrentItem(mode);
00215 }
00216 }
00217
00218 MarginWidget::~MarginWidget()
00219 {
00220 }
00221
00222 void MarginWidget::slotCustomMarginsToggled(bool b)
00223 {
00224 m_bottom->setEnabled(b && !m_symetric);
00225 m_right->setEnabled(b && !m_symetric);
00226 if (!b)
00227 resetDefault();
00228 }
00229
00230 void MarginWidget::setSymetricMargins(bool on)
00231 {
00232 if (on == m_symetric)
00233 return;
00234
00235 m_symetric = on;
00236 m_bottom->setEnabled(on && m_custom->isChecked());
00237 m_right->setEnabled(on && m_custom->isChecked());
00238 if (on)
00239 {
00240 connect(m_top, SIGNAL(marginChanged(float)), m_bottom, SLOT(setMargin(float)));
00241 connect(m_left, SIGNAL(marginChanged(float)), m_right, SLOT(setMargin(float)));
00242 m_bottom->setMargin(m_top->margin());
00243 m_right->setMargin(m_left->margin());
00244 }
00245 else
00246 {
00247 disconnect(m_top, 0, m_bottom, 0);
00248 disconnect(m_left, 0, m_right, 0);
00249 }
00250 m_preview->setSymetric(on);
00251 }
00252
00253 void MarginWidget::slotMarginValueChanged()
00254 {
00255 if (m_block)
00256 return;
00257 m_preview->setMargins(m_top->margin(), m_bottom->margin(), m_left->margin(), m_right->margin());
00258 }
00259
00260 void MarginWidget::slotMarginPreviewChanged(int type, float value)
00261 {
00262 m_block = true;
00263 switch (type)
00264 {
00265 case MarginPreview::TMoving:
00266 m_top->setMargin(value);
00267 break;
00268 case MarginPreview::BMoving:
00269 m_bottom->setMargin(value);
00270 break;
00271 case MarginPreview::LMoving:
00272 m_left->setMargin(value);
00273 break;
00274 case MarginPreview::RMoving:
00275 m_right->setMargin(value);
00276 break;
00277 }
00278 m_block = false;
00279 }
00280
00281 void MarginWidget::setPageSize(float w, float h)
00282 {
00283
00284 int dpi = m_top->resolution();
00285 m_pagesize[ 0 ] = w;
00286 m_pagesize[ 1 ] = h;
00287 if (m_landscape)
00288 m_preview->setPageSize((m_pagesize[ 1 ]*dpi)/72, (m_pagesize[ 0 ]*dpi)/72);
00289 else
00290 m_preview->setPageSize((m_pagesize[ 0 ]*dpi)/72, (m_pagesize[ 1 ]*dpi)/72);
00291 }
00292
00293 float MarginWidget::top() const
00294 {
00295 return m_top->margin();
00296 }
00297
00298 float MarginWidget::bottom() const
00299 {
00300 return m_bottom->margin();
00301 }
00302
00303 float MarginWidget::left() const
00304 {
00305 return m_left->margin();
00306 }
00307
00308 float MarginWidget::right() const
00309 {
00310 return m_right->margin();
00311 }
00312
00313 void MarginWidget::setTop(float value)
00314 {
00315 m_top->setMargin(value);
00316 }
00317
00318 void MarginWidget::setBottom(float value)
00319 {
00320 m_bottom->setMargin(value);
00321 }
00322
00323 void MarginWidget::setLeft(float value)
00324 {
00325 m_left->setMargin(value);
00326 }
00327
00328 void MarginWidget::setRight(float value)
00329 {
00330 m_right->setMargin(value);
00331 }
00332
00333 void MarginWidget::setResolution(int dpi)
00334 {
00335 m_top->setResolution(dpi);
00336 m_bottom->setResolution(dpi);
00337 m_left->setResolution(dpi);
00338 m_right->setResolution(dpi);
00339 }
00340
00341 void MarginWidget::setDefaultMargins(float t, float b, float l, float r)
00342 {
00343 int dpi = m_top->resolution();
00344 m_default[0] = (t*dpi)/72;
00345 m_default[1] = (b*dpi)/72;
00346 m_default[2] = (l*dpi)/72;
00347 m_default[3] = (r*dpi)/72;
00348 if (!m_custom->isChecked())
00349 resetDefault();
00350 }
00351
00352 void MarginWidget::resetDefault()
00353 {
00354 m_top->setMargin(m_landscape ? m_default[2] : m_default[0]);
00355 m_bottom->setMargin(m_landscape ? m_default[3] : m_default[1]);
00356 m_left->setMargin(m_landscape ? m_default[1] : m_default[2]);
00357 m_right->setMargin(m_landscape ? m_default[0] : m_default[3]);
00358 }
00359
00360 void MarginWidget::setCustomEnabled(bool on)
00361 {
00362 m_custom->setChecked(on);
00363 }
00364
00365 bool MarginWidget::isCustomEnabled() const
00366 {
00367 return m_custom->isChecked();
00368 }
00369
00370 void MarginWidget::setOrientation(int orient)
00371 {
00372 m_landscape = (orient == KPrinter::Landscape);
00373 setPageSize(m_pagesize[ 0 ], m_pagesize[ 1 ]);
00374 }
00375
00376 #include "marginwidget.moc"