/* 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 namespace lay { SaltGrainDetailsTextWidget::SaltGrainDetailsTextWidget (QWidget *w) : QTextBrowser (w), mp_grain (0) { // .. nothing yet .. } void SaltGrainDetailsTextWidget::set_grain (SaltGrain *g) { if (mp_grain != g) { mp_grain = g; setHtml (details_text ()); } } QVariant SaltGrainDetailsTextWidget::loadResource (int type, const QUrl &url) { if (url.path () == QString::fromUtf8 ("/icon")) { // @@@ return QImage (":/salt_icon.png"); // @@@ } 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 << "
"; 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->url ().empty ()) { stream << "" << QObject::tr ("Documentation link") << ": url ()) << "\">" << tl::to_qstring (tl::escaped_to_html (g->url ())) << ""; } else { stream << ""; stream << QObject::tr ("This package does not have a documentation link. " "Use the <url> element of the specification file or edit the package properties to provide a link."); stream << ""; } stream << "

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