kdeprint Library API Documentation

kptagspage.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  *  Boston, MA 02111-1307, USA.
00018  **/
00019 
00020 #include "kptagspage.h"
00021 
00022 #include <qtable.h>
00023 #include <qheader.h>
00024 #include <qlayout.h>
00025 #include <qlabel.h>
00026 #include <qregexp.h>
00027 #include <qwhatsthis.h>
00028 
00029 #include <klocale.h>
00030 
00031 KPTagsPage::KPTagsPage(bool ro, QWidget *parent, const char *name)
00032 : KPrintDialogPage(parent, name)
00033 {
00034 
00035     QString whatsThisAdditionalTagsTable = i18n(" <qt><p>You may send additional messages to the operator(s) of your"
00036                         " production printers (e.g. in your <em>Central Repro Department</p>)"
00037                         " Your messages can be read by the operator(s) (or yourself) by viewing"
00038                         " the <em>\"Job IPP Report\"</em> for the respective job.</p>"
00039                         " <b>Examples:</b><br><pre>"
00040                         " <em>Call_after_completion</em> (Name) -- <em>Joe User, phone extension 1234</em> (Value)<br>"
00041                         " <em>Mail_after_completion</em> (Name) -- <em>Jill User &lt;juser@somecompany.com&gt;</em> (Value)<br>"
00042                         " <em>Deliver_after_completion</em> (Name) -- <em>to Marketing Department</em> (Value)"
00043                         " </pre>"
00044                         " <p><b>Note:</b> the \"Name\" field must not include spaces or tabs."
00045                             " </qt>" );
00046     setTitle(i18n("Additional Tags"));
00047     setOnlyRealPrinters(true);
00048 
00049     m_tags = new QTable(10, 2, this);
00050     m_tags->horizontalHeader()->setStretchEnabled(true);
00051     m_tags->horizontalHeader()->setLabel(0, i18n("Name"));
00052     m_tags->horizontalHeader()->setLabel(1, i18n("Value"));
00053     m_tags->setReadOnly(ro);
00054     QWhatsThis::add(m_tags, whatsThisAdditionalTagsTable);
00055 
00056     QVBoxLayout *l0 = new QVBoxLayout(this, 0, 5);
00057     l0->addWidget(m_tags);
00058 
00059     if (ro)
00060     {
00061         QLabel  *lab = new QLabel(i18n("Read-Only"), this);
00062         QFont   f = lab->font();
00063         f.setBold(true);
00064         lab->setFont(f);
00065         lab->setAlignment(AlignVCenter|AlignRight);
00066         l0->addWidget(lab);
00067     }
00068 }
00069 
00070 KPTagsPage::~KPTagsPage()
00071 {
00072 }
00073 
00074 bool KPTagsPage::isValid(QString& msg)
00075 {
00076     QRegExp re("\\s");
00077     for (int r=0; r<m_tags->numCols(); r++)
00078     {
00079         QString tag(m_tags->text(r, 0));
00080         if (tag.isEmpty())
00081             continue;
00082         else if (tag.find(re) != -1)
00083         {
00084             msg = i18n("The tag name must not contain any spaces: <b>%1</b>.").arg(tag);
00085             return false;
00086         }
00087     }
00088     return true;
00089 }
00090 
00091 void KPTagsPage::setOptions(const QMap<QString,QString>& opts)
00092 {
00093     int r(0);
00094     QRegExp re("^\"|\"$");
00095     for (QMap<QString,QString>::ConstIterator it=opts.begin(); it!=opts.end() && r<m_tags->numRows(); ++it)
00096     {
00097         if (it.key().startsWith("KDEPrint-"))
00098         {
00099             m_tags->setText(r, 0, it.key().mid(9));
00100             QString data = it.data();
00101             m_tags->setText(r, 1, data.replace(re, ""));
00102             r++;
00103         }
00104     }
00105     for (; r<m_tags->numRows(); r++)
00106     {
00107         m_tags->setText(r, 0, QString::null);
00108         m_tags->setText(r, 1, QString::null);
00109     }
00110 }
00111 
00112 void KPTagsPage::getOptions(QMap<QString,QString>& opts, bool)
00113 {
00114     for (int r=0; r<m_tags->numRows(); r++)
00115     {
00116         QString tag(m_tags->text(r, 0)), val(m_tags->text(r, 1));
00117         if (!tag.isEmpty())
00118         {
00119             tag.prepend("KDEPrint-");
00120             opts[tag] = val.prepend("\"").append("\"");
00121         }
00122     }
00123 }
00124 
00125 QSize KPTagsPage::sizeHint() const
00126 {
00127     return QSize(-1, -1);
00128 }
00129 
00130 QSize KPTagsPage::minimumSizeHint() const
00131 {
00132     return QSize(-1, -1);
00133 }
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed May 12 09:08:51 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003