summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/application.cpp15
-rw-r--r--src/homepage.cpp67
-rw-r--r--src/homepage.h2
-rw-r--r--src/main.cpp2
-rw-r--r--src/mainview.cpp18
-rw-r--r--src/mainview.h7
-rw-r--r--src/mainwindow.cpp42
-rw-r--r--src/previewimage.cpp160
-rw-r--r--src/previewimage.h21
-rw-r--r--src/webpluginfactory.cpp6
-rw-r--r--src/websnap.cpp45
-rw-r--r--src/websnap.h3
-rw-r--r--src/webview.cpp128
-rw-r--r--src/webview.h19
15 files changed, 388 insertions, 149 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index daae3f44..71b2d77b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -66,6 +66,8 @@ TARGET_LINK_LIBRARIES ( rekonq
${QT_QTUITOOLS_LIBRARY}
${KDE4_KUTILS_LIBS}
${KDE4_KDEUI_LIBS}
+ ${KDE4_KIO_LIBS}
+ ${KDE4_KPARTS_LIBS}
)
diff --git a/src/application.cpp b/src/application.cpp
index 69acf2f2..41fcd515 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -249,8 +249,8 @@ KIcon Application::icon(const KUrl &url)
if(url.isEmpty() && Application::instance()->mainWindow()->currentTab()->url().scheme() == "rekonq")
return KIcon("arrow-right");
- if(url == KUrl("rekonq:allTabs"))
- return KIcon("tab-duplicate");
+ if(url == KUrl("rekonq:closedTabs"))
+ return KIcon("tab-close");
if(url == KUrl("rekonq:history"))
return KIcon("view-history");
if(url == KUrl("rekonq:bookmarks"))
@@ -339,12 +339,18 @@ void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type)
return;
}
+ // WARNING this is just a temporary hack waiting for the new "awesome bar" (rekonq 0.4 target)
+ // and it may not work in all cases.
+ // Known issues are (add that here to test the awesome bar code):
+ // - web shortcuts with space separator
+ // - relative urls
+ // - ...
KUrl loadingUrl(url);
if (loadingUrl.isRelative())
{
QString fn = loadingUrl.url(KUrl::RemoveTrailingSlash);
- if(loadingUrl.path().contains('.'))
+ if(loadingUrl.path().contains('.') && !loadingUrl.path().contains(' '))
{
loadingUrl.setUrl("//" + fn);
loadingUrl.setScheme("http");
@@ -365,6 +371,7 @@ void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type)
{
loadingUrl = data.uri().url();
}
+ // ------------------- END WARNING --------------------------------------
WebView *webView = 0;
MainWindow *w = 0;
@@ -442,7 +449,7 @@ MainWindowList Application::mainWindowList()
bool Application::homePage(const KUrl &url)
{
- if ( url == KUrl("rekonq:allTabs")
+ if ( url == KUrl("rekonq:closedTabs")
|| url == KUrl("rekonq:history")
|| url == KUrl("rekonq:bookmarks")
|| url == KUrl("rekonq:favorites")
diff --git a/src/homepage.cpp b/src/homepage.cpp
index 79345556..835be043 100644
--- a/src/homepage.cpp
+++ b/src/homepage.cpp
@@ -75,10 +75,10 @@ QString HomePage::rekonqHomePage(const KUrl &url)
QString speed;
QString title;
- if(url == KUrl("rekonq:allTabs"))
+ if(url == KUrl("rekonq:closedTabs"))
{
- speed = fillAllTabs();
- title = i18n("All Tabs");
+ speed = fillClosedTabs();
+ title = i18n("Closed Tabs");
}
if(url == KUrl("rekonq:history"))
{
@@ -115,26 +115,20 @@ QString HomePage::fillFavorites()
QString speed;
for(int i=0; i<8; ++i)
{
- QString text = names.at(i);
- if(text.length() > 20)
- {
- text.truncate(17);
- text += "...";
- }
speed += "<div class=\"thumbnail\">";
- speed += "<object type=\"application/image-preview\" data=\"";
- speed += urls.at(i) + "\" width=\"200\">";
+ speed += "<object type=\"application/image-preview\" data=\"" + urls.at(i) + "\" >";
+ speed += "<param name=\"title\" value=\"" + names.at(i) + "\" />";
speed += "<param name=\"index\" value=\"" + QString::number(i) + "\" />";
speed += "<param name=\"isFavorite\" value=\"true\" />";
speed += "</object>";
- speed += "<br />";
- speed += "<a href=\"" + urls.at(i) + "\">" + text + "</a></div>";
+ speed += "</div>";
}
return speed;
}
+// FIXME : port to new PreviewImage API to use...
QString HomePage::lastVisitedSites()
{
QString last;
@@ -143,11 +137,10 @@ QString HomePage::lastVisitedSites()
{
HistoryItem it = history.at(i);
last += "<div class=\"thumbnail\">";
- last += "<object type=\"application/image-preview\" data=\"" + it.url;
- last += "\" width=\"200\">";
+ last += "<object type=\"application/image-preview\" data=\"" + it.url + "\" >";
last += "</object>";
last += "<br />";
- last += "<a href=\"" + it.url + "\">" + it.url + "</a></div>";
+ last += "<a href=\"" + it.url + "\">" + it.title + "</a></div>";
}
return last;
@@ -170,11 +163,11 @@ QString HomePage::homePageMenu(KUrl currentUrl)
menu += "</a></div>";
menu += "<div class=\"link";
- if(currentUrl == "rekonq:allTabs")
+ if(currentUrl == "rekonq:closedTabs")
menu += " current";
- menu += "\"><a href=\"rekonq:allTabs\">";
- menu += "<img src=\"file:///" + loader->iconPath("tab-duplicate", KIconLoader::Desktop || KIconLoader::SizeSmall) + "\" />";
- menu += i18n("All Tabs");
+ menu += "\"><a href=\"rekonq:closedTabs\">";
+ menu += "<img src=\"file:///" + loader->iconPath("tab-close", KIconLoader::Desktop || KIconLoader::SizeSmall) + "\" />";
+ menu += i18n("Closed Tabs");
menu += "</a></div>";
menu += "<div class=\"link";
@@ -276,29 +269,19 @@ QString HomePage::createBookItem(const KBookmark &bookmark)
}
-QString HomePage::fillAllTabs()
+QString HomePage::fillClosedTabs()
{
- QString tabs;
+ QList<HistoryItem> links = Application::instance()->mainWindow()->mainView()->recentlyClosedTabs();
+ QString closed;
- MainView *mv = Application::instance()->mainWindow()->mainView();
- for (int i = 0 ; i < mv->count() -1 ; i++)
+ Q_FOREACH( const HistoryItem &item, links)
{
- QString urlString = mv->webView(i)->url().toEncoded(QUrl::StripTrailingSlash);
- QString title = mv->webView(i)->title();
-
- if(title.length() > 20)
- {
- title.truncate(17);
- title += "...";
- }
- tabs += "<div class=\"thumbnail\">";
- tabs += "<object type=\"application/image-preview\" data=\"";
- tabs += urlString + "\" width=\"200\">";
- tabs += "<param name=\"index\" value=\"" + QString::number(i) + "\" />";
- tabs += "</object>";
- tabs += "<br />";
- tabs += "<a href=\"" + urlString + "\">" + title + "</a></div>";
- }
-
- return tabs;
+ closed += "<div class=\"thumbnail\">";
+ closed += "<object type=\"application/image-preview\" data=\"" + item.url + "\" >";
+ closed += "<param name=\"title\" value=\"" + item.title + "\" />";
+ closed += "</object>";
+ closed += "</div>";
+ }
+
+ return closed;
}
diff --git a/src/homepage.h b/src/homepage.h
index 06db0822..7963119c 100644
--- a/src/homepage.h
+++ b/src/homepage.h
@@ -55,7 +55,7 @@ private:
QString lastVisitedSites();
QString fillHistory();
QString fillBookmarks();
- QString fillAllTabs();
+ QString fillClosedTabs();
QString createBookItem(const KBookmark &bookmark);
diff --git a/src/main.cpp b/src/main.cpp
index e0e8292f..d30ae8e5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -38,7 +38,7 @@ static const char description[] =
I18N_NOOP("A lightweight Web Browser for KDE based on WebKit");
-static const char version[] = "0.2.68";
+static const char version[] = "0.2.69";
int main(int argc, char **argv)
diff --git a/src/mainview.cpp b/src/mainview.cpp
index 8c6ba19b..1848e682 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -181,6 +181,8 @@ void MainView::clear()
// What exactly do we need to clear here?
m_urlBar->clearHistory();
m_urlBar->clear();
+
+ m_recentlyClosedTabs.clear();
}
@@ -414,6 +416,16 @@ void MainView::slotCloseTab(int index)
return;
}
hasFocus = tab->hasFocus();
+
+ //store close tab except homepage
+ if (!tab->url().prettyUrl().startsWith("rekonq:") && !tab->url().isEmpty())
+ {
+ QString title = tab->title();
+ QString url = tab->url().prettyUrl();
+ HistoryItem item(url, QDateTime::currentDateTime(), title);
+ m_recentlyClosedTabs.removeAll(item);
+ m_recentlyClosedTabs.prepend(item);
+ }
}
QWidget *webView = widget(index);
@@ -573,6 +585,12 @@ QLabel *MainView::animatedLoading(int index, bool addMovie)
}
+QList<HistoryItem> MainView::recentlyClosedTabs()
+{
+ return m_recentlyClosedTabs;
+}
+
+
void MainView::resizeEvent(QResizeEvent *event)
{
updateTabBar();
diff --git a/src/mainview.h b/src/mainview.h
index 4ba65e28..c2795048 100644
--- a/src/mainview.h
+++ b/src/mainview.h
@@ -34,6 +34,7 @@
#include "webview.h"
#include "webpage.h"
#include "application.h"
+#include "history.h"
// KDE Includes
#include <KTabWidget>
@@ -89,6 +90,8 @@ public:
*/
WebView *newWebView(bool focused = true, bool nearParent = false);
+ QList<HistoryItem> recentlyClosedTabs();
+
signals:
// tab widget signals
void tabsChanged();
@@ -154,8 +157,10 @@ private:
TabBar *m_tabBar;
QString m_loadingGitPath;
-
+
int m_currentTabIndex;
+
+ QList<HistoryItem> m_recentlyClosedTabs;
};
#endif // MAINVIEW_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 7f2bcdeb..4e9c4b26 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -147,7 +147,7 @@ MainWindow::~MainWindow()
{
Application::instance()->removeMainWindow(this);
delete m_popup;
- delete m_view;
+// delete m_view;
}
@@ -207,7 +207,9 @@ void MainWindow::postLaunch()
// update toolbar actions signals
connect(m_view, SIGNAL(tabsChanged()), this, SLOT(slotUpdateActions()));
connect(m_view, SIGNAL(currentChanged(int)), this, SLOT(slotUpdateActions()));
-
+ // launch it manually. Just the first time...
+ slotUpdateActions();
+
// Find Bar signal
connect(m_findBar, SIGNAL(searchString(const QString &)), this, SLOT(slotFind(const QString &)));
@@ -1054,22 +1056,22 @@ void MainWindow::slotAboutToShowBackMenu()
return;
QWebHistory *history = currentTab()->history();
int historyCount = history->count();
+
// Limit history views in the menu to 8
- int limit = 0;
+ if(historyCount > 8)
+ historyCount = 8;
+
+ kDebug() << "History Count: " << historyCount;
for (int i = history->backItems(historyCount).count() - 1; i >= 0; --i)
{
- qDebug() << history->currentItemIndex();
QWebHistoryItem item = history->backItems(history->count()).at(i);
KAction *action = new KAction(this);
- action->setData(history->currentItemIndex() - (i + 1));
- QIcon icon = Application::icon(item.url());
+ action->setData( i - history->currentItemIndex() );
+ kDebug() << "Current Item Index: " << history->currentItemIndex();
+ QIcon icon = Application::icon(item.url());
action->setIcon(icon);
action->setText(item.title());
m_historyBackMenu->addAction(action);
- ++limit;
- if (limit >= 8) {
- break;
- }
}
}
@@ -1077,20 +1079,26 @@ void MainWindow::slotAboutToShowBackMenu()
void MainWindow::slotOpenActionUrl(QAction *action)
{
int offset = action->data().toInt();
+ kDebug() << "Offset: " << offset;
QWebHistory *history = currentTab()->history();
- qDebug() << offset;
- qDebug() << history->itemAt(offset).isValid();
+
+ if(!history->itemAt(offset).isValid())
+ {
+ kDebug() << "Invalid Offset!";
+ return;
+ }
+
if (offset < 0)
{
history->goToItem(history->itemAt(offset)); // back
+ return;
}
- else
+
+ if (offset > 0)
{
- if (offset > 0)
- {
- history->goToItem(history->forwardItems(history->count() - offset + 1).back()); // forward
- }
+ history->goToItem(history->forwardItems(history->count() - offset).back()); // forward FIXME CRASH
}
+
}
diff --git a/src/previewimage.cpp b/src/previewimage.cpp
index 03741770..e7f8aea5 100644
--- a/src/previewimage.cpp
+++ b/src/previewimage.cpp
@@ -48,17 +48,31 @@
#include <QMovie>
#include <QMouseEvent>
#include <QHBoxLayout>
+#include <QVBoxLayout>
-PreviewImage::PreviewImage(const QUrl &url, int index, bool isFavorite)
- : QLabel()
+PreviewImage::PreviewImage(const QUrl &url, const QString &title, int index, bool isFavorite)
+ : QWidget()
, ws(0)
- , m_url(0)
, loadingSnapshot(false)
+ , m_url(0)
+ , m_title(title)
, m_isFavorite(isFavorite)
, m_index(index)
, m_button(0)
-{
+ , m_imageLabel(new QLabel)
+ , m_textLabel(new QLabel)
+{
+ setMinimumSize(300,200);
+
+ m_imageLabel->setAlignment(Qt::AlignCenter);
+ m_textLabel->setAlignment(Qt::AlignCenter);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(m_imageLabel);
+ mainLayout->addWidget(m_textLabel);
+ setLayout(mainLayout);
+
loadUrlPreview(url);
}
@@ -66,6 +80,8 @@ PreviewImage::PreviewImage(const QUrl &url, int index, bool isFavorite)
PreviewImage::~PreviewImage()
{
delete ws;
+ delete m_textLabel;
+ delete m_imageLabel;
}
@@ -73,33 +89,36 @@ PreviewImage::~PreviewImage()
void PreviewImage::loadUrlPreview(const QUrl& url)
{
m_url = url;
-
+
if(url.isEmpty())
{
showEmptyPreview();
return;
}
-
+
m_savePath = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(m_url) + ".png", true);
-
+
if(QFile::exists(m_savePath))
{
m_pixmap.load(m_savePath);
- setPixmap(m_pixmap);
+ m_imageLabel->setPixmap(m_pixmap);
+ checkTitle();
+ m_textLabel->setText(m_title);
}
else
{
loadingSnapshot = true;
ws = new WebSnap( url );
connect(ws, SIGNAL(finished()), this, SLOT(snapFinished()));
-
+
QString path = KStandardDirs::locate("appdata", "pics/busywidget.gif");
-
+
// load an animation waiting for site preview
QMovie *movie = new QMovie(path, QByteArray(), this);
movie->setSpeed(50);
- setMovie(movie);
+ m_imageLabel->setMovie(movie);
movie->start();
+ m_textLabel->setText( i18n("Loading preview...") );
}
}
@@ -107,29 +126,36 @@ void PreviewImage::loadUrlPreview(const QUrl& url)
void PreviewImage::snapFinished()
{
loadingSnapshot = false;
- QMovie *m = movie();
+ QMovie *m = m_imageLabel->movie();
delete m;
- setMovie(0);
+ m_imageLabel->setMovie(0);
m_pixmap = ws->previewImage();
- setPixmap(m_pixmap);
-
- m_pixmap.save(m_savePath);
+ m_imageLabel->setPixmap(m_pixmap);
+ checkTitle();
+ m_textLabel->setText(m_title);
+// kDebug() << "m_pixmap: " << m_pixmap.size();
+// kDebug() << "text label: " << m_textLabel->size();
+// kDebug() << "image label: " << m_imageLabel->size();
+// kDebug() << "widget: " << size();
+
+ m_pixmap.save(m_savePath);
+
if(m_index > -1)
{
// Update title
QStringList names = ReKonfig::previewNames();
// update url (for added thumbs)
QStringList urls = ReKonfig::previewUrls();
-
+
// stripTrailingSlash to be sure to get the same string for same adress
urls.replace(m_index, ws->snapUrl().toString(QUrl::StripTrailingSlash));
names.replace(m_index, ws->snapTitle());
-
+
ReKonfig::setPreviewNames(names);
ReKonfig::setPreviewUrls(urls);
-
+
ReKonfig::self()->writeConfig();
}
}
@@ -140,10 +166,11 @@ void PreviewImage::showEmptyPreview()
if(!m_isFavorite)
return;
- clear();
+ m_imageLabel->clear();
+ m_textLabel->clear();
- QHBoxLayout *layout = new QHBoxLayout(this);
- m_button = new QToolButton(this);
+ QHBoxLayout *layout = new QHBoxLayout(m_imageLabel);
+ m_button = new QToolButton(m_imageLabel);
m_button->setDefaultAction(historyMenu());
m_button->setPopupMode(QToolButton::InstantPopup);
m_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
@@ -151,6 +178,7 @@ void PreviewImage::showEmptyPreview()
m_button->setAutoRaise(true);
m_button->setIconSize(QSize(48, 48));
layout->addWidget(m_button);
+ m_imageLabel->setLayout(layout);
}
@@ -172,24 +200,10 @@ void PreviewImage::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
- if(m_isFavorite)
- {
- Application::instance()->loadUrl(m_url);
- }
- else
- {
- MainView *mv = Application::instance()->mainWindow()->mainView();
- int actualIndex = mv->currentIndex();
-
- kDebug() << "Actual index: " << actualIndex;
- kDebug() << "m_index: " << m_index;
-
- mv->slotCloseTab(actualIndex);
- mv->setCurrentIndex(m_index);
- }
+ Application::instance()->loadUrl(m_url);
return;
};
- QLabel::mousePressEvent(event);
+ QWidget::mousePressEvent(event);
}
@@ -198,31 +212,31 @@ void PreviewImage::mouseReleaseEvent(QMouseEvent *event)
kDebug() << "NO000... don't leave your finger from the button!!";
Q_UNUSED(event)
}
-
+
void PreviewImage::contextMenuEvent(QContextMenuEvent* event)
{
if(!m_isFavorite)
return;
-
+
if(loadingSnapshot)
return;
-
+
KMenu menu(this);
KAction *a;
-
+
if(!m_url.isEmpty())
{
a = new KAction(KIcon("edit-delete"), i18n("Remove Thumbnail"), this);
connect(a, SIGNAL(triggered(bool)), this, SLOT(removeMe()));
menu.addAction(a);
-
+
a = new KAction(KIcon("view-refresh"), i18n("Refresh Thumbnail"), &menu);
connect(a, SIGNAL(triggered(bool)), this, SLOT(refreshPreview()));
menu.addAction(a);
}
menu.addAction(historyMenu());
-
+
menu.exec(mapToGlobal(event->pos()));
}
@@ -231,7 +245,7 @@ KActionMenu* PreviewImage::historyMenu()
{
KActionMenu *histMenu = new KActionMenu(KIcon("insert-image"), i18n("Set page to preview"), this);
QList<HistoryItem> history = Application::historyManager()->history();
-
+
if(history.isEmpty())
{
KAction *a = new KAction(i18n("History is empty"), this);
@@ -239,17 +253,19 @@ KActionMenu* PreviewImage::historyMenu()
histMenu->addAction(a);
return histMenu;
}
-
+
int maxItems = 15;
for (int i = 0; i < maxItems && i < history.size() ; ++i)
{
HistoryItem it = history.at(i);
KAction *a = new KAction(Application::icon(it.url), it.title, this);
- a->setData(it.url);
+ QStringList urlData;
+ urlData << it.url << it.title;
+ a->setData(urlData);
connect(a, SIGNAL(triggered(bool)), this, SLOT(setUrlFromAction()));
histMenu->addAction(a);
}
-
+
return histMenu;
}
@@ -258,20 +274,20 @@ void PreviewImage::removeMe()
{
QStringList names = ReKonfig::previewNames();
QStringList urls = ReKonfig::previewUrls();
-
+
int index = urls.indexOf(QRegExp(m_url.toString(QUrl::StripTrailingSlash), Qt::CaseSensitive, QRegExp::FixedString));
urls.replace(index, QString(""));
names.replace(index, QString(""));
-
+
ReKonfig::setPreviewNames(names);
ReKonfig::setPreviewUrls(urls);
-
+
// sync file data
ReKonfig::self()->writeConfig();
showEmptyPreview();
-
+
m_url = "";
}
@@ -279,15 +295,33 @@ void PreviewImage::removeMe()
void PreviewImage::setUrlFromAction()
{
KAction *a = qobject_cast<KAction*>(sender());
- KUrl url = KUrl(a->data().toString());
-
+ QStringList urlData = a->data().toStringList();
+
+ m_url = KUrl(urlData.at(0));
+ m_title = urlData.at(1);
+ checkTitle();
+
if(m_button)
{
- layout()->deleteLater();
+ m_imageLabel->layout()->deleteLater();
m_button->menu()->deleteLater();
m_button->deleteLater();
- }
- loadUrlPreview(url);
+ }
+ loadUrlPreview(m_url);
+
+ // Update title
+ QStringList names = ReKonfig::previewNames();
+ // update url (for added thumbs)
+ QStringList urls = ReKonfig::previewUrls();
+
+ // stripTrailingSlash to be sure to get the same string for same adress
+ urls.replace(m_index, m_url.toString(QUrl::StripTrailingSlash));
+ names.replace(m_index, m_title);
+
+ ReKonfig::setPreviewNames(names);
+ ReKonfig::setPreviewUrls(urls);
+
+ ReKonfig::self()->writeConfig();
}
@@ -313,6 +347,16 @@ QString PreviewImage::guessNameFromUrl(QUrl url)
name.remove('?');
name.remove('=');
name.remove('+');
-
+
return name;
}
+
+
+void PreviewImage::checkTitle()
+{
+ if(m_title.length() > 23)
+ {
+ m_title.truncate(20);
+ m_title += "...";
+ }
+}
diff --git a/src/previewimage.h b/src/previewimage.h
index 5568dd29..d7f4d2aa 100644
--- a/src/previewimage.h
+++ b/src/previewimage.h
@@ -35,16 +35,19 @@
// Qt Includes
#include <QLabel>
+#include <QFrame>
#include <QImage>
#include <QUrl>
#include <QToolButton>
+#include <QSize>
-class PreviewImage : public QLabel
+
+class PreviewImage : public QWidget
{
Q_OBJECT
public:
- PreviewImage(const QUrl &url, int index, bool isFavorite);
+ PreviewImage(const QUrl &url, const QString &title, int index, bool isFavorite);
~PreviewImage();
QString guessNameFromUrl(QUrl url);
@@ -54,7 +57,7 @@ public slots:
void removeMe();
void setUrlFromAction();
void refreshPreview();
-
+
protected:
void contextMenuEvent(QContextMenuEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
@@ -67,17 +70,23 @@ protected:
void showEmptyPreview();
private:
+ void checkTitle();
+
QPixmap m_pixmap;
WebSnap *ws;
- QUrl m_url;
- QString m_savePath;
-
+ QString m_savePath;
bool loadingSnapshot;
+
+ QUrl m_url;
+ QString m_title;
bool m_isFavorite;
int m_index;
QToolButton *m_button;
+
+ QLabel *m_imageLabel;
+ QLabel *m_textLabel;
};
#endif // PREVIEW_IMAGE_H
diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp
index b9d50697..3daffbb6 100644
--- a/src/webpluginfactory.cpp
+++ b/src/webpluginfactory.cpp
@@ -57,10 +57,14 @@ QObject *WebPluginFactory::create(const QString &mimeType,
if(mimeType == QString("application/image-preview") )
{
+ QString title;
int number = -1;
bool isFavorite = false;
int i;
+ i = argumentNames.indexOf( QString("title") );
+ if(i > -1)
+ title = argumentValues.at(i);
i = argumentNames.indexOf( QString("isFavorite") );
if(i > -1)
isFavorite = true;
@@ -68,7 +72,7 @@ QObject *WebPluginFactory::create(const QString &mimeType,
if(i > -1)
number = argumentValues.at(i).toInt();
- return new PreviewImage(url, number, isFavorite);
+ return new PreviewImage(url, title, number, isFavorite);
}
// this let QtWebKit using builtin plugins
diff --git a/src/websnap.cpp b/src/websnap.cpp
index 577370ba..bb2baf49 100644
--- a/src/websnap.cpp
+++ b/src/websnap.cpp
@@ -74,7 +74,7 @@ void WebSnap::load()
}
-QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h)
+QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h, bool border)
{
// prepare page
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); // Why it doesn't work with one setScrollBarPolicy?
@@ -95,16 +95,15 @@ QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h)
size = QSize(width,width*((0.0+h)/w));
page.setViewportSize(size);
}
-
- // create the target surface
- QPixmap image = QPixmap(size);
- image.fill(Qt::transparent);
-
- // render
- QPainter p(&image);
+
+ // create the page image
+ QImage pageImage = QImage(size, QImage::Format_ARGB32_Premultiplied);
+ pageImage.fill(Qt::transparent);
+ // render it
+ QPainter p(&pageImage);
page.mainFrame()->render(&p);
p.end();
- image = image.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
+ pageImage = pageImage.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
// restore page settings
page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAsNeeded);
@@ -112,7 +111,31 @@ QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h)
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);
- return image;
+ if(!border)
+ return QPixmap::fromImage(pageImage);
+
+ // background image
+ QSize fixedSize(w + 30, h + 26);
+ QImage backImage = QImage(fixedSize, QImage::Format_ARGB32_Premultiplied);
+ QString backImagePath = KStandardDirs::locate("appdata", "pics/bg.png");
+ backImage.load( backImagePath );
+
+ // create target
+ QImage resultImage = QImage(fixedSize, QImage::Format_ARGB32_Premultiplied);
+ resultImage.fill(Qt::transparent);
+
+ QPainter pt(&resultImage);
+ pt.setCompositionMode(QPainter::CompositionMode_Source);
+ pt.fillRect(resultImage.rect(), Qt::transparent);
+ pt.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ pt.drawImage(0, 0, backImage);
+ pt.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ pt.drawImage(15, 13, pageImage);
+ pt.setCompositionMode(QPainter::CompositionMode_DestinationOver);
+ pt.fillRect(resultImage.rect(), Qt::transparent);
+ pt.end();
+
+ return QPixmap::fromImage(resultImage);
}
@@ -125,7 +148,7 @@ void WebSnap::saveResult(bool ok)
return;
}
- m_image = renderPreview(m_page, WIDTH, HEIGHT);
+ m_image = renderPreview(m_page, WIDTH, HEIGHT, true);
emit finished();
}
diff --git a/src/websnap.h b/src/websnap.h
index 53686677..026c236c 100644
--- a/src/websnap.h
+++ b/src/websnap.h
@@ -34,6 +34,7 @@
// Qt Includes
#include <QtCore/QObject>
#include <QPixmap>
+#include <QImage>
#include <QWebPage>
@@ -51,7 +52,7 @@ public:
~WebSnap();
QPixmap previewImage();
- static QPixmap renderPreview(const QWebPage &page, int w, int h);
+ static QPixmap renderPreview(const QWebPage &page, int w, int h, bool border = false);
QString snapTitle();
QUrl snapUrl();
diff --git a/src/webview.cpp b/src/webview.cpp
index 9e06c9da..2fe3775b 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -52,18 +52,27 @@
#include <QtGui/QClipboard>
#include <QtGui/QKeyEvent>
#include <QtGui/QAction>
+#include <QtCore/QTimer>
WebView::WebView(QWidget* parent)
: QWebView(parent)
, m_page(new WebPage(this))
, m_progress(0)
+ , m_scrollTimer(new QTimer(this))
+ , m_scrollDirection(WebView::NoScroll)
+ , m_scrollSpeedVertical(0)
+ , m_scrollSpeedHorizontal(0)
+
{
setPage(m_page);
connect(page(), SIGNAL(statusBarMessage(const QString&)), this, SLOT(setStatusBarText(const QString&)));
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotUpdateProgress(int)));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));
+
+ connect(m_scrollTimer, SIGNAL(timeout()), this, SLOT(scrollFrameChanged()));
+ m_scrollTimer->setInterval(50);
}
@@ -106,6 +115,7 @@ void WebView::setStatusBarText(const QString &string)
m_statusBarText = string;
}
+
void WebView::contextMenuEvent(QContextMenuEvent *event)
{
QWebHitTestResult result = page()->mainFrame()->hitTestContent(event->pos());
@@ -135,6 +145,8 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
a = pageAction(QWebPage::CopyLinkToClipboard);
a->setIcon(KIcon("edit-copy"));
menu.addAction(a);
+
+ menu.addSeparator();
}
// is content editable && selected? Add CUT
@@ -153,6 +165,10 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
a = pageAction(QWebPage::Copy);
a->setIcon(KIcon("edit-copy"));
a->setShortcut(KStandardShortcut::copy().primary());
+ if(!result.isContentEditable()) // "Cut" "Copy Text" "Paste" is ugly. Don't add "text" with cut/paste
+ a->setText(i18n("Copy Text"));
+ else
+ a->setText(i18n("Copy"));
menu.addAction(a);
}
@@ -168,7 +184,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
// is content selected? Add SEARCH actions
if(result.isContentSelected())
{
- KActionMenu *searchMenu = new KActionMenu(i18n("Search with"), this);
+ KActionMenu *searchMenu = new KActionMenu(KIcon("edit-find"), i18n("Search with"), this);
KConfig config("kuriikwsfilterrc"); //Share with konqueror
KConfigGroup cg = config.group("General");
@@ -196,12 +212,12 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
}
}
}
-
+
if (!searchMenu->menu()->isEmpty())
{
menu.addAction(searchMenu);
}
-
+
menu.addSeparator();
// TODO Add translate, show translation
}
@@ -233,7 +249,10 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
{
// page action
QString text = selectedText();
- if (text.startsWith( QLatin1String("http://") ) || text.startsWith( QLatin1String("https://") ) || text.startsWith( QLatin1String("www.") ) )
+ if (text.startsWith( QLatin1String("http://") )
+ || text.startsWith( QLatin1String("https://") )
+ || text.startsWith( QLatin1String("www.") )
+ )
{
QString truncatedURL = text;
if (text.length() > 18)
@@ -322,8 +341,82 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
}
+void WebView::stopScrollAnimation()
+{
+ m_scrollTimer->stop();
+ m_scrollSpeedVertical = 0;
+ m_scrollSpeedHorizontal = 0;
+ m_scrollDirection = WebView::NoScroll;
+}
+
+
+void WebView::startScrollAnimation(ScrollDirection direction)
+{
+ // if no scrollspeed, set the requested direction, otherwise it's just a slowdown or speedup
+ if (m_scrollSpeedVertical == 0 && (direction == WebView::Up || direction == WebView::Down))
+ m_scrollDirection |= direction;
+ if (m_scrollSpeedHorizontal == 0 && (direction == WebView::Left || direction == WebView::Right))
+ m_scrollDirection |= direction;
+
+ // update scrollspeed
+ switch (direction)
+ {
+ case WebView::Up:
+ --m_scrollSpeedVertical;
+ break;
+ case WebView::Down:
+ ++m_scrollSpeedVertical;
+ break;
+ case WebView::Left:
+ --m_scrollSpeedHorizontal;
+ break;
+ case WebView::Right:
+ ++m_scrollSpeedHorizontal;
+ break;
+ default:
+ break;
+ }
+
+ if (!m_scrollTimer->isActive())
+ m_scrollTimer->start();
+
+ return;
+}
+
+
+void WebView::scrollFrameChanged()
+{
+ // clear finished scrolling
+ if (m_scrollSpeedVertical == 0)
+ m_scrollDirection &= ~WebView::Up | ~WebView::Down;
+ if (m_scrollSpeedHorizontal == 0)
+ m_scrollDirection &= ~WebView::Left | ~WebView::Right;
+
+ // all scrolling finished
+ if (m_scrollDirection == WebView::NoScroll)
+ {
+ m_scrollTimer->stop();
+ return;
+ }
+
+ // do the scrolling
+ page()->currentFrame()->scroll(m_scrollSpeedHorizontal, m_scrollSpeedVertical);
+
+ // check if we reached the end
+ int y = page()->currentFrame()->scrollPosition().y();
+ int x = page()->currentFrame()->scrollPosition().x();
+
+ if (y == 0 || y == page()->currentFrame()->scrollBarMaximum(Qt::Vertical))
+ m_scrollSpeedVertical = 0;
+ if (x == 0 || x == page()->currentFrame()->scrollBarMaximum(Qt::Horizontal))
+ m_scrollSpeedHorizontal = 0;
+}
+
+
void WebView::mousePressEvent(QMouseEvent *event)
{
+ stopScrollAnimation();
+
m_page->m_pressedButtons = event->buttons();
m_page->m_keyboardModifiers = event->modifiers();
@@ -352,6 +445,8 @@ void WebView::mouseMoveEvent(QMouseEvent *event)
void WebView::wheelEvent(QWheelEvent *event)
{
+ stopScrollAnimation();
+
if (QApplication::keyboardModifiers() & Qt::ControlModifier)
{
int numDegrees = event->delta() / 8;
@@ -395,7 +490,7 @@ void WebView::viewImage(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifier
{
KAction *a = qobject_cast<KAction*>(sender());
KUrl url(a->data().toUrl());
-
+
if (modifiers & Qt::ControlModifier || buttons == Qt::MidButton)
{
Application::instance()->loadUrl(url, Rekonq::SettingOpenTab);
@@ -423,7 +518,6 @@ void WebView::openLinkInNewTab()
}
-// HACK short term hack: remove this function, unuseful in kdewebkit porting
void WebView::keyPressEvent(QKeyEvent *event)
{
if ((event->modifiers() == Qt::ControlModifier) && (event->key() == Qt::Key_C))
@@ -431,5 +525,27 @@ void WebView::keyPressEvent(QKeyEvent *event)
triggerPageAction(QWebPage::Copy);
return;
}
+
+ if (event->modifiers() == Qt::ShiftModifier)
+ {
+ switch (event->key())
+ {
+ case Qt::Key_Down:
+ startScrollAnimation(WebView::Down);
+ return;
+ case Qt::Key_Up:
+ startScrollAnimation(WebView::Up);
+ return;
+ case Qt::Key_Left:
+ startScrollAnimation(WebView::Left);
+ return;
+ case Qt::Key_Right:
+ startScrollAnimation(WebView::Right);
+ return;
+ default:
+ break;
+ }
+ }
+
QWebView::keyPressEvent(event);
}
diff --git a/src/webview.h b/src/webview.h
index 3388348d..d3f58f2e 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -37,13 +37,24 @@
// Forward Declarations
class WebPage;
+class QTimer;
class WebView : public QWebView
{
Q_OBJECT
+ Q_ENUMS(ScrollDirection)
public:
+ enum ScrollDirection
+ {
+ NoScroll = 0,
+ Up = 2,
+ Down = 4,
+ Left = 6,
+ Right = 16
+ };
+
explicit WebView(QWidget *parent = 0);
~WebView();
@@ -71,10 +82,18 @@ private slots:
void openLinkInNewWindow();
void openLinkInNewTab();
+ void startScrollAnimation(ScrollDirection direction);
+ void stopScrollAnimation();
+ void scrollFrameChanged();
+
private:
WebPage *m_page;
int m_progress;
QString m_statusBarText;
+ QTimer *m_scrollTimer;
+ int m_scrollDirection;
+ int m_scrollSpeedVertical;
+ int m_scrollSpeedHorizontal;
};
#endif