From f508189682b6fba62e08feeb1596f682bad5fff9 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 24 Feb 2010 18:42:24 +0000 Subject: Added KDE3 version of PikLab git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/devices/base/device_group.cpp | 362 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 362 insertions(+) create mode 100644 src/devices/base/device_group.cpp (limited to 'src/devices/base/device_group.cpp') diff --git a/src/devices/base/device_group.cpp b/src/devices/base/device_group.cpp new file mode 100644 index 0000000..df230d1 --- /dev/null +++ b/src/devices/base/device_group.cpp @@ -0,0 +1,362 @@ +/*************************************************************************** + * 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 + +QColor Device::statusColor(Status status) +{ + switch (status.type()) { + case Status::Future: return Qt::blue; + case Status::InProduction: return Qt::green; + case Status::Mature: + case Status::NotRecommended: return QColor("orange"); + case Status::EOL: return Qt::red; + case Status::Unknown: + case Status::Nb_Types: break; + } + return Qt::black; +} + +QString coloredString(const QString &text, QColor color) +{ + return QString("" + text + ""; +} + +QString supportedString(bool supported) +{ + return coloredString(supported ? i18n("Supported") : i18n("Unsupported"), + supported ? Qt::green : Qt::red); +} + +class Tick { +public: + Tick() {} + Tick(double value, double oValue) { + s = KGlobal::locale()->formatNumber(value, 1); + min = oValue; + } + QString s; + double min; +}; + +class TickMap : public QMap +{ +public: + TickMap() {} + void add(double value, double oValue) { + insert(value, Tick(value, oValue), false); + (*this)[value].min = QMIN((*this)[value].min, oValue); + } +}; + +QPixmap drawGraph(const QValueVector &boxes) +{ + const uint w = 300, h = 200; + QPixmap pixmap(w, h); + pixmap.fill(Qt::white); + QPainter p(&pixmap); + QFontMetrics 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; + QPixmap graph = drawGraph(boxes); + QPainter p; + QFontMetrics f(p.font()); + QPixmap pixmap(graph.width() + sp + f.width(xLabel), graph.height() + sp + f.lineSpacing()); + pixmap.fill(Qt::white); + copyBlt(&pixmap, 0, f.lineSpacing() + sp, &graph, 0, 0, graph.width(), graph.height()); + p.begin(&pixmap); + p.setPen(Qt::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").arg(href).arg(data.alternatives()[i].upper()); + } + } + doc += htmlTableRow(i18n("Alternatives"), s); + } + doc += documentHtml; + doc += ""; + + doc += "
"; + doc += ""; + doc += data.group().informationHtml(data); + QString 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 += "(" + QString::number(package->pins.count()) + ")"; + } + doc += "
"; + QString label = data.name() + "_pins_graph.png"; + doc += ""; + if (msf) msf->setPixmap(label, pix); + doc += "
"; + } + return doc; +} + +QString Device::htmlVoltageFrequencyGraphs(const Device::Data &data, const QString &imagePrefix, QMimeSourceFactory *msf) +{ + QString doc; + FOR_EACH(Special, special) { + for (uint k=0; k"; + QString 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; +} + +QPixmap Device::memoryGraph(const QValueList &r) +{ + QValueList ranges = r; + QPixmap pixmap; + QPainter p; + QFontMetrics fm(p.font()); + // order + qHeapSort(ranges); + // add empty ranges + QValueList::iterator it; + for (it=ranges.begin(); it!=ranges.end(); ) { + QValueList::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 = QMAX(w1, fm.width((*it).start)); + w1 = QMAX(w1, fm.width((*it).end)); + w2 = QMAX(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(Qt::white); + p.begin(&pixmap); + int h = 0; + // draw ranges + for (it=ranges.begin(); it!=ranges.end(); ++it) { + p.setPen(QPen(Qt::black, 1, Qt::DotLine)); + p.drawLine(0,h, width-1,h); + p.setPen(QPen(Qt::black, 1)); + p.setBrush((*it).label.isEmpty() ? Qt::gray : Qt::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(QPen(Qt::black, 1, Qt::DotLine)); + p.drawLine(0,h, width-1,h); + } + p.end(); + return pixmap; +} + +#endif -- cgit v1.2.1