summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-11-25 01:36:38 +0100
committerAndrea Diamantini <adjam7@gmail.com>2009-11-25 01:36:38 +0100
commitce86e965bd8781f6fe18e4b50eadaf7402a07847 (patch)
tree0b019499f5a4e91c5767684fdafdbb23c774e26e
parentFix headers (diff)
downloadrekonq-ce86e965bd8781f6fe18e4b50eadaf7402a07847.tar.xz
Last history fixes
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/history/autosaver.cpp (renamed from src/autosaver.cpp)0
-rw-r--r--src/history/autosaver.h (renamed from src/autosaver.h)0
-rw-r--r--src/history/history.h3
-rw-r--r--src/history/historymodels.h1
-rw-r--r--src/modelmenu.cpp223
-rw-r--r--src/modelmenu.h109
7 files changed, 1 insertions, 338 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e214c7d9..96fddbff 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -9,13 +9,11 @@ ADD_SUBDIRECTORY( adblock )
SET( rekonq_KDEINIT_SRCS
application.cpp
- autosaver.cpp
bookmarks.cpp
findbar.cpp
lineedit.cpp
mainview.cpp
mainwindow.cpp
- modelmenu.cpp
previewimage.cpp
sessionmanager.cpp
sidepanel.cpp
@@ -26,6 +24,7 @@ SET( rekonq_KDEINIT_SRCS
websnap.cpp
webview.cpp
#----------------------------------------
+ history/autosaver.cpp
history/history.cpp
history/historymodels.cpp
history/historypanel.cpp
diff --git a/src/autosaver.cpp b/src/history/autosaver.cpp
index 236922b5..236922b5 100644
--- a/src/autosaver.cpp
+++ b/src/history/autosaver.cpp
diff --git a/src/autosaver.h b/src/history/autosaver.h
index 80583f9c..80583f9c 100644
--- a/src/autosaver.h
+++ b/src/history/autosaver.h
diff --git a/src/history/history.h b/src/history/history.h
index 2ccf8cb4..ff3b4381 100644
--- a/src/history/history.h
+++ b/src/history/history.h
@@ -30,9 +30,6 @@
#define HISTORY_H
-// Local Includes
-#include "modelmenu.h"
-
// KDE Includes
#include <KUrl>
diff --git a/src/history/historymodels.h b/src/history/historymodels.h
index 93e72c6a..cb8bea41 100644
--- a/src/history/historymodels.h
+++ b/src/history/historymodels.h
@@ -32,7 +32,6 @@
// Local Includes
#include "history.h"
-#include "modelmenu.h"
// KDE Includes
#include <KUrl>
diff --git a/src/modelmenu.cpp b/src/modelmenu.cpp
deleted file mode 100644
index 4ef2bd76..00000000
--- a/src/modelmenu.cpp
+++ /dev/null
@@ -1,223 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved
-* Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com>*
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License as
-* published by the Free Software Foundation; either version 2 of
-* the License or (at your option) version 3 or any later version
-* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
-* defined in Section 14 of version 3 of the license.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* ============================================================ */
-
-
-// Self Includes
-#include "modelmenu.h"
-#include "modelmenu.moc"
-
-
-ModelMenu::ModelMenu(QWidget * parent)
- : KMenu(parent)
- , m_maxRows(7)
- , m_firstSeparator(-1)
- , m_maxWidth(-1)
- , m_hoverRole(0)
- , m_separatorRole(0)
- , m_model(0)
-{
- 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()))
- {
- QVariant v = menu->menuAction()->data();
- if (v.canConvert<QModelIndex>())
- {
- QModelIndex idx = qvariant_cast<QModelIndex>(v);
- createMenu(idx, -1, menu, menu);
- disconnect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShow()));
- return;
- }
- }
-
- clear();
- if (prePopulated())
- addSeparator();
- int max = m_maxRows;
- if (max != -1)
- max += m_firstSeparator;
- createMenu(m_root, max, this, this);
- postPopulated();
-}
-
-
-// WARNING
-// the code commented out here is to create a second separator in the history menu
-// with ALL history, subdivided by days.
-void ModelMenu::createMenu(const QModelIndex &parent, int max, QMenu *parentMenu, QMenu *menu)
-{
- Q_UNUSED(parentMenu)
-
- if (!menu)
- {
- return;
- }
-
- int end = m_model->rowCount(parent);
- 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*)));
-
- for (int i = 0; i < end; ++i)
- {
- QModelIndex idx = m_model->index(i, 0, parent);
-
- if( !m_model->hasChildren(idx) && ( m_separatorRole == 0 || !idx.data(m_separatorRole).toBool() ) )
- {
- menu->addAction(makeAction(idx));
- }
- }
-}
-
-KAction *ModelMenu::makeAction(const QModelIndex &index)
-{
- 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;
-}
-
-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 KAction(icon, smallText, parent);
-}
-
-void ModelMenu::triggered(QAction *action)
-{
- QVariant v = action->data();
- if (v.canConvert<QModelIndex>())
- {
- QModelIndex idx = qvariant_cast<QModelIndex>(v);
- emit activated(idx);
- }
-}
-
-void ModelMenu::hovered(QAction *action)
-{
- QVariant v = action->data();
- if (v.canConvert<QModelIndex>())
- {
- QModelIndex idx = qvariant_cast<QModelIndex>(v);
- QString hoveredString = idx.data(m_hoverRole).toString();
- if (!hoveredString.isEmpty())
- emit hovered(hoveredString);
- }
-}
diff --git a/src/modelmenu.h b/src/modelmenu.h
deleted file mode 100644
index 719319bc..00000000
--- a/src/modelmenu.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved
-* Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com>*
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License as
-* published by the Free Software Foundation; either version 2 of
-* the License or (at your option) version 3 or any later version
-* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
-* defined in Section 14 of version 3 of the license.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* ============================================================ */
-
-
-#ifndef MODELMENU_H
-#define MODELMENU_H
-
-
-// KDE Includes
-#include <KIcon>
-#include <KAction>
-#include <KMenu>
-
-// Qt Includes
-#include <QtCore/QAbstractItemModel>
-#include <QtCore/QModelIndex>
-
-// Forward Declarations
-class QString;
-class QWidget;
-class QObject;
-class QPersistentModelIndex;
-
-class KIcon;
-
-
-/**
- * A KMenu that is dynamically populated
- * from a QAbstractItemModel
- *
- */
-class ModelMenu : public KMenu
-{
- Q_OBJECT
-
-signals:
- void activated(const QModelIndex &index);
- void hovered(const QString &text);
-
-public:
- ModelMenu(QWidget *parent = 0);
-
- void setModel(QAbstractItemModel *model);
- QAbstractItemModel *model() const;
-
- void setMaxRows(int max);
- int maxRows() const;
-
- void setFirstSeparator(int offset);
- int firstSeparator() const;
-
- void setRootIndex(const QModelIndex &index);
- QModelIndex rootIndex() const;
-
- void setHoverRole(int role);
- int hoverRole() const;
-
- void setSeparatorRole(int role);
- int separatorRole() const;
-
- KAction *makeAction(const KIcon &icon, const QString &text, QObject *parent);
-
-protected:
- // add any actions before the tree, return true if any actions are added.
- virtual bool prePopulated();
- // add any actions after the tree
- virtual void postPopulated();
- // put all of the children of parent into menu up to max
- void createMenu(const QModelIndex &parent, int max, QMenu *parentMenu = 0, QMenu *menu = 0);
-
-private slots:
- void aboutToShow();
- void triggered(QAction *action);
- void hovered(QAction *action);
-
-private:
- KAction *makeAction(const QModelIndex &index);
- int m_maxRows;
- int m_firstSeparator;
- int m_maxWidth;
- int m_hoverRole;
- int m_separatorRole;
- QAbstractItemModel *m_model;
- QPersistentModelIndex m_root;
-};
-
-#endif // MODELMENU_H