/**************************************************************************** ** ** Copyright (C) 2007 Aleksey Luzin. All rights reserved. ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** http://www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** http://www.trolltech.com/products/qt/licensing.html or contact the ** sales department at sales@trolltech.com. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ****************************************************************************/ #include #include #include #include "newlabel.h" #include "qmainwindow.h" NewLabel::NewLabel(){ setupUi(this); papers = new Papers(); templates = new Templates(); int i; for(i=0;ilist.count();i++) { QDomElement child = papers->list.at(i).toElement(); QString id = child.attribute("id"); paperCombo->addItem(child.attribute("_name"), QVariant(id)); } scene = new QGraphicsScene(view); view->setScene(scene); view->setBackgroundRole(QPalette::Window); view->setMinimumWidth(190); view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); pr = scene->addRect(QRect(0+13,0,140,200)); pr->setBrush(QBrush( Qt::white )); // QDialogButtonBox *buttons = new QDialogButtonBox(); // buttons->addButton(new QPushButton(QIcon(":/images/button_ok.png"), "Ok"),QDialogButtonBox::AcceptRole); // buttons->addButton(new QPushButton(QIcon(":/images/button_cancel.png"), "Cancel"),QDialogButtonBox::RejectRole); connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); connect(buttons, SIGNAL(accepted()), this, SLOT(accept())); connect(paperCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(cchanged(int))); connect(templateCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(tchanged(int))); cchanged(0); setWindowTitle(tr("Create new label")); } void NewLabel::cchanged(int index) { qDebug("cchanged"); QString size = paperCombo->itemData(index).toString(); QDomElement l = templates->doc.firstChildElement(size); l1 = l.elementsByTagName("Template"); int i; // current_paper = NULL; for(i=0;ilist.count();i++) { QDomElement c = papers->list.at(i).toElement(); if (size.compare(c.attribute("id"))==0) { current_paper = c; break; } } double width = unit_to_point(current_paper.attribute("width")); double height = unit_to_point(current_paper.attribute("height")); double ar = width/height; pr->setRect(QRect(0,0,int(ar*200),200)); templateCombo->clear(); for(i=0;iaddItem(child.attribute("name"), QVariant(id)); } current_template = l1.at(0).toElement(); draw_template(); return; } void NewLabel::tchanged(int index) { QString name = templateCombo->itemData(index).toString(); // QDomElement l = templates->doc.firstChildElement(size); int i; for(i=0;isetText(desc); desc = current_paper.attribute("_name"); page_size->setText(desc); QDomNodeList items = current_template.childNodes(); int i; QList list = scene->items(); QList::Iterator it = list.begin(); for (; it != list.end(); ++it) { if ( *it ) delete *it; } double ar = width/height; pr = scene->addRect(QRect(0+15,0,int(ar*200),200),QPen(),QBrush( Qt::white )); int count = 0; for(i=0;isetText(QString().number(mm_width, 'f', 2) + " x " + QString().number(mm_height, 'f', 2) + " " + tr("mm")); QDomNodeList l = c.elementsByTagName("Layout"); if (l.isEmpty ()) { }; int k; for(k=0;kaddRect(QRect(int(x0+xi*dx), int(y0+dy*yi),int(rect_width*sc), int(rect_height*sc))); r->setZValue(10); count++; } } } } else if ((c.tagName().compare("Label-cd", Qt::CaseInsensitive)==0)or(c.tagName().compare("Label-round", Qt::CaseInsensitive)==0)) { double radius = unit_to_point(c.attribute("radius")); double mm_radius = point_to_unit(radius, "mm", 1); label_size->setText(QString().number(mm_radius*2,'f', 2) + " " + tr("mm") + " " + tr("diameter")); QDomNodeList l = c.elementsByTagName("Layout"); if (l.isEmpty ()) { }; int k; for(k=0;kaddEllipse(QRect(int(x0+xi*dx), int(y0+dy*yi),int(radius*2*sc), int(radius*2*sc))); r->setZValue(10); count++; } } } } format->setText(QString().number(count)+" labels at page"); } }