00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kptextpage.h"
00021 #include "marginwidget.h"
00022 #include "driver.h"
00023 #include "kprinter.h"
00024
00025 #include <qbuttongroup.h>
00026 #include <qgroupbox.h>
00027 #include <qlayout.h>
00028 #include <qlabel.h>
00029 #include <qradiobutton.h>
00030 #include <qwhatsthis.h>
00031 #include <knuminput.h>
00032 #include <klocale.h>
00033 #include <kiconloader.h>
00034 #include <kseparator.h>
00035 #include <kdebug.h>
00036
00037 KPTextPage::KPTextPage(DrMain *driver, QWidget *parent, const char *name)
00038 : KPrintDialogPage(0, driver, parent, name)
00039 {
00040
00041 QString whatsThisCPITextPage = i18n( " <qt> "
00042 " <p><b>Characters Per Inch</b></p> "
00043 " <p>This setting controls the horizontal size of characters when printing a text file. </p>"
00044 " <p>The default value is 10, meaning that the font is scaled in a way that 10 characters "
00045 " per inch will be printed. </p> "
00046 " <hr> "
00047 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00048 " with the CUPS commandline job option parameter:</em> "
00049 " <pre>"
00050 " -o cpi=... # example: \"8\" or \"12\" "
00051 " </pre>"
00052 " </p> "
00053 " </qt>" );
00054
00055 QString whatsThisLPITextPage = i18n( " <qt> "
00056 " <p><b>Lines Per Inch</b></p> "
00057 " <p>This setting controls the vertical size of characters when printing a text file. </p>"
00058 " <p>The default value is 6, meaning that the font is scaled in a way that 6 lines "
00059 " per inch will be printed. </p> "
00060 " <hr> "
00061 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00062 " with the CUPS commandline job option parameter:</em> "
00063 " <pre>"
00064 " -o lpi=... # example \"5\" or \"7\" "
00065 " </pre>"
00066 " </p> "
00067 " </qt>" );
00068
00069 QString whatsThisColumnsTextPage = i18n( " <qt> "
00070 " <p><b>Columns</b></p> "
00071 " <p>This setting controls how many columns of text will be printed on each page when."
00072 " printing text files. </p> "
00073 " <p>The default value is 1, meaning that only one column of text per page "
00074 " will be printed. </p> "
00075 " <hr> "
00076 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00077 " with the CUPS commandline job option parameter:</em> "
00078 " <pre>"
00079 " -o columns=... # example: \"2\" or \"4\" "
00080 " </pre>"
00081 " </p> "
00082 " </qt>" );
00083
00084 QString whatsThisPrettyprintPreviewIconTextPage = i18n( " <qt> "
00085 " Preview icon changes when you turn on or off prettyprint. "
00086 " </qt>" );
00087 QString whatsThisFormatTextPage = i18n( " <qt> "
00088 " <p><b>Text Formats</b></p> "
00089 " <p>These settings control the appearance of text on printouts. They are only valid for "
00090 " printing text files or input directly through kprinter. </p> "
00091 " <p><b>Note:</b> These settings have no effect whatsoever for other input formats than "
00092 " text, or for printing from applications such as the KDE Advanced Text Editor. (Applications "
00093 " in general send PostScript to the print system, and 'kate' in particular has its own "
00094 " knobs to control the print output. </p>."
00095 " <hr> "
00096 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00097 " with the CUPS commandline job option parameter:</em> "
00098 " <pre>"
00099 " -o cpi=... # example: \"8\" or \"12\" "
00100 " <br> "
00101 " -o lpi=... # example: \"5\" or \"7\" "
00102 " <br> "
00103 " -o columns=... # example: \"2\" or \"4\" "
00104 " </pre>"
00105 " </p> "
00106 " </qt>" );
00107
00108 QString whatsThisMarginsTextPage = i18n( " <qt> "
00109 " <p><b>Margins</b></p> "
00110 " <p>These settings control the margins of printouts on the paper. They are not valid for "
00111 " jobs originating from applications which define their own page layout internally and "
00112 " send PostScript to KDEPrint (such as KOffice or OpenOffice.org). </p> "
00113 " <p>When printing from KDE applications, such as KMail and Konqueror, or printing an ASCII text "
00114 " file through kprinter, you can choose your preferred margin settings here. </p> "
00115 " <p>Margins may be set individually for each edge of the paper. The combo box at the bottom lets you change "
00116 " the units of measurement between Pixels, Millimeters, Centimeters, and Inches. </p> "
00117 " <p>You can even use the mouse to grab one margin and drag it to the intended position (see the "
00118 " preview picture on the right side). </p> "
00119 " <hr> "
00120 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00121 " with the CUPS commandline job option parameter:</em> "
00122 " <pre>"
00123 " -o page-top=... # example: \"72\" "
00124 " <br> "
00125 " -o page-bottom=... # example: \"24\" "
00126 " <br> "
00127 " -o page-left=... # example: \"36\" "
00128 " <br> "
00129 " -o page-right=... # example: \"12\" "
00130 " </pre>"
00131 " </p> "
00132 " </qt>" );
00133
00134 QString whatsThisPrettyprintButtonOnTextPage = i18n( " <qt> "
00135 " <p><b>Turn Text Printing with Syntax Highlighting (Prettyprint) On!</b></p> "
00136 " <p>ASCII text file printouts can be 'prettyfied' by enabling this option. If you do so, "
00137 " a header is printed at the top of each page. The header contains "
00138 " the page number, job title (usually the filename), and the date. In addition, C and "
00139 " C++ keywords are highlighted, and comment lines are italicized.</p>"
00140 " <p>This prettyprint option is handled by CUPS.</p> "
00141 " <p>If you prefer another 'plaintext-to-prettyprint' converter, look for the <em>enscript</em> "
00142 " pre-filter on the <em>Filters</em> tab. </p>"
00143 " <br> "
00144 " <hr> "
00145 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00146 " with the CUPS commandline job option parameter:</em> "
00147 " <pre>"
00148 " -o prettyprint=true. "
00149 " </pre>"
00150 " </p> "
00151 " </qt>" );
00152
00153 QString whatsThisPrettyprintButtonOffTextPage = i18n( " <qt> "
00154 " <p><b>Turn Text Printing with Syntax Highlighting (Prettyprint) Off! </b></p> "
00155 " <p>ASCII text file printing with this option turned off are appearing without a page "
00156 " header and without syntax highlighting. (You can still set the page margins, though.) </p> "
00157 " <br> "
00158 " <hr> "
00159 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00160 " with the CUPS commandline job option parameter:</em> "
00161 " <pre>"
00162 " -o prettyprint=false "
00163 " </pre>"
00164 " </p> "
00165 " </qt>" );
00166
00167 QString whatsThisPrettyprintFrameTextPage = i18n( " <qt> "
00168 " <p><b>Print Text with Syntax Highlighting (Prettyprint)</b></p> "
00169 " <p>ASCII file printouts can be 'prettyfied' by enabling this option. If you do so, "
00170 " a header is printed at the top of each page. The header contains "
00171 " the page number, job title (usually the filename), and the date. In addition, C and "
00172 " C++ keywords are highlighted, and comment lines are italicized.</p>"
00173 " <p>This prettyprint option is handled by CUPS.</p> "
00174 " <p>If you prefer another 'plaintext-to-prettyprint' converter, look for the <em>enscript</em> "
00175 " pre-filter on the <em>Filters</em> tab. </p> "
00176 " <br> "
00177 " <hr> "
00178 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00179 " with the CUPS commandline job option parameter:</em> "
00180 " <pre>"
00181 " -o prettyprint=true. "
00182 " <br> "
00183 " -o prettyprint=false "
00184 " </pre>"
00185 " </p> "
00186 " </qt>" );
00187
00188 setTitle(i18n("Text"));
00189 m_block = false;
00190
00191 QGroupBox *formatbox = new QGroupBox(0, Qt::Vertical, i18n("Text Format"), this);
00192 QWhatsThis::add(formatbox, whatsThisFormatTextPage);
00193 QGroupBox *prettybox = new QGroupBox(0, Qt::Vertical, i18n("Syntax Highlighting"), this);
00194 QWhatsThis::add(prettybox, whatsThisPrettyprintFrameTextPage);
00195 QGroupBox *marginbox = new QGroupBox(0, Qt::Vertical, i18n("Margins"), this);
00196 QWhatsThis::add(marginbox, whatsThisMarginsTextPage);
00197
00198 m_cpi = new KIntNumInput(10, formatbox);
00199 QWhatsThis::add(m_cpi, whatsThisCPITextPage);
00200 m_cpi->setLabel(i18n("&Chars per inch:"), Qt::AlignLeft|Qt::AlignVCenter);
00201 m_cpi->setRange(1, 999, 1, false);
00202 m_lpi = new KIntNumInput(m_cpi, 6, formatbox);
00203 QWhatsThis::add(m_lpi, whatsThisLPITextPage);
00204 m_lpi->setLabel(i18n("&Lines per inch:"), Qt::AlignLeft|Qt::AlignVCenter);
00205 m_lpi->setRange(1, 999, 1, false);
00206 m_columns = new KIntNumInput(m_lpi, 1, formatbox);
00207 QWhatsThis::add(m_columns, whatsThisColumnsTextPage);
00208 m_columns->setLabel(i18n("C&olumns:"), Qt::AlignLeft|Qt::AlignVCenter);
00209 m_columns->setRange(1, 10, 1, false);
00210 KSeparator *sep = new KSeparator(Qt::Horizontal, formatbox);
00211 connect(m_columns, SIGNAL(valueChanged(int)), SLOT(slotColumnsChanged(int)));
00212
00213 m_prettypix = new QLabel(prettybox);
00214 QWhatsThis::add(m_prettypix, whatsThisPrettyprintPreviewIconTextPage);
00215 m_prettypix->setAlignment(Qt::AlignCenter);
00216 QRadioButton *off = new QRadioButton(i18n("&Disabled"), prettybox);
00217 QWhatsThis::add(off, whatsThisPrettyprintButtonOffTextPage);
00218 QRadioButton *on = new QRadioButton(i18n("&Enabled"), prettybox);
00219 QWhatsThis::add(on, whatsThisPrettyprintButtonOnTextPage);
00220 m_prettyprint = new QButtonGroup(prettybox);
00221 m_prettyprint->hide();
00222 m_prettyprint->insert(off, 0);
00223 m_prettyprint->insert(on, 1);
00224 m_prettyprint->setButton(0);
00225 connect(m_prettyprint, SIGNAL(clicked(int)), SLOT(slotPrettyChanged(int)));
00226 slotPrettyChanged(0);
00227
00228 m_margin = new MarginWidget(marginbox);
00229 QWhatsThis::add(m_margin, whatsThisMarginsTextPage);
00230 m_margin->setPageSize(595, 842);
00231
00232 QGridLayout *l0 = new QGridLayout(this, 2, 2, 0, 10);
00233 l0->addWidget(formatbox, 0, 0);
00234 l0->addWidget(prettybox, 0, 1);
00235 l0->addMultiCellWidget(marginbox, 1, 1, 0, 1);
00236 QVBoxLayout *l1 = new QVBoxLayout(formatbox->layout(), 5);
00237 l1->addWidget(m_cpi);
00238 l1->addWidget(m_lpi);
00239 l1->addWidget(sep);
00240 l1->addWidget(m_columns);
00241 QGridLayout *l2 = new QGridLayout(prettybox->layout(), 2, 2, 10);
00242 l2->addWidget(off, 0, 0);
00243 l2->addWidget(on, 1, 0);
00244 l2->addMultiCellWidget(m_prettypix, 0, 1, 1, 1);
00245 QVBoxLayout *l3 = new QVBoxLayout(marginbox->layout(), 10);
00246 l3->addWidget(m_margin);
00247 }
00248
00249 KPTextPage::~KPTextPage()
00250 {
00251 }
00252
00253 void KPTextPage::setOptions(const QMap<QString,QString>& opts)
00254 {
00255 QString value;
00256
00257 if (!(value=opts["cpi"]).isEmpty())
00258 m_cpi->setValue(value.toInt());
00259 if (!(value=opts["lpi"]).isEmpty())
00260 m_lpi->setValue(value.toInt());
00261 if (!(value=opts["columns"]).isEmpty())
00262 m_columns->setValue(value.toInt());
00263 int ID(0);
00264 if (opts.contains("prettyprint") && (opts["prettyprint"].isEmpty() || opts["prettyprint"] == "true"))
00265 ID = 1;
00266 m_prettyprint->setButton(ID);
00267 slotPrettyChanged(ID);
00268
00269
00270 m_currentps = opts["PageSize"];
00271 QString orient = opts["orientation-requested"];
00272 bool landscape = (orient == "4" || orient == "5");
00273 initPageSize(landscape);
00274
00275 bool marginset(false);
00276 if (!(value=opts["page-top"]).isEmpty() && value.toFloat() != m_margin->top())
00277 {
00278 marginset = true;
00279 m_margin->setTop(value.toFloat());
00280 }
00281 if (!(value=opts["page-bottom"]).isEmpty() && value.toFloat() != m_margin->bottom())
00282 {
00283 marginset = true;
00284 m_margin->setBottom(value.toFloat());
00285 }
00286 if (!(value=opts["page-left"]).isEmpty() && value.toFloat() != m_margin->left())
00287 {
00288 marginset = true;
00289 m_margin->setLeft(value.toFloat());
00290 }
00291 if (!(value=opts["page-right"]).isEmpty() && value.toFloat() != m_margin->right())
00292 {
00293 marginset = true;
00294 m_margin->setRight(value.toFloat());
00295 }
00296 m_margin->setCustomEnabled(marginset);
00297 }
00298
00299 void KPTextPage::getOptions(QMap<QString,QString>& opts, bool incldef)
00300 {
00301 if (incldef || m_cpi->value() != 10)
00302 opts["cpi"] = QString::number(m_cpi->value());
00303 if (incldef || m_lpi->value() != 6)
00304 opts["lpi"] = QString::number(m_lpi->value());
00305 if (incldef || m_columns->value() != 1)
00306 opts["columns"] = QString::number(m_columns->value());
00307
00308
00309 if (m_margin->isCustomEnabled())
00310 {
00311 opts["page-top"] = QString::number(( int )( m_margin->top()+0.5 ));
00312 opts["page-bottom"] = QString::number(( int )( m_margin->bottom()+0.5 ));
00313 opts["page-left"] = QString::number(( int )( m_margin->left()+0.5 ));
00314 opts["page-right"] = QString::number(( int )( m_margin->right()+0.5 ));
00315 }
00316 else
00317 {
00318 opts.remove("page-top");
00319 opts.remove("page-bottom");
00320 opts.remove("page-left");
00321 opts.remove("page-right");
00322 }
00323
00324 if (m_prettyprint->id(m_prettyprint->selected()) == 1)
00325 opts["prettyprint"] = "true";
00326 else if (incldef)
00327 opts["prettyprint"] = "false";
00328 else
00329 opts.remove("prettyprint");
00330 }
00331
00332 void KPTextPage::slotPrettyChanged(int ID)
00333 {
00334 QString iconstr = (ID == 0 ? "kdeprint_nup1" : "kdeprint_prettyprint");
00335 m_prettypix->setPixmap(UserIcon(iconstr));
00336 }
00337
00338 void KPTextPage::slotColumnsChanged(int)
00339 {
00340
00341 }
00342
00343 void KPTextPage::initPageSize(bool landscape)
00344 {
00345 float w( -1 ), h( -1 );
00346 float mt( 36 ), mb( mt ), ml( 18 ), mr( ml );
00347 if (driver())
00348 {
00349 if (m_currentps.isEmpty())
00350 {
00351 DrListOption *o = (DrListOption*)driver()->findOption("PageSize");
00352 if (o)
00353 m_currentps = o->get("default");
00354 }
00355 if (!m_currentps.isEmpty())
00356 {
00357 DrPageSize *ps = driver()->findPageSize(m_currentps);
00358 if (ps)
00359 {
00360 w = ps->pageWidth();
00361 h = ps->pageHeight();
00362 mt = ps->topMargin();
00363 ml = ps->leftMargin();
00364 mr = ps->rightMargin();
00365 mb = ps->bottomMargin();
00366 }
00367 }
00368 }
00369 m_margin->setPageSize(w, h);
00370 m_margin->setOrientation(landscape ? KPrinter::Landscape : KPrinter::Portrait);
00371 m_margin->setDefaultMargins( mt, mb, ml, mr );
00372 m_margin->setCustomEnabled(false);
00373 }
00374
00375 #include "kptextpage.moc"