/*************************************************************************** * Copyright (C) 2005-2006 Nicolas Hadacek * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "device_group.h" #if !defined(NO_KDE) # include # include TQColor Device::statusColor(Status status) { switch (status.type()) { case Status::Future: return TQt::blue; case Status::InProduction: return TQt::green; case Status::Mature: case Status::NotRecommended: return TQColor("orange"); case Status::EOL: return TQt::red; case Status::Unknown: case Status::Nb_Types: break; } return TQt::black; } TQString coloredString(const TQString &text, TQColor color) { return TQString("" + text + ""; } TQString supportedString(bool supported) { return coloredString(supported ? i18n("Supported") : i18n("Unsupported"), supported ? TQt::green : TQt::red); } class Tick { public: Tick() {} Tick(double value, double oValue) { s = KGlobal::locale()->formatNumber(value, 1); min = oValue; } TQString s; double min; }; class TickMap : public TQMap { public: TickMap() {} void add(double value, double oValue) { insert(value, Tick(value, oValue), false); (*this)[value].min = TQMIN((*this)[value].min, oValue); } }; TQPixmap drawGraph(const TQValueVector &boxes) { const uint w = 300, h = 200; TQPixmap pixmap(w, h); pixmap.fill(TQt::white); TQPainter p(&pixmap); TQFontMetrics f(p.font()); TickMap xTicks, yTicks; xTicks.add(0.0, 0.0); yTicks.add(0.0, 0.0); for (uint i=0; i &boxes) { uint sp = 10; TQPixmap graph = drawGraph(boxes); TQPainter p; TQFontMetrics f(p.font()); TQPixmap pixmap(graph.width() + sp + f.width(xLabel), graph.height() + sp + f.lineSpacing()); pixmap.fill(TQt::white); copyBlt(&pixmap, 0, f.lineSpacing() + sp, &graph, 0, 0, graph.width(), graph.height()); p.begin(&pixmap); p.setPen(TQt::black); p.drawText(0, f.lineSpacing(), yLabel); p.drawText(pixmap.width()-1-f.width(xLabel), pixmap.height()-1, xLabel); return pixmap; } const Device::Package *Device::barPackage(const char *name, const Device::Data &data) { for (uint i=0; i%2").tqarg(href).tqarg(data.alternatives()[i].upper()); } } doc += htmlTableRow(i18n("Alternatives"), s); } doc += documentHtml; doc += ""; doc += "
"; doc += ""; doc += data.group().informationHtml(data); TQString s; for (uint i=0; i
"; for (uint k=0; ktypes.count(); k++) { if ( k!=0 ) doc += " "; doc += i18n(Package::TYPE_DATA[package->types[k]].label); doc += "(" + TQString::number(package->pins.count()) + ")"; } doc += "
"; TQString label = data.name() + "_pins_graph.png"; doc += ""; if (msf) msf->setPixmap(label, pix); doc += "
"; } return doc; } TQString Device::htmlVoltageFrequencyGraphs(const Device::Data &data, const TQString &imagePrefix, TQMimeSourceFactory *msf) { TQString doc; FOR_EACH(Special, special) { for (uint k=0; k"; TQString label = data.name() + "_" + data.fname(special) + "_" + fr.operatingCondition.key() + ".png"; doc += ""; if (msf) msf->setPixmap(label, Device::vddGraph(i18n("F (MHz)"), i18n("Vdd (V)"), fr.vdds)); } } return doc; } TQPixmap Device::memoryGraph(const TQValueList &r) { TQValueList ranges = r; TQPixmap pixmap; TQPainter p; TQFontMetrics fm(p.font()); // order qHeapSort(ranges); // add empty ranges TQValueList::iterator it; for (it=ranges.begin(); it!=ranges.end(); ) { TQValueList::iterator prev = it; ++it; if ( it==ranges.end() ) break; if ( (*prev).endAddress+1==(*it).startAddress ) continue; MemoryGraphData data; data.startAddress = (*prev).endAddress + 1; data.endAddress = (*it).startAddress-1; ranges.insert(it, data); } // compute widths and total height int theight = fm.ascent() + (fm.ascent()%2==0 ? 1 : 0); int hspacing = 5; int height = 1; int w1 = 0, w2 = 0; for (it=ranges.begin(); it!=ranges.end(); ++it) { w1 = TQMAX(w1, fm.width((*it).start)); w1 = TQMAX(w1, fm.width((*it).end)); w2 = TQMAX(w2, fm.width((*it).label)); (*it).height = 2*hspacing + theight; if ( (*it).startAddress!=(*it).endAddress ) (*it).height += 2*theight; height += (*it).height; } int wspacing = 4; int width = wspacing + w1 + wspacing + wspacing + w2; pixmap.resize(width, height); pixmap.fill(TQt::white); p.begin(&pixmap); int h = 0; // draw ranges for (it=ranges.begin(); it!=ranges.end(); ++it) { p.setPen(TQPen(TQt::black, 1, TQt::DotLine)); p.drawLine(0,h, width-1,h); p.setPen(TQPen(TQt::black, 1)); p.setBrush((*it).label.isEmpty() ? TQt::gray : TQt::white); p.drawRect(0,h, wspacing+w1+wspacing,(*it).height+1); int hmid = h+(*it).height/2+theight/2; p.drawText(wspacing+w1+wspacing+wspacing,hmid, (*it).label); if ( (*it).startAddress==(*it).endAddress ) p.drawText(wspacing,hmid, (*it).start); else { p.drawText(wspacing,h+theight, (*it).start); p.drawText(wspacing,h+(*it).height-3, (*it).end); } h += (*it).height; p.setPen(TQPen(TQt::black, 1, TQt::DotLine)); p.drawLine(0,h, width-1,h); } p.end(); return pixmap; } #endif