/* KLayout Layout Viewer Copyright (C) 2006-2017 Matthias Koefferlein 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "laySaltGrainDetailsTextWidget.h" #include "laySaltGrain.h" #include "tlString.h" #include #include #include #include namespace lay { SaltGrainDetailsTextWidget::SaltGrainDetailsTextWidget (QWidget *w) : QTextBrowser (w), mp_grain (0) { // .. nothing yet .. } void SaltGrainDetailsTextWidget::set_grain (SaltGrain *g) { mp_grain = g; setHtml (details_text ()); } QVariant SaltGrainDetailsTextWidget::loadResource (int type, const QUrl &url) { if (url.path () == QString::fromUtf8 ("/icon")) { int icon_dim = 64; if (!mp_grain || mp_grain->icon ().isNull ()) { return QImage (":/salt_icon.png"); } else { QImage img = mp_grain->icon (); if (img.width () != icon_dim || img.height () != icon_dim) { img = img.scaled (QSize (icon_dim, icon_dim), Qt::KeepAspectRatio, Qt::SmoothTransformation); QImage final_img (icon_dim, icon_dim, QImage::Format_ARGB32); final_img.fill (QColor (0, 0, 0, 0)); QPainter painter (&final_img); painter.drawImage ((icon_dim - img.width ()) / 2, (icon_dim - img.height ()) / 2, img); return final_img; } else { return img; } } } else if (url.path () == QString::fromUtf8 ("/screenshot")) { QImage s = mp_grain->screenshot ().convertToFormat (QImage::Format_ARGB32_Premultiplied); QImage smask (s.size (), QImage::Format_ARGB32_Premultiplied); smask.fill (QColor (0, 0, 0, 0)); { int border = 0; int radius = 6; QPainter painter (&smask); painter.setRenderHint (QPainter::Antialiasing); painter.setCompositionMode (QPainter::CompositionMode_Source); for (int b = border; b > 0; --b) { QPen pen (QColor (255, 255, 255, ((border - b + 1) * 255) / border)); pen.setWidth (b * 2 + 1); painter.setBrush (Qt::NoBrush); painter.setPen (pen); painter.drawRoundedRect (QRectF (border, border, s.width () - 2 * border, s.height () - 2 * border), radius, radius, Qt::AbsoluteSize); } painter.setPen (Qt::white); painter.setBrush (Qt::white); painter.drawRoundedRect (QRectF (border, border, s.width () - 2 * border, s.height () - 2 * border), radius, radius, Qt::AbsoluteSize); } { QPainter painter (&s); painter.setCompositionMode (QPainter::CompositionMode_DestinationIn); painter.drawImage (0, 0, smask); } return s; } else { return QTextBrowser::loadResource (type, url); } } QString SaltGrainDetailsTextWidget::details_text () { SaltGrain *g = mp_grain; if (! g) { return QString (); } QBuffer buffer; buffer.open (QIODevice::WriteOnly); QTextStream stream (&buffer); stream.setCodec ("UTF-8"); stream << ""; stream << ""; stream << ""; stream << "
"; stream << "

"; stream << tl::to_qstring (tl::escaped_to_html (g->name ())) << " " << tl::to_qstring (tl::escaped_to_html (g->version ())); stream << "

"; if (! g->title ().empty()) { stream << "

" << tl::to_qstring (tl::escaped_to_html (g->title ())) << "

"; } if (g->version ().empty ()) { stream << "

"; stream << QObject::tr ("This package does not have a version. " "Use the <version> element of the specification file or edit the package properties to provide a version."); stream << "

"; } if (g->title ().empty ()) { stream << "

"; stream << QObject::tr ("This package does not have a title. " "Use the <title> element of the specification file or edit the package properties to provide a title."); stream << "

"; } stream << "


"; if (! g->doc ().empty ()) { stream << tl::to_qstring (tl::escaped_to_html (g->doc ())); } else { stream << ""; stream << QObject::tr ("This package does not have a description. " "Use the <doc> element of the specification file or edit the package properties to provide a description."); stream << ""; } stream << "

"; stream << "

"; if (! g->author ().empty ()) { stream << "" << QObject::tr ("Author") << ": " << tl::to_qstring (tl::escaped_to_html (g->author ())) << " "; if (! g->author_contact ().empty ()) { stream << "(" << tl::to_qstring (tl::escaped_to_html (g->author_contact ())) << ")"; } if (!g->authored_time ().isNull ()) { stream << "
"; stream << "" << QObject::tr ("Released") << ": " << g->authored_time ().date ().toString (Qt::ISODate); } } else { stream << ""; stream << QObject::tr ("This package does not have a author information. " "Use the <author>, <authored-time> and <author-contact> elements of the specification file or edit the package properties to provide authoring information."); stream << ""; } stream << "

"; stream << "

"; if (! g->license ().empty ()) { stream << "" << QObject::tr ("License") << ": " << tl::to_qstring (tl::escaped_to_html (g->license ())) << " "; } else { stream << ""; stream << QObject::tr ("This package does not have license information. " "Use the <license> elements of the specification file or edit the package properties to provide license information."); stream << ""; } stream << "

"; stream << "

"; if (! g->doc_url ().empty ()) { stream << "" << QObject::tr ("Documentation link") << ": doc_url ()) << "\">" << tl::to_qstring (tl::escaped_to_html (g->doc_url ())) << ""; } else { stream << ""; stream << QObject::tr ("This package does not have a documentation link. " "Use the <doc-url> element of the specification file or edit the package properties to provide a link."); stream << ""; } stream << "

"; if (! g->screenshot ().isNull ()) { stream << "
"; stream << "

" << QObject::tr ("Screenshot") << "

"; } stream << "
"; stream << "

" << QObject::tr ("Installation") << "

"; stream << "

" << QObject::tr ("Installation path: ") << "" << tl::to_qstring (tl::escaped_to_html (g->path ())) << "

"; if (! g->url ().empty ()) { stream << "

" << QObject::tr ("Download URL: ") << "" << tl::to_qstring (tl::escaped_to_html (g->url ())) << "

"; } if (! g->installed_time ().isNull ()) { stream << "

" << QObject::tr ("Installed: ") << "" << g->installed_time ().toString () << "

"; } if (! g->dependencies ().empty ()) { stream << "

" << QObject::tr ("Depends on: ") << "
"; for (std::vector::const_iterator d = g->dependencies ().begin (); d != g->dependencies ().end (); ++d) { stream << "    " << tl::to_qstring (tl::escaped_to_html (d->name)) << " "; stream << tl::to_qstring (tl::escaped_to_html (d->version)); if (! d->url.empty ()) { stream << " - "; stream << "[" << tl::to_qstring (tl::escaped_to_html (d->url)) << "]
"; } } stream << "

"; } stream << "
"; stream << ""; stream.flush (); return QString::fromUtf8 (buffer.buffer()); } }