summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-04-12 02:00:13 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-04-12 02:00:13 +0200
commitd2b1a62a0ecdd286b9d83275170a3322ffafd32c (patch)
tree7ab453799004d0caa7fc3a3106c1c0374f3d9b6f
parentfix strings (diff)
downloadrekonq-d2b1a62a0ecdd286b9d83275170a3322ffafd32c.tar.xz
URLBAR ANIMATION: implementation fix
This commit follows the logic explained somewhere else, moving rekonq to a better management for urls from user input. 1) users type strings --> we store them in QStrings 2) app load urls --> we should ever work with KUrls, trying to guess users needs Here I also removed the unuseful QString icon from UrlSearchItem definition, as we just have a type (Search, Browse, History, Books..), a (k)url and an Application::icon method :)
-rw-r--r--src/urlbar/completionwidget.h2
-rw-r--r--src/urlbar/listitem.cpp57
-rw-r--r--src/urlbar/listitem.h6
-rw-r--r--src/urlbar/urlbar.cpp11
-rw-r--r--src/urlbar/urlbar.h2
-rw-r--r--src/urlbar/urlresolver.cpp34
-rw-r--r--src/urlbar/urlresolver.h10
7 files changed, 51 insertions, 71 deletions
diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h
index a714bb17..ab78e489 100644
--- a/src/urlbar/completionwidget.h
+++ b/src/urlbar/completionwidget.h
@@ -58,7 +58,7 @@ private slots:
void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton);
signals:
- void chosenUrl(const QString&, Rekonq::OpenType);
+ void chosenUrl(const KUrl &, Rekonq::OpenType);
private:
void sizeAndPosition();
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index 959db360..91af352b 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -35,6 +35,7 @@
#include <KIcon>
#include <KStandardDirs>
#include <KDebug>
+#include <KUrl>
// Qt Includes
#include <QHBoxLayout>
@@ -45,12 +46,10 @@
#include <QStylePainter>
#include <QFile>
#include <QMouseEvent>
-#include <QWebSettings>
ListItem::ListItem(const UrlSearchItem &item, QWidget *parent)
: QWidget(parent)
- , m_option()
{
//preview and icon
@@ -60,7 +59,9 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent)
previewLabelIcon->setFixedSize(45,33);
hLayout->addWidget(previewLabelIcon);
- QPixmap pixmapIcon = KIcon(QWebSettings::iconForUrl(item.url)).pixmap(16);
+ // pixmap should ever exists
+ QPixmap pixmapIcon = Application::icon(item.url).pixmap(16);
+
QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(item.url) + ".png", true);
if(QFile::exists(path))
{
@@ -68,35 +69,23 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent)
previewLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
QPixmap preview;
preview.load(path);
- if (!pixmapIcon.isNull())
- {
- previewLabel->setFixedSize(38,29);
- previewLabel->setPixmap(preview.scaled(38,29, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
- }
- else
- {
- previewLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- previewLabel->setFixedSize(45,33);
- previewLabel->setPixmap(preview.scaled(45,33, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
- }
+
+ previewLabel->setFixedSize(38,29);
+ previewLabel->setPixmap(preview.scaled(38,29, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
- if (!pixmapIcon.isNull())
- {
- QLabel *iconLabel = new QLabel(previewLabelIcon);
- iconLabel->setPixmap(pixmapIcon);
- iconLabel->move(27, 16);
- }
-
- //title and url
+ QLabel *iconLabel = new QLabel(previewLabelIcon);
+ iconLabel->setPixmap(pixmapIcon);
+ iconLabel->move(27, 16);
+ //title and url
QVBoxLayout *vLayout = new QVBoxLayout;
hLayout->addLayout(vLayout);
QLabel *titleLabel = new QLabel("<b>" + item.title + "</b>");
titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- QLabel *urlLabel = new QLabel("<i>" + item.url + "</i>");
+ QLabel *urlLabel = new QLabel("<i>" + item.url.url() + "</i>");
urlLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
vLayout->addWidget(titleLabel);
@@ -126,8 +115,8 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent)
setLayout(hLayout);
- m_option.initFrom(this);
- m_option.direction = Qt::LeftToRight;
+ _option.initFrom(this);
+ _option.direction = Qt::LeftToRight;
deactivate();
}
@@ -150,9 +139,9 @@ void ListItem::insertIcon(QLayout *layout, QString icon)
//TODO: REMOVE DUPLICATE CODE WITH PREVIEWIMAGE
-QString ListItem::guessNameFromUrl(QUrl url)
+QString ListItem::guessNameFromUrl(KUrl url)
{
- QString name = url.toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash );
+ QString name = url.url();// toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash );
// TODO learn Regular Expressions :)
// and implement something better here..
@@ -171,14 +160,14 @@ QString ListItem::guessNameFromUrl(QUrl url)
void ListItem::activate()
{
- m_option.state |= QStyle::State_Selected;
+ _option.state |= QStyle::State_Selected;
update();
}
void ListItem::deactivate()
{
- m_option.state &= ~QStyle::State_Selected;
+ _option.state &= ~QStyle::State_Selected;
update();
}
@@ -187,18 +176,18 @@ void ListItem::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
- if( m_option.state.testFlag(QStyle::State_Selected) || m_option.state.testFlag(QStyle::State_MouseOver))
+ if( _option.state.testFlag(QStyle::State_Selected) || _option.state.testFlag(QStyle::State_MouseOver) )
{
QPainter painter(this);
- m_option.rect=QRect(QPoint(),size());
- style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &m_option, &painter, this);
+ _option.rect = QRect(QPoint(),size());
+ style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &_option, &painter, this);
}
}
void ListItem::enterEvent(QEvent *e)
{
- m_option.state |= QStyle::State_MouseOver;
+ _option.state |= QStyle::State_MouseOver;
update();
QWidget::enterEvent(e);
}
@@ -206,7 +195,7 @@ void ListItem::enterEvent(QEvent *e)
void ListItem::leaveEvent(QEvent *e)
{
- m_option.state &= ~QStyle::State_MouseOver;
+ _option.state &= ~QStyle::State_MouseOver;
update();
QWidget::enterEvent(e);
}
diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h
index de22d739..1b594115 100644
--- a/src/urlbar/listitem.h
+++ b/src/urlbar/listitem.h
@@ -31,6 +31,7 @@
// Forward Declarations
class UrlSearchItem;
+class KUrl;
class ListItem : public QWidget
@@ -54,7 +55,8 @@ protected:
virtual void mousePressEvent(QMouseEvent *e);
private:
- QStyleOptionViewItemV4 m_option;
- QString guessNameFromUrl(QUrl url);
+ QString guessNameFromUrl(KUrl url);
void insertIcon(QLayout *layout, QString icon);
+
+ QStyleOptionViewItemV4 _option;
};
diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp
index 6f916482..3b79b06b 100644
--- a/src/urlbar/urlbar.cpp
+++ b/src/urlbar/urlbar.cpp
@@ -73,7 +73,7 @@ UrlBar::UrlBar(QWidget *parent)
// suggestions
installEventFilter(_box);
- connect(_box, SIGNAL(chosenUrl(const QString&, Rekonq::OpenType)), SLOT(activated(const QString&, Rekonq::OpenType)));
+ connect(_box, SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), SLOT(activated(const KUrl &, Rekonq::OpenType)));
}
@@ -103,16 +103,13 @@ void UrlBar::setQUrl(const QUrl& url)
}
-void UrlBar::activated(const QString& urlString, Rekonq::OpenType type)
+void UrlBar::activated(const KUrl& url, Rekonq::OpenType type)
{
disconnect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &)));
- if (urlString.isEmpty())
- return;
-
clearFocus();
- setText(urlString);
- Application::instance()->loadUrl(urlString.trimmed(), type);
+ setUrl(url);
+ Application::instance()->loadUrl(url, type);
}
diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h
index 2536c27b..a473638b 100644
--- a/src/urlbar/urlbar.h
+++ b/src/urlbar/urlbar.h
@@ -60,7 +60,7 @@ public:
void setPrivateMode(bool on);
private slots:
- void activated(const QString& url, Rekonq::OpenType = Rekonq::CurrentTab);
+ void activated(const KUrl& url, Rekonq::OpenType = Rekonq::CurrentTab);
void suggestUrls(const QString &editedText);
void setQUrl(const QUrl &url);
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index 5f025cb5..4ff6b461 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -60,7 +60,7 @@ bool UrlSearchItem::operator==(UrlSearchItem i)
}
UrlResolver::UrlResolver(const QString &typedUrl)
- : _urlString(typedUrl)
+ : _urlString( typedUrl.trimmed() )
{
}
@@ -162,15 +162,10 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution()
QUrl urlFromUserInput = QUrl::fromUserInput(url2);
if(urlFromUserInput.isValid())
{
- QByteArray ba = urlFromUserInput.toEncoded();
- if(!ba.isEmpty())
- {
- QString gUrl = QString(ba);
- QString gTitle = i18n("Browse");
- UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle, QString("") );
- list << gItem;
-
- }
+ KUrl gUrl(urlFromUserInput);
+ QString gTitle = i18n("Browse");
+ UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle);
+ list << gItem;
}
return list;
@@ -182,19 +177,14 @@ UrlSearchList UrlResolver::webSearchesResolution()
{
UrlSearchList list;
- QString url1 = _urlString;
- if(KUrl(url1).isRelative())
+ KUrl url1(_urlString);
+ if(url1.isRelative())
{
// KUriFilter has the worst performance possible here and let this trick unusable
- QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(url1);
- QString gTitle = i18n("Search Google for %1", url1);
- UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle, QString("http://www.google.com") );
+ KUrl gUrl( QString("gg:") + _urlString );
+ QString gTitle = i18n("Search Google for %1", _urlString);
+ UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle );
list << gItem;
-
-// QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1);
-// QString wTitle = i18n("Search Wikipedia for %1", url1);
-// UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") );
-// list << wItem;
}
return list;
@@ -210,7 +200,7 @@ UrlSearchList UrlResolver::historyResolution()
QStringList historyResults = historyCompletion->substringCompletion(_urlString);
Q_FOREACH(const QString &s, historyResults)
{
- UrlSearchItem it(UrlSearchItem::History, s, Application::historyManager()->titleForHistoryUrl(s), QString("view-history"));
+ UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s) ); //, QString("view-history"));
list << it;
}
@@ -227,7 +217,7 @@ UrlSearchList UrlResolver::bookmarksResolution()
QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString);
Q_FOREACH(const QString &s, bookmarkResults)
{
- UrlSearchItem it(UrlSearchItem::Bookmark, s, Application::bookmarkProvider()->titleForBookmarkUrl(s), QString("rating") );
+ UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s) ); //, QString("rating") );
list << it;
}
diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h
index 489a5a79..3c082e00 100644
--- a/src/urlbar/urlresolver.h
+++ b/src/urlbar/urlresolver.h
@@ -28,6 +28,9 @@
#define URL_RESOLVER_H
+// KDE Includes
+#include <KUrl>
+
// Qt Includes
#include <QString>
#include <QList>
@@ -48,12 +51,11 @@ class UrlSearchItem
};
int type;
- QString url;
+ KUrl url;
QString title;
- QString icon;
- UrlSearchItem(const int &_type, const QString &_url, const QString &_title = QString(), const QString &_icon = QString())
- : type(_type), url(_url), title(_title), icon(_icon)
+ UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString())
+ : type(_type), url(_url), title(_title)
{};
bool operator==(UrlSearchItem i);