"; + text += tl::escaped_to_html (g->doc ()); + text += "
"; + } + text += ""; + + return tl::to_qstring (text); + + } else { + return QVariant (); + } + } + + QModelIndex index (int row, int column, const QModelIndex &parent) const + { + if (parent.isValid ()) { + return QModelIndex (); + } else { + return createIndex (row, column); + } + } + + QModelIndex parent (const QModelIndex & /*index*/) const + { + return QModelIndex (); + } + + int columnCount(const QModelIndex & /*parent*/) const + { + return 1; + } + + int rowCount (const QModelIndex &parent) const + { + if (parent.isValid ()) { + return 0; + } else { + return mp_salt->end_flat () - mp_salt->begin_flat (); + } + } + +public: + lay::Salt *mp_salt; +}; + +class SaltItemDelegate + : public QStyledItemDelegate +{ +public: + SaltItemDelegate (QObject *parent) + : QStyledItemDelegate (parent) + { + // .. nothing yet .. + } + + void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const + { + QStyleOptionViewItemV4 optionV4 = option; + initStyleOption (&optionV4, index); + + QStyle *style = optionV4.widget ? optionV4.widget->style () : QApplication::style (); + + QTextDocument doc; + doc.setHtml (optionV4.text); + + optionV4.text = QString (); + style->drawControl (QStyle::CE_ItemViewItem, &optionV4, painter); + + QAbstractTextDocumentLayout::PaintContext ctx; + + if (optionV4.state & QStyle::State_Selected) { + ctx.palette.setColor (QPalette::Text, optionV4.palette.color (QPalette::Active, QPalette::HighlightedText)); + } + + QRect textRect = style->subElementRect (QStyle::SE_ItemViewItemText, &optionV4); + painter->save (); + painter->translate (textRect.topLeft ()); + painter->setClipRect (textRect.translated (-textRect.topLeft ())); + doc.documentLayout()->draw (painter, ctx); + painter->restore (); + } + + QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const + { + const int textWidth = 500; + + QStyleOptionViewItemV4 optionV4 = option; + initStyleOption (&optionV4, index); + + QTextDocument doc; + doc.setHtml (optionV4.text); + doc.setTextWidth (textWidth); + return QSize (textWidth, doc.size ().height ()); + } +}; + +// @@@ +lay::Salt salt; +static bool salt_initialized = false; +void make_salt () +{ + if (!salt_initialized) { + salt_initialized = true; + salt.add_location (tl::to_string (QDir::homePath () + QString::fromUtf8("/.klayout/salt"))); + } +} +// @@@ + SaltManagerDialog::SaltManagerDialog (QWidget *parent) : QDialog (parent) { Ui::SaltManagerDialog::setupUi (this); + salt = lay::Salt (); salt_initialized = false; // @@@ + make_salt (); // @@@ + salt_view->setModel (new SaltModel (this, &salt)); + salt_view->setItemDelegate (new SaltItemDelegate (this)); + // ... } diff --git a/src/laybasic/rdbMarkerBrowserPage.cc b/src/laybasic/rdbMarkerBrowserPage.cc index e31087072..f14e57338 100644 --- a/src/laybasic/rdbMarkerBrowserPage.cc +++ b/src/laybasic/rdbMarkerBrowserPage.cc @@ -1820,24 +1820,6 @@ MarkerBrowserPage::set_max_marker_count (size_t max_marker_count) } } -static void -escape_to_html (std::string &out, const std::string &in) -{ - for (const char *cp = in.c_str (); *cp; ++cp) { - if (*cp == '<') { - out += "<"; - } else if (*cp == '>') { - out += ">"; - } else if (*cp == '&') { - out += "&"; - } else if (*cp == '\n') { - out += ""; - escape_to_html (info, category->description ()); + tl::escape_to_html (info, category->description ()); info += "
"; } if (! m_error_text.empty ()) { info += ""; - escape_to_html (info, m_error_text); + tl::escape_to_html (info, m_error_text); info += "
"; } @@ -1978,7 +1960,7 @@ MarkerBrowserPage::update_info_text () if (v->tag_id () != 0) { const rdb::Tag &tag = mp_database->tags ().tag (v->tag_id ()); info += ""; - escape_to_html (info, tag.name ()); + tl::escape_to_html (info, tag.name ()); info += ": "; } @@ -1989,7 +1971,7 @@ MarkerBrowserPage::update_info_text () value_string = std::string (value_string.begin (), value_string.begin () + max_length) + "..."; } - escape_to_html (info, value_string); + tl::escape_to_html (info, value_string); info += "