diff options
author | kh1 <qt-info@nokia.com> | 2010-08-30 14:40:21 (GMT) |
---|---|---|
committer | kh1 <qt-info@nokia.com> | 2010-09-06 10:02:52 (GMT) |
commit | 2f006420bbbf5a53524256c003157a275d658a2d (patch) | |
tree | d7cedfdd2eac1f4cb2b7021b212f52985982480b /tools/assistant | |
parent | 55e787106e925eea89968bf9f91f063de8bbef98 (diff) | |
download | Qt-2f006420bbbf5a53524256c003157a275d658a2d.zip Qt-2f006420bbbf5a53524256c003157a275d658a2d.tar.gz Qt-2f006420bbbf5a53524256c003157a275d658a2d.tar.bz2 |
Implement bookmarks toolbar.
Diffstat (limited to 'tools/assistant')
-rw-r--r-- | tools/assistant/tools/assistant/bookmarkfiltermodel.cpp | 11 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/bookmarkmanager.cpp | 87 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/bookmarkmanager.h | 9 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/bookmarkmodel.cpp | 35 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/mainwindow.cpp | 11 |
5 files changed, 117 insertions, 36 deletions
diff --git a/tools/assistant/tools/assistant/bookmarkfiltermodel.cpp b/tools/assistant/tools/assistant/bookmarkfiltermodel.cpp index 7a7c2e3..2e4062b 100644 --- a/tools/assistant/tools/assistant/bookmarkfiltermodel.cpp +++ b/tools/assistant/tools/assistant/bookmarkfiltermodel.cpp @@ -79,7 +79,7 @@ BookmarkFilterModel::setSourceModel(QAbstractItemModel *_sourceModel) connect(sourceModel, SIGNAL(modelReset()), this, SLOT(modelReset())); if (sourceModel) - setupCache(sourceModel->index(0, 0, QModelIndex())); + setupCache(sourceModel->index(0, 0, QModelIndex()).parent()); endResetModel(); } @@ -172,7 +172,7 @@ BookmarkFilterModel::filterBookmarks() if (sourceModel) { beginResetModel(); hideBookmarks = true; - setupCache(sourceModel->index(0, 0, QModelIndex())); + setupCache(sourceModel->index(0, 0, QModelIndex()).parent()); endResetModel(); } } @@ -183,7 +183,7 @@ BookmarkFilterModel::filterBookmarkFolders() if (sourceModel) { beginResetModel(); hideBookmarks = false; - setupCache(sourceModel->index(0, 0, QModelIndex())); + setupCache(sourceModel->index(0, 0, QModelIndex()).parent()); endResetModel(); } } @@ -271,7 +271,7 @@ void BookmarkFilterModel::modelReset() { if (sourceModel) - setupCache(sourceModel->index(0, 0, QModelIndex())); + setupCache(sourceModel->index(0, 0, QModelIndex()).parent()); endResetModel(); } @@ -279,7 +279,8 @@ void BookmarkFilterModel::setupCache(const QModelIndex &parent) { cache.clear(); - collectItems(parent); + for (int i = 0; i < sourceModel->rowCount(parent); ++i) + collectItems(sourceModel->index(i, 0, parent)); } void diff --git a/tools/assistant/tools/assistant/bookmarkmanager.cpp b/tools/assistant/tools/assistant/bookmarkmanager.cpp index eb5a37a..85f7e19 100644 --- a/tools/assistant/tools/assistant/bookmarkmanager.cpp +++ b/tools/assistant/tools/assistant/bookmarkmanager.cpp @@ -53,6 +53,7 @@ #include <QtGui/QKeyEvent> #include <QtGui/QMessageBox> #include <QtGui/QSortFilterProxyModel> +#include <QtGui/QToolBar> QT_BEGIN_NAMESPACE @@ -136,11 +137,18 @@ QWidget* BookmarkManager::bookmarkDockWidget() const return 0; } -void BookmarkManager::takeBookmarksMenu(QMenu* menu) +void BookmarkManager::setBookmarksMenu(QMenu* menu) { TRACE_OBJ bookmarkMenu = menu; - refeshBookmarkMenu(); + refreshBookmarkMenu(); +} + +void BookmarkManager::setBookmarksToolbar(QToolBar *toolBar) +{ + TRACE_OBJ + m_toolBar = toolBar; + refreshBookmarkToolBar(); } // -- public slots @@ -157,6 +165,7 @@ void BookmarkManager::addBookmark(const QString &title, const QString &url) BookmarkManager::BookmarkManager() : typeAndSearch(false) , bookmarkMenu(0) + , m_toolBar(0) , bookmarkModel(new BookmarkModel) , bookmarkFilterModel(0) , typeAndSearchModel(0) @@ -188,11 +197,18 @@ BookmarkManager::BookmarkManager() connect(&HelpEngineWrapper::instance(), SIGNAL(setupFinished()), this, SLOT(setupFinished())); connect(bookmarkModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, - SLOT(refeshBookmarkMenu())); + SLOT(refreshBookmarkMenu())); + connect(bookmarkModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, + SLOT(refreshBookmarkMenu())); + connect(bookmarkModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, + SLOT(refreshBookmarkMenu())); + + connect(bookmarkModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, + SLOT(refreshBookmarkToolBar())); connect(bookmarkModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, - SLOT(refeshBookmarkMenu())); + SLOT(refreshBookmarkToolBar())); connect(bookmarkModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, - SLOT(refeshBookmarkMenu())); + SLOT(refreshBookmarkToolBar())); } BookmarkManager::~BookmarkManager() @@ -312,7 +328,8 @@ void BookmarkManager::setupFinished() bookmarkModel->setBookmarks(HelpEngineWrapper::instance().bookmarks()); bookmarkModel->expandFoldersIfNeeeded(bookmarkTreeView); - refeshBookmarkMenu(); + refreshBookmarkMenu(); + refreshBookmarkToolBar(); bookmarkTreeView->hideColumn(1); bookmarkTreeView->header()->setVisible(false); @@ -358,7 +375,7 @@ void BookmarkManager::manageBookmarks() bookmarkManagerWidget->raise(); } -void BookmarkManager::refeshBookmarkMenu() +void BookmarkManager::refreshBookmarkMenu() { TRACE_OBJ if (!bookmarkMenu) @@ -369,11 +386,10 @@ void BookmarkManager::refeshBookmarkMenu() bookmarkMenu->addAction(tr("Manage Bookmarks..."), this, SLOT(manageBookmarks())); bookmarkMenu->addAction(QIcon::fromTheme("bookmark-new"), - tr("Add Bookmark..."), this, SLOT(addBookmark()), - QKeySequence(tr("Ctrl+D"))); + tr("Add Bookmark..."), this, SLOT(addBookmark()), QKeySequence(tr("Ctrl+D"))); bookmarkMenu->addSeparator(); - const QModelIndex &root = bookmarkModel->index(0, 0, QModelIndex()); + const QModelIndex &root = bookmarkModel->index(1, 0, QModelIndex()); for (int i = 0; i < bookmarkModel->rowCount(root); ++i) buildBookmarksMenu(bookmarkModel->index(i, 0, root), bookmarkMenu); @@ -381,6 +397,41 @@ void BookmarkManager::refeshBookmarkMenu() SLOT(setSourceFromAction(QAction*))); } +void BookmarkManager::refreshBookmarkToolBar() +{ + TRACE_OBJ + if (!m_toolBar) + return; + + m_toolBar->clear(); + m_toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + + const QModelIndex &root = bookmarkModel->index(0, 0, QModelIndex()); + for (int i = 0; i < bookmarkModel->rowCount(root); ++i) { + const QModelIndex &index = bookmarkModel->index(i, 0, root); + if (index.data(UserRoleFolder).toBool()) { + QToolButton *button = new QToolButton(m_toolBar); + button->setPopupMode(QToolButton::InstantPopup); + button->setText(index.data().toString()); + QMenu *menu = new QMenu(button); + for (int j = 0; j < bookmarkModel->rowCount(index); ++j) + buildBookmarksMenu(bookmarkModel->index(j, 0, index), menu); + connect(menu, SIGNAL(triggered(QAction*)), this, + SLOT(setSourceFromAction(QAction*))); + button->setMenu(menu); + button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + button->setIcon(qvariant_cast<QIcon>(index.data(Qt::DecorationRole))); + QAction *a = m_toolBar->addWidget(button); + a->setText(index.data().toString()); + } else { + QAction *action = m_toolBar->addAction( + qvariant_cast<QIcon>(index.data(Qt::DecorationRole)), + index.data().toString(), this, SLOT(setSourceFromAction())); + action->setData(index.data(UserRoleUrl).toString()); + } + } +} + void BookmarkManager::renameBookmark(const QModelIndex &index) { // check if we should rename the "Bookmarks Menu", bail @@ -392,13 +443,21 @@ void BookmarkManager::renameBookmark(const QModelIndex &index) bookmarkModel->setItemsEditable(false); } -void BookmarkManager::setSourceFromAction(QAction *action) + +void BookmarkManager::setSourceFromAction() { TRACE_OBJ - const QVariant &data = action->data(); + setSourceFromAction(qobject_cast<QAction*> (sender())); +} - if (data.canConvert<QUrl>()) - emit setSource(data.toUrl()); +void BookmarkManager::setSourceFromAction(QAction *action) +{ + TRACE_OBJ + if (action) { + const QVariant &data = action->data(); + if (data.canConvert<QUrl>()) + emit setSource(data.toUrl()); + } } void BookmarkManager::setSourceFromIndex(const QModelIndex &index, bool newTab) diff --git a/tools/assistant/tools/assistant/bookmarkmanager.h b/tools/assistant/tools/assistant/bookmarkmanager.h index c26dad8..ae27b59 100644 --- a/tools/assistant/tools/assistant/bookmarkmanager.h +++ b/tools/assistant/tools/assistant/bookmarkmanager.h @@ -53,6 +53,7 @@ class BookmarkModel; class BookmarkFilterModel; class QKeyEvent; class QSortFilterProxyModel; +class QToolBar; class BookmarkManager : public QObject { @@ -67,7 +68,8 @@ public: static void destroy(); QWidget* bookmarkDockWidget() const; - void takeBookmarksMenu(QMenu* menu); + void setBookmarksMenu(QMenu* menu); + void setBookmarksToolbar(QToolBar *toolBar); public slots: void addBookmark(const QString &title, const QString &url); @@ -92,9 +94,11 @@ private slots: void addBookmark(); void removeBookmark(); void manageBookmarks(); - void refeshBookmarkMenu(); + void refreshBookmarkMenu(); + void refreshBookmarkToolBar(); void renameBookmark(const QModelIndex &index); + void setSourceFromAction(); void setSourceFromAction(QAction *action); void setSourceFromIndex(const QModelIndex &index, bool newTab = false); @@ -110,6 +114,7 @@ private: static BookmarkManager *bookmarkManager; QMenu *bookmarkMenu; + QToolBar *m_toolBar; BookmarkModel *bookmarkModel; BookmarkFilterModel *bookmarkFilterModel; diff --git a/tools/assistant/tools/assistant/bookmarkmodel.cpp b/tools/assistant/tools/assistant/bookmarkmodel.cpp index 4c30b42..320b233 100644 --- a/tools/assistant/tools/assistant/bookmarkmodel.cpp +++ b/tools/assistant/tools/assistant/bookmarkmodel.cpp @@ -48,6 +48,7 @@ #include <QtGui/QStyle> #include <QtGui/QTreeView> +const quint32 VERSION = 0xe53798; const QLatin1String MIMETYPE("application/bookmarks.assistant"); BookmarkModel::BookmarkModel() @@ -68,8 +69,9 @@ BookmarkModel::bookmarks() const { QByteArray ba; QDataStream stream(&ba, QIODevice::WriteOnly); + stream << qint32(VERSION); - const QModelIndex &root = index(0,0, QModelIndex()); + const QModelIndex &root = index(0,0, QModelIndex()).parent(); for (int i = 0; i < rowCount(root); ++i) collectItems(index(i, 0, root), 0, &stream); @@ -87,24 +89,35 @@ BookmarkModel::setBookmarks(const QByteArray &bookmarks) rootItem = new BookmarkItem(DataVector() << tr("Name") << tr("Address") << true); - BookmarkItem* item = new BookmarkItem(DataVector() << tr("Bookmarks Menu") - << QLatin1String("Folder") << true); - rootItem->addChild(item); QStack<BookmarkItem*> parents; - parents.push(item); + QDataStream stream(bookmarks); + + qint32 version; + stream >> version; + if (version < VERSION) { + stream.device()->seek(0); + BookmarkItem* toolbar = new BookmarkItem(DataVector() << tr("Toolbar Menu") + << QLatin1String("Folder") << true); + rootItem->addChild(toolbar); + + BookmarkItem* menu = new BookmarkItem(DataVector() << tr("Bookmarks Menu") + << QLatin1String("Folder") << true); + rootItem->addChild(menu); + parents.push(menu); + } else { + parents.push(rootItem); + } qint32 depth; bool expanded; QString name, url; - QDataStream stream(bookmarks); while (!stream.atEnd()) { stream >> depth >> name >> url >> expanded; - while ((parents.count() - 1) != depth) parents.pop(); - item = new BookmarkItem(DataVector() << name << url << expanded); + BookmarkItem *item = new BookmarkItem(DataVector() << name << url << expanded); if (url == QLatin1String("Folder")) { parents.top()->addChild(item); parents.push(item); @@ -114,11 +127,7 @@ BookmarkModel::setBookmarks(const QByteArray &bookmarks) } cache.clear(); - const QModelIndex &root = index(0,0, QModelIndex()); - - setupCache(root); - cache.insert(static_cast<BookmarkItem*> (root.internalPointer()), root); - + setupCache(index(0,0, QModelIndex().parent())); endResetModel(); } diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp index a47a501..4707a65 100644 --- a/tools/assistant/tools/assistant/mainwindow.cpp +++ b/tools/assistant/tools/assistant/mainwindow.cpp @@ -117,6 +117,7 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) } HelpEngineWrapper &helpEngineWrapper = HelpEngineWrapper::instance(collectionFile); + BookmarkManager *bookMarkManager = BookmarkManager::instance(); if (!initHelpDB()) { qDebug("Fatal error: Help engine initialization failed. " @@ -148,7 +149,6 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) searchDock->setWidget(m_searchWindow); addDockWidget(Qt::LeftDockWidgetArea, searchDock); - BookmarkManager *bookMarkManager = BookmarkManager::instance(); QDockWidget *bookmarkDock = new QDockWidget(tr("Bookmarks"), this); bookmarkDock->setObjectName(QLatin1String("BookmarkWindow")); bookmarkDock->setWidget(m_bookmarkWidget @@ -198,9 +198,16 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) qApp->setWindowIcon(appIcon); } + QToolBar *toolBar = addToolBar(tr("Bookmark Toolbar")); + bookMarkManager->setBookmarksToolbar(toolBar); + // Show the widget here, otherwise the restore geometry and state won't work // on x11. show(); + + toolBar->hide(); + toolBarMenu()->addAction(toolBar->toggleViewAction()); + QByteArray ba(helpEngineWrapper.mainWindow()); if (!ba.isEmpty()) restoreState(ba); @@ -528,7 +535,7 @@ void MainWindow::setupActions() connect(sct, SIGNAL(activated()), openPages, SLOT(previousPageWithSwitcher())); #endif - BookmarkManager::instance()->takeBookmarksMenu(menuBar()->addMenu(tr("&Bookmarks"))); + BookmarkManager::instance()->setBookmarksMenu(menuBar()->addMenu(tr("&Bookmarks"))); menu = menuBar()->addMenu(tr("&Help")); m_aboutAction = menu->addAction(tr("About..."), this, SLOT(showAboutDialog())); |