summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkh <qtc-committer@nokia.com>2009-07-01 13:05:49 (GMT)
committerkh <qtc-committer@nokia.com>2009-07-01 13:05:49 (GMT)
commit7c6ae7d93b2fe7fb3054798ad77b411608801388 (patch)
tree3d11883d06064a41c6f2ba004574f8724e7b234b
parent1813a6d2bc0ba611cecd2d74dea75cd4644a9f95 (diff)
downloadQt-7c6ae7d93b2fe7fb3054798ad77b411608801388.zip
Qt-7c6ae7d93b2fe7fb3054798ad77b411608801388.tar.gz
Qt-7c6ae7d93b2fe7fb3054798ad77b411608801388.tar.bz2
Sync with QtCreator.
Reviewed-by: kh
-rw-r--r--tools/assistant/tools/assistant/bookmarkmanager.cpp54
-rw-r--r--tools/assistant/tools/assistant/bookmarkmanager.h8
-rw-r--r--tools/assistant/tools/assistant/mainwindow.cpp37
-rw-r--r--tools/assistant/tools/assistant/mainwindow.h5
4 files changed, 94 insertions, 10 deletions
diff --git a/tools/assistant/tools/assistant/bookmarkmanager.cpp b/tools/assistant/tools/assistant/bookmarkmanager.cpp
index 3bca573..250262e 100644
--- a/tools/assistant/tools/assistant/bookmarkmanager.cpp
+++ b/tools/assistant/tools/assistant/bookmarkmanager.cpp
@@ -347,7 +347,7 @@ void BookmarkWidget::filterChanged()
filterBookmarkModel->setFilterRegExp(regExp);
- QModelIndex index = treeView->indexAt(QPoint(1, 1));
+ const QModelIndex &index = treeView->indexAt(QPoint(1, 1));
if (index.isValid())
treeView->setCurrentIndex(index);
@@ -445,9 +445,10 @@ void BookmarkWidget::setup(bool showButtons)
treeView = new TreeView(this);
vlayout->addWidget(treeView);
- QString system = QLatin1String("win");
#ifdef Q_OS_MAC
- system = QLatin1String("mac");
+# define SYSTEM "mac"
+#else
+# define SYSTEM "win"
#endif
if (showButtons) {
@@ -458,8 +459,8 @@ void BookmarkWidget::setup(bool showButtons)
addButton = new QToolButton(this);
addButton->setText(tr("Add"));
- addButton->setIcon(QIcon(QString::fromUtf8(
- ":/trolltech/assistant/images/%1/addtab.png").arg(system)));
+ addButton->setIcon(QIcon(QLatin1String(":/trolltech/assistant/images/"
+ SYSTEM "/addtab.png")));
addButton->setAutoRaise(true);
addButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
hlayout->addWidget(addButton);
@@ -467,8 +468,8 @@ void BookmarkWidget::setup(bool showButtons)
removeButton = new QToolButton(this);
removeButton->setText(tr("Remove"));
- removeButton->setIcon(QIcon(QString::fromUtf8(
- ":/trolltech/assistant/images/%1/closetab.png").arg(system)));
+ removeButton->setIcon(QIcon(QLatin1String(":/trolltech/assistant/images/"
+ SYSTEM "/closetab.png")));
removeButton->setAutoRaise(true);
removeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
hlayout->addWidget(removeButton);
@@ -626,6 +627,10 @@ BookmarkManager::BookmarkManager(QHelpEngineCore *_helpEngine)
connect(treeModel, SIGNAL(itemChanged(QStandardItem*)), this,
SLOT(itemChanged(QStandardItem*)));
+ connect(treeModel, SIGNAL(itemChanged(QStandardItem*)), this,
+ SIGNAL(bookmarksChanged()));
+ connect(treeModel, SIGNAL(rowsRemoved(QModelIndex, int, int)),
+ this, SIGNAL(bookmarksChanged()));
}
BookmarkManager::~BookmarkManager()
@@ -736,6 +741,41 @@ void BookmarkManager::addNewBookmark(const QModelIndex &index,
else
treeModel->appendRow(item);
listModel->appendRow(item->clone());
+ emit bookmarksChanged();
+}
+
+void BookmarkManager::fillBookmarkMenu(QMenu *menu)
+{
+ if (!menu || !treeModel)
+ return;
+
+ map.clear();
+ fillBookmarkMenu(menu, treeModel->invisibleRootItem());
+}
+
+void BookmarkManager::fillBookmarkMenu(QMenu *menu, QStandardItem *root)
+{
+ for (int i = 0; i < root->rowCount(); ++i) {
+ QStandardItem *item = root->child(i);
+ if (item && item->data(Qt::UserRole + 10)
+ .toString() == QLatin1String("Folder")) {
+ QMenu* newMenu = menu->addMenu(folderIcon, item->text());
+ if (item->rowCount() > 0)
+ fillBookmarkMenu(newMenu, item);
+ } else {
+ map.insert(menu->addAction(item->text()), item->index());
+ }
+ }
+}
+
+QUrl BookmarkManager::urlForAction(QAction* action) const
+{
+ if (map.contains(action)) {
+ const QModelIndex &index = map.value(action);
+ if (QStandardItem* item = treeModel->itemFromIndex(index))
+ return QUrl(item->data(Qt::UserRole + 10).toString());
+ }
+ return QUrl();
}
void BookmarkManager::itemChanged(QStandardItem *item)
diff --git a/tools/assistant/tools/assistant/bookmarkmanager.h b/tools/assistant/tools/assistant/bookmarkmanager.h
index bf7af41..33db5b6 100644
--- a/tools/assistant/tools/assistant/bookmarkmanager.h
+++ b/tools/assistant/tools/assistant/bookmarkmanager.h
@@ -183,6 +183,12 @@ public:
const QString &url);
void setupBookmarkModels();
+ void fillBookmarkMenu(QMenu *menu);
+ QUrl urlForAction(QAction* action) const;
+
+signals:
+ void bookmarksChanged();
+
private slots:
void itemChanged(QStandardItem *item);
@@ -191,6 +197,7 @@ private:
void removeBookmarkFolderItems(QStandardItem *item);
void readBookmarksRecursive(const QStandardItem *item, QDataStream &stream,
const qint32 depth) const;
+ void fillBookmarkMenu(QMenu *menu, QStandardItem *root);
private:
QString oldText;
@@ -200,6 +207,7 @@ private:
BookmarkModel *listModel;
QStandardItem *renameItem;
QHelpEngineCore *helpEngine;
+ QMap<QAction*, QModelIndex> map;
};
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp
index 5b3e731..0340297 100644
--- a/tools/assistant/tools/assistant/mainwindow.cpp
+++ b/tools/assistant/tools/assistant/mainwindow.cpp
@@ -137,7 +137,14 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
if (initHelpDB()) {
setupFilterToolbar();
setupAddressToolbar();
+
m_bookmarkManager->setupBookmarkModels();
+ m_bookmarkMenu->addSeparator();
+ m_bookmarkManager->fillBookmarkMenu(m_bookmarkMenu);
+ connect(m_bookmarkMenu, SIGNAL(triggered(QAction*)), this,
+ SLOT(showBookmark(QAction*)));
+ connect(m_bookmarkManager, SIGNAL(bookmarksChanged()), this,
+ SLOT(updateBookmarkMenu()));
setWindowTitle(m_helpEngine->customValue(QLatin1String("WindowTitle"),
defWindowTitle).toString());
@@ -370,6 +377,29 @@ void MainWindow::checkInitState()
}
}
+void MainWindow::updateBookmarkMenu()
+{
+ if (m_bookmarkManager) {
+ m_bookmarkMenu->removeAction(m_bookmarkMenuAction);
+
+ m_bookmarkMenu->clear();
+
+ m_bookmarkMenu->addAction(m_bookmarkMenuAction);
+ m_bookmarkMenu->addSeparator();
+
+ m_bookmarkManager->fillBookmarkMenu(m_bookmarkMenu);
+ }
+}
+
+void MainWindow::showBookmark(QAction *action)
+{
+ if (m_bookmarkManager) {
+ const QUrl &url = m_bookmarkManager->urlForAction(action);
+ if (url.isValid())
+ m_centralWidget->setSource(url);
+ }
+}
+
void MainWindow::insertLastPages()
{
if (m_cmdLine->url().isValid())
@@ -495,9 +525,10 @@ void MainWindow::setupActions()
tmp->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Alt+Left"))
<< QKeySequence(Qt::CTRL + Qt::Key_PageUp));
- menu = menuBar()->addMenu(tr("&Bookmarks"));
- tmp = menu->addAction(tr("Add Bookmark..."), this, SLOT(addBookmark()));
- tmp->setShortcut(tr("CTRL+D"));
+ m_bookmarkMenu = menuBar()->addMenu(tr("&Bookmarks"));
+ m_bookmarkMenuAction = m_bookmarkMenu->addAction(tr("Add Bookmark..."),
+ this, SLOT(addBookmark()));
+ m_bookmarkMenuAction->setShortcut(tr("CTRL+D"));
menu = menuBar()->addMenu(tr("&Help"));
m_aboutAction = menu->addAction(tr("About..."), this, SLOT(showAboutDialog()));
diff --git a/tools/assistant/tools/assistant/mainwindow.h b/tools/assistant/tools/assistant/mainwindow.h
index 9ab3185..f7df724 100644
--- a/tools/assistant/tools/assistant/mainwindow.h
+++ b/tools/assistant/tools/assistant/mainwindow.h
@@ -119,6 +119,9 @@ private slots:
void qtDocumentationInstalled(bool newDocsInstalled);
void checkInitState();
+ void updateBookmarkMenu();
+ void showBookmark(QAction *action);
+
private:
bool initHelpDB();
void setupActions();
@@ -157,6 +160,8 @@ private:
QMenu *m_viewMenu;
QMenu *m_toolBarMenu;
+ QMenu *m_bookmarkMenu;
+ QAction *m_bookmarkMenuAction;
CmdLineParser *m_cmdLine;