summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2008-11-30 17:30:57 +0100
committerAndrea Diamantini <adjam7@gmail.com>2008-11-30 17:30:57 +0100
commitd62176f7f2a6a204b5017bc661fff2d3a9f76e6e (patch)
treebaf13e65cc1cf88fc03e5ead6649b49527c6d9f1 /src
parentFixing ToolBar, some icons and code.. (diff)
downloadrekonq-d62176f7f2a6a204b5017bc661fff2d3a9f76e6e.tar.xz
- Ported historyMenu to KAction
- some adjs on urlbar - added TODO file to remember things
Diffstat (limited to 'src')
-rw-r--r--src/browsermainwindow.cpp48
-rw-r--r--src/browsermainwindow.h9
-rw-r--r--src/findbar.cpp78
-rw-r--r--src/findbar.h16
-rw-r--r--src/history.cpp120
-rw-r--r--src/history.h23
-rw-r--r--src/modelmenu.cpp46
-rw-r--r--src/modelmenu.h13
-rw-r--r--src/urlbar.cpp4
-rw-r--r--src/urlbar.h1
10 files changed, 246 insertions, 112 deletions
diff --git a/src/browsermainwindow.cpp b/src/browsermainwindow.cpp
index 3a79f995..0bf8b0ef 100644
--- a/src/browsermainwindow.cpp
+++ b/src/browsermainwindow.cpp
@@ -84,8 +84,8 @@ BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags)
layout->addWidget(m_tabWidget);
// Find Bar
- m_findBar = new FindBar(centralWidget);
- layout->addWidget(m_findBar);
+ m_findBar = new FindBar(this);
+ connect( m_findBar, SIGNAL( searchString(const QString &) ), this, SLOT( slotFind(const QString &) ) );
centralWidget->setLayout(layout);
setCentralWidget(centralWidget);
@@ -271,8 +271,8 @@ void BrowserMainWindow::setupMenu()
editMenu->addSeparator();
editMenu->addAction( KStandardAction::find(this, SLOT( slotViewFindBar() ) , this ) );
- editMenu->addAction( KStandardAction::findNext(this, SLOT( slotEditFindNext() ) , this ) );
- editMenu->addAction( KStandardAction::findPrev(this, SLOT( slotEditFindPrevious() ) , this ) );
+ editMenu->addAction( KStandardAction::findNext(this, SLOT( slotFindNext() ) , this ) );
+ editMenu->addAction( KStandardAction::findPrev(this, SLOT( slotFindPrevious() ) , this ) );
editMenu->addSeparator();
@@ -313,7 +313,7 @@ void BrowserMainWindow::setupMenu()
connect(historyMenu, SIGNAL(hovered(const QString&)), this, SLOT(slotUpdateStatusbar(const QString&)));
historyMenu->setTitle( i18n("Hi&story") );
menuBar()->addMenu(historyMenu);
- QList<QAction*> historyActions;
+ QList<KAction*> historyActions;
m_historyBack = new KAction( i18n("Back"), this);
m_tabWidget->addWebAction(m_historyBack, QWebPage::Back);
@@ -325,7 +325,7 @@ void BrowserMainWindow::setupMenu()
// m_historyForward->setShortcuts(QKeySequence::Forward); FIXME
m_historyForward->setIconVisibleInMenu(false);
- m_restoreLastSession = new QAction( i18n("Restore Last Session"), this);
+ m_restoreLastSession = new KAction( i18n("Restore Last Session"), this);
connect(m_restoreLastSession, SIGNAL(triggered()), BrowserApplication::instance(), SLOT(restoreLastSession()));
m_restoreLastSession->setEnabled(BrowserApplication::instance()->canRestoreSession());
@@ -653,33 +653,26 @@ void BrowserMainWindow::closeEvent(QCloseEvent *event)
}
-// FIXME: reimplement me A-LA KATE search bar
-void BrowserMainWindow::slotEditFind()
+void BrowserMainWindow::slotFind(const QString & search)
{
-// if (!currentTab())
-// return;
-// bool ok;
-// QString search = QInputDialog::getText(this, i18n("Find"),
-// i18n("Text:"), QLineEdit::Normal,
-// m_lastSearch, &ok);
-// if (ok && !search.isEmpty()) {
-// m_lastSearch = search;
-// if (!currentTab()->findText(m_lastSearch))
-// slotUpdateStatusbar( QString(m_lastSearch) + i18n(" not found.") );
-// }
-// m_findWidg->setVisible( true );
-/*if ( !currentTab() )
- return;
-bool ok;
-m_lastSearch = findWidg->*/
+ if (!currentTab())
+ return;
+ if (!search.isEmpty())
+ {
+ m_lastSearch = search;
+ if (!currentTab()->findText(m_lastSearch))
+ slotUpdateStatusbar( QString(m_lastSearch) + i18n(" not found.") );
+ }
}
+
void BrowserMainWindow::slotViewFindBar()
{
- m_findBar->show();
+ m_findBar->showFindBar();
}
-void BrowserMainWindow::slotEditFindNext()
+
+void BrowserMainWindow::slotFindNext()
{
if (!currentTab() && !m_lastSearch.isEmpty())
return;
@@ -687,8 +680,7 @@ void BrowserMainWindow::slotEditFindNext()
}
-
-void BrowserMainWindow::slotEditFindPrevious()
+void BrowserMainWindow::slotFindPrevious()
{
if (!currentTab() && !m_lastSearch.isEmpty())
return;
diff --git a/src/browsermainwindow.h b/src/browsermainwindow.h
index 349d2384..5ead8dda 100644
--- a/src/browsermainwindow.h
+++ b/src/browsermainwindow.h
@@ -67,6 +67,9 @@ public:
public slots:
void loadPage(const QString &url);
void slotHome();
+ void slotFind(const QString &);
+ void slotFindNext();
+ void slotFindPrevious();
protected:
void closeEvent(QCloseEvent *event);
@@ -87,9 +90,7 @@ private slots:
void slotFilePrint();
void slotPrivateBrowsing();
void slotFileSaveAs();
- void slotEditFind();
- void slotEditFindNext();
- void slotEditFindPrevious();
+
void slotAddBookmark();
void slotViewTextBigger();
void slotViewTextNormal();
@@ -141,7 +142,7 @@ private:
KAction *m_stopReload;
KAction *m_goHome;
KAction *m_viewStatusbar;
- QAction *m_restoreLastSession;
+ KAction *m_restoreLastSession;
KAction *m_addBookmark;
KIcon m_reloadIcon;
diff --git a/src/findbar.cpp b/src/findbar.cpp
index a0e1948d..2d9e0d5c 100644
--- a/src/findbar.cpp
+++ b/src/findbar.cpp
@@ -25,14 +25,31 @@
#include <KIconLoader>
#include <KToolBar>
#include <KStandardAction>
+#include <KDialog>
#include <QtGui>
-FindBar::FindBar(QWidget *parent)
- : KToolBar(parent)
+FindBar::FindBar(QMainWindow *parent)
+ : KToolBar( "FindBar" , parent, Qt::BottomToolBarArea, true, false, false)
, m_lineEdit(0)
{
- initializeFindWidget();
+ KAction *close = new KAction(KIcon("dialog-close") , "close" , this);
+ connect( close , SIGNAL( triggered() ), this, SLOT( hide() ) );
+ addAction( close );
+
+ QLabel *label = new QLabel("Find: ");
+ addWidget( label );
+
+ m_lineEdit = new KLineEdit();
+ connect( m_lineEdit, SIGNAL( returnPressed() ), parent, SLOT( slotFindNext() ) );
+ connect( m_lineEdit, SIGNAL( textEdited(const QString &) ), parent, SLOT( slotFindNext() ) );
+ addWidget( m_lineEdit );
+
+ addAction( KStandardAction::findNext(parent, SLOT( slotFindNext() ) , this ) );
+ addAction( KStandardAction::findPrev(parent, SLOT( slotFindPrevious() ) , this ) );
+
+ QLabel *spaceLabel = new QLabel(" "); // FIXME
+ addWidget( spaceLabel );
// we start off hidden
hide();
@@ -51,34 +68,13 @@ KLineEdit *FindBar::lineEdit()
}
-void FindBar::initializeFindWidget()
-{
- addAction( KIcon("dialog-close") , "close" , this, SLOT( hide() ) );
-
- QLabel *label = new QLabel("Find: ");
- addWidget( label );
-
- m_lineEdit = new KLineEdit();
- connect( m_lineEdit, SIGNAL( returnPressed() ), this, SLOT( slotFindNext() ) );
- connect( m_lineEdit, SIGNAL( textEdited(const QString &) ), this, SLOT( slotFindNext() ) );
- addWidget( m_lineEdit );
-
- addAction( KStandardAction::findNext(this, SLOT( slotFindNext() ) , this ) );
- addAction( KStandardAction::findPrev(this, SLOT( slotFindPrevious() ) , this ) );
-
- QLabel *spaceLabel = new QLabel(" "); // FIXME
- addWidget( spaceLabel );
-}
-
-
-
void FindBar::clear()
{
m_lineEdit->setText(QString());
}
-void FindBar::showFind()
+void FindBar::showFindBar()
{
if (!isVisible())
{
@@ -89,21 +85,17 @@ void FindBar::showFind()
}
-
-// void FindBar::frameChanged(int frame)
-// {
-// /* if (!m_widget)
-// return;
-// m_widget->move(0, frame);
-// int height = qMax(0, m_widget->y() + m_widget->height());
-// setMinimumHeight(height);
-// setMaximumHeight(height);*/
-// }
-
-
-void FindBar::slotFindNext()
-{}
-
-void FindBar::slotFindPrevious()
-{}
-
+void FindBar::keyPressEvent(QKeyEvent* event)
+{
+ if (event->key() == Qt::Key_Escape)
+ {
+ hide();
+ return;
+ }
+ if(event->key() == Qt::Key_Return && ! ( m_lineEdit->text().isEmpty() ) )
+ {
+ emit searchString( m_lineEdit->text() );
+ return;
+ }
+ QWidget::keyPressEvent(event);
+}
diff --git a/src/findbar.h b/src/findbar.h
index bd3c5960..ece34f83 100644
--- a/src/findbar.h
+++ b/src/findbar.h
@@ -23,26 +23,28 @@
#include <KLineEdit>
#include <KToolBar>
-#include <QWidget>
+#include <QMainWindow>
class FindBar : public KToolBar
{
Q_OBJECT
public:
- FindBar(QWidget *parent = 0);
+ FindBar(QMainWindow *parent);
~FindBar();
KLineEdit *lineEdit();
public slots:
void clear();
- void showFind();
- void slotFindNext();
- void slotFindPrevious();
+ void showFindBar();
+
+protected Q_SLOTS:
+ void keyPressEvent(QKeyEvent* event);
-private:
- void initializeFindWidget();
+signals:
+ void searchString(const QString &);
+private:
KLineEdit *m_lineEdit;
QWidget *m_centralWidget;
};
diff --git a/src/history.cpp b/src/history.cpp
index ea322b65..cb6e80b0 100644
--- a/src/history.cpp
+++ b/src/history.cpp
@@ -44,8 +44,10 @@
#include <QDebug>
+
static const unsigned int HISTORY_VERSION = 23;
+
HistoryManager::HistoryManager(QObject *parent)
: QWebHistoryInterface(parent)
, m_saveTimer(new AutoSaver(this))
@@ -68,21 +70,25 @@ HistoryManager::HistoryManager(QObject *parent)
QWebHistoryInterface::setDefaultInterface(this);
}
+
HistoryManager::~HistoryManager()
{
m_saveTimer->saveIfNeccessary();
}
+
QList<HistoryItem> HistoryManager::history() const
{
return m_history;
}
+
bool HistoryManager::historyContains(const QString &url) const
{
return m_historyFilterModel->historyContains(url);
}
+
void HistoryManager::addHistoryEntry(const QString &url)
{
QUrl cleanUrl(url);
@@ -92,6 +98,7 @@ void HistoryManager::addHistoryEntry(const QString &url)
addHistoryItem(item);
}
+
void HistoryManager::setHistory(const QList<HistoryItem> &history, bool loadedAndSorted)
{
m_history = history;
@@ -111,21 +118,25 @@ void HistoryManager::setHistory(const QList<HistoryItem> &history, bool loadedAn
emit historyReset();
}
+
HistoryModel *HistoryManager::historyModel() const
{
return m_historyModel;
}
+
HistoryFilterModel *HistoryManager::historyFilterModel() const
{
return m_historyFilterModel;
}
+
HistoryTreeModel *HistoryManager::historyTreeModel() const
{
return m_historyTreeModel;
}
+
void HistoryManager::checkForExpired()
{
if (m_historyLimit < 0 || m_history.isEmpty())
@@ -155,6 +166,7 @@ void HistoryManager::checkForExpired()
m_expiredTimer.start(nextTimeout * 1000);
}
+
void HistoryManager::addHistoryItem(const HistoryItem &item)
{
QWebSettings *globalSettings = QWebSettings::globalSettings();
@@ -167,6 +179,8 @@ void HistoryManager::addHistoryItem(const HistoryItem &item)
checkForExpired();
}
+
+
void HistoryManager::updateHistoryItem(const QUrl &url, const QString &title)
{
for (int i = 0; i < m_history.count(); ++i) {
@@ -181,11 +195,13 @@ void HistoryManager::updateHistoryItem(const QUrl &url, const QString &title)
}
}
+
int HistoryManager::historyLimit() const
{
return m_historyLimit;
}
+
void HistoryManager::setHistoryLimit(int limit)
{
if (m_historyLimit == limit)
@@ -195,6 +211,7 @@ void HistoryManager::setHistoryLimit(int limit)
m_saveTimer->changeOccurred();
}
+
void HistoryManager::clear()
{
m_history.clear();
@@ -204,6 +221,7 @@ void HistoryManager::clear()
historyReset();
}
+
void HistoryManager::loadSettings()
{
// load settings
@@ -212,6 +230,8 @@ void HistoryManager::loadSettings()
m_historyLimit = settings.value(QLatin1String("historyLimit"), 30).toInt();
}
+
+
void HistoryManager::load()
{
loadSettings();
@@ -275,6 +295,7 @@ void HistoryManager::load()
}
}
+
void HistoryManager::save()
{
QSettings settings;
@@ -339,6 +360,10 @@ void HistoryManager::save()
m_lastSavedUrl = m_history.value(0).url;
}
+
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
HistoryModel::HistoryModel(HistoryManager *history, QObject *parent)
: QAbstractTableModel(parent)
, m_history(history)
@@ -350,23 +375,27 @@ HistoryModel::HistoryModel(HistoryManager *history, QObject *parent)
connect(m_history, SIGNAL(entryUpdated(int)), this, SLOT(entryUpdated(int)));
}
+
void HistoryModel::historyReset()
{
reset();
}
+
void HistoryModel::entryAdded()
{
beginInsertRows(QModelIndex(), 0, 0);
endInsertRows();
}
+
void HistoryModel::entryUpdated(int offset)
{
QModelIndex idx = index(offset, 0);
emit dataChanged(idx, idx);
}
+
QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal
@@ -379,6 +408,7 @@ QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int
return QAbstractTableModel::headerData(section, orientation, role);
}
+
QVariant HistoryModel::data(const QModelIndex &index, int role) const
{
QList<HistoryItem> lst = m_history->history();
@@ -419,16 +449,19 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const
return QVariant();
}
+
int HistoryModel::columnCount(const QModelIndex &parent) const
{
return (parent.isValid()) ? 0 : 2;
}
+
int HistoryModel::rowCount(const QModelIndex &parent) const
{
return (parent.isValid()) ? 0 : m_history->history().count();
}
+
bool HistoryModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
@@ -445,6 +478,10 @@ bool HistoryModel::removeRows(int row, int count, const QModelIndex &parent)
return true;
}
+
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
#define MOVEDROWS 15
/*
@@ -563,23 +600,27 @@ QModelIndex HistoryMenuModel::parent(const QModelIndex &index) const
}
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
HistoryMenu::HistoryMenu(QWidget *parent)
: ModelMenu(parent)
, m_history(0)
{
- connect(this, SIGNAL(activated(const QModelIndex &)),
- this, SLOT(activated(const QModelIndex &)));
+ connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(activated(const QModelIndex &)));
setHoverRole(HistoryModel::UrlStringRole);
}
+
void HistoryMenu::activated(const QModelIndex &index)
{
emit openUrl(index.data(HistoryModel::UrlRole).toUrl());
}
+
bool HistoryMenu::prePopulated()
{
- if (!m_history) {
+ if (!m_history)
+ {
m_history = BrowserApplication::historyManager();
m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this);
setModel(m_historyMenuModel);
@@ -594,41 +635,47 @@ bool HistoryMenu::prePopulated()
return false;
}
+
void HistoryMenu::postPopulated()
{
if (m_history->history().count() > 0)
addSeparator();
- QAction *showAllAction = new QAction( i18n("Show All History"), this);
+ KAction *showAllAction = new KAction( i18n("Show All History"), this);
connect(showAllAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog()));
addAction(showAllAction);
- QAction *clearAction = new QAction( i18n("Clear History"), this);
+ KAction *clearAction = new KAction( i18n("Clear History"), this);
connect(clearAction, SIGNAL(triggered()), m_history, SLOT(clear()));
addAction(clearAction);
}
+
void HistoryMenu::showHistoryDialog()
{
HistoryDialog *dialog = new HistoryDialog(this);
- connect(dialog, SIGNAL(openUrl(const QUrl&)),
- this, SIGNAL(openUrl(const QUrl&)));
+ connect(dialog, SIGNAL(openUrl(const QUrl&)), this, SIGNAL(openUrl(const QUrl&)));
dialog->show();
}
-void HistoryMenu::setInitialActions(QList<QAction*> actions)
+
+void HistoryMenu::setInitialActions(QList<KAction*> actions)
{
m_initialActions = actions;
for (int i = 0; i < m_initialActions.count(); ++i)
addAction(m_initialActions.at(i));
}
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
TreeProxyModel::TreeProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
{
setSortRole(HistoryModel::DateTimeRole);
setFilterCaseSensitivity(Qt::CaseInsensitive);
}
+
bool TreeProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
if (!source_parent.isValid())
@@ -636,6 +683,9 @@ bool TreeProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) : QDialog(parent)
{
HistoryManager *history = setHistory;
@@ -666,6 +716,7 @@ HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) : QDia
this, SLOT(customContextMenuRequested(const QPoint &)));
}
+
void HistoryDialog::customContextMenuRequested(const QPoint &pos)
{
QMenu menu;
@@ -680,6 +731,7 @@ void HistoryDialog::customContextMenuRequested(const QPoint &pos)
menu.exec(QCursor::pos());
}
+
void HistoryDialog::open()
{
QModelIndex index = tree->currentIndex();
@@ -688,6 +740,7 @@ void HistoryDialog::open()
emit openUrl(index.data(HistoryModel::UrlRole).toUrl());
}
+
void HistoryDialog::copy()
{
QModelIndex index = tree->currentIndex();
@@ -699,6 +752,9 @@ void HistoryDialog::copy()
clipboard->setText(url);
}
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject *parent)
: QAbstractProxyModel(parent),
m_loaded(false)
@@ -706,6 +762,7 @@ HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject
setSourceModel(sourceModel);
}
+
int HistoryFilterModel::historyLocation(const QString &url) const
{
load();
@@ -714,11 +771,13 @@ int HistoryFilterModel::historyLocation(const QString &url) const
return sourceModel()->rowCount() - m_historyHash.value(url);
}
+
QVariant HistoryFilterModel::data(const QModelIndex &index, int role) const
{
return QAbstractProxyModel::data(index, role);
}
+
void HistoryFilterModel::setSourceModel(QAbstractItemModel *newSourceModel)
{
if (sourceModel()) {
@@ -745,22 +804,26 @@ void HistoryFilterModel::setSourceModel(QAbstractItemModel *newSourceModel)
}
}
+
void HistoryFilterModel::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
emit dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight));
}
+
QVariant HistoryFilterModel::headerData(int section, Qt::Orientation orientation, int role) const
{
return sourceModel()->headerData(section, orientation, role);
}
+
void HistoryFilterModel::sourceReset()
{
m_loaded = false;
reset();
}
+
int HistoryFilterModel::rowCount(const QModelIndex &parent) const
{
load();
@@ -769,11 +832,13 @@ int HistoryFilterModel::rowCount(const QModelIndex &parent) const
return m_historyHash.count();
}
+
int HistoryFilterModel::columnCount(const QModelIndex &parent) const
{
return (parent.isValid()) ? 0 : 2;
}
+
QModelIndex HistoryFilterModel::mapToSource(const QModelIndex &proxyIndex) const
{
load();
@@ -781,6 +846,7 @@ QModelIndex HistoryFilterModel::mapToSource(const QModelIndex &proxyIndex) const
return sourceModel()->index(sourceRow, proxyIndex.column());
}
+
QModelIndex HistoryFilterModel::mapFromSource(const QModelIndex &sourceIndex) const
{
load();
@@ -807,6 +873,7 @@ QModelIndex HistoryFilterModel::mapFromSource(const QModelIndex &sourceIndex) co
return createIndex(realRow, sourceIndex.column(), sourceModel()->rowCount() - sourceIndex.row());
}
+
QModelIndex HistoryFilterModel::index(int row, int column, const QModelIndex &parent) const
{
load();
@@ -817,11 +884,13 @@ QModelIndex HistoryFilterModel::index(int row, int column, const QModelIndex &pa
return createIndex(row, column, m_sourceRow[row]);
}
+
QModelIndex HistoryFilterModel::parent(const QModelIndex &) const
{
return QModelIndex();
}
+
void HistoryFilterModel::load() const
{
if (m_loaded)
@@ -840,6 +909,7 @@ void HistoryFilterModel::load() const
m_loaded = true;
}
+
void HistoryFilterModel::sourceRowsInserted(const QModelIndex &parent, int start, int end)
{
Q_ASSERT(start == end && start == 0);
@@ -862,6 +932,7 @@ void HistoryFilterModel::sourceRowsInserted(const QModelIndex &parent, int start
endInsertRows();
}
+
void HistoryFilterModel::sourceRowsRemoved(const QModelIndex &, int start, int end)
{
Q_UNUSED(start);
@@ -869,6 +940,9 @@ void HistoryFilterModel::sourceRowsRemoved(const QModelIndex &, int start, int e
sourceReset();
}
+
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*
Removing a continuous block of rows will remove filtered rows too as this is
the users intention.
@@ -894,11 +968,13 @@ bool HistoryFilterModel::removeRows(int row, int count, const QModelIndex &paren
return true;
}
+
HistoryCompletionModel::HistoryCompletionModel(QObject *parent)
: QAbstractProxyModel(parent)
{
}
+
QVariant HistoryCompletionModel::data(const QModelIndex &index, int role) const
{
if (sourceModel()
@@ -919,22 +995,26 @@ QVariant HistoryCompletionModel::data(const QModelIndex &index, int role) const
return QAbstractProxyModel::data(index, role);
}
+
int HistoryCompletionModel::rowCount(const QModelIndex &parent) const
{
return (parent.isValid() || !sourceModel()) ? 0 : sourceModel()->rowCount(parent) * 2;
}
+
int HistoryCompletionModel::columnCount(const QModelIndex &parent) const
{
return (parent.isValid()) ? 0 : 1;
}
+
QModelIndex HistoryCompletionModel::mapFromSource(const QModelIndex &sourceIndex) const
{
int row = sourceIndex.row() * 2;
return index(row, sourceIndex.column());
}
+
QModelIndex HistoryCompletionModel::mapToSource(const QModelIndex &proxyIndex) const
{
if (!sourceModel())
@@ -943,6 +1023,7 @@ QModelIndex HistoryCompletionModel::mapToSource(const QModelIndex &proxyIndex) c
return sourceModel()->index(row, proxyIndex.column());
}
+
QModelIndex HistoryCompletionModel::index(int row, int column, const QModelIndex &parent) const
{
if (row < 0 || row >= rowCount(parent)
@@ -951,11 +1032,13 @@ QModelIndex HistoryCompletionModel::index(int row, int column, const QModelIndex
return createIndex(row, column, 0);
}
+
QModelIndex HistoryCompletionModel::parent(const QModelIndex &) const
{
return QModelIndex();
}
+
void HistoryCompletionModel::setSourceModel(QAbstractItemModel *newSourceModel)
{
if (sourceModel()) {
@@ -979,22 +1062,29 @@ void HistoryCompletionModel::setSourceModel(QAbstractItemModel *newSourceModel)
reset();
}
+
void HistoryCompletionModel::sourceReset()
{
reset();
}
+
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
HistoryTreeModel::HistoryTreeModel(QAbstractItemModel *sourceModel, QObject *parent)
: QAbstractProxyModel(parent)
{
setSourceModel(sourceModel);
}
+
QVariant HistoryTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
return sourceModel()->headerData(section, orientation, role);
}
+
QVariant HistoryTreeModel::data(const QModelIndex &index, int role) const
{
if ((role == Qt::EditRole || role == Qt::DisplayRole)) {
@@ -1024,11 +1114,13 @@ QVariant HistoryTreeModel::data(const QModelIndex &index, int role) const
return QAbstractProxyModel::data(index, role);
}
+
int HistoryTreeModel::columnCount(const QModelIndex &parent) const
{
return sourceModel()->columnCount(mapToSource(parent));
}
+
int HistoryTreeModel::rowCount(const QModelIndex &parent) const
{
if ( parent.internalId() != 0
@@ -1062,6 +1154,7 @@ int HistoryTreeModel::rowCount(const QModelIndex &parent) const
return (end - start);
}
+
// Translate the top level date row into the offset where that date starts
int HistoryTreeModel::sourceDateRow(int row) const
{
@@ -1079,6 +1172,7 @@ int HistoryTreeModel::sourceDateRow(int row) const
return m_sourceRowCache.at(row);
}
+
QModelIndex HistoryTreeModel::mapToSource(const QModelIndex &proxyIndex) const
{
int offset = proxyIndex.internalId();
@@ -1088,6 +1182,7 @@ QModelIndex HistoryTreeModel::mapToSource(const QModelIndex &proxyIndex) const
return sourceModel()->index(startDateRow + proxyIndex.row(), proxyIndex.column());
}
+
QModelIndex HistoryTreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (row < 0
@@ -1100,6 +1195,7 @@ QModelIndex HistoryTreeModel::index(int row, int column, const QModelIndex &pare
return createIndex(row, column, parent.row() + 1);
}
+
QModelIndex HistoryTreeModel::parent(const QModelIndex &index) const
{
int offset = index.internalId();
@@ -1108,6 +1204,7 @@ QModelIndex HistoryTreeModel::parent(const QModelIndex &index) const
return createIndex(offset - 1, 0, 0);
}
+
bool HistoryTreeModel::hasChildren(const QModelIndex &parent) const
{
QModelIndex grandparent = parent.parent();
@@ -1116,6 +1213,7 @@ bool HistoryTreeModel::hasChildren(const QModelIndex &parent) const
return false;
}
+
Qt::ItemFlags HistoryTreeModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
@@ -1123,6 +1221,7 @@ Qt::ItemFlags HistoryTreeModel::flags(const QModelIndex &index) const
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
}
+
bool HistoryTreeModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (row < 0 || count <= 0 || row + count > rowCount(parent))
@@ -1144,6 +1243,7 @@ bool HistoryTreeModel::removeRows(int row, int count, const QModelIndex &parent)
return true;
}
+
void HistoryTreeModel::setSourceModel(QAbstractItemModel *newSourceModel)
{
if (sourceModel()) {
@@ -1169,12 +1269,14 @@ void HistoryTreeModel::setSourceModel(QAbstractItemModel *newSourceModel)
reset();
}
+
void HistoryTreeModel::sourceReset()
{
m_sourceRowCache.clear();
reset();
}
+
void HistoryTreeModel::sourceRowsInserted(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(parent); // Avoid warnings when compiling release
@@ -1197,6 +1299,7 @@ void HistoryTreeModel::sourceRowsInserted(const QModelIndex &parent, int start,
}
}
+
QModelIndex HistoryTreeModel::mapFromSource(const QModelIndex &sourceIndex) const
{
if (!sourceIndex.isValid())
@@ -1214,6 +1317,7 @@ QModelIndex HistoryTreeModel::mapFromSource(const QModelIndex &sourceIndex) cons
return createIndex(row, sourceIndex.column(), dateRow + 1);
}
+
void HistoryTreeModel::sourceRowsRemoved(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(parent); // Avoid warnings when compiling release
diff --git a/src/history.h b/src/history.h
index 80b9f517..97d7f34e 100644
--- a/src/history.h
+++ b/src/history.h
@@ -34,6 +34,10 @@
#include <QSortFilterProxyModel>
#include <QWebHistoryInterface>
+// KDE Includes
+#include <KAction>
+
+
class HistoryItem
{
public:
@@ -55,10 +59,15 @@ public:
QDateTime dateTime;
};
+
+
+
class AutoSaver;
class HistoryModel;
class HistoryFilterModel;
class HistoryTreeModel;
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
class HistoryManager : public QWebHistoryInterface
{
Q_OBJECT
@@ -115,6 +124,8 @@ private:
HistoryTreeModel *m_historyTreeModel;
};
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
class HistoryModel : public QAbstractTableModel
{
Q_OBJECT
@@ -143,6 +154,8 @@ private:
HistoryManager *m_history;
};
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*!
Proxy model that will remove any duplicate entries.
Both m_sourceRow and m_historyHash store their offsets not from
@@ -184,6 +197,8 @@ private:
mutable bool m_loaded;
};
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*
The history menu
- Removes the first twenty entries and puts them as children of the top level.
@@ -211,6 +226,8 @@ private:
HistoryTreeModel *m_treeModel;
};
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Menu that is dynamically populated from the history
class HistoryMenu : public ModelMenu
{
@@ -221,7 +238,7 @@ signals:
public:
HistoryMenu(QWidget *parent = 0);
- void setInitialActions(QList<QAction*> actions);
+ void setInitialActions(QList<KAction*> actions);
protected:
bool prePopulated();
@@ -234,9 +251,11 @@ private slots:
private:
HistoryManager *m_history;
HistoryMenuModel *m_historyMenuModel;
- QList<QAction*> m_initialActions;
+ QList<KAction*> m_initialActions;
};
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// proxy model for the history model that
// exposes each url http://www.foo.com and it url starting at the host www.foo.com
class HistoryCompletionModel : public QAbstractProxyModel
diff --git a/src/modelmenu.cpp b/src/modelmenu.cpp
index 3f543a1f..7c8fb128 100644
--- a/src/modelmenu.cpp
+++ b/src/modelmenu.cpp
@@ -20,8 +20,6 @@
#include "modelmenu.h"
-#include <QtCore/QAbstractItemModel>
-#include <qdebug.h>
ModelMenu::ModelMenu(QWidget * parent)
: QMenu(parent)
@@ -35,81 +33,98 @@ ModelMenu::ModelMenu(QWidget * parent)
connect(this, SIGNAL(aboutToShow()), this, SLOT(aboutToShow()));
}
+
bool ModelMenu::prePopulated()
{
return false;
}
+
void ModelMenu::postPopulated()
{
}
+
void ModelMenu::setModel(QAbstractItemModel *model)
{
m_model = model;
}
+
QAbstractItemModel *ModelMenu::model() const
{
return m_model;
}
+
void ModelMenu::setMaxRows(int max)
{
m_maxRows = max;
}
+
int ModelMenu::maxRows() const
{
return m_maxRows;
}
+
void ModelMenu::setFirstSeparator(int offset)
{
m_firstSeparator = offset;
}
+
int ModelMenu::firstSeparator() const
{
return m_firstSeparator;
}
+
void ModelMenu::setRootIndex(const QModelIndex &index)
{
m_root = index;
}
+
QModelIndex ModelMenu::rootIndex() const
{
return m_root;
}
+
void ModelMenu::setHoverRole(int role)
{
m_hoverRole = role;
}
+
int ModelMenu::hoverRole() const
{
return m_hoverRole;
}
+
void ModelMenu::setSeparatorRole(int role)
{
m_separatorRole = role;
}
+
int ModelMenu::separatorRole() const
{
return m_separatorRole;
}
+
Q_DECLARE_METATYPE(QModelIndex)
void ModelMenu::aboutToShow()
{
- if (QMenu *menu = qobject_cast<QMenu*>(sender())) {
+ if (QMenu *menu = qobject_cast<QMenu*>(sender()))
+ {
QVariant v = menu->menuAction()->data();
- if (v.canConvert<QModelIndex>()) {
+ if (v.canConvert<QModelIndex>())
+ {
QModelIndex idx = qvariant_cast<QModelIndex>(v);
createMenu(idx, -1, menu, menu);
disconnect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShow()));
@@ -129,7 +144,8 @@ void ModelMenu::aboutToShow()
void ModelMenu::createMenu(const QModelIndex &parent, int max, QMenu *parentMenu, QMenu *menu)
{
- if (!menu) {
+ if (!menu)
+ {
QString title = parent.data().toString();
menu = new QMenu(title, this);
QIcon icon = qvariant_cast<QIcon>(parent.data(Qt::DecorationRole));
@@ -146,8 +162,8 @@ void ModelMenu::createMenu(const QModelIndex &parent, int max, QMenu *parentMenu
if (max != -1)
end = qMin(max, end);
- connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(triggered(QAction*)));
- connect(menu, SIGNAL(hovered(QAction*)), this, SLOT(hovered(QAction*)));
+ connect(menu, SIGNAL( triggered(QAction*) ), this, SLOT( triggered(QAction*) ) );
+ connect(menu, SIGNAL( hovered(QAction*) ), this, SLOT( hovered(QAction*) ) );
for (int i = 0; i < end; ++i) {
QModelIndex idx = m_model->index(i, 0, parent);
@@ -165,29 +181,30 @@ void ModelMenu::createMenu(const QModelIndex &parent, int max, QMenu *parentMenu
}
}
-QAction *ModelMenu::makeAction(const QModelIndex &index)
+KAction *ModelMenu::makeAction(const QModelIndex &index)
{
- QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
- QAction *action = makeAction(icon, index.data().toString(), this);
+ QIcon icon = qvariant_cast<QIcon>( index.data(Qt::DecorationRole) );
+ KAction *action = (KAction *) makeAction(KIcon(icon), index.data().toString(), this);
QVariant v;
v.setValue(index);
action->setData(v);
return action;
}
-QAction *ModelMenu::makeAction(const QIcon &icon, const QString &text, QObject *parent)
+KAction *ModelMenu::makeAction(const KIcon &icon, const QString &text, QObject *parent)
{
QFontMetrics fm(font());
if (-1 == m_maxWidth)
m_maxWidth = fm.width(QLatin1Char('m')) * 30;
QString smallText = fm.elidedText(text, Qt::ElideMiddle, m_maxWidth);
- return new QAction(icon, smallText, parent);
+ return new KAction(icon, smallText, parent);
}
void ModelMenu::triggered(QAction *action)
{
QVariant v = action->data();
- if (v.canConvert<QModelIndex>()) {
+ if (v.canConvert<QModelIndex>())
+ {
QModelIndex idx = qvariant_cast<QModelIndex>(v);
emit activated(idx);
}
@@ -196,7 +213,8 @@ void ModelMenu::triggered(QAction *action)
void ModelMenu::hovered(QAction *action)
{
QVariant v = action->data();
- if (v.canConvert<QModelIndex>()) {
+ if (v.canConvert<QModelIndex>())
+ {
QModelIndex idx = qvariant_cast<QModelIndex>(v);
QString hoveredString = idx.data(m_hoverRole).toString();
if (!hoveredString.isEmpty())
diff --git a/src/modelmenu.h b/src/modelmenu.h
index d539d6bf..61ec370b 100644
--- a/src/modelmenu.h
+++ b/src/modelmenu.h
@@ -22,8 +22,13 @@
#ifndef MODELMENU_H
#define MODELMENU_H
-#include <QtGui/QMenu>
-#include <QtCore/QAbstractItemModel>
+// Qt Includes
+#include <QtGui>
+#include <QtCore>
+
+// KDE Includes
+#include <KIcon>
+#include <KAction>
// A QMenu that is dynamically populated from a QAbstractItemModel
class ModelMenu : public QMenu
@@ -55,7 +60,7 @@ public:
void setSeparatorRole(int role);
int separatorRole() const;
- QAction *makeAction(const QIcon &icon, const QString &text, QObject *parent);
+ KAction *makeAction(const KIcon &icon, const QString &text, QObject *parent);
protected:
// add any actions before the tree, return true if any actions are added.
@@ -71,7 +76,7 @@ private slots:
void hovered(QAction *action);
private:
- QAction *makeAction(const QModelIndex &index);
+ KAction *makeAction(const QModelIndex &index);
int m_maxRows;
int m_firstSeparator;
int m_maxWidth;
diff --git a/src/urlbar.cpp b/src/urlbar.cpp
index 07b5168b..cde55cb3 100644
--- a/src/urlbar.cpp
+++ b/src/urlbar.cpp
@@ -45,8 +45,8 @@ UrlBar::UrlBar(QWidget *parent)
setLayout(layout);
m_defaultBaseColor = palette().color(QPalette::Base);
- setPalette( QPalette(Qt::white) );
- setAutoFillBackground( true );
+// setPalette( QPalette(Qt::white) );
+ setAutoFillBackground( false );
webViewIconChanged();
}
diff --git a/src/urlbar.h b/src/urlbar.h
index 56ba7686..72b64654 100644
--- a/src/urlbar.h
+++ b/src/urlbar.h
@@ -25,6 +25,7 @@
// KDE Includes
#include <KLineEdit>
+#include <KComboBox>
// Qt Includes
#include <QWidget>