diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp | 4 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/bookmarkmanager.cpp | 54 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/bookmarkmanager.h | 8 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/centralwidget.cpp | 29 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/mainwindow.cpp | 37 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/mainwindow.h | 5 |
6 files changed, 114 insertions, 23 deletions
diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp index b6e726b..c50f48d 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp +++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp @@ -639,7 +639,7 @@ void QHelpSearchIndexWriter::run() QFileInfo fInfo(indexPath); if (fInfo.exists() && !fInfo.isWritable()) { - qWarning("Full Text Search, could not create index (missing permissions)."); + qWarning("Full Text Search, could not create index (missing permissions for '%s').", qPrintable(indexPath)); return; } @@ -720,7 +720,7 @@ void QHelpSearchIndexWriter::run() } #if !defined(QT_NO_EXCEPTIONS) } catch (...) { - qWarning("Full Text Search, could not create index writer."); + qWarning("Full Text Search, could not create index writer in '%s'.", qPrintable(indexPath)); return; } #endif 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/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp index 385f0bb..a384544 100644 --- a/tools/assistant/tools/assistant/centralwidget.cpp +++ b/tools/assistant/tools/assistant/centralwidget.cpp @@ -286,6 +286,10 @@ CentralWidget::CentralWidget(QHelpEngine *engine, MainWindow *parent) CentralWidget::~CentralWidget() { +#ifndef QT_NO_PRINTER + delete printer; +#endif + QHelpEngineCore engine(collectionFile, 0); if (!engine.setupData()) return; @@ -357,10 +361,10 @@ void CentralWidget::findNext() void CentralWidget::nextPage() { - if(tabWidget->currentIndex() < tabWidget->count() -1) - tabWidget->setCurrentIndex(tabWidget->currentIndex() +1); - else - tabWidget->setCurrentIndex(0); + int index = tabWidget->currentIndex() + 1; + if (index >= tabWidget->count()) + index = 0; + tabWidget->setCurrentIndex(index); } void CentralWidget::resetZoom() @@ -376,10 +380,9 @@ void CentralWidget::resetZoom() void CentralWidget::previousPage() { int index = tabWidget->currentIndex() -1; - if(index >= 0) - tabWidget->setCurrentIndex(index); - else - tabWidget->setCurrentIndex(tabWidget->count() -1); + if (index < 0) + index = tabWidget->count() -1; + tabWidget->setCurrentIndex(index); } void CentralWidget::findPrevious() @@ -400,7 +403,8 @@ void CentralWidget::closeTab() void CentralWidget::setSource(const QUrl &url) { HelpViewer *viewer = currentHelpViewer(); - HelpViewer *lastViewer = qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage)); + HelpViewer *lastViewer = + qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage)); if (!viewer && !lastViewer) { viewer = new HelpViewer(helpEngine, this); @@ -427,8 +431,11 @@ void CentralWidget::setLastShownPages() QString::SkipEmptyParts); const int pageCount = lastShownPageList.count(); - if (pageCount == 0 && usesDefaultCollection) { - setSource(QUrl(QLatin1String("help"))); + if (pageCount == 0) { + if (usesDefaultCollection) + setSource(QUrl(QLatin1String("help"))); + else + setSource(QUrl(QLatin1String("about:blank"))); return; } diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp index 8860601..617ac4d 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; |