summaryrefslogtreecommitdiff
path: root/src/urlbar
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-10-11 12:23:07 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-10-11 12:23:07 +0200
commitab7a1d8e856894a0074178aee111b4043738d439 (patch)
tree732390d3b542a53a1c850bb262b077d157b54237 /src/urlbar
parentNo need to check progress if load is finished. (diff)
parentListItem: add auto test for multiple word highlighting. (diff)
downloadrekonq-ab7a1d8e856894a0074178aee111b4043738d439.tar.xz
Merge branch 'm213'
Diffstat (limited to 'src/urlbar')
-rw-r--r--src/urlbar/listitem.cpp44
-rw-r--r--src/urlbar/listitem.h2
-rw-r--r--src/urlbar/urlbar.cpp1
-rw-r--r--src/urlbar/urlbar.h2
4 files changed, 40 insertions, 9 deletions
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index c60e69a8..8b908149 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -204,22 +204,52 @@ IconLabel::IconLabel(const KIcon &icon, QWidget *parent)
// ---------------------------------------------------------------
+static QString highlightWordsInText(const QString &text, const QStringList &words)
+{
+ QString ret = text;
+ QBitArray boldSections(ret.size());
+ foreach (const QString &wordToPointOut, words) {
+ int index = ret.indexOf(wordToPointOut, 0, Qt::CaseInsensitive);
+ while(index > -1) {
+ boldSections.fill(true,index + 1, index + wordToPointOut.size() + 1);
+ index = ret.indexOf(wordToPointOut, index + wordToPointOut.size(), Qt::CaseInsensitive);
+ }
+ }
+ int numSections = 0;
+ bool bold = false;
+ for(int i=0; i < boldSections.size() - 1; ++i ) {
+ if (boldSections.testBit(i) && (i == boldSections.size() || !boldSections.testBit(i+1)))
+ numSections++;
+ }
+ const int tagLength = 7; // length of "<b>" and "</b>" we're going to add for each bold section.
+ ret.reserve(ret.size() + numSections * tagLength);
+ bold = false;
+ for (int i = boldSections.size() - 1; i >= 0; --i) {
+ if (!bold && boldSections.testBit(i)) {
+ ret.insert(i, QL1S("</b>"));
+ bold = true;
+ } else if (bold && !boldSections.testBit(i)) {
+ ret.insert(i, QL1S("<b>"));
+ bold = false;
+ }
+ }
+ return ret;
+}
TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget *parent)
: QLabel(parent)
{
+ setTextFormat(Qt::RichText);
+ setMouseTracking(false);
QString t = text;
const bool wasItalic = t.startsWith(QL1S("<i>"));
if (wasItalic)
- t.remove(QRegExp("<[/ib]*>"));
-
+ t.remove(QRegExp(QL1S("<[/ib]*>")));
t = Qt::escape(t);
- QString ss = Qt::escape(textToPointOut);
- t.replace(QRegExp('(' + ss + ')', Qt::CaseInsensitive), "<b>\\1</b>");
-
+ QStringList words = Qt::escape(textToPointOut.simplified()).split(QL1C(' '));
+ t = highlightWordsInText(t, words);
if (wasItalic)
t = QL1S("<i>") + t + QL1S("</i>");
-
setText(t);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
}
@@ -228,6 +258,8 @@ TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget
TextLabel::TextLabel(QWidget *parent)
: QLabel(parent)
{
+ setTextFormat(Qt::RichText);
+ setMouseTracking(false);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
}
diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h
index be5a2569..975c3724 100644
--- a/src/urlbar/listitem.h
+++ b/src/urlbar/listitem.h
@@ -115,7 +115,7 @@ public:
// -------------------------------------------------------------------------
-class TextLabel : public QLabel
+class REKONQ_TESTS_EXPORT TextLabel : public QLabel
{
Q_OBJECT
diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp
index ad3383fe..4039e8bf 100644
--- a/src/urlbar/urlbar.cpp
+++ b/src/urlbar/urlbar.cpp
@@ -148,7 +148,6 @@ void UrlBar::setQUrl(const QUrl& url)
void UrlBar::activated(const KUrl& url, Rekonq::OpenType type)
{
activateSuggestions(false);
-
clearFocus();
setUrl(url);
Application::instance()->loadUrl(url, type);
diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h
index 6e05ea7e..dcd0ba5b 100644
--- a/src/urlbar/urlbar.h
+++ b/src/urlbar/urlbar.h
@@ -90,6 +90,7 @@ public:
~UrlBar();
void setPrivateMode(bool on);
+ void activateSuggestions(bool);
public slots:
void setQUrl(const QUrl &url);
@@ -120,7 +121,6 @@ protected:
private:
IconButton *addRightIcon(UrlBar::icon);
- void activateSuggestions(bool);
QWeakPointer<CompletionWidget> _box;
WebTab *_tab;