forked from mirror/openmw-tes3mp
highlight (bold) search string in results
This commit is contained in:
parent
6d165dabb6
commit
4928e3705f
6 changed files with 68 additions and 23 deletions
|
@ -79,31 +79,36 @@ void CSMTools::Search::searchRecordStateCell (const CSMWorld::IdTableBase *model
|
||||||
|
|
||||||
QString CSMTools::Search::formatDescription (const QString& description, int pos, int length) const
|
QString CSMTools::Search::formatDescription (const QString& description, int pos, int length) const
|
||||||
{
|
{
|
||||||
int padding = 10; ///< \todo make this configurable
|
QString text (description);
|
||||||
|
|
||||||
if (pos<padding)
|
|
||||||
{
|
|
||||||
length += pos;
|
|
||||||
pos = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pos -= padding;
|
|
||||||
length += padding;
|
|
||||||
}
|
|
||||||
|
|
||||||
length += padding;
|
|
||||||
|
|
||||||
QString text = description.mid (pos, length);
|
|
||||||
|
|
||||||
// compensate for Windows nonsense
|
// compensate for Windows nonsense
|
||||||
text.remove ('\r');
|
text.remove ('\r');
|
||||||
|
|
||||||
|
// split
|
||||||
|
int padding = 10; ///< \todo make this configurable
|
||||||
|
|
||||||
|
QString highlight = flatten (text.mid (pos, length));
|
||||||
|
QString before = flatten (padding<=pos ? text.mid (0, pos) : text.mid (pos-padding, padding));
|
||||||
|
QString after = flatten (text.mid (pos+length, padding));
|
||||||
|
|
||||||
|
// join
|
||||||
|
text = before + "<b>" + highlight + "</b>" + after;
|
||||||
|
|
||||||
// improve layout for single line display
|
// improve layout for single line display
|
||||||
text.replace ("\n", "<CR>");
|
text.replace ("\n", "<CR>");
|
||||||
text.replace ('\t', ' ');
|
text.replace ('\t', ' ');
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CSMTools::Search::flatten (const QString& text) const
|
||||||
|
{
|
||||||
|
QString flat (text);
|
||||||
|
|
||||||
|
flat.replace ("&", "&");
|
||||||
|
flat.replace ("<", "<");
|
||||||
|
|
||||||
|
return flat;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMTools::Search::Search() : mType (Type_None) {}
|
CSMTools::Search::Search() : mType (Type_None) {}
|
||||||
|
|
|
@ -57,7 +57,9 @@ namespace CSMTools
|
||||||
CSMDoc::Messages& messages) const;
|
CSMDoc::Messages& messages) const;
|
||||||
|
|
||||||
QString formatDescription (const QString& description, int pos, int length) const;
|
QString formatDescription (const QString& description, int pos, int length) const;
|
||||||
|
|
||||||
|
QString flatten (const QString& text) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Search();
|
Search();
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
CSVTools::ReportSubView::ReportSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
CSVTools::ReportSubView::ReportSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||||
: CSVDoc::SubView (id)
|
: CSVDoc::SubView (id)
|
||||||
{
|
{
|
||||||
setWidget (mTable = new ReportTable (document, id, this));
|
setWidget (mTable = new ReportTable (document, id, false, this));
|
||||||
|
|
||||||
connect (mTable, SIGNAL (editRequest (const CSMWorld::UniversalId&, const std::string&)),
|
connect (mTable, SIGNAL (editRequest (const CSMWorld::UniversalId&, const std::string&)),
|
||||||
SIGNAL (focusId (const CSMWorld::UniversalId&, const std::string&)));
|
SIGNAL (focusId (const CSMWorld::UniversalId&, const std::string&)));
|
||||||
|
|
|
@ -6,11 +6,45 @@
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
#include <QTextDocument>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#include "../../model/tools/reportmodel.hpp"
|
#include "../../model/tools/reportmodel.hpp"
|
||||||
|
|
||||||
#include "../../view/world/idtypedelegate.hpp"
|
#include "../../view/world/idtypedelegate.hpp"
|
||||||
|
|
||||||
|
namespace CSVTools
|
||||||
|
{
|
||||||
|
class RichTextDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
RichTextDelegate (QObject *parent = 0);
|
||||||
|
|
||||||
|
virtual void paint(QPainter *painter, const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex& index) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVTools::RichTextDelegate::RichTextDelegate (QObject *parent) : QStyledItemDelegate (parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void CSVTools::RichTextDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
QTextDocument document;
|
||||||
|
QVariant value = index.data (Qt::DisplayRole);
|
||||||
|
if (value.isValid() && !value.isNull())
|
||||||
|
{
|
||||||
|
document.setHtml (value.toString());
|
||||||
|
painter->translate (option.rect.topLeft());
|
||||||
|
document.drawContents (painter);
|
||||||
|
painter->translate (-option.rect.topLeft());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CSVTools::ReportTable::contextMenuEvent (QContextMenuEvent *event)
|
void CSVTools::ReportTable::contextMenuEvent (QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||||
|
@ -67,7 +101,7 @@ void CSVTools::ReportTable::mouseDoubleClickEvent (QMouseEvent *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVTools::ReportTable::ReportTable (CSMDoc::Document& document,
|
CSVTools::ReportTable::ReportTable (CSMDoc::Document& document,
|
||||||
const CSMWorld::UniversalId& id, QWidget *parent)
|
const CSMWorld::UniversalId& id, bool richTextDescription, QWidget *parent)
|
||||||
: CSVWorld::DragRecordTable (document, parent), mModel (document.getReport (id))
|
: CSVWorld::DragRecordTable (document, parent), mModel (document.getReport (id))
|
||||||
{
|
{
|
||||||
horizontalHeader()->setResizeMode (QHeaderView::Interactive);
|
horizontalHeader()->setResizeMode (QHeaderView::Interactive);
|
||||||
|
@ -85,6 +119,9 @@ CSVTools::ReportTable::ReportTable (CSMDoc::Document& document,
|
||||||
|
|
||||||
setItemDelegateForColumn (0, mIdTypeDelegate);
|
setItemDelegateForColumn (0, mIdTypeDelegate);
|
||||||
|
|
||||||
|
if (richTextDescription)
|
||||||
|
setItemDelegateForColumn (mModel->columnCount()-1, new RichTextDelegate (this));
|
||||||
|
|
||||||
mShowAction = new QAction (tr ("Show"), this);
|
mShowAction = new QAction (tr ("Show"), this);
|
||||||
connect (mShowAction, SIGNAL (triggered()), this, SLOT (showSelection()));
|
connect (mShowAction, SIGNAL (triggered()), this, SLOT (showSelection()));
|
||||||
addAction (mShowAction);
|
addAction (mShowAction);
|
||||||
|
|
|
@ -36,8 +36,9 @@ namespace CSVTools
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/// \param richTextDescription Use rich text in the description column.
|
||||||
ReportTable (CSMDoc::Document& document, const CSMWorld::UniversalId& id,
|
ReportTable (CSMDoc::Document& document, const CSMWorld::UniversalId& id,
|
||||||
QWidget *parent = 0);
|
bool richTextDescription, QWidget *parent = 0);
|
||||||
|
|
||||||
virtual std::vector<CSMWorld::UniversalId> getDraggedRecords() const;
|
virtual std::vector<CSMWorld::UniversalId> getDraggedRecords() const;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
||||||
|
|
||||||
layout->addWidget (&mSearchBox);
|
layout->addWidget (&mSearchBox);
|
||||||
|
|
||||||
layout->addWidget (mTable = new ReportTable (document, id), 2);
|
layout->addWidget (mTable = new ReportTable (document, id, true), 2);
|
||||||
|
|
||||||
QWidget *widget = new QWidget;
|
QWidget *widget = new QWidget;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue