Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tabhistory: first cut

  • Loading branch information...
commit 035bff74bf2e31c5bc518dcdb2bcf6cdbee43bfc 1 parent b44f73b
@mwenge mwenge authored committed
View
10 README
@@ -1,3 +1,13 @@
+Tab History Flicking
+
+This builds on the work in http://github.com/mwenge/torora/tree/screenhistory.
+
+Thumbnails of the screens contained in hidden tabs pop down when you hover over
+the tab. You can then flick through a thumbnail history of the tab using the
+mouse wheel. Clicking the tab will load the page presented by the thumbnail.
+
+
+--------------
Quickflick
This feature proposal allows the user to flick quickly back and forth through their
View
3  src/browsermainwindow.cpp
@@ -1629,8 +1629,7 @@ void BrowserMainWindow::keyReleaseEvent ( QKeyEvent * event ) {
m_lookback = false;
QWebHistory *history = currentTab()->history();
currentTab()->clearScreenShot();
- if (currentTab()->lookBackItem() != history->currentItemIndex())
- history->goToItem(history->items().at(currentTab()->lookBackItem()));
+ currentTab()->loadLookBackItem();
event->accept();
return;
}
View
46 src/tabbar.cpp
@@ -67,6 +67,7 @@
#include <qaction.h>
#include <qapplication.h>
#include <qclipboard.h>
+#include <qdebug.h>
#include <qevent.h>
#include <qmenu.h>
#include <qstyle.h>
@@ -89,6 +90,7 @@ TabBar::TabBar(QWidget *parent)
: QTabBar(parent)
, m_viewTabBarAction(0)
, m_showTabBarWhenOneTab(true)
+ , m_oldIndex(0)
{
setContextMenuPolicy(Qt::CustomContextMenu);
setAcceptDrops(true);
@@ -343,3 +345,47 @@ void TabBar::updateVisibility()
updateViewToolBarAction();
}
+void TabBar::wheelEvent(QWheelEvent *event)
+{
+// if (event->modifiers() & Qt::ControlModifier) {
+ int index = tabAt(event->pos());
+ int numDegrees = event->delta() / 8;
+ int numSteps = numDegrees / 15;
+ QRect rect = tabRect(index);
+
+ emit rotateThumb(numSteps, index, rect.x());
+ event->accept();
+ return;
+// }
+ QTabBar::wheelEvent(event);
+}
+
+void TabBar::enterEvent(QEvent *event)
+{
+ int index = tabAt(QWidget::mapFromGlobal(QCursor::pos()));
+ QRect rect = tabRect(index);
+ emit displayThumb(index, rect.x());
+ event->accept();
+}
+
+void TabBar::leaveEvent(QEvent *event)
+{
+ emit clearThumb(m_oldIndex);
+ event->accept();
+}
+
+bool TabBar::event(QEvent *event)
+{
+ if (event->type() == QEvent::HoverMove
+ || event->type() == QEvent::HoverEnter) {
+ QHoverEvent *he = static_cast<QHoverEvent *>(event);
+ int index = tabAt(he->pos());
+ if (index != -1 && index != m_oldIndex) {
+ emit clearThumb(m_oldIndex);
+ QRect rect = tabRect(index);
+ emit displayThumb(index, rect.x());
+ m_oldIndex = index;
+ }
+ }
+ return QTabBar::event(event);
+}
View
8 src/tabbar.h
@@ -82,6 +82,9 @@ class TabBar : public QTabBar
void reloadTab(int index);
void reloadAllTabs();
void loadUrl(const QUrl &url, TabWidget::OpenUrlIn tab);
+ void displayThumb(int index, int x);
+ void rotateThumb(int index, int numSteps, int x);
+ void clearThumb(int index);
public:
TabBar(QWidget *parent = 0);
@@ -111,14 +114,19 @@ private slots:
void contextMenuRequested(const QPoint &position);
void updateViewToolBarAction();
void viewTabBar();
+ bool event(QEvent *event);
private:
void updateVisibility();
friend class TabWidget;
+ void wheelEvent(QWheelEvent *event);
+ void enterEvent(QEvent *event);
+ void leaveEvent(QEvent *event);
QPoint m_dragStartPos;
QAction *m_viewTabBarAction;
bool m_showTabBarWhenOneTab;
+ int m_oldIndex;
};
View
56 src/tabwidget.cpp
@@ -129,6 +129,9 @@ TabWidget::TabWidget(QWidget *parent)
connect(m_tabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(closeOtherTabs(int)));
connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
connect(m_tabBar, SIGNAL(reloadAllTabs()), this, SLOT(reloadAllTabs()));
+ connect(m_tabBar, SIGNAL(displayThumb(int, int)), this, SLOT(displayThumb(int, int)));
+ connect(m_tabBar, SIGNAL(rotateThumb(int, int, int)), this, SLOT(rotateThumb(int, int, int)));
+ connect(m_tabBar, SIGNAL(clearThumb(int)), this, SLOT(clearThumb(int)));
setTabBar(m_tabBar);
setDocumentMode(true);
connect(m_tabBar, SIGNAL(tabMoved(int, int)),
@@ -280,6 +283,9 @@ void TabWidget::currentChanged(int index)
} else if (!webView->url().isEmpty()) {
webView->setFocus();
}
+
+ webView->loadLookBackItem();
+
}
QAction *TabWidget::newTabAction() const
@@ -1126,3 +1132,53 @@ void TabWidget::createTab(const QByteArray &historyState, TabWidget::OpenUrlIn t
#endif
}
+void TabWidget::displayThumb(int index, int x)
+{
+ if (index < 0)
+ index = currentIndex();
+ if (index < 0 || index >= count())
+ return;
+ if (index == currentIndex())
+ return;
+
+ if (WebView *tab = webView(index)) {
+ WebView *currentTab = webView(currentIndex());
+ QPixmap image = tab->currentScreenImage();
+ int height = image.height() / 3;
+ int width = image.width() / 3;
+ currentTab->displayThumb(image.scaled(width,height), x);
+ }
+}
+
+void TabWidget::rotateThumb(int numSteps, int index, int x)
+{
+ if (index < 0)
+ index = currentIndex();
+ if (index < 0 || index >= count())
+ return;
+ if (index == currentIndex())
+ return;
+
+ if (WebView *tab = webView(index)) {
+ bool moved;
+ if (numSteps < 0)
+ moved = tab->quickBack();
+ else
+ moved = tab->quickForward();
+ if (moved) {
+ WebView *currentTab = webView(currentIndex());
+ QPixmap image = tab->currentScreenImage();
+ int height = image.height() / 3;
+ int width = image.width() / 3;
+ currentTab->displayThumb(image.scaled(width,height), x);
+ }
+ }
+}
+
+void TabWidget::clearThumb(int index)
+{
+ WebView *currentTab = webView(currentIndex());
+ currentTab->clearThumb();
+ if (WebView *tab = webView(index))
+ tab->resetQuickHistory();
+}
View
3  src/tabwidget.h
@@ -165,6 +165,9 @@ public slots:
void nextTab();
void previousTab();
void bookmarkTabs();
+ void displayThumb(int index, int x);
+ void rotateThumb(int numSteps, int index, int x);
+ void clearThumb(int index);
private slots:
void currentChanged(int index);
View
99 src/webview.cpp
@@ -114,6 +114,7 @@ WebView::WebView(QWidget *parent)
, m_accessKeysPressed(false)
#endif
, m_screenshot()
+ , m_quickhistorycurrentitem(0)
{
setPage(m_page);
#if QT_VERSION >= 0x040600
@@ -954,68 +955,120 @@ void WebView::paintEvent(QPaintEvent *event)
if (m_quickhistorycurrentitem >= (history()->count() - 1) && (toaster.width() == m_screenshot.width())) {
m_screenshot = 0L;
m_quickhistorycurrentitem = history()->count() - 1;
+ event->accept();
return;
}
-
+ event->accept();
return;
}
+ if (!m_thumbnail.isNull()) {
+ QPixmap toaster;
+ m_height += 50;
+ QPainter painter(this);
+ painter.setPen(Qt::white);
+
+ if (m_height < m_thumbnail.height()) {
+ int ty = (m_thumbnail.height() - m_height);
+ toaster = m_thumbnail.copy(QRect(0, ty, m_thumbnail.width(), m_height));
+ QTimer::singleShot(20, this, SLOT(update()));
+ } else
+ toaster = m_thumbnail;
+
+ painter.setBrush(palette().color(QPalette::Background));
+ painter.drawRoundedRect(QRect(m_thumbx - 10, y() - 10, m_thumbnail.width() + 15, m_height - 5), 10, 10);
+ QPen pen(Qt::white);
+ pen.setWidth(1);
+ painter.setPen(pen);
+ painter.setBrush(Qt::NoBrush);
+ painter.drawRoundedRect(QRect(m_thumbx - 10, y() - 10, m_thumbnail.width() + 12, m_height - 8), 10, 10);
+
+ painter.drawPixmap(QPoint(m_thumbx, y()), toaster);
+ event->accept();
+ return;
+ }
QWebView::paintEvent(event);
}
-void WebView::quickBack()
+bool WebView::quickBack()
{
if (m_quickhistorycurrentitem == 0)
- return;
+ return false;
m_quickhistorycurrentitem--;
m_width = 0;
m_forward = false;
- QString urlString = history()->items().at(m_quickhistorycurrentitem).url().toString();
- QString directory = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
- QString filename = QString(QLatin1String("%1/%2.png"))
- .arg(directory)
- .arg(urlString.replace(QLatin1String("/"),QLatin1String("")));
-
QPixmap screenshot;
- bool loaded = screenshot.load(filename);
+ screenshot = currentScreenImage();
displayScreenShot(screenshot);
-
- qDebug() << "quick screenshot " << filename;
- qDebug() << "loaded " << loaded;
-
+ return true;
}
-void WebView::quickForward()
+bool WebView::quickForward()
{
qDebug() << "m_quickhistorycurrentitem " << m_quickhistorycurrentitem;
qDebug() << "history()->items().count() " << history()->items().count();
- if (m_quickhistorycurrentitem >= (history()->items().count() - 1)) {
- return;
+ if (m_quickhistorycurrentitem >= (history()->items().count() - 1)) {
+ return false;
}
m_width = 0;
m_forward = true;
m_quickhistorycurrentitem++;
+ QPixmap screenshot;
+ screenshot = currentScreenImage();
+
+ displayScreenShot(screenshot);
+ return true;
+}
+
+int WebView::lookBackItem()
+{
+ return m_quickhistorycurrentitem;
+}
+
+QPixmap WebView::currentScreenImage()
+{
+ if (!history()->items().count())
+ return QPixmap();
QString urlString = history()->items().at(m_quickhistorycurrentitem).url().toString();
QString directory = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
QString filename = QString(QLatin1String("%1/%2.png"))
.arg(directory)
.arg(urlString.replace(QLatin1String("/"),QLatin1String("")));
-
QPixmap screenshot;
bool loaded = screenshot.load(filename);
+ return screenshot;
+}
- displayScreenShot(screenshot);
+void WebView::displayThumb(const QPixmap &thumb, int x)
+{
+ m_height = 0;
+ m_thumbnail = thumb;
+ m_thumbx = x;
+ update();
+}
- qDebug() << "quick screenshot " << filename;
- qDebug() << "loaded " << loaded;
+void WebView::clearThumb()
+{
+ m_thumbnail = 0L;
+ repaint();
}
-int WebView::lookBackItem()
+void WebView::loadLookBackItem()
{
- return m_quickhistorycurrentitem;
+ if (lookBackItem() != history()->currentItemIndex())
+ history()->goToItem(history()->items().at(lookBackItem()));
+// m_screenshot = 0L;
+ m_thumbnail = 0L;
+}
+
+void WebView::resetQuickHistory()
+{
+ m_quickhistorycurrentitem = history()->currentItemIndex();
+ m_screenshot = 0L;
+ update();
}
View
13 src/webview.h
@@ -106,6 +106,11 @@ class WebView : public QWebView
int lookBackItem();
void clearScreenShot() { m_screenshot = 0L; }
void addScreenShot(const QString &filename) { m_screenshotfiles << filename; }
+ QPixmap currentScreenImage();
+ void clearThumb();
+ void loadLookBackItem();
+ void resetQuickHistory();
+
signals:
void search(const QUrl &searchUrl, TabWidget::OpenUrlIn openIn);
@@ -114,8 +119,9 @@ public slots:
void zoomOut();
void resetZoom();
void applyZoom();
- void quickBack();
- void quickForward();
+ bool quickBack();
+ bool quickForward();
+ void displayThumb(const QPixmap &thumb, int x);
protected:
void mousePressEvent(QMouseEvent *event);
@@ -163,8 +169,11 @@ private slots:
void paintEvent(QPaintEvent *event);
QPixmap m_screenshot;
+ QPixmap m_thumbnail;
int m_width;
+ int m_height;
bool m_forward;
+ int m_thumbx;
#if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK)
bool m_enableAccessKeys;
Please sign in to comment.
Something went wrong with that request. Please try again.