From b0773d144e1cd31f49be5f70c357d6be030a2e8f Mon Sep 17 00:00:00 2001 From: ck Date: Wed, 10 Mar 2010 16:49:03 +0100 Subject: Assistant: Move search widget into the dock area. Task-number: QTBUG-2048 Reviewed-by: kh1 --- tools/assistant/tools/assistant/centralwidget.cpp | 276 +++++---------------- tools/assistant/tools/assistant/centralwidget.h | 16 +- .../tools/assistant/helpenginewrapper.cpp | 12 - .../assistant/tools/assistant/helpenginewrapper.h | 3 - tools/assistant/tools/assistant/mainwindow.cpp | 80 +++--- tools/assistant/tools/assistant/mainwindow.h | 11 +- 6 files changed, 107 insertions(+), 291 deletions(-) diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp index f56e9e3..e562198 100644 --- a/tools/assistant/tools/assistant/centralwidget.cpp +++ b/tools/assistant/tools/assistant/centralwidget.cpp @@ -92,7 +92,6 @@ CentralWidget::CentralWidget(MainWindow *parent) , findWidget(0) , printer(0) , usesDefaultCollection(parent->usesDefaultCollection()) - , m_searchWidget(0) { TRACE_OBJ globalActionList.clear(); @@ -168,10 +167,7 @@ CentralWidget::~CentralWidget() QStringList zoomFactors; QStringList currentPages; - bool searchAttached = m_searchWidget->isAttached(); - - int i = searchAttached ? 1 : 0; - for (; i < tabWidget->count(); ++i) { + for (int i = 0; i < tabWidget->count(); ++i) { HelpViewer *viewer = qobject_cast(tabWidget->widget(i)); if (viewer && viewer->source().isValid()) { currentPages << viewer->source().toString(); @@ -182,7 +178,6 @@ CentralWidget::~CentralWidget() HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); helpEngine.setLastTabPage(tabWidget->currentIndex()); helpEngine.setLastShownPages(currentPages); - helpEngine.setSearchWasAttached(searchAttached); helpEngine.setLastZoomFactors(zoomFactors); } @@ -197,9 +192,7 @@ void CentralWidget::newTab() TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); #if !defined(QT_NO_WEBKIT) - if (viewer && viewer->hasLoadFinished()) -#else - if (viewer) + if (viewer->hasLoadFinished()) #endif setSourceInNewTab(viewer->source()); } @@ -207,23 +200,13 @@ void CentralWidget::newTab() void CentralWidget::zoomIn() { TRACE_OBJ - HelpViewer *viewer = currentHelpViewer(); - if (viewer) - viewer->scaleUp(); - - if (tabWidget->currentWidget() == m_searchWidget) - m_searchWidget->zoomIn(); + currentHelpViewer()->scaleUp(); } void CentralWidget::zoomOut() { TRACE_OBJ - HelpViewer *viewer = currentHelpViewer(); - if (viewer) - viewer->scaleDown(); - - if (tabWidget->currentWidget() == m_searchWidget) - m_searchWidget->zoomOut(); + currentHelpViewer()->scaleDown(); } void CentralWidget::nextPage() @@ -238,11 +221,7 @@ void CentralWidget::nextPage() void CentralWidget::resetZoom() { TRACE_OBJ - if (HelpViewer *viewer = currentHelpViewer()) - viewer->resetScale(); - - if (tabWidget->currentWidget() == m_searchWidget) - m_searchWidget->resetZoom(); + currentHelpViewer()->resetScale(); } void CentralWidget::previousPage() @@ -257,10 +236,10 @@ void CentralWidget::previousPage() void CentralWidget::closeTab() { TRACE_OBJ - HelpViewer *viewer = currentHelpViewer(); - if (!viewer|| tabWidget->count() == 1) + if (tabWidget->count() == 1) return; + HelpViewer *viewer = currentHelpViewer(); tabWidget->removeTab(tabWidget->indexOf(viewer)); QTimer::singleShot(0, viewer, SLOT(deleteLater())); } @@ -323,20 +302,13 @@ void CentralWidget::setLastShownPages() while (zoomFactors.count() < pageCount) zoomFactors.append(CollectionConfiguration::DefaultZoomFactor); - const bool searchIsAttached = m_searchWidget->isAttached(); - const bool searchWasAttached = helpEngine.searchWasAttached(); int tabToShow = helpEngine.lastTabPage(); - if (searchWasAttached && !searchIsAttached && tabToShow != 0) - --tabToShow; - else if (!searchWasAttached && searchIsAttached) - ++tabToShow; - for (int curTab = 0; curTab < pageCount; ++curTab) { const QString &curFile = lastShownPageList.at(curTab); if (helpEngine.findFile(curFile).isValid() || curFile == QLatin1String("about:blank")) { setSourceInNewTab(curFile, zoomFactors.at(curTab).toFloat()); - } else if (curTab + searchIsAttached <= tabToShow) + } else if (curTab <= tabToShow) --tabToShow; } @@ -346,36 +318,25 @@ void CentralWidget::setLastShownPages() bool CentralWidget::hasSelection() const { TRACE_OBJ - const HelpViewer *viewer = currentHelpViewer(); - return viewer ? viewer->hasSelection() : false; + return currentHelpViewer()->hasSelection(); } QUrl CentralWidget::currentSource() const { TRACE_OBJ - const HelpViewer *viewer = currentHelpViewer(); - if (viewer) - return viewer->source(); - - return QUrl(); + return currentHelpViewer()->source(); } QString CentralWidget::currentTitle() const { TRACE_OBJ - const HelpViewer *viewer = currentHelpViewer(); - if (viewer) - return viewer->documentTitle(); - - return QString(); + return currentHelpViewer()->documentTitle(); } void CentralWidget::copySelection() { TRACE_OBJ - HelpViewer *viewer = currentHelpViewer(); - if (viewer) - viewer->copy(); + currentHelpViewer()->copy(); } void CentralWidget::showTextSearch() @@ -398,11 +359,7 @@ void CentralWidget::print() TRACE_OBJ #ifndef QT_NO_PRINTER HelpViewer *viewer = currentHelpViewer(); - if (!viewer) - return; - initPrinter(); - QPrintDialog dlg(printer, this); #if defined(QT_NO_WEBKIT) if (viewer->textCursor().hasSelection()) @@ -433,9 +390,7 @@ void CentralWidget::printPreview(QPrinter *p) { TRACE_OBJ #ifndef QT_NO_PRINTER - HelpViewer *viewer = currentHelpViewer(); - if (viewer) - viewer->print(p); + currentHelpViewer()->print(p); #endif } @@ -449,54 +404,34 @@ void CentralWidget::pageSetup() #endif } -bool CentralWidget::isHomeAvailable() const -{ - TRACE_OBJ - return currentHelpViewer() ? true : false; -} - void CentralWidget::home() { TRACE_OBJ - HelpViewer *viewer = currentHelpViewer(); - if (viewer) - viewer->home(); + currentHelpViewer()->home(); } bool CentralWidget::isForwardAvailable() const { TRACE_OBJ - const HelpViewer *viewer = currentHelpViewer(); - if (viewer) - return viewer->isForwardAvailable(); - - return false; + return currentHelpViewer()->isForwardAvailable(); } void CentralWidget::forward() { TRACE_OBJ - HelpViewer *viewer = currentHelpViewer(); - if (viewer) - viewer->forward(); + currentHelpViewer()->forward(); } bool CentralWidget::isBackwardAvailable() const { TRACE_OBJ - const HelpViewer *viewer = currentHelpViewer(); - if (viewer) - return viewer->isBackwardAvailable(); - - return false; + return currentHelpViewer()->isBackwardAvailable(); } void CentralWidget::backward() { TRACE_OBJ - HelpViewer *viewer = currentHelpViewer(); - if (viewer) - viewer->backward(); + currentHelpViewer()->backward(); } @@ -515,10 +450,9 @@ void CentralWidget::setGlobalActions(const QList &actions) void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom) { TRACE_OBJ - if (HelpViewer *viewer = currentHelpViewer()) { - if (viewer->launchWithExternalApp(url)) - return; - } + + if (AbstractHelpViewer::launchWithExternalApp(url)) + return; HelpViewer *viewer = new HelpViewer(this, zoom); viewer->installEventFilter(this); @@ -548,20 +482,18 @@ void CentralWidget::connectSignals() { TRACE_OBJ const HelpViewer *viewer = currentHelpViewer(); - if (viewer) { - connect(viewer, SIGNAL(copyAvailable(bool)), this, + connect(viewer, SIGNAL(copyAvailable(bool)), this, SIGNAL(copyAvailable(bool))); - connect(viewer, SIGNAL(forwardAvailable(bool)), this, + connect(viewer, SIGNAL(forwardAvailable(bool)), this, SIGNAL(forwardAvailable(bool))); - connect(viewer, SIGNAL(backwardAvailable(bool)), this, + connect(viewer, SIGNAL(backwardAvailable(bool)), this, SIGNAL(backwardAvailable(bool))); - connect(viewer, SIGNAL(sourceChanged(QUrl)), this, + connect(viewer, SIGNAL(sourceChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl))); - connect(viewer, SIGNAL(highlighted(QString)), this, + connect(viewer, SIGNAL(highlighted(QString)), this, SIGNAL(highlighted(QString))); - connect(viewer, SIGNAL(sourceChanged(QUrl)), this, + connect(viewer, SIGNAL(sourceChanged(QUrl)), this, SLOT(setTabTitle(QUrl))); - } } HelpViewer* CentralWidget::viewerAt(int index) const @@ -576,18 +508,10 @@ HelpViewer* CentralWidget::currentHelpViewer() const return qobject_cast(tabWidget->currentWidget()); } -void CentralWidget::activateTab(bool onlyHelpViewer) +void CentralWidget::activateTab() { TRACE_OBJ - if (currentHelpViewer()) { - currentHelpViewer()->setFocus(); - } else { - int idx = 0; - if (onlyHelpViewer) - idx = lastTabPage; - tabWidget->setCurrentIndex(idx); - tabWidget->currentWidget()->setFocus(); - } + currentHelpViewer()->setFocus(); } void CentralWidget::setTabTitle(const QUrl &url) @@ -605,25 +529,18 @@ void CentralWidget::setTabTitle(const QUrl &url) } #else HelpViewer *viewer = currentHelpViewer(); - if (viewer) { - tabWidget->setTabText(lastTabPage, - quoteTabTitle(viewer->documentTitle().trimmed())); - } + tabWidget->setTabText(lastTabPage, + quoteTabTitle(viewer->documentTitle().trimmed())); #endif } void CentralWidget::currentPageChanged(int index) { TRACE_OBJ - const HelpViewer *viewer = currentHelpViewer(); - if (viewer) - lastTabPage = index; + lastTabPage = index; - QWidget *widget = tabWidget->cornerWidget(Qt::TopRightCorner); - widget->setEnabled(viewer && enableTabCloseAction()); - - widget = tabWidget->cornerWidget(Qt::TopLeftCorner); - widget->setEnabled(viewer ? true : false); + QWidget *closeButton = tabWidget->cornerWidget(Qt::TopRightCorner); + closeButton->setEnabled(enableTabCloseAction()); emit currentViewerChanged(); } @@ -778,34 +695,33 @@ bool CentralWidget::findInWebPage(const QString &ttf, bool forward) { TRACE_OBJ #if !defined(QT_NO_WEBKIT) - if (HelpViewer *viewer = currentHelpViewer()) { - bool found = false; - QWebPage::FindFlags options; - if (!ttf.isEmpty()) { - if (!forward) - options |= QWebPage::FindBackward; + HelpViewer *viewer = currentHelpViewer(); + bool found = false; + QWebPage::FindFlags options; + if (!ttf.isEmpty()) { + if (!forward) + options |= QWebPage::FindBackward; - if (findWidget->caseSensitive()) - options |= QWebPage::FindCaseSensitively; + if (findWidget->caseSensitive()) + options |= QWebPage::FindCaseSensitively; - found = viewer->findText(ttf, options); - findWidget->setTextWrappedVisible(false); + found = viewer->findText(ttf, options); + findWidget->setTextWrappedVisible(false); - if (!found) { - options |= QWebPage::FindWrapsAroundDocument; - found = viewer->findText(ttf, options); - if (found) - findWidget->setTextWrappedVisible(true); - } + if (!found) { + options |= QWebPage::FindWrapsAroundDocument; + found = viewer->findText(ttf, options); + if (found) + findWidget->setTextWrappedVisible(true); } - // force highlighting of all other matches, also when empty (clear) - options = QWebPage::HighlightAllOccurrences; - if (findWidget->caseSensitive()) - options |= QWebPage::FindCaseSensitively; - viewer->findText(QLatin1String(""), options); - viewer->findText(ttf, options); - return found; } + // force highlighting of all other matches, also when empty (clear) + options = QWebPage::HighlightAllOccurrences; + if (findWidget->caseSensitive()) + options |= QWebPage::FindCaseSensitively; + viewer->findText(QLatin1String(""), options); + viewer->findText(ttf, options); + return found; // this needs to stay, case for active search results page return findInTextBrowser(ttf, forward); @@ -820,8 +736,6 @@ bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward) { TRACE_OBJ QTextBrowser *browser = qobject_cast(currentHelpViewer()); - if (tabWidget->currentWidget() == m_searchWidget) - browser = qFindChild(m_searchWidget); if (!browser || ttf.isEmpty()) return false; @@ -868,88 +782,22 @@ bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward) void CentralWidget::updateBrowserFont() { TRACE_OBJ - const bool searchAttached = searchWidgetAttached(); - if (searchAttached) { - HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); - m_searchWidget->setFont(helpEngine.usesBrowserFont() - ? helpEngine.browserFont() : qApp->font()); - } - const int count = tabWidget->count(); - if (HelpViewer* viewer = viewerAt(count - 1)) { - const QFont &font = viewer->viewerFont(); - for (int i = searchAttached ? 1 : 0; i < count; ++i) - viewerAt(i)->setViewerFont(font); - } -} - -bool CentralWidget::searchWidgetAttached() const -{ - TRACE_OBJ - return m_searchWidget && m_searchWidget->isAttached(); -} - -void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine) -{ - TRACE_OBJ - if (m_searchWidget) - return; - - m_searchWidget = new SearchWidget(searchEngine, this); - connect(m_searchWidget, SIGNAL(requestShowLink(QUrl)), this, - SLOT(setSourceFromSearch(QUrl))); - connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(QUrl)), this, - SLOT(setSourceFromSearchInNewTab(QUrl))); - - HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); - m_searchWidget->setFont(!helpEngine.usesBrowserFont() ? qApp->font() - : helpEngine.browserFont()); -} - -void CentralWidget::activateSearchWidget(bool updateLastTabPage) -{ - TRACE_OBJ - if (!m_searchWidget) - createSearchWidget(HelpEngineWrapper::instance().searchEngine()); - - if (!m_searchWidget->isAttached()) { - tabWidget->insertTab(0, m_searchWidget, tr("Search")); - m_searchWidget->setAttached(true); - - if (updateLastTabPage) - lastTabPage++; - } - - tabWidget->setCurrentWidget(m_searchWidget); - m_searchWidget->setFocus(); -} - -void CentralWidget::removeSearchWidget() -{ - TRACE_OBJ - if (searchWidgetAttached()) { - tabWidget->removeTab(0); - m_searchWidget->setAttached(false); - } + const QFont &font = viewerAt(count - 1)->viewerFont(); + for (int i = 0; i < count; ++i) + viewerAt(i)->setViewerFont(font); } int CentralWidget::availableHelpViewer() const { TRACE_OBJ - int count = tabWidget->count(); - if (searchWidgetAttached()) - count--; - return count; + return tabWidget->count(); } bool CentralWidget::enableTabCloseAction() const { TRACE_OBJ - int minTabCount = 1; - if (searchWidgetAttached()) - minTabCount = 2; - - return (tabWidget->count() > minTabCount); + return tabWidget->count() > 1; } QString CentralWidget::quoteTabTitle(const QString &title) const @@ -990,8 +838,6 @@ CentralWidget::highlightSearchTerms() { TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); - if (!viewer) - return; QHelpSearchEngine *searchEngine = HelpEngineWrapper::instance().searchEngine(); diff --git a/tools/assistant/tools/assistant/centralwidget.h b/tools/assistant/tools/assistant/centralwidget.h index f286ff7..66d4142 100644 --- a/tools/assistant/tools/assistant/centralwidget.h +++ b/tools/assistant/tools/assistant/centralwidget.h @@ -51,7 +51,6 @@ class HelpViewer; class MainWindow; class QHelpSearchEngine; class QTabWidget; -class SearchWidget; class CentralWidget : public QWidget { @@ -65,7 +64,6 @@ public: bool hasSelection() const; QUrl currentSource() const; QString currentTitle() const; - bool isHomeAvailable() const; bool isForwardAvailable() const; bool isBackwardAvailable() const; QList globalActions() const; @@ -74,11 +72,6 @@ public: HelpViewer *viewerAt(int index) const; HelpViewer *currentHelpViewer() const; - bool searchWidgetAttached() const; - void createSearchWidget(QHelpSearchEngine *searchEngine); - void activateSearchWidget(bool updateLastTabPage = false); - void removeSearchWidget(); - int availableHelpViewer() const; bool enableTabCloseAction() const; @@ -107,12 +100,15 @@ public slots: void forward(); void backward(); - void activateTab(bool onlyHelpViewer = false); + void activateTab(); void findNext(); void findPrevious(); void find(const QString &text, bool forward); + void setSourceFromSearch(const QUrl &url); + void setSourceFromSearchInNewTab(const QUrl &url); + signals: void currentViewerChanged(); void copyAvailable(bool yes); @@ -132,8 +128,6 @@ private slots: void currentPageChanged(int index); void showTabBarContextMenu(const QPoint &point); void printPreview(QPrinter *printer); - void setSourceFromSearch(const QUrl &url); - void setSourceFromSearchInNewTab(const QUrl &url); void highlightSearchTerms(); private: @@ -153,8 +147,6 @@ private: FindWidget *findWidget; QPrinter *printer; bool usesDefaultCollection; - - SearchWidget *m_searchWidget; }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/helpenginewrapper.cpp b/tools/assistant/tools/assistant/helpenginewrapper.cpp index e21e95d..c7f4091 100644 --- a/tools/assistant/tools/assistant/helpenginewrapper.cpp +++ b/tools/assistant/tools/assistant/helpenginewrapper.cpp @@ -566,18 +566,6 @@ void HelpEngineWrapper::setLastTabPage(int lastPage) CollectionConfiguration::setLastTabPage(*d->m_helpEngine, lastPage); } -bool HelpEngineWrapper::searchWasAttached() const -{ - TRACE_OBJ - return d->m_helpEngine->customValue(SearchWasAttachedKey).toBool(); -} - -void HelpEngineWrapper::setSearchWasAttached(bool attached) -{ - TRACE_OBJ - d->m_helpEngine->setCustomValue(SearchWasAttachedKey, attached); -} - int HelpEngineWrapper::startOption() const { TRACE_OBJ diff --git a/tools/assistant/tools/assistant/helpenginewrapper.h b/tools/assistant/tools/assistant/helpenginewrapper.h index c1041b6..f1a381a 100644 --- a/tools/assistant/tools/assistant/helpenginewrapper.h +++ b/tools/assistant/tools/assistant/helpenginewrapper.h @@ -170,9 +170,6 @@ public: int startOption() const; void setStartOption(int option); - bool searchWasAttached() const; - void setSearchWasAttached(bool attached); - bool hasFontSettings() const; bool usesAppFont() const; void setUseAppFont(bool useAppFont); diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp index 8096218..2605050 100644 --- a/tools/assistant/tools/assistant/mainwindow.cpp +++ b/tools/assistant/tools/assistant/mainwindow.cpp @@ -131,30 +131,34 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) contentDock->setWidget(m_contentWindow); addDockWidget(Qt::LeftDockWidgetArea, contentDock); - QDockWidget *bookmarkDock = 0; - if (BookmarkManager *manager = BookmarkManager::instance()) { - bookmarkDock = new QDockWidget(tr("Bookmarks"), this); - bookmarkDock->setObjectName(QLatin1String("BookmarkWindow")); - bookmarkDock->setWidget(m_bookmarkWidget = manager->bookmarkDockWidget()); - addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock); - - connect(manager, SIGNAL(escapePressed()), this, + m_searchWindow = new SearchWidget(helpEngineWrapper.searchEngine()); + m_searchWindow->setFont(!helpEngineWrapper.usesBrowserFont() ? qApp->font() + : helpEngineWrapper.browserFont()); + QDockWidget *searchDock = new QDockWidget(tr("Search"), this); + searchDock->setObjectName(QLatin1String("SearchWindow")); + 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 + = bookMarkManager->bookmarkDockWidget()); + addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock); + + connect(bookMarkManager, SIGNAL(escapePressed()), this, SLOT(activateCurrentCentralWidgetTab())); - connect(manager, SIGNAL(setSource(QUrl)), m_centralWidget, + connect(bookMarkManager, SIGNAL(setSource(QUrl)), m_centralWidget, SLOT(setSource(QUrl))); - connect(manager, SIGNAL(setSourceInNewTab(QUrl)), m_centralWidget, + connect(bookMarkManager, SIGNAL(setSourceInNewTab(QUrl)), m_centralWidget, SLOT(setSourceInNewTab(QUrl))); - connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)), manager, - SLOT(addBookmark(QString, QString))); - } + connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)), + bookMarkManager, SLOT(addBookmark(QString, QString))); QHelpSearchEngine *searchEngine = helpEngineWrapper.searchEngine(); connect(searchEngine, SIGNAL(indexingStarted()), this, SLOT(indexingStarted())); connect(searchEngine, SIGNAL(indexingFinished()), this, SLOT(indexingFinished())); - m_centralWidget->createSearchWidget(searchEngine); - m_centralWidget->activateSearchWidget(); - QString defWindowTitle = tr("Qt Assistant"); setWindowTitle(defWindowTitle); @@ -190,10 +194,10 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) restoreGeometry(ba); } else { tabifyDockWidget(contentDock, indexDock); - if (bookmarkDock) - tabifyDockWidget(indexDock, bookmarkDock); + tabifyDockWidget(indexDock, bookmarkDock); + tabifyDockWidget(bookmarkDock, searchDock); contentDock->raise(); - resize(QSize(800, 600)); + resize(QSize(1024, 768)); } if (!helpEngineWrapper.hasFontSettings()) { @@ -490,7 +494,7 @@ void MainWindow::setupActions() QKeySequence(tr("ALT+I"))); m_viewMenu->addAction(tr("Bookmarks"), this, SLOT(showBookmarksDockWidget()), QKeySequence(tr("ALT+O"))); - m_viewMenu->addAction(tr("Search"), this, SLOT(showSearchWidget()), + m_viewMenu->addAction(tr("Search"), this, SLOT(showSearch()), QKeySequence(tr("ALT+S"))); menu = menuBar()->addMenu(tr("&Go")); @@ -524,8 +528,7 @@ void MainWindow::setupActions() tmp->setShortcuts(QList() << QKeySequence(tr("Ctrl+Alt+Left")) << QKeySequence(Qt::CTRL + Qt::Key_PageUp)); - if (BookmarkManager *manager = BookmarkManager::instance()) - manager->takeBookmarksMenu(menuBar()->addMenu(tr("&Bookmarks"))); + BookmarkManager::instance()->takeBookmarksMenu(menuBar()->addMenu(tr("&Bookmarks"))); menu = menuBar()->addMenu(tr("&Help")); m_aboutAction = menu->addAction(tr("About..."), this, SLOT(showAboutDialog())); @@ -601,6 +604,12 @@ void MainWindow::setupActions() connect(m_contentWindow, SIGNAL(escapePressed()), this, SLOT(activateCurrentCentralWidgetTab())); + // search window + connect(m_searchWindow, SIGNAL(requestShowLink(QUrl)), m_centralWidget, + SLOT(setSourceFromSearch(QUrl))); + connect(m_searchWindow, SIGNAL(requestShowLinkInNewTab(QUrl)), + m_centralWidget, SLOT(setSourceFromSearchInNewTab(QUrl))); + #if defined(QT_NO_PRINTER) m_pageSetupAction->setVisible(false); m_printPreviewAction->setVisible(false); @@ -727,15 +736,9 @@ void MainWindow::gotoAddress() void MainWindow::updateNavigationItems() { TRACE_OBJ - bool hasCurrentViewer = m_centralWidget->isHomeAvailable(); m_copyAction->setEnabled(m_centralWidget->hasSelection()); - m_homeAction->setEnabled(hasCurrentViewer); - m_syncAction->setEnabled(hasCurrentViewer); - m_printPreviewAction->setEnabled(hasCurrentViewer); - m_printAction->setEnabled(hasCurrentViewer); m_nextAction->setEnabled(m_centralWidget->isForwardAvailable()); m_backAction->setEnabled(m_centralWidget->isBackwardAvailable()); - m_newTabAction->setEnabled(hasCurrentViewer); } void MainWindow::updateTabCloseAction() @@ -891,15 +894,13 @@ void MainWindow::setBookmarksVisible(bool visible) void MainWindow::showBookmarksDockWidget() { TRACE_OBJ - if (m_bookmarkWidget) - activateDockWidget(m_bookmarkWidget); + activateDockWidget(m_bookmarkWidget); } void MainWindow::hideBookmarksDockWidget() { TRACE_OBJ - if (m_bookmarkWidget) - m_bookmarkWidget->parentWidget()->hide(); + m_bookmarkWidget->parentWidget()->hide(); } void MainWindow::setSearchVisible(bool visible) @@ -914,13 +915,13 @@ void MainWindow::setSearchVisible(bool visible) void MainWindow::showSearch() { TRACE_OBJ - m_centralWidget->activateSearchWidget(); + activateDockWidget(m_searchWindow); } void MainWindow::hideSearch() { TRACE_OBJ - m_centralWidget->removeSearchWidget(); + m_searchWindow->parentWidget()->hide(); } void MainWindow::activateDockWidget(QWidget *w) @@ -940,10 +941,7 @@ void MainWindow::setIndexString(const QString &str) void MainWindow::activateCurrentBrowser() { TRACE_OBJ - CentralWidget *cw = CentralWidget::instance(); - if (cw) { - cw->activateTab(true); - } + CentralWidget::instance()->activateTab(); } void MainWindow::activateCurrentCentralWidgetTab() @@ -952,12 +950,6 @@ void MainWindow::activateCurrentCentralWidgetTab() m_centralWidget->activateTab(); } -void MainWindow::showSearchWidget() -{ - TRACE_OBJ - m_centralWidget->activateSearchWidget(true); -} - void MainWindow::updateApplicationFont() { TRACE_OBJ diff --git a/tools/assistant/tools/assistant/mainwindow.h b/tools/assistant/tools/assistant/mainwindow.h index 40ca624..6ac148e 100644 --- a/tools/assistant/tools/assistant/mainwindow.h +++ b/tools/assistant/tools/assistant/mainwindow.h @@ -53,13 +53,14 @@ class QLineEdit; class QComboBox; class QMenu; -class IndexWindow; -class QHelpEngineCore; -class QHelpEngine; class CentralWidget; -class ContentWindow; class CmdLineParser; +class ContentWindow; +class IndexWindow; class QtDocInstaller; +class QHelpEngineCore; +class QHelpEngine; +class SearchWidget; class MainWindow : public QMainWindow { @@ -87,7 +88,6 @@ public slots: void setIndexVisible(bool visible); void setBookmarksVisible(bool visible); void setSearchVisible(bool visible); - void showSearchWidget(); void syncContents(); void activateCurrentCentralWidgetTab(); void currentFilterChanged(const QString &filter); @@ -144,6 +144,7 @@ private: CentralWidget *m_centralWidget; IndexWindow *m_indexWindow; ContentWindow *m_contentWindow; + SearchWidget *m_searchWindow; QLineEdit *m_addressLineEdit; QComboBox *m_filterCombo; -- cgit v0.12 From bd9adf630d8f95cfb2cb18731ee581de4efda167 Mon Sep 17 00:00:00 2001 From: ck Date: Tue, 6 Apr 2010 12:47:49 +0200 Subject: Assistant: Get rid of tabs. A QTabWidget is not the right widget if there are more than a handful of pages. Therefore, we now manage pages in a special widget. Reviewed-by: kh1 --- tools/assistant/tools/assistant/assistant.pro | 12 +- .../assistant/tools/assistant/assistant_images.qrc | 6 +- tools/assistant/tools/assistant/centralwidget.cpp | 456 +++------------------ tools/assistant/tools/assistant/centralwidget.h | 43 +- tools/assistant/tools/assistant/contentwindow.cpp | 5 +- tools/assistant/tools/assistant/globalactions.cpp | 163 ++++++++ tools/assistant/tools/assistant/globalactions.h | 91 ++++ tools/assistant/tools/assistant/helpviewer_qtb.cpp | 15 +- tools/assistant/tools/assistant/helpviewer_qtb.h | 7 +- tools/assistant/tools/assistant/helpviewer_qwv.cpp | 35 +- tools/assistant/tools/assistant/helpviewer_qwv.h | 5 +- .../tools/assistant/images/closebutton.png | Bin 0 -> 288 bytes .../tools/assistant/images/darkclosebutton.png | Bin 0 -> 319 bytes tools/assistant/tools/assistant/indexwindow.cpp | 3 +- tools/assistant/tools/assistant/mainwindow.cpp | 234 ++++------- tools/assistant/tools/assistant/mainwindow.h | 16 +- .../assistant/tools/assistant/openpagesmanager.cpp | 308 ++++++++++++++ tools/assistant/tools/assistant/openpagesmanager.h | 104 +++++ tools/assistant/tools/assistant/openpagesmodel.cpp | 120 ++++++ tools/assistant/tools/assistant/openpagesmodel.h | 76 ++++ .../assistant/tools/assistant/openpageswidget.cpp | 181 ++++++++ tools/assistant/tools/assistant/openpageswidget.h | 76 ++++ .../tools/assistant/preferencesdialog.cpp | 15 +- .../assistant/tools/assistant/preferencesdialog.h | 1 - tools/assistant/tools/assistant/remotecontrol.cpp | 10 +- 25 files changed, 1336 insertions(+), 646 deletions(-) create mode 100644 tools/assistant/tools/assistant/globalactions.cpp create mode 100644 tools/assistant/tools/assistant/globalactions.h create mode 100644 tools/assistant/tools/assistant/images/closebutton.png create mode 100644 tools/assistant/tools/assistant/images/darkclosebutton.png create mode 100644 tools/assistant/tools/assistant/openpagesmanager.cpp create mode 100644 tools/assistant/tools/assistant/openpagesmanager.h create mode 100644 tools/assistant/tools/assistant/openpagesmodel.cpp create mode 100644 tools/assistant/tools/assistant/openpagesmodel.h create mode 100644 tools/assistant/tools/assistant/openpageswidget.cpp create mode 100644 tools/assistant/tools/assistant/openpageswidget.h diff --git a/tools/assistant/tools/assistant/assistant.pro b/tools/assistant/tools/assistant/assistant.pro index ff0ecc5..78f48c1 100644 --- a/tools/assistant/tools/assistant/assistant.pro +++ b/tools/assistant/tools/assistant/assistant.pro @@ -12,6 +12,8 @@ DESTDIR = ../../../../bin target.path = $$[QT_INSTALL_BINS] INSTALLS += target DEPENDPATH += ../shared +DEPENDPATH += . +INCLUDEPATH += . # ## Work around a qmake issue when statically linking to # ## not-yet-installed plugins @@ -42,7 +44,11 @@ HEADERS += aboutdialog.h \ topicchooser.h \ tracer.h \ xbelsupport.h \ - ../shared/collectionconfiguration.h + ../shared/collectionconfiguration.h \ + openpagesmodel.h \ + globalactions.h \ + openpageswidget.h \ + openpagesmanager.h win32:HEADERS += remotecontrol_win.h SOURCES += aboutdialog.cpp \ @@ -72,6 +78,10 @@ SOURCES += aboutdialog.cpp \ topicchooser.cpp \ xbelsupport.cpp \ ../shared/collectionconfiguration.cpp \ + openpagesmodel.cpp \ + globalactions.cpp \ + openpageswidget.cpp \ + openpagesmanager.cpp FORMS += bookmarkdialog.ui \ bookmarkmanagerwidget.ui \ diff --git a/tools/assistant/tools/assistant/assistant_images.qrc b/tools/assistant/tools/assistant/assistant_images.qrc index 34918c0..b4f2523 100644 --- a/tools/assistant/tools/assistant/assistant_images.qrc +++ b/tools/assistant/tools/assistant/assistant_images.qrc @@ -1,11 +1,10 @@ - + images/trolltech-logo.png images/assistant-128.png images/assistant.png images/wrap.png images/bookmark.png -#mac images/mac/addtab.png images/mac/book.png images/mac/closetab.png @@ -19,7 +18,6 @@ images/mac/zoomin.png images/mac/zoomout.png images/mac/resetzoom.png -#win images/win/addtab.png images/win/book.png images/win/closetab.png @@ -33,5 +31,7 @@ images/win/zoomin.png images/win/zoomout.png images/win/resetzoom.png + images/closebutton.png + images/darkclosebutton.png diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp index e562198..c5a46af 100644 --- a/tools/assistant/tools/assistant/centralwidget.cpp +++ b/tools/assistant/tools/assistant/centralwidget.cpp @@ -38,97 +38,49 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "tracer.h" #include "centralwidget.h" + #include "findwidget.h" #include "helpenginewrapper.h" #include "helpviewer_qtb.h" #include "helpviewer_qwv.h" -#include "searchwidget.h" -#include "mainwindow.h" +#include "tracer.h" #include "../shared/collectionconfiguration.h" #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include #include #include +#include +#include +#include +#include #include QT_BEGIN_NAMESPACE namespace { - HelpViewer* helpViewerFromTabPosition(const QTabWidget *widget, - const QPoint &point) - { - TRACE_OBJ - QTabBar *tabBar = qFindChild(widget); - for (int i = 0; i < tabBar->count(); ++i) { - if (tabBar->tabRect(i).contains(point)) - return qobject_cast(widget->widget(i)); - } - return 0; - } CentralWidget *staticCentralWidget = 0; } // -- CentralWidget -CentralWidget::CentralWidget(MainWindow *parent) +CentralWidget::CentralWidget(QWidget *parent) : QWidget(parent) - , lastTabPage(0) - , tabWidget(0) , findWidget(0) , printer(0) - , usesDefaultCollection(parent->usesDefaultCollection()) { TRACE_OBJ - globalActionList.clear(); staticCentralWidget = this; QVBoxLayout *vboxLayout = new QVBoxLayout(this); - QString resourcePath = QLatin1String(":/trolltech/assistant/images/"); vboxLayout->setMargin(0); - tabWidget = new QTabWidget(this); -#ifndef Q_OS_MAC - resourcePath.append(QLatin1String("win")); -#else - resourcePath.append(QLatin1String("mac")); - tabWidget->setDocumentMode(true); -#endif - - connect(tabWidget, SIGNAL(currentChanged(int)), this, - SLOT(currentPageChanged(int))); - - QToolButton *newTabButton = new QToolButton(this); - newTabButton->setAutoRaise(true); - newTabButton->setToolTip(tr("Add new page")); - newTabButton->setIcon(QIcon(resourcePath + QLatin1String("/addtab.png"))); - - tabWidget->setCornerWidget(newTabButton, Qt::TopLeftCorner); - connect(newTabButton, SIGNAL(clicked()), this, SLOT(newTab())); - - QToolButton *closeTabButton = new QToolButton(this); - closeTabButton->setEnabled(false); - closeTabButton->setAutoRaise(true); - closeTabButton->setToolTip(tr("Close current page")); - closeTabButton->setIcon(QIcon(resourcePath + QLatin1String("/closetab.png"))); - - tabWidget->setCornerWidget(closeTabButton, Qt::TopRightCorner); - connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeTab())); - - vboxLayout->addWidget(tabWidget); + m_stackedWidget = new QStackedWidget(this); + vboxLayout->addWidget(m_stackedWidget); findWidget = new FindWidget(this); vboxLayout->addWidget(findWidget); @@ -140,14 +92,6 @@ CentralWidget::CentralWidget(MainWindow *parent) SLOT(find(QString, bool))); connect(findWidget, SIGNAL(escapePressed()), this, SLOT(activateTab())); - QTabBar *tabBar = qFindChild(tabWidget); - if (tabBar) { - tabBar->installEventFilter(this); - tabBar->setContextMenuPolicy(Qt::CustomContextMenu); - connect(tabBar, SIGNAL(customContextMenuRequested(QPoint)), this, - SLOT(showTabBarContextMenu(QPoint))); - } - #if defined(QT_NO_WEBKIT) QPalette p = palette(); p.setColor(QPalette::Inactive, QPalette::Highlight, @@ -167,18 +111,19 @@ CentralWidget::~CentralWidget() QStringList zoomFactors; QStringList currentPages; - for (int i = 0; i < tabWidget->count(); ++i) { - HelpViewer *viewer = qobject_cast(tabWidget->widget(i)); - if (viewer && viewer->source().isValid()) { - currentPages << viewer->source().toString(); + for (int i = 0; i < m_stackedWidget->count(); ++i) { + const HelpViewer * const viewer = viewerAt(i); + const QUrl &source = viewer->source(); + if (source.isValid()) { + currentPages << source.toString(); zoomFactors << QString::number(viewer->scale()); } } HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); - helpEngine.setLastTabPage(tabWidget->currentIndex()); helpEngine.setLastShownPages(currentPages); helpEngine.setLastZoomFactors(zoomFactors); + helpEngine.setLastTabPage(m_stackedWidget->currentIndex()); } CentralWidget *CentralWidget::instance() @@ -187,16 +132,6 @@ CentralWidget *CentralWidget::instance() return staticCentralWidget; } -void CentralWidget::newTab() -{ - TRACE_OBJ - HelpViewer *viewer = currentHelpViewer(); -#if !defined(QT_NO_WEBKIT) - if (viewer->hasLoadFinished()) -#endif - setSourceInNewTab(viewer->source()); -} - void CentralWidget::zoomIn() { TRACE_OBJ @@ -209,110 +144,18 @@ void CentralWidget::zoomOut() currentHelpViewer()->scaleDown(); } -void CentralWidget::nextPage() -{ - TRACE_OBJ - int index = tabWidget->currentIndex() + 1; - if (index >= tabWidget->count()) - index = 0; - tabWidget->setCurrentIndex(index); -} - void CentralWidget::resetZoom() { TRACE_OBJ currentHelpViewer()->resetScale(); } -void CentralWidget::previousPage() -{ - TRACE_OBJ - int index = tabWidget->currentIndex() -1; - if (index < 0) - index = tabWidget->count() -1; - tabWidget->setCurrentIndex(index); -} - -void CentralWidget::closeTab() -{ - TRACE_OBJ - if (tabWidget->count() == 1) - return; - - HelpViewer *viewer = currentHelpViewer(); - tabWidget->removeTab(tabWidget->indexOf(viewer)); - QTimer::singleShot(0, viewer, SLOT(deleteLater())); -} - void CentralWidget::setSource(const QUrl &url) { TRACE_OBJ HelpViewer *viewer = currentHelpViewer(); - HelpViewer *lastViewer = - qobject_cast(tabWidget->widget(lastTabPage)); - - if (!viewer && !lastViewer) { - viewer = new HelpViewer(this); - viewer->installEventFilter(this); - lastTabPage = tabWidget->addTab(viewer, QString()); - tabWidget->setCurrentIndex(lastTabPage); - connectSignals(); - } else { - viewer = lastViewer; - } - viewer->setSource(url); - currentPageChanged(lastTabPage); viewer->setFocus(Qt::OtherFocusReason); - tabWidget->setCurrentIndex(lastTabPage); - tabWidget->setTabText(lastTabPage, quoteTabTitle(viewer->documentTitle())); -} - -void CentralWidget::setupWidget() -{ - TRACE_OBJ - HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); - int option = helpEngine.startOption(); - if (option != ShowLastPages) { - QString homePage; - if (option == ShowHomePage) - homePage = helpEngine.homePage(); - else if (option == ShowBlankPage) - homePage = QLatin1String("about:blank"); - setSource(homePage); - } else { - setLastShownPages(); - } -} - -void CentralWidget::setLastShownPages() -{ - TRACE_OBJ - HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); - const QStringList &lastShownPageList = helpEngine.lastShownPages(); - const int pageCount = lastShownPageList.count(); - if (pageCount == 0) { - if (usesDefaultCollection) - setSource(QUrl(QLatin1String("help"))); - else - setSource(QUrl(QLatin1String("about:blank"))); - return; - } - QStringList zoomFactors = helpEngine.lastZoomFactors(); - while (zoomFactors.count() < pageCount) - zoomFactors.append(CollectionConfiguration::DefaultZoomFactor); - - int tabToShow = helpEngine.lastTabPage(); - for (int curTab = 0; curTab < pageCount; ++curTab) { - const QString &curFile = lastShownPageList.at(curTab); - if (helpEngine.findFile(curFile).isValid() - || curFile == QLatin1String("about:blank")) { - setSourceInNewTab(curFile, zoomFactors.at(curTab).toFloat()); - } else if (curTab <= tabToShow) - --tabToShow; - } - - tabWidget->setCurrentIndex(tabToShow); } bool CentralWidget::hasSelection() const @@ -434,78 +277,30 @@ void CentralWidget::backward() currentHelpViewer()->backward(); } - -QList CentralWidget::globalActions() const +void CentralWidget::connectSignals(HelpViewer *page) { TRACE_OBJ - return globalActionList; -} - -void CentralWidget::setGlobalActions(const QList &actions) -{ - TRACE_OBJ - globalActionList = actions; -} - -void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom) -{ - TRACE_OBJ - - if (AbstractHelpViewer::launchWithExternalApp(url)) - return; - - HelpViewer *viewer = new HelpViewer(this, zoom); - viewer->installEventFilter(this); - viewer->setSource(url); - viewer->setFocus(Qt::OtherFocusReason); - tabWidget->setCurrentIndex(tabWidget->addTab(viewer, - quoteTabTitle(viewer->documentTitle()))); - connectSignals(); -} - -HelpViewer *CentralWidget::newEmptyTab() -{ - TRACE_OBJ - HelpViewer *viewer = new HelpViewer(this); - viewer->installEventFilter(this); - viewer->setFocus(Qt::OtherFocusReason); -#if defined(QT_NO_WEBKIT) - viewer->setDocumentTitle(tr("unknown")); -#endif - tabWidget->setCurrentIndex(tabWidget->addTab(viewer, tr("unknown"))); - - connectSignals(); - return viewer; -} - -void CentralWidget::connectSignals() -{ - TRACE_OBJ - const HelpViewer *viewer = currentHelpViewer(); - connect(viewer, SIGNAL(copyAvailable(bool)), this, - SIGNAL(copyAvailable(bool))); - connect(viewer, SIGNAL(forwardAvailable(bool)), this, - SIGNAL(forwardAvailable(bool))); - connect(viewer, SIGNAL(backwardAvailable(bool)), this, - SIGNAL(backwardAvailable(bool))); - connect(viewer, SIGNAL(sourceChanged(QUrl)), this, - SIGNAL(sourceChanged(QUrl))); - connect(viewer, SIGNAL(highlighted(QString)), this, + connect(page, SIGNAL(copyAvailable(bool)), this, SIGNAL(copyAvailable(bool))); + connect(page, SIGNAL(forwardAvailable(bool)), this, + SIGNAL(forwardAvailable(bool))); + connect(page, SIGNAL(backwardAvailable(bool)), this, + SIGNAL(backwardAvailable(bool))); + connect(page, SIGNAL(sourceChanged(QUrl)), this, + SLOT(handleSourceChanged(QUrl))); + connect(page, SIGNAL(highlighted(QString)), this, SIGNAL(highlighted(QString))); - connect(viewer, SIGNAL(sourceChanged(QUrl)), this, - SLOT(setTabTitle(QUrl))); } HelpViewer* CentralWidget::viewerAt(int index) const { TRACE_OBJ - return qobject_cast(tabWidget->widget(index)); + return static_cast(m_stackedWidget->widget(index)); } HelpViewer* CentralWidget::currentHelpViewer() const { TRACE_OBJ - return qobject_cast(tabWidget->currentWidget()); + return static_cast(m_stackedWidget->currentWidget()); } void CentralWidget::activateTab() @@ -514,90 +309,6 @@ void CentralWidget::activateTab() currentHelpViewer()->setFocus(); } -void CentralWidget::setTabTitle(const QUrl &url) -{ - TRACE_OBJ - Q_UNUSED(url) -#if !defined(QT_NO_WEBKIT) - QTabBar *tabBar = qFindChild(tabWidget); - for (int tab = 0; tab < tabBar->count(); ++tab) { - HelpViewer *viewer = qobject_cast(tabWidget->widget(tab)); - if (viewer) { - tabWidget->setTabText(tab, - quoteTabTitle(viewer->documentTitle().trimmed())); - } - } -#else - HelpViewer *viewer = currentHelpViewer(); - tabWidget->setTabText(lastTabPage, - quoteTabTitle(viewer->documentTitle().trimmed())); -#endif -} - -void CentralWidget::currentPageChanged(int index) -{ - TRACE_OBJ - lastTabPage = index; - - QWidget *closeButton = tabWidget->cornerWidget(Qt::TopRightCorner); - closeButton->setEnabled(enableTabCloseAction()); - - emit currentViewerChanged(); -} - -void CentralWidget::showTabBarContextMenu(const QPoint &point) -{ - TRACE_OBJ - HelpViewer *viewer = helpViewerFromTabPosition(tabWidget, point); - if (!viewer) - return; - - QTabBar *tabBar = qFindChild(tabWidget); - - QMenu menu(QLatin1String(""), tabBar); - QAction *newPage = menu.addAction(tr("Add New Page")); - - bool enableAction = enableTabCloseAction(); - QAction *closePage = menu.addAction(tr("Close This Page")); - closePage->setEnabled(enableAction); - - QAction *closePages = menu.addAction(tr("Close Other Pages")); - closePages->setEnabled(enableAction); - - menu.addSeparator(); - - QAction *newBookmark = menu.addAction(tr("Add Bookmark for this Page...")); - const QString &url = viewer->source().toString(); - if (url.isEmpty() || url == QLatin1String("about:blank")) - newBookmark->setEnabled(false); - - QAction *pickedAction = menu.exec(tabBar->mapToGlobal(point)); - if (pickedAction == newPage) - setSourceInNewTab(viewer->source()); - - if (pickedAction == closePage) { - tabWidget->removeTab(tabWidget->indexOf(viewer)); - QTimer::singleShot(0, viewer, SLOT(deleteLater())); - } - - if (pickedAction == closePages) { - int currentPage = tabWidget->indexOf(viewer); - for (int i = tabBar->count() -1; i >= 0; --i) { - viewer = qobject_cast(tabWidget->widget(i)); - if (i != currentPage && viewer) { - tabWidget->removeTab(i); - QTimer::singleShot(0, viewer, SLOT(deleteLater())); - - if (i < currentPage) - --currentPage; - } - } - } - - if (pickedAction == newBookmark) - emit addBookmark(viewer->documentTitle(), viewer->source().toString()); -} - bool CentralWidget::eventFilter(QObject *object, QEvent *e) { TRACE_OBJ @@ -624,25 +335,6 @@ bool CentralWidget::eventFilter(QObject *object, QEvent *e) } } - if (qobject_cast(object)) { - const bool dblClick = e->type() == QEvent::MouseButtonDblClick; - if ((e->type() == QEvent::MouseButtonRelease) || dblClick) { - QMouseEvent *mouseEvent = static_cast(e); - HelpViewer *viewer = helpViewerFromTabPosition(tabWidget, - mouseEvent->pos()); - if (viewer) { - if ((mouseEvent->button() == Qt::MidButton) || dblClick) { - if (availableHelpViewer() > 1) { - tabWidget->removeTab(tabWidget->indexOf(viewer)); - QTimer::singleShot(0, viewer, SLOT(deleteLater())); - currentPageChanged(tabWidget->currentIndex()); - return true; - } - } - } - } - } - return QWidget::eventFilter(object, e); } @@ -782,31 +474,12 @@ bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward) void CentralWidget::updateBrowserFont() { TRACE_OBJ - const int count = tabWidget->count(); + const int count = m_stackedWidget->count(); const QFont &font = viewerAt(count - 1)->viewerFont(); for (int i = 0; i < count; ++i) viewerAt(i)->setViewerFont(font); } -int CentralWidget::availableHelpViewer() const -{ - TRACE_OBJ - return tabWidget->count(); -} - -bool CentralWidget::enableTabCloseAction() const -{ - TRACE_OBJ - return tabWidget->count() > 1; -} - -QString CentralWidget::quoteTabTitle(const QString &title) const -{ - TRACE_OBJ - QString s = title; - return s.replace(QLatin1Char('&'), QLatin1String("&&")); -} - void CentralWidget::setSourceFromSearch(const QUrl &url) { @@ -821,19 +494,6 @@ CentralWidget::setSourceFromSearch(const QUrl &url) } void -CentralWidget::setSourceFromSearchInNewTab(const QUrl &url) -{ - TRACE_OBJ - setSourceInNewTab(url); -#if defined(QT_NO_WEBKIT) - highlightSearchTerms(); -#else - connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this, - SLOT(highlightSearchTerms())); -#endif -} - -void CentralWidget::highlightSearchTerms() { TRACE_OBJ @@ -900,48 +560,48 @@ CentralWidget::highlightSearchTerms() #endif } - -void CentralWidget::closeOrReloadTabs(const QList &indices, bool tryReload) +void CentralWidget::addPage(HelpViewer *page, bool fromSearch) { TRACE_OBJ - QList sortedIndices = indices; - qSort(sortedIndices); - for (int i = sortedIndices.count(); --i >= 0;) { - const int tab = sortedIndices.at(i); - bool close = true; - if (tryReload) { - HelpViewer *viewer = - qobject_cast(tabWidget->widget(tab)); - if (HelpEngineWrapper::instance().findFile(viewer->source()).isValid()) { - viewer->reload(); - close = false; - } - } - if (close) - closeTabAt(tab); + page->installEventFilter(this); + page->setFocus(Qt::OtherFocusReason); + connectSignals(page); + m_stackedWidget->addWidget(page); + if (fromSearch) { +#if defined(QT_NO_WEBKIT) + highlightSearchTerms(); +#else + connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); +#endif } - if (availableHelpViewer() == 0) - setSource(QUrl(QLatin1String("about:blank"))); } -void CentralWidget::closeTabAt(int index) +void CentralWidget::removePage(int index) { TRACE_OBJ - HelpViewer *viewer = qobject_cast(tabWidget->widget(index)); - tabWidget->removeTab(index); - QTimer::singleShot(0, viewer, SLOT(deleteLater())); + const bool currentChanged = index == currentIndex(); + m_stackedWidget->removeWidget(m_stackedWidget->widget(index)); + if (currentChanged) + emit currentViewerChanged(); } -QMap CentralWidget::currentSourceFileList() const +void CentralWidget::setCurrentPage(HelpViewer *page) { TRACE_OBJ - QMap sourceList; - for (int i = 0; i < tabWidget->count(); ++i) { - HelpViewer *viewer = qobject_cast(tabWidget->widget(i)); - if (viewer && viewer->source().isValid()) - sourceList.insert(i, viewer->source().host()); - } - return sourceList; + m_stackedWidget->setCurrentWidget(page); + emit currentViewerChanged(); +} + +int CentralWidget::currentIndex() const +{ + return m_stackedWidget->currentIndex(); +} + +void CentralWidget::handleSourceChanged(const QUrl &url) +{ + if (sender() == currentHelpViewer()) + emit sourceChanged(url); } QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/centralwidget.h b/tools/assistant/tools/assistant/centralwidget.h index 66d4142..9b8db30 100644 --- a/tools/assistant/tools/assistant/centralwidget.h +++ b/tools/assistant/tools/assistant/centralwidget.h @@ -48,45 +48,36 @@ QT_BEGIN_NAMESPACE class FindWidget; class HelpViewer; -class MainWindow; -class QHelpSearchEngine; -class QTabWidget; +class QStackedWidget; class CentralWidget : public QWidget { Q_OBJECT public: - CentralWidget(MainWindow *parent); + CentralWidget(QWidget *parent); ~CentralWidget(); - void setupWidget(); bool hasSelection() const; QUrl currentSource() const; QString currentTitle() const; bool isForwardAvailable() const; bool isBackwardAvailable() const; - QList globalActions() const; - void setGlobalActions(const QList &actions); HelpViewer *viewerAt(int index) const; HelpViewer *currentHelpViewer() const; - int availableHelpViewer() const; - bool enableTabCloseAction() const; - - void closeOrReloadTabs(const QList &indices, bool tryReload); - void closeTabAt(int index); - QMap currentSourceFileList() const; + void addPage(HelpViewer *page, bool fromSearch = false); + void removePage(int index); + void setCurrentPage(HelpViewer *page); + int currentIndex() const; static CentralWidget *instance(); public slots: void zoomIn(); void zoomOut(); - void nextPage(); void resetZoom(); - void previousPage(); void copySelection(); void showTextSearch(); void print(); @@ -94,8 +85,7 @@ public slots: void printPreview(); void updateBrowserFont(); void setSource(const QUrl &url); - void setSourceInNewTab(const QUrl &url, qreal zoom = 0.0); - HelpViewer *newEmptyTab(); + void setSourceFromSearch(const QUrl &url); void home(); void forward(); void backward(); @@ -106,9 +96,6 @@ public slots: void findPrevious(); void find(const QString &text, bool forward); - void setSourceFromSearch(const QUrl &url); - void setSourceFromSearchInNewTab(const QUrl &url); - signals: void currentViewerChanged(); void copyAvailable(bool yes); @@ -122,31 +109,21 @@ protected: void keyPressEvent(QKeyEvent *); private slots: - void newTab(); - void closeTab(); - void setTabTitle(const QUrl& url); - void currentPageChanged(int index); - void showTabBarContextMenu(const QPoint &point); void printPreview(QPrinter *printer); void highlightSearchTerms(); + void handleSourceChanged(const QUrl &url); private: - void connectSignals(); + void connectSignals(HelpViewer *page); bool eventFilter(QObject *object, QEvent *e); bool findInWebPage(const QString &ttf, bool forward); bool findInTextBrowser(const QString &ttf, bool forward); void initPrinter(); - QString quoteTabTitle(const QString &title) const; - void setLastShownPages(); private: - int lastTabPage; - QList globalActionList; - - QTabWidget *tabWidget; + QStackedWidget *m_stackedWidget; FindWidget *findWidget; QPrinter *printer; - bool usesDefaultCollection; }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/contentwindow.cpp b/tools/assistant/tools/assistant/contentwindow.cpp index e0347c8..3af4d34 100644 --- a/tools/assistant/tools/assistant/contentwindow.cpp +++ b/tools/assistant/tools/assistant/contentwindow.cpp @@ -44,6 +44,7 @@ #include "centralwidget.h" #include "helpenginewrapper.h" #include "helpviewer.h" +#include "openpagesmanager.h" #include #include @@ -145,7 +146,7 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e) if (contentModel) { QHelpContentItem *itm = contentModel->contentItemAt(index); if (itm && AbstractHelpViewer::canOpenPage(itm->url().path())) - CentralWidget::instance()->setSourceInNewTab(itm->url()); + OpenPagesManager::instance()->createPage(itm->url()); } } else if (button == Qt::LeftButton) { itemClicked(index); @@ -179,7 +180,7 @@ void ContentWindow::showContextMenu(const QPoint &pos) if (curTab == action) emit linkActivated(itm->url()); else if (newTab == action) - CentralWidget::instance()->setSourceInNewTab(itm->url()); + OpenPagesManager::instance()->createPage(itm->url()); } void ContentWindow::itemClicked(const QModelIndex &index) diff --git a/tools/assistant/tools/assistant/globalactions.cpp b/tools/assistant/tools/assistant/globalactions.cpp new file mode 100644 index 0000000..75c57b6 --- /dev/null +++ b/tools/assistant/tools/assistant/globalactions.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Assistant module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "globalactions.h" + +#include "centralwidget.h" +#include "tracer.h" + +#include + +GlobalActions *GlobalActions::instance(QObject *parent) +{ + Q_ASSERT(!m_instance != !parent); + if (!m_instance) + m_instance = new GlobalActions(parent); + return m_instance; +} + +GlobalActions::GlobalActions(QObject *parent) : QObject(parent) +{ + TRACE_OBJ + + // TODO: Put resource path in misc class + QString resourcePath = QLatin1String(":/trolltech/assistant/images/"); +#ifdef Q_OS_MAC + resourcePath.append(QLatin1String("mac")); +#else + resourcePath.append(QLatin1String("win")); +#endif + CentralWidget *centralWidget = CentralWidget::instance(); + + m_backAction = new QAction(tr("&Back"), parent); + m_backAction->setEnabled(false); + m_backAction->setShortcuts(QKeySequence::Back); + m_backAction->setIcon(QIcon(resourcePath + QLatin1String("/previous.png"))); + connect(m_backAction, SIGNAL(triggered()), centralWidget, SLOT(backward())); + m_actionList << m_backAction; + + m_nextAction = new QAction(tr("&Forward"), parent); + m_nextAction->setPriority(QAction::LowPriority); + m_nextAction->setEnabled(false); + m_nextAction->setShortcuts(QKeySequence::Forward); + m_nextAction->setIcon(QIcon(resourcePath + QLatin1String("/next.png"))); + connect(m_nextAction, SIGNAL(triggered()), centralWidget, SLOT(forward())); + m_actionList << m_nextAction; + + m_homeAction = new QAction(tr("&Home"), parent); + m_homeAction->setShortcut(tr("ALT+Home")); + m_homeAction->setIcon(QIcon(resourcePath + QLatin1String("/home.png"))); + connect(m_homeAction, SIGNAL(triggered()), centralWidget, SLOT(home())); + m_actionList << m_homeAction; + + QAction *separator = new QAction(parent); + separator->setSeparator(true); + m_actionList << separator; + + m_zoomInAction = new QAction(tr("Zoom &in"), parent); + m_zoomInAction->setPriority(QAction::LowPriority); + m_zoomInAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomin.png"))); + m_zoomInAction->setShortcut(QKeySequence::ZoomIn); + connect(m_zoomInAction, SIGNAL(triggered()), centralWidget, SLOT(zoomIn())); + m_actionList << m_zoomInAction; + + m_zoomOutAction = new QAction(tr("Zoom &out"), parent); + m_zoomOutAction->setPriority(QAction::LowPriority); + m_zoomOutAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomout.png"))); + m_zoomOutAction->setShortcut(QKeySequence::ZoomOut); + connect(m_zoomOutAction, SIGNAL(triggered()), centralWidget, SLOT(zoomOut())); + m_actionList << m_zoomOutAction; + + separator = new QAction(parent); + separator->setSeparator(true); + m_actionList << separator; + + m_copyAction = new QAction(tr("&Copy selected Text"), parent); + m_copyAction->setPriority(QAction::LowPriority); + m_copyAction->setIconText("&Copy"); + m_copyAction->setIcon(QIcon(resourcePath + QLatin1String("/editcopy.png"))); + m_copyAction->setShortcuts(QKeySequence::Copy); + m_copyAction->setEnabled(false); + connect(m_copyAction, SIGNAL(triggered()), centralWidget, SLOT(copySelection())); + m_actionList << m_copyAction; + + m_printAction = new QAction(tr("&Print..."), parent); + m_printAction->setPriority(QAction::LowPriority); + m_printAction->setIcon(QIcon(resourcePath + QLatin1String("/print.png"))); + m_printAction->setShortcut(QKeySequence::Print); + connect(m_printAction, SIGNAL(triggered()), centralWidget, SLOT(print())); + m_actionList << m_printAction; + + m_findAction = new QAction(tr("&Find in Text..."), parent); + m_findAction->setIconText(tr("&Find")); + m_findAction->setIcon(QIcon(resourcePath + QLatin1String("/find.png"))); + m_findAction->setShortcuts(QKeySequence::Find); + connect(m_findAction, SIGNAL(triggered()), centralWidget, SLOT(showTextSearch())); + m_actionList << m_findAction; + + #ifdef Q_WS_X11 + m_backAction->setIcon(QIcon::fromTheme("go-previous" , m_backAction->icon())); + m_nextAction->setIcon(QIcon::fromTheme("go-next" , m_nextAction->icon())); + m_zoomInAction->setIcon(QIcon::fromTheme("zoom-in" , m_zoomInAction->icon())); + m_zoomOutAction->setIcon(QIcon::fromTheme("zoom-out" , m_zoomOutAction->icon())); + m_copyAction->setIcon(QIcon::fromTheme("edit-copy" , m_copyAction->icon())); + m_findAction->setIcon(QIcon::fromTheme("edit-find" , m_findAction->icon())); + m_homeAction->setIcon(QIcon::fromTheme("go-home" , m_homeAction->icon())); + m_printAction->setIcon(QIcon::fromTheme("document-print" , m_printAction->icon())); +#endif +} + +void GlobalActions::updateActions() +{ + TRACE_OBJ + CentralWidget *centralWidget = CentralWidget::instance(); + m_copyAction->setEnabled(centralWidget->hasSelection()); + m_nextAction->setEnabled(centralWidget->isForwardAvailable()); + m_backAction->setEnabled(centralWidget->isBackwardAvailable()); +} + +void GlobalActions::setCopyAvailable(bool available) +{ + TRACE_OBJ + m_copyAction->setEnabled(available); +} + +GlobalActions *GlobalActions::m_instance = 0; diff --git a/tools/assistant/tools/assistant/globalactions.h b/tools/assistant/tools/assistant/globalactions.h new file mode 100644 index 0000000..e53e08f --- /dev/null +++ b/tools/assistant/tools/assistant/globalactions.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Assistant module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GLOBALACTION_H +#define GLOBALACTION_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QAction; + +class GlobalActions : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(GlobalActions) +public: + static GlobalActions *instance(QObject *parent = 0); + + QList actionList() const { return m_actionList; } + QAction *backAction() const { return m_backAction; } + QAction *nextAction() const { return m_nextAction; } + QAction *homeAction() const { return m_homeAction; } + QAction *zoomInAction() const { return m_zoomInAction; } + QAction *zoomOutAction() const { return m_zoomOutAction; } + QAction *copyAction() const { return m_copyAction; } + QAction *printAction() const { return m_printAction; } + QAction *findAction() const { return m_findAction; } + + Q_SLOT void updateActions(); + Q_SLOT void setCopyAvailable(bool available); + +private: + GlobalActions(QObject *parent); + + static GlobalActions *m_instance; + + QAction *m_backAction; + QAction *m_nextAction; + QAction *m_homeAction; + QAction *m_zoomInAction; + QAction *m_zoomOutAction; + QAction *m_copyAction; + QAction *m_printAction; + QAction *m_findAction; + + QList m_actionList; +}; + +QT_END_NAMESPACE + +#endif // GLOBALACTION_H diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.cpp b/tools/assistant/tools/assistant/helpviewer_qtb.cpp index bba2850..f6df611 100644 --- a/tools/assistant/tools/assistant/helpviewer_qtb.cpp +++ b/tools/assistant/tools/assistant/helpviewer_qtb.cpp @@ -42,8 +42,9 @@ #if defined(QT_NO_WEBKIT) -#include "centralwidget.h" +#include "globalactions.h" #include "helpenginewrapper.h" +#include "openpagesmanager.h" #include "tracer.h" #include @@ -55,12 +56,10 @@ QT_BEGIN_NAMESPACE -HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom) - : QTextBrowser(parent) - , zoomCount(zoom) +HelpViewer::HelpViewer(qreal zoom) + : zoomCount(zoom) , controlPressed(false) , lastAnchor(QString()) - , parentWidget(parent) , helpEngine(HelpEngineWrapper::instance()) , forceFont(false) { @@ -71,6 +70,7 @@ HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom) QFont font = viewerFont(); font.setPointSize(int(font.pointSize() + zoom)); setViewerFont(font); + connect(this, SIGNAL(sourceChanged(QUrl), this, SIGNAL(titleChanged())); } HelpViewer::~HelpViewer() @@ -176,7 +176,7 @@ void HelpViewer::openLinkInNewTab() if(lastAnchor.isEmpty()) return; - parentWidget->setSourceInNewTab(QUrl(lastAnchor)); + OpenPagesManager::instance()->createNewTab(QUrl(lastAnchor)); lastAnchor.clear(); } @@ -222,7 +222,8 @@ void HelpViewer::contextMenuEvent(QContextMenuEvent *e) SLOT(openLinkInNewTab())); menu.addSeparator(); } - menu.addActions(parentWidget->globalActions()); + + menu.addActions(GlobalActions::instance()->actionList()); QAction *action = menu.exec(e->globalPos()); if (action == copyAnchorAction) QApplication::clipboard()->setText(link.toString()); diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.h b/tools/assistant/tools/assistant/helpviewer_qtb.h index 5b38870..b6ab903 100644 --- a/tools/assistant/tools/assistant/helpviewer_qtb.h +++ b/tools/assistant/tools/assistant/helpviewer_qtb.h @@ -54,7 +54,6 @@ QT_BEGIN_NAMESPACE -class CentralWidget; class HelpEngineWrapper; class QContextMenuEvent; class QKeyEvent; @@ -65,7 +64,7 @@ class HelpViewer : public QTextBrowser, public AbstractHelpViewer Q_OBJECT public: - HelpViewer(CentralWidget *parent, qreal zoom = 0.0); + HelpViewer(qreal zoom = 0.0); ~HelpViewer(); QFont viewerFont() const; @@ -81,6 +80,9 @@ public: inline bool hasSelection() const { return textCursor().hasSelection(); } +signals: + void titleChanged(); + public Q_SLOTS: void home(); @@ -103,7 +105,6 @@ private: int zoomCount; bool controlPressed; QString lastAnchor; - CentralWidget* parentWidget; HelpEngineWrapper &helpEngine; bool forceFont; diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.cpp b/tools/assistant/tools/assistant/helpviewer_qwv.cpp index 9bb66e1..934fb03 100644 --- a/tools/assistant/tools/assistant/helpviewer_qwv.cpp +++ b/tools/assistant/tools/assistant/helpviewer_qwv.cpp @@ -45,6 +45,7 @@ #include "centralwidget.h" #include "helpenginewrapper.h" +#include "openpagesmanager.h" #include "tracer.h" #include @@ -156,7 +157,7 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, class HelpPage : public QWebPage { public: - HelpPage(CentralWidget *central, QObject *parent); + HelpPage(QObject *parent); protected: virtual QWebPage *createWindow(QWebPage::WebWindowType); @@ -166,7 +167,6 @@ protected: const QNetworkRequest &request, NavigationType type); private: - CentralWidget *centralWidget; bool closeNewTabIfNeeded; friend class HelpViewer; @@ -174,9 +174,8 @@ private: Qt::KeyboardModifiers m_keyboardModifiers; }; -HelpPage::HelpPage(CentralWidget *central, QObject *parent) +HelpPage::HelpPage(QObject *parent) : QWebPage(parent) - , centralWidget(central) , closeNewTabIfNeeded(false) , m_pressedButtons(Qt::NoButton) , m_keyboardModifiers(Qt::NoModifier) @@ -187,9 +186,8 @@ HelpPage::HelpPage(CentralWidget *central, QObject *parent) QWebPage *HelpPage::createWindow(QWebPage::WebWindowType) { TRACE_OBJ - HelpPage* newPage = static_cast(centralWidget->newEmptyTab()->page()); - if (newPage) - newPage->closeNewTabIfNeeded = closeNewTabIfNeeded; + HelpPage* newPage = static_cast(OpenPagesManager::instance()->createPage()->page()); + newPage->closeNewTabIfNeeded = closeNewTabIfNeeded; closeNewTabIfNeeded = false; return newPage; } @@ -216,18 +214,17 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *, const QUrl &url = request.url(); if (AbstractHelpViewer::launchWithExternalApp(url)) { if (closeNewTab) - QMetaObject::invokeMethod(centralWidget, "closeTab"); + QMetaObject::invokeMethod(OpenPagesManager::instance(), "closeCurrentTab"); return false; } if (type == QWebPage::NavigationTypeLinkClicked && (m_keyboardModifiers & Qt::ControlModifier || m_pressedButtons == Qt::MidButton)) { - if (HelpViewer* viewer = centralWidget->newEmptyTab()) - centralWidget->setSource(url); - m_pressedButtons = Qt::NoButton; - m_keyboardModifiers = Qt::NoModifier; - return false; + OpenPagesManager::instance()->createPage(url); + m_pressedButtons = Qt::NoButton; + m_keyboardModifiers = Qt::NoModifier; + return false; } return true; @@ -235,23 +232,18 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *, // -- HelpViewer -HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom) - : QWebView(parent) - , parentWidget(parent) - , loadFinished(false) +HelpViewer::HelpViewer(qreal zoom) + : loadFinished(false) , helpEngine(HelpEngineWrapper::instance()) { TRACE_OBJ setAcceptDrops(false); - setPage(new HelpPage(parent, this)); - + setPage(new HelpPage(this)); page()->setNetworkAccessManager(new HelpNetworkAccessManager(this)); QAction* action = pageAction(QWebPage::OpenLinkInNewWindow); action->setText(tr("Open Link in New Tab")); - if (!parent) - action->setVisible(false); pageAction(QWebPage::DownloadLinkToDisk)->setVisible(false); pageAction(QWebPage::DownloadImageToDisk)->setVisible(false); @@ -267,6 +259,7 @@ HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom) SIGNAL(highlighted(QString))); connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl))); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool))); + connect(this, SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged())); setFont(viewerFont()); setTextSizeMultiplier(zoom == 0.0 ? 1.0 : zoom); diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.h b/tools/assistant/tools/assistant/helpviewer_qwv.h index fbfbaac..ea5ec78 100644 --- a/tools/assistant/tools/assistant/helpviewer_qwv.h +++ b/tools/assistant/tools/assistant/helpviewer_qwv.h @@ -53,7 +53,6 @@ QT_BEGIN_NAMESPACE -class CentralWidget; class HelpEngineWrapper; class QMouseEvent; @@ -62,7 +61,7 @@ class HelpViewer : public QWebView, public AbstractHelpViewer Q_OBJECT public: - HelpViewer(CentralWidget *parent, qreal zoom = 0.0); + HelpViewer(qreal zoom = 0.0); ~HelpViewer(); QFont viewerFont() const; @@ -102,6 +101,7 @@ Q_SIGNALS: void backwardAvailable(bool enabled); void highlighted(const QString &); void sourceChanged(const QUrl &); + void titleChanged(); protected: virtual void wheelEvent(QWheelEvent *); @@ -113,7 +113,6 @@ private Q_SLOTS: void setLoadFinished(bool ok); private: - CentralWidget* parentWidget; bool loadFinished; HelpEngineWrapper &helpEngine; }; diff --git a/tools/assistant/tools/assistant/images/closebutton.png b/tools/assistant/tools/assistant/images/closebutton.png new file mode 100644 index 0000000..c978cf5 Binary files /dev/null and b/tools/assistant/tools/assistant/images/closebutton.png differ diff --git a/tools/assistant/tools/assistant/images/darkclosebutton.png b/tools/assistant/tools/assistant/images/darkclosebutton.png new file mode 100644 index 0000000..1077663 Binary files /dev/null and b/tools/assistant/tools/assistant/images/darkclosebutton.png differ diff --git a/tools/assistant/tools/assistant/indexwindow.cpp b/tools/assistant/tools/assistant/indexwindow.cpp index 63ddbe4..7a47e85 100644 --- a/tools/assistant/tools/assistant/indexwindow.cpp +++ b/tools/assistant/tools/assistant/indexwindow.cpp @@ -44,6 +44,7 @@ #include "centralwidget.h" #include "helpenginewrapper.h" #include "helpviewer.h" +#include "openpagesmanager.h" #include "topicchooser.h" #include @@ -222,7 +223,7 @@ void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index) if (!AbstractHelpViewer::canOpenPage(url.path())) CentralWidget::instance()->setSource(url); else - CentralWidget::instance()->setSourceInNewTab(url); + OpenPagesManager::instance()->createPage(url); } } diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp index 2605050..4c8a2dc 100644 --- a/tools/assistant/tools/assistant/mainwindow.cpp +++ b/tools/assistant/tools/assistant/mainwindow.cpp @@ -38,57 +38,55 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "tracer.h" #include "mainwindow.h" +#include "aboutdialog.h" #include "bookmarkmanager.h" #include "centralwidget.h" -#include "indexwindow.h" -#include "topicchooser.h" +#include "cmdlineparser.h" #include "contentwindow.h" -#include "preferencesdialog.h" +#include "globalactions.h" #include "helpenginewrapper.h" +#include "indexwindow.h" +#include "openpagesmanager.h" +#include "preferencesdialog.h" +#include "qtdocinstaller.h" #include "remotecontrol.h" -#include "cmdlineparser.h" -#include "aboutdialog.h" #include "searchwidget.h" -#include "qtdocinstaller.h" - -// #define TRACING_REQUESTED +#include "topicchooser.h" +#include "tracer.h" -#include -#include +#include #include #include -#include +#include #include #include -#include #include -#include +#include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include #include -#include #include -#include -#include +#include +#include #include -#include -#include #include -#include +#include +#include #include -#include -#include -#include #include +#include #include +#include QT_BEGIN_NAMESPACE @@ -105,6 +103,7 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) TRACE_OBJ setToolButtonStyle(Qt::ToolButtonFollowStyle); + setDockOptions(ForceTabbedDocks); // Has no effect; Qt bug? QString collectionFile; if (usesDefaultCollection()) { @@ -146,12 +145,19 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) = bookMarkManager->bookmarkDockWidget()); addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock); + QDockWidget *openPagesDock = new QDockWidget(tr("Open Pages"), this); + openPagesDock->setObjectName(QLatin1String("Open Pages")); + OpenPagesManager *openPagesManager + = OpenPagesManager::createInstance(this, usesDefaultCollection(), m_cmdLine->url()); + openPagesDock->setWidget(openPagesManager->openPagesWidget()); + addDockWidget(Qt::LeftDockWidgetArea, openPagesDock); + connect(bookMarkManager, SIGNAL(escapePressed()), this, SLOT(activateCurrentCentralWidgetTab())); connect(bookMarkManager, SIGNAL(setSource(QUrl)), m_centralWidget, SLOT(setSource(QUrl))); - connect(bookMarkManager, SIGNAL(setSourceInNewTab(QUrl)), m_centralWidget, - SLOT(setSourceInNewTab(QUrl))); + connect(bookMarkManager, SIGNAL(setSourceInNewTab(QUrl)), + openPagesManager, SLOT(createPage(QUrl))); connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)), bookMarkManager, SLOT(addBookmark(QString, QString))); @@ -195,9 +201,11 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) } else { tabifyDockWidget(contentDock, indexDock); tabifyDockWidget(indexDock, bookmarkDock); - tabifyDockWidget(bookmarkDock, searchDock); + tabifyDockWidget(bookmarkDock, openPagesDock); + tabifyDockWidget(openPagesDock, searchDock); contentDock->raise(); - resize(QSize(1024, 768)); + const QRect screen = QApplication::desktop()->screenGeometry(); + resize(4*screen.width()/5, 4*screen.height()/5); } if (!helpEngineWrapper.hasFontSettings()) { @@ -261,6 +269,8 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) this, SLOT(documentationUpdated(QString))); } setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North); + GlobalActions::instance()->updateActions(); + showNewAddress(); } MainWindow::~MainWindow() @@ -391,11 +401,6 @@ void MainWindow::checkInitState() void MainWindow::insertLastPages() { TRACE_OBJ - if (m_cmdLine->url().isValid()) - m_centralWidget->setSource(m_cmdLine->url()); - else - m_centralWidget->setupWidget(); - if (m_cmdLine->search() == CmdLineParser::Activate) showSearch(); } @@ -418,18 +423,16 @@ void MainWindow::setupActions() m_printPreviewAction = menu->addAction(tr("Print Preview..."), m_centralWidget, SLOT(printPreview())); - m_printAction = menu->addAction(tr("&Print..."), m_centralWidget, SLOT(print())); - m_printAction->setPriority(QAction::LowPriority); - m_printAction->setIcon(QIcon(resourcePath + QLatin1String("/print.png"))); - m_printAction->setShortcut(QKeySequence::Print); - + GlobalActions *globalActions = GlobalActions::instance(this); + menu->addAction(globalActions->printAction()); menu->addSeparator(); - m_newTabAction = menu->addAction(tr("New &Tab"), m_centralWidget, SLOT(newTab())); + OpenPagesManager * const openPages = OpenPagesManager::instance(); + m_newTabAction + = menu->addAction(tr("New &Tab"), openPages, SLOT(createPage())); m_newTabAction->setShortcut(QKeySequence::AddTab); - - m_closeTabAction = menu->addAction(tr("&Close Tab"), m_centralWidget, - SLOT(closeTab())); + m_closeTabAction = menu->addAction(tr("&Close Tab"), + openPages, SLOT(closeCurrentPage())); m_closeTabAction->setShortcuts(QKeySequence::Close); QAction *tmp = menu->addAction(tr("&Quit"), this, SLOT(close())); @@ -441,19 +444,8 @@ void MainWindow::setupActions() #endif menu = menuBar()->addMenu(tr("&Edit")); - m_copyAction = menu->addAction(tr("&Copy selected Text"), m_centralWidget, - SLOT(copySelection())); - m_copyAction->setPriority(QAction::LowPriority); - m_copyAction->setIconText("&Copy"); - m_copyAction->setIcon(QIcon(resourcePath + QLatin1String("/editcopy.png"))); - m_copyAction->setShortcuts(QKeySequence::Copy); - m_copyAction->setEnabled(false); - - m_findAction = menu->addAction(tr("&Find in Text..."), m_centralWidget, - SLOT(showTextSearch())); - m_findAction->setIconText(tr("&Find")); - m_findAction->setIcon(QIcon(resourcePath + QLatin1String("/find.png"))); - m_findAction->setShortcuts(QKeySequence::Find); + menu->addAction(globalActions->copyAction()); + menu->addAction(globalActions->findAction()); QAction *findNextAction = menu->addAction(tr("Find &Next"), m_centralWidget, SLOT(findNext())); @@ -468,17 +460,8 @@ void MainWindow::setupActions() tmp->setMenuRole(QAction::PreferencesRole); m_viewMenu = menuBar()->addMenu(tr("&View")); - m_zoomInAction = m_viewMenu->addAction(tr("Zoom &in"), m_centralWidget, - SLOT(zoomIn())); - m_zoomInAction->setPriority(QAction::LowPriority); - m_zoomInAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomin.png"))); - m_zoomInAction->setShortcut(QKeySequence::ZoomIn); - - m_zoomOutAction = m_viewMenu->addAction(tr("Zoom &out"), m_centralWidget, - SLOT(zoomOut())); - m_zoomOutAction->setPriority(QAction::LowPriority); - m_zoomOutAction->setIcon(QIcon(resourcePath + QLatin1String("/zoomout.png"))); - m_zoomOutAction->setShortcut(QKeySequence::ZoomOut); + m_viewMenu->addAction(globalActions->zoomInAction()); + m_viewMenu->addAction(globalActions->zoomOutAction()); m_resetZoomAction = m_viewMenu->addAction(tr("Normal &Size"), m_centralWidget, SLOT(resetZoom())); @@ -496,22 +479,13 @@ void MainWindow::setupActions() QKeySequence(tr("ALT+O"))); m_viewMenu->addAction(tr("Search"), this, SLOT(showSearch()), QKeySequence(tr("ALT+S"))); + m_viewMenu->addAction(tr("Open Pages"), this, SLOT(showOpenPages()), + QKeySequence(tr("ALT+P"))); menu = menuBar()->addMenu(tr("&Go")); - m_homeAction = menu->addAction(tr("&Home"), m_centralWidget, SLOT(home())); - m_homeAction->setShortcut(tr("ALT+Home")); - m_homeAction->setIcon(QIcon(resourcePath + QLatin1String("/home.png"))); - - m_backAction = menu->addAction(tr("&Back"), m_centralWidget, SLOT(backward())); - m_backAction->setEnabled(false); - m_backAction->setShortcuts(QKeySequence::Back); - m_backAction->setIcon(QIcon(resourcePath + QLatin1String("/previous.png"))); - - m_nextAction = menu->addAction(tr("&Forward"), m_centralWidget, SLOT(forward())); - m_nextAction->setPriority(QAction::LowPriority); - m_nextAction->setEnabled(false); - m_nextAction->setShortcuts(QKeySequence::Forward); - m_nextAction->setIcon(QIcon(resourcePath + QLatin1String("/next.png"))); + menu->addAction(globalActions->homeAction()); + menu->addAction(globalActions->backAction()); + menu->addAction(globalActions->nextAction()); m_syncAction = menu->addAction(tr("Sync with Table of Contents"), this, SLOT(syncContents())); @@ -520,11 +494,11 @@ void MainWindow::setupActions() menu->addSeparator(); - tmp = menu->addAction(tr("Next Page"), m_centralWidget, SLOT(nextPage())); + tmp = menu->addAction(tr("Next Page"), openPages, SLOT(nextPage())); tmp->setShortcuts(QList() << QKeySequence(tr("Ctrl+Alt+Right")) << QKeySequence(Qt::CTRL + Qt::Key_PageDown)); - tmp = menu->addAction(tr("Previous Page"), m_centralWidget, SLOT(previousPage())); + tmp = menu->addAction(tr("Previous Page"), openPages, SLOT(previousPage())); tmp->setShortcuts(QList() << QKeySequence(tr("Ctrl+Alt+Left")) << QKeySequence(Qt::CTRL + Qt::Key_PageUp)); @@ -535,39 +509,25 @@ void MainWindow::setupActions() m_aboutAction->setMenuRole(QAction::AboutRole); #ifdef Q_WS_X11 - m_backAction->setIcon(QIcon::fromTheme("go-previous" , m_backAction->icon())); - m_nextAction->setIcon(QIcon::fromTheme("go-next" , m_nextAction->icon())); - m_zoomInAction->setIcon(QIcon::fromTheme("zoom-in" , m_zoomInAction->icon())); - m_zoomOutAction->setIcon(QIcon::fromTheme("zoom-out" , m_zoomOutAction->icon())); m_resetZoomAction->setIcon(QIcon::fromTheme("zoom-original" , m_resetZoomAction->icon())); m_syncAction->setIcon(QIcon::fromTheme("view-refresh" , m_syncAction->icon())); - m_copyAction->setIcon(QIcon::fromTheme("edit-copy" , m_copyAction->icon())); - m_findAction->setIcon(QIcon::fromTheme("edit-find" , m_findAction->icon())); - m_homeAction->setIcon(QIcon::fromTheme("go-home" , m_homeAction->icon())); - m_printAction->setIcon(QIcon::fromTheme("document-print" , m_printAction->icon())); #endif QToolBar *navigationBar = addToolBar(tr("Navigation Toolbar")); navigationBar->setObjectName(QLatin1String("NavigationToolBar")); - navigationBar->addAction(m_backAction); - navigationBar->addAction(m_nextAction); - navigationBar->addAction(m_homeAction); + navigationBar->addAction(globalActions->backAction()); + navigationBar->addAction(globalActions->nextAction()); + navigationBar->addAction(globalActions->homeAction()); navigationBar->addAction(m_syncAction); - QAction *sep = navigationBar->addSeparator(); - navigationBar->addAction(m_copyAction); - navigationBar->addAction(m_printAction); - navigationBar->addAction(m_findAction); - QAction *sep2 = navigationBar->addSeparator(); - navigationBar->addAction(m_zoomInAction); - navigationBar->addAction(m_zoomOutAction); + navigationBar->addSeparator(); + navigationBar->addAction(globalActions->copyAction()); + navigationBar->addAction(globalActions->printAction()); + navigationBar->addAction(globalActions->findAction()); + navigationBar->addSeparator(); + navigationBar->addAction(globalActions->zoomInAction()); + navigationBar->addAction(globalActions->zoomOutAction()); navigationBar->addAction(m_resetZoomAction); - QList actionList; - actionList << m_backAction << m_nextAction << m_homeAction << sep - << m_zoomInAction << m_zoomOutAction << sep2 << m_copyAction - << m_printAction << m_findAction; - m_centralWidget->setGlobalActions(actionList); - #if defined(Q_WS_MAC) QMenu *windowMenu = new QMenu(tr("&Window"), this); menuBar()->insertMenu(menu->menuAction(), windowMenu); @@ -577,16 +537,14 @@ void MainWindow::setupActions() #endif // content viewer connections - connect(m_centralWidget, SIGNAL(copyAvailable(bool)), this, - SLOT(copyAvailable(bool))); - connect(m_centralWidget, SIGNAL(currentViewerChanged()), this, - SLOT(updateNavigationItems())); - connect(m_centralWidget, SIGNAL(currentViewerChanged()), this, - SLOT(updateTabCloseAction())); - connect(m_centralWidget, SIGNAL(forwardAvailable(bool)), this, - SLOT(updateNavigationItems())); - connect(m_centralWidget, SIGNAL(backwardAvailable(bool)), this, - SLOT(updateNavigationItems())); + connect(m_centralWidget, SIGNAL(copyAvailable(bool)), globalActions, + SLOT(setCopyAvailable(bool))); + connect(m_centralWidget, SIGNAL(currentViewerChanged()), globalActions, + SLOT(updateActions())); + connect(m_centralWidget, SIGNAL(forwardAvailable(bool)), globalActions, + SLOT(updateActions())); + connect(m_centralWidget, SIGNAL(backwardAvailable(bool)), globalActions, + SLOT(updateActions())); connect(m_centralWidget, SIGNAL(highlighted(QString)), statusBar(), SLOT(showMessage(QString))); @@ -605,10 +563,10 @@ void MainWindow::setupActions() SLOT(activateCurrentCentralWidgetTab())); // search window - connect(m_searchWindow, SIGNAL(requestShowLink(QUrl)), m_centralWidget, - SLOT(setSourceFromSearch(QUrl))); + connect(m_searchWindow, SIGNAL(requestShowLink(QUrl)), + CentralWidget::instance(), SLOT(setSourceFromSearch(QUrl))); connect(m_searchWindow, SIGNAL(requestShowLinkInNewTab(QUrl)), - m_centralWidget, SLOT(setSourceFromSearchInNewTab(QUrl))); + OpenPagesManager::instance(), SLOT(createNewPageFromSearch(QUrl))); #if defined(QT_NO_PRINTER) m_pageSetupAction->setVisible(false); @@ -733,20 +691,6 @@ void MainWindow::gotoAddress() m_centralWidget->setSource(m_addressLineEdit->text()); } -void MainWindow::updateNavigationItems() -{ - TRACE_OBJ - m_copyAction->setEnabled(m_centralWidget->hasSelection()); - m_nextAction->setEnabled(m_centralWidget->isForwardAvailable()); - m_backAction->setEnabled(m_centralWidget->isBackwardAvailable()); -} - -void MainWindow::updateTabCloseAction() -{ - TRACE_OBJ - m_closeTabAction->setEnabled(m_centralWidget->enableTabCloseAction()); -} - void MainWindow::showTopicChooser(const QMap &links, const QString &keyword) { @@ -780,12 +724,6 @@ void MainWindow::syncContents() qApp->restoreOverrideCursor(); } -void MainWindow::copyAvailable(bool yes) -{ - TRACE_OBJ - m_copyAction->setEnabled(yes); -} - void MainWindow::showAboutDialog() { TRACE_OBJ @@ -918,6 +856,12 @@ void MainWindow::showSearch() activateDockWidget(m_searchWindow); } +void MainWindow::showOpenPages() +{ + TRACE_OBJ + activateDockWidget(OpenPagesManager::instance()->openPagesWidget()); +} + void MainWindow::hideSearch() { TRACE_OBJ @@ -1071,17 +1015,13 @@ void MainWindow::currentFilterChanged(const QString &filter) void MainWindow::documentationRemoved(const QString &namespaceName) { TRACE_OBJ - CentralWidget* widget = CentralWidget::instance(); - widget->closeOrReloadTabs(widget->currentSourceFileList(). - keys(namespaceName), false); + OpenPagesManager::instance()->closePages(namespaceName); } void MainWindow::documentationUpdated(const QString &namespaceName) { TRACE_OBJ - CentralWidget* widget = CentralWidget::instance(); - widget->closeOrReloadTabs(widget->currentSourceFileList(). - keys(namespaceName), true); + OpenPagesManager::instance()->reloadPages(namespaceName); } void MainWindow::resetQtDocInfo(const QString &component) diff --git a/tools/assistant/tools/assistant/mainwindow.h b/tools/assistant/tools/assistant/mainwindow.h index 6ac148e..93cc1ac 100644 --- a/tools/assistant/tools/assistant/mainwindow.h +++ b/tools/assistant/tools/assistant/mainwindow.h @@ -42,21 +42,23 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include #include #include QT_BEGIN_NAMESPACE class QAction; +class QComboBox; class QFileSystemWatcher; class QLineEdit; -class QComboBox; class QMenu; class CentralWidget; class CmdLineParser; class ContentWindow; class IndexWindow; +class OpenPagesWindow; class QtDocInstaller; class QHelpEngineCore; class QHelpEngine; @@ -96,14 +98,12 @@ private slots: void showContents(); void showIndex(); void showSearch(); + void showOpenPages(); void insertLastPages(); void gotoAddress(); void showPreferences(); void showNewAddress(); void showAboutDialog(); - void copyAvailable(bool yes); - void updateNavigationItems(); - void updateTabCloseAction(); void showNewAddress(const QUrl &url); void showTopicChooser(const QMap &links, const QString &keyword); void updateApplicationFont(); @@ -148,17 +148,9 @@ private: QLineEdit *m_addressLineEdit; QComboBox *m_filterCombo; - QAction *m_backAction; - QAction *m_nextAction; - QAction *m_homeAction; QAction *m_syncAction; - QAction *m_copyAction; - QAction *m_findAction; - QAction *m_printAction; QAction *m_printPreviewAction; QAction *m_pageSetupAction; - QAction *m_zoomInAction; - QAction *m_zoomOutAction; QAction *m_resetZoomAction; QAction *m_aboutAction; QAction *m_closeTabAction; diff --git a/tools/assistant/tools/assistant/openpagesmanager.cpp b/tools/assistant/tools/assistant/openpagesmanager.cpp new file mode 100644 index 0000000..cd4460a --- /dev/null +++ b/tools/assistant/tools/assistant/openpagesmanager.cpp @@ -0,0 +1,308 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Assistant module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "openpagesmanager.h" + +#include "centralwidget.h" +#include "helpenginewrapper.h" +#include "helpviewer.h" +#include "helpviewer_qtb.h" +#include "helpviewer_qwv.h" +#include "openpagesmodel.h" +#include "openpageswidget.h" +#include "tracer.h" +#include "../shared/collectionconfiguration.h" + +#include + +QT_BEGIN_NAMESPACE + +OpenPagesManager *OpenPagesManager::createInstance(QObject *parent, + bool defaultCollection, const QUrl &cmdLineUrl) +{ + TRACE_OBJ + Q_ASSERT(!m_instance); + m_instance = new OpenPagesManager(parent, defaultCollection, cmdLineUrl); + return m_instance; +} + +OpenPagesManager *OpenPagesManager::instance() +{ + TRACE_OBJ + Q_ASSERT(m_instance); + return m_instance; +} + +OpenPagesManager::OpenPagesManager(QObject *parent, bool defaultCollection, + const QUrl &cmdLineUrl) + : QObject(parent), m_model(new OpenPagesModel(this)), + m_openPagesWidget(new OpenPagesWidget(m_model)) +{ + TRACE_OBJ + connect(m_openPagesWidget, SIGNAL(setCurrentPage(QModelIndex)), this, + SLOT(setCurrentPage(QModelIndex))); + connect(m_openPagesWidget, SIGNAL(closePage(QModelIndex)), this, + SLOT(closePage(QModelIndex))); + connect(m_openPagesWidget, SIGNAL(closePagesExcept(QModelIndex)), this, + SLOT(closePagesExcept(QModelIndex))); + setupInitialPages(defaultCollection, cmdLineUrl); +} + +int OpenPagesManager::pageCount() const +{ + TRACE_OBJ + return m_model->rowCount(); +} + +void OpenPagesManager::setupInitialPages(bool defaultCollection, + const QUrl &cmdLineUrl) +{ + TRACE_OBJ + if (cmdLineUrl.isValid()) { + createPage(cmdLineUrl); + return; + } + + HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); + int initialPage = 0; + switch (helpEngine.startOption()) { + case ShowHomePage: + m_model->addPage(helpEngine.homePage()); + break; + case ShowBlankPage: + m_model->addPage(QUrl(QLatin1String("about:blank"))); + break; + case ShowLastPages: { + const QStringList &lastShownPageList = helpEngine.lastShownPages(); + const int pageCount = lastShownPageList.count(); + if (pageCount == 0) { + if (defaultCollection) + m_model->addPage(QUrl(QLatin1String("help"))); + else + m_model->addPage(QUrl(QLatin1String("about:blank"))); + } else { + QStringList zoomFactors = helpEngine.lastZoomFactors(); + while (zoomFactors.count() < pageCount) + zoomFactors.append(CollectionConfiguration::DefaultZoomFactor); + initialPage = helpEngine.lastTabPage(); + if (initialPage >= pageCount) { + qWarning("Initial page set to %d, maximum possible value is %d", + initialPage, pageCount - 1); + initialPage = 0; + } + for (int curPage = 0; curPage < pageCount; ++curPage) { + const QString &curFile = lastShownPageList.at(curPage); + if (helpEngine.findFile(curFile).isValid() + || curFile == QLatin1String("about:blank")) { + m_model->addPage(curFile, zoomFactors.at(curPage).toFloat()); + } else if (curPage <= initialPage && initialPage > 0) + --initialPage; + } + } + break; + } + default: + Q_ASSERT(!"Unhandled option"); + } + + if (m_model->rowCount() == 0) + m_model->addPage(helpEngine.homePage()); + for (int i = 0; i < m_model->rowCount(); ++i) + CentralWidget::instance()->addPage(m_model->pageAt(i)); + setCurrentPage(initialPage); +} + +HelpViewer *OpenPagesManager::createPage() +{ + TRACE_OBJ + return createPage(QUrl(QLatin1String("about:blank"))); +} + +void OpenPagesManager::closeCurrentPage() +{ + TRACE_OBJ + Q_ASSERT(m_model->rowCount() > 1); + const QModelIndexList selectedIndexes + = m_openPagesWidget->selectionModel()->selectedRows(); + if (selectedIndexes.isEmpty()) + return; + Q_ASSERT(selectedIndexes.count() == 1); + removePage(selectedIndexes.first().row()); +} + +HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch) +{ + TRACE_OBJ + if (AbstractHelpViewer::launchWithExternalApp(url)) + return 0; + + m_model->addPage(url); + const int index = m_model->rowCount() - 1; + HelpViewer * const page = m_model->pageAt(index); + CentralWidget::instance()->addPage(page, fromSearch); + setCurrentPage(index); + return page; +} + +HelpViewer *OpenPagesManager::createNewPageFromSearch(const QUrl &url) +{ + return createPage(url, true); +} + +void OpenPagesManager::closePage(const QModelIndex &index) +{ + if (index.isValid()) + removePage(index.row()); +} + +void OpenPagesManager::closePages(const QString &nameSpace) +{ + TRACE_OBJ + closeOrReloadPages(nameSpace, false); +} + +void OpenPagesManager::reloadPages(const QString &nameSpace) +{ + TRACE_OBJ + closeOrReloadPages(nameSpace, true); + selectCurrentPage(); +} + +void OpenPagesManager::closeOrReloadPages(const QString &nameSpace, bool tryReload) +{ + TRACE_OBJ + + for (int i = m_model->rowCount() - 1; i >= 0; --i) { + HelpViewer *page = m_model->pageAt(i); + if (page->source().host() != nameSpace) + continue; + if (tryReload && HelpEngineWrapper::instance().findFile(page->source()).isValid()) + page->reload(); + else if (m_model->rowCount() == 1) + page->setSource(QUrl(QLatin1String("about:blank"))); + else + removePage(i); + } +} + +bool OpenPagesManager::pagesOpenForNamespace(const QString &nameSpace) const +{ + TRACE_OBJ + for (int i = 0; i < m_model->rowCount(); ++i) + if (m_model->pageAt(i)->source().host() == nameSpace) + return true; + return false; +} + +void OpenPagesManager::setCurrentPage(const QModelIndex &index) +{ + TRACE_OBJ + if (!index.isValid()) + return; + HelpViewer * const page = m_model->pageAt(index.row()); + CentralWidget::instance()->setCurrentPage(page); +} + +void OpenPagesManager::setCurrentPage(int index) +{ + TRACE_OBJ + CentralWidget::instance()->setCurrentPage(m_model->pageAt(index)); + selectCurrentPage(); +} + +void OpenPagesManager::selectCurrentPage() +{ + TRACE_OBJ + QItemSelectionModel * const selModel = m_openPagesWidget->selectionModel(); + selModel->clearSelection(); + selModel->select(m_model->index(CentralWidget::instance()->currentIndex(), 0), + QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + m_openPagesWidget->scrollTo(m_openPagesWidget->currentIndex()); +} + +void OpenPagesManager::removePage(int index) +{ + TRACE_OBJ + CentralWidget::instance()->removePage(index); + m_model->removePage(index); + selectCurrentPage(); +} + + +void OpenPagesManager::closePagesExcept(const QModelIndex &index) +{ + TRACE_OBJ + if (!index.isValid()) + return; + + int i = 0; + HelpViewer *viewer = m_model->pageAt(index.row()); + while (m_model->rowCount() > 1) { + if (m_model->pageAt(i) != viewer) + removePage(i); + else + ++i; + } +} + +QWidget *OpenPagesManager::openPagesWidget() const +{ + return m_openPagesWidget; +} + +void OpenPagesManager::nextPage() +{ + nextOrPreviousPage(1); +} + +void OpenPagesManager::previousPage() +{ + nextOrPreviousPage(-1); +} + +void OpenPagesManager::nextOrPreviousPage(int offset) +{ + setCurrentPage((CentralWidget::instance()->currentIndex() + offset + + m_model->rowCount()) % m_model->rowCount()); +} + +OpenPagesManager *OpenPagesManager::m_instance = 0; + +QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/openpagesmanager.h b/tools/assistant/tools/assistant/openpagesmanager.h new file mode 100644 index 0000000..95bf247 --- /dev/null +++ b/tools/assistant/tools/assistant/openpagesmanager.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Assistant module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef OPENPAGESMANAGER_H +#define OPENPAGESMANAGER_H + +#include + +QT_BEGIN_NAMESPACE + +class QModelIndex; +class QUrl; +class QWidget; + +class HelpViewer; +class OpenPagesModel; +class OpenPagesWidget; + +class OpenPagesManager : public QObject + { + Q_OBJECT + public: + static OpenPagesManager *createInstance(QObject *parent, + bool defaultCollection, const QUrl &cmdLineUrl); + static OpenPagesManager *instance(); + + bool pagesOpenForNamespace(const QString &nameSpace) const; + void closePages(const QString &nameSpace); + void reloadPages(const QString &nameSpace); + + QWidget* openPagesWidget() const; + + int pageCount() const; + + public slots: + HelpViewer *createPage(const QUrl &url, bool fromSearch = false); + HelpViewer *createNewPageFromSearch(const QUrl &url); + HelpViewer *createPage(); + void closeCurrentPage(); + void nextPage(); + void previousPage(); + +private slots: + void setCurrentPage(const QModelIndex &index); + void closePage(const QModelIndex &index); + void closePagesExcept(const QModelIndex &index); + +private: + OpenPagesManager(QObject *parent, bool defaultCollection, + const QUrl &cmdLineUrl); + void setupInitialPages(bool defaultCollection, const QUrl &cmdLineUrl); + void closeOrReloadPages(const QString &nameSpace, bool tryReload); + void setCurrentPage(int index); + void selectCurrentPage(); + void removePage(int index); + void nextOrPreviousPage(int offset); + + OpenPagesModel *m_model; + OpenPagesWidget *m_openPagesWidget; + + static OpenPagesManager *m_instance; + }; + +QT_END_NAMESPACE + +#endif // OPENPAGESMANAGER_H diff --git a/tools/assistant/tools/assistant/openpagesmodel.cpp b/tools/assistant/tools/assistant/openpagesmodel.cpp new file mode 100644 index 0000000..9e31b84 --- /dev/null +++ b/tools/assistant/tools/assistant/openpagesmodel.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Assistant module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "openpagesmodel.h" + +#include "helpenginewrapper.h" +#include "helpviewer_qtb.h" +#include "helpviewer_qwv.h" +#include "tracer.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +OpenPagesModel::OpenPagesModel(QObject *parent) : QAbstractTableModel(parent) +{ + TRACE_OBJ +} + +int OpenPagesModel::rowCount(const QModelIndex &parent) const +{ + TRACE_OBJ + return parent.isValid() ? 0 : m_pages.count(); +} + +int OpenPagesModel::columnCount(const QModelIndex &/*parent*/) const +{ + TRACE_OBJ + return 2; +} + +QVariant OpenPagesModel::data(const QModelIndex &index, int role) const +{ + TRACE_OBJ + if (!index.isValid() || index.row() >= rowCount() || index.column() > 0 + || role != Qt::DisplayRole) + return QVariant(); + QString title = m_pages.at(index.row())->documentTitle(); + title.replace(QLatin1Char('&'), QLatin1String("&&")); + return title.isEmpty() ? QLatin1String("(Untitled)") : title; +} + +void OpenPagesModel::addPage(const QUrl &url, qreal zoom) +{ + TRACE_OBJ + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + HelpViewer *page = new HelpViewer(zoom); + connect(page, SIGNAL(titleChanged()), this, SLOT(handleTitleChanged())); + m_pages << page; + endInsertRows(); + page->setSource(url); +} + +void OpenPagesModel::removePage(int index) +{ + TRACE_OBJ + Q_ASSERT(index >= 0 && index < rowCount()); + beginRemoveRows(QModelIndex(), index, index); + HelpViewer *page = m_pages.at(index); + m_pages.removeAt(index); + endRemoveRows(); + page->deleteLater(); +} + +HelpViewer *OpenPagesModel::pageAt(int index) const +{ + TRACE_OBJ + Q_ASSERT(index >= 0 && index < rowCount()); + return m_pages.at(index); +} + +void OpenPagesModel::handleTitleChanged() +{ + TRACE_OBJ + HelpViewer *page = static_cast(sender()); + const int row = m_pages.indexOf(page); + Q_ASSERT(row != -1 ); + const QModelIndex &item = index(row, 0); + emit dataChanged(item, item); +} + +QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/openpagesmodel.h b/tools/assistant/tools/assistant/openpagesmodel.h new file mode 100644 index 0000000..64013a6 --- /dev/null +++ b/tools/assistant/tools/assistant/openpagesmodel.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Assistant module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef OPENPAGESMODEL_H +#define OPENPAGESMODEL_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class HelpViewer; +class QUrl; + +class OpenPagesModel : public QAbstractTableModel +{ + Q_OBJECT +public: + OpenPagesModel(QObject *parent); + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + void addPage(const QUrl &url, qreal zoom = 0); + void removePage(int index); + HelpViewer *pageAt(int index) const; + +private slots: + void handleTitleChanged(); + +private: + QList m_pages; +}; + +QT_END_NAMESPACE + +#endif // OPENPAGESMODEL_H diff --git a/tools/assistant/tools/assistant/openpageswidget.cpp b/tools/assistant/tools/assistant/openpageswidget.cpp new file mode 100644 index 0000000..648ead8 --- /dev/null +++ b/tools/assistant/tools/assistant/openpageswidget.cpp @@ -0,0 +1,181 @@ +/************************************************************************** +** +** This file is part of the Assistant module of the Qt toolkit. +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "openpageswidget.h" + +#include "openpagesmodel.h" + +#include +#include +#include +#include +#include +#include + +#ifdef Q_WS_MAC +#include +#endif + +QT_BEGIN_NAMESPACE + +OpenPagesDelegate::OpenPagesDelegate(QObject *parent) + : QStyledItemDelegate(parent) +{ +} + +void OpenPagesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + if (option.state & QStyle::State_MouseOver) { + if ((QApplication::mouseButtons() & Qt::LeftButton) == 0) + pressedIndex = QModelIndex(); + QBrush brush = option.palette.alternateBase(); + if (index == pressedIndex) + brush = option.palette.dark(); + painter->fillRect(option.rect, brush); + } + + QStyledItemDelegate::paint(painter, option, index); + + if (index.column() == 1 && option.state & QStyle::State_MouseOver) { + QIcon icon((option.state & QStyle::State_Selected) + ? ":/trolltech/assistant/images/closebutton.png" + : ":/trolltech/assistant/images/darkclosebutton.png"); + + const QRect iconRect(option.rect.right() - option.rect.height(), + option.rect.top(), option.rect.height(), option.rect.height()); + icon.paint(painter, iconRect, Qt::AlignRight | Qt::AlignVCenter); + } +} + + +OpenPagesWidget::OpenPagesWidget(OpenPagesModel *model) +{ + setModel(model); + setIndentation(0); + setItemDelegate((m_delegate = new OpenPagesDelegate(this))); + + setFrameStyle(QFrame::NoFrame); + setTextElideMode(Qt::ElideMiddle); + setAttribute(Qt::WA_MacShowFocusRect, false); + + viewport()->setAttribute(Qt::WA_Hover); + setSelectionBehavior(QAbstractItemView::SelectRows); + setSelectionMode(QAbstractItemView::SingleSelection); + + header()->hide(); + header()->setStretchLastSection(false); + header()->setResizeMode(0, QHeaderView::Stretch); + header()->setResizeMode(1, QHeaderView::Fixed); + header()->resizeSection(1, 18); + + installEventFilter(this); + setUniformRowHeights(true); + setContextMenuPolicy(Qt::CustomContextMenu); + + connect(this, SIGNAL(clicked(QModelIndex)), this, + SLOT(handleClicked(QModelIndex))); + connect(this, SIGNAL(pressed(QModelIndex)), this, + SLOT(handlePressed(QModelIndex))); + connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, + SLOT(contextMenuRequested(QPoint))); +} + +OpenPagesWidget::~OpenPagesWidget() +{ +} + +void OpenPagesWidget::contextMenuRequested(QPoint pos) +{ + const QModelIndex &index = indexAt(pos); + if (!index.isValid()) + return; + + QMenu contextMenu; + QAction *closeEditor = contextMenu.addAction(tr("Close %1").arg(index.data() + .toString())); + QAction *closeOtherEditors = contextMenu.addAction(tr("Close All Except %1") + .arg(index.data().toString())); + + if (model()->rowCount() == 1) { + closeEditor->setEnabled(false); + closeOtherEditors->setEnabled(false); + } + + QAction *action = contextMenu.exec(mapToGlobal(pos)); + if (action == closeEditor) + emit closePage(index); + else if (action == closeOtherEditors) + emit closePagesExcept(index); +} + +void OpenPagesWidget::handlePressed(const QModelIndex &index) +{ + if (index.column() == 0) + emit setCurrentPage(index); + + if (index.column() == 1) + m_delegate->pressedIndex = index; +} + +void OpenPagesWidget::handleClicked(const QModelIndex &index) +{ + // implemented here to handle the funky close button and to work around a + // bug in item views where the delegate wouldn't get the QStyle::State_MouseOver + if (index.column() == 1) { + if (model()->rowCount() > 1) + emit closePage(index); + + QWidget *vp = viewport(); + const QPoint &cursorPos = QCursor::pos(); + QMouseEvent e(QEvent::MouseMove, vp->mapFromGlobal(cursorPos), cursorPos, + Qt::NoButton, 0, 0); + QCoreApplication::sendEvent(vp, &e); + } +} + +bool OpenPagesWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == this && event->type() == QEvent::KeyPress) { + if (currentIndex().isValid()) { + QKeyEvent *ke = static_cast(event); + const int key = ke->key(); + if ((key == Qt::Key_Return || key == Qt::Key_Enter || key == Qt::Key_Space) + && ke->modifiers() == 0) { + emit setCurrentPage(currentIndex()); + } else if ((key == Qt::Key_Delete || key == Qt::Key_Backspace) + && ke->modifiers() == 0 && model()->rowCount() > 1) { + emit closePage(currentIndex()); + } + } + } + return QWidget::eventFilter(obj, event); +} + +QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/openpageswidget.h b/tools/assistant/tools/assistant/openpageswidget.h new file mode 100644 index 0000000..5b35321 --- /dev/null +++ b/tools/assistant/tools/assistant/openpageswidget.h @@ -0,0 +1,76 @@ +/************************************************************************** +** +** This file is part of the Assistant module of the Qt toolkit. +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef OPENPAGESWIDGET_H +#define OPENPAGESWIDGET_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class OpenPagesModel; + +class OpenPagesDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + explicit OpenPagesDelegate(QObject *parent = 0); + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + + mutable QModelIndex pressedIndex; +}; + +class OpenPagesWidget : public QTreeView +{ + Q_OBJECT +public: + OpenPagesWidget(OpenPagesModel *model); + ~OpenPagesWidget(); + +signals: + void setCurrentPage(const QModelIndex &index); + void closePage(const QModelIndex &index); + void closePagesExcept(const QModelIndex &index); + +private slots: + void contextMenuRequested(QPoint pos); + void handlePressed(const QModelIndex &index); + void handleClicked(const QModelIndex &index); + +private: + bool eventFilter(QObject *obj, QEvent *event); + + OpenPagesDelegate *m_delegate; +}; + +QT_END_NAMESPACE + +#endif // OPENPAGESWIDGET_H diff --git a/tools/assistant/tools/assistant/preferencesdialog.cpp b/tools/assistant/tools/assistant/preferencesdialog.cpp index 0e1d719..3535e5a 100644 --- a/tools/assistant/tools/assistant/preferencesdialog.cpp +++ b/tools/assistant/tools/assistant/preferencesdialog.cpp @@ -45,6 +45,7 @@ #include "fontpanel.h" #include "helpenginewrapper.h" #include "installdialog.h" +#include "openpagesmanager.h" #include "tracer.h" #include @@ -302,15 +303,12 @@ void PreferencesDialog::addDocumentationLocal() void PreferencesDialog::removeDocumentation() { TRACE_OBJ - bool foundBefore = false; - CentralWidget* widget = CentralWidget::instance(); - QMap openedDocList = widget->currentSourceFileList(); - QStringList values(openedDocList.values()); + bool foundBefore = false; QList l = m_ui.registeredDocsListWidget->selectedItems(); foreach (QListWidgetItem* item, l) { const QString& ns = item->text(); - if (!foundBefore && values.contains(ns)) { + if (!foundBefore && OpenPagesManager::instance()->pagesOpenForNamespace(ns)) { if (0 == QMessageBox::information(this, tr("Remove Documentation"), tr("Some documents currently opened in Assistant reference the " "documentation you are attempting to remove. Removing the " @@ -320,7 +318,6 @@ void PreferencesDialog::removeDocumentation() } m_unregDocs.append(ns); - m_TabsToClose += openedDocList.keys(ns); delete m_ui.registeredDocsListWidget->takeItem( m_ui.registeredDocsListWidget->row(item)); } @@ -374,10 +371,10 @@ void PreferencesDialog::applyChanges() } } - CentralWidget::instance()->closeOrReloadTabs(m_TabsToClose, false); - - foreach (const QString &doc, m_unregDocs) + foreach (const QString &doc, m_unregDocs) { + OpenPagesManager::instance()->closePages(doc); helpEngine.unregisterDocumentation(doc); + } if (filtersWereChanged || !m_regDocs.isEmpty() || !m_unregDocs.isEmpty()) helpEngine.setupData(); diff --git a/tools/assistant/tools/assistant/preferencesdialog.h b/tools/assistant/tools/assistant/preferencesdialog.h index 2894494..7a17275 100644 --- a/tools/assistant/tools/assistant/preferencesdialog.h +++ b/tools/assistant/tools/assistant/preferencesdialog.h @@ -96,7 +96,6 @@ private: QStringList m_docsBackup; QStringList m_regDocs; QStringList m_unregDocs; - QList m_TabsToClose; FontPanel *m_appFontPanel; FontPanel *m_browserFontPanel; bool m_appFontChanged; diff --git a/tools/assistant/tools/assistant/remotecontrol.cpp b/tools/assistant/tools/assistant/remotecontrol.cpp index 5ecdd69..06e5602 100644 --- a/tools/assistant/tools/assistant/remotecontrol.cpp +++ b/tools/assistant/tools/assistant/remotecontrol.cpp @@ -38,12 +38,13 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "tracer.h" - #include "remotecontrol.h" -#include "mainwindow.h" + #include "centralwidget.h" #include "helpenginewrapper.h" +#include "mainwindow.h" +#include "openpagesmanager.h" +#include "tracer.h" #include #include @@ -323,8 +324,7 @@ void RemoteControl::handleUnregisterCommand(const QString &arg) const QString &absFileName = QFileInfo(arg).absoluteFilePath(); const QString &ns = QHelpEngineCore::namespaceName(absFileName); if (helpEngine.registeredDocumentations().contains(ns)) { - CentralWidget* widget = CentralWidget::instance(); - widget->closeOrReloadTabs(widget->currentSourceFileList().keys(ns), false); + OpenPagesManager::instance()->closePages(ns); if (helpEngine.unregisterDocumentation(ns)) helpEngine.setupData(); } -- cgit v0.12 From 242845a50410e7b97206f6374408a2e53b5c29fb Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Thu, 15 Apr 2010 15:28:31 +0200 Subject: Added support for symlinks and junction points on Windows Since ntfs symlinks (not .lnk files) can use relative paths to targets, support for relative links needed to be added. Directory junctions can also be used to mount another filesystem directly into an existing folder. Such junctions in that case use the volume id of the target volume for the link path. Therefor this commit also includes an implementation for resolving volume ids. To be independent of existing directories in test code i added a function to create own junction points. Reviewed-by: Joao Task-number: QTBUG-9009, QTBUG-7036 --- src/corelib/io/qfsfileengine.cpp | 2 + src/corelib/io/qfsfileengine_win.cpp | 18 +++- tests/auto/qfileinfo/tst_qfileinfo.cpp | 113 ++++++++++++++++++++++++- tests/benchmarks/corelib/io/qfileinfo/main.cpp | 44 +++++++++- tests/shared/filesystem.h | 58 +++++++++++++ 5 files changed, 231 insertions(+), 4 deletions(-) diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index a1ffb81..3cf08a7 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -208,6 +208,8 @@ QString QFSFileEnginePrivate::canonicalized(const QString &path) fi.setFile(prefix); if (fi.isSymLink()) { QString target = fi.symLinkTarget(); + if(QFileInfo(target).isRelative()) + target = fi.absolutePath() + slash + target; if (separatorPos != -1) { if (fi.isDir() && !target.endsWith(slash)) target.append(slash); diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index eeca07e..668379f 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -1275,7 +1275,12 @@ static QString readSymLink(const QString &link) REPARSE_DATA_BUFFER *rdb = (REPARSE_DATA_BUFFER*)qMalloc(bufsize); DWORD retsize = 0; if (::DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, 0, 0, rdb, bufsize, &retsize, 0)) { - if (rdb->ReparseTag == IO_REPARSE_TAG_SYMLINK) { + if (rdb->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { + int length = rdb->MountPointReparseBuffer.SubstituteNameLength / sizeof(wchar_t); + int offset = rdb->MountPointReparseBuffer.SubstituteNameOffset / sizeof(wchar_t); + const wchar_t* PathBuffer = &rdb->MountPointReparseBuffer.PathBuffer[offset]; + result = QString::fromWCharArray(PathBuffer, length); + } else if (rdb->ReparseTag == IO_REPARSE_TAG_SYMLINK) { int length = rdb->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(wchar_t); int offset = rdb->SymbolicLinkReparseBuffer.SubstituteNameOffset / sizeof(wchar_t); const wchar_t* PathBuffer = &rdb->SymbolicLinkReparseBuffer.PathBuffer[offset]; @@ -1287,6 +1292,15 @@ static QString readSymLink(const QString &link) } qFree(rdb); CloseHandle(handle); + + QRegExp matchVolName(QLatin1String("^Volume\\{([a-z]|[0-9]|-)+\\}\\\\"), Qt::CaseInsensitive); + if(matchVolName.indexIn(result) == 0) { + DWORD len; + wchar_t buffer[MAX_PATH]; + QString volumeName = result.mid(0, matchVolName.matchedLength()).prepend(QLatin1String("\\\\?\\")); + if(GetVolumePathNamesForVolumeNameW(volumeName.utf16(), buffer, MAX_PATH, &len) != 0) + result.replace(0,matchVolName.matchedLength(), QString::fromWCharArray(buffer)); + } } #else Q_UNUSED(link); @@ -1538,7 +1552,7 @@ bool QFSFileEnginePrivate::isSymlink() const if (hFind != INVALID_HANDLE_VALUE) { ::FindClose(hFind); if ((findData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) - && findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK) { + && (findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK || findData.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT)) { is_link = true; } } diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index 403c5f9..d482cbc 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -56,6 +56,7 @@ #endif #ifdef Q_OS_WIN #include +#include #endif #include #include @@ -65,6 +66,7 @@ #endif #include "../network-settings.h" #include +#include "../../shared/filesystem.h" #if defined(Q_OS_SYMBIAN) # define SRCDIR "" @@ -161,6 +163,8 @@ private slots: void refresh(); #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + void ntfsJunctionPointsAndSymlinks_data(); + void ntfsJunctionPointsAndSymlinks(); void brokenShortcut(); #endif @@ -194,8 +198,15 @@ tst_QFileInfo::~tst_QFileInfo() #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) QDir().rmdir("./.hidden-directory"); #endif -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) QDir().rmdir("./hidden-directory"); + QDir().rmdir("abs_symlink"); + QDir().rmdir("rel_symlink"); + QDir().rmdir("junction_pwd"); + QDir().rmdir("junction_root"); + QDir().rmdir("mountpoint"); + QFile::remove("abs_symlink.cpp"); + QFile::remove("rel_symlink.cpp"); #endif } @@ -1236,6 +1247,106 @@ void tst_QFileInfo::refresh() } #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data() +{ + QTest::addColumn("path"); + QTest::addColumn("isSymLink"); + QTest::addColumn("linkTarget"); + QTest::addColumn("canonicalFilePath"); + + QDir pwd; + pwd.mkdir("target"); + + QLibrary kernel32("kernel32"); + typedef BOOLEAN (WINAPI *PtrCreateSymbolicLink)(LPCWSTR, LPCWSTR, DWORD); + PtrCreateSymbolicLink createSymbolicLinkW = 0; + createSymbolicLinkW = (PtrCreateSymbolicLink) kernel32.resolve("CreateSymbolicLinkW"); + if (!createSymbolicLinkW) + QSKIP("symbolic links not supported by operating system",SkipSingle); + + { + //Directory symlinks + QDir target("target"); + QVERIFY(target.exists()); + + QString absTarget = QDir::toNativeSeparators(target.absolutePath()); + QString absSymlink = QDir::toNativeSeparators(pwd.absolutePath()).append("\\abs_symlink"); + QString relTarget = "target"; + QString relSymlink = "rel_symlink"; + QString fileInTarget(absTarget); + fileInTarget.append("\\file"); + QString fileInSymlink(absSymlink); + fileInSymlink.append("\\file"); + QFile file(fileInTarget); + file.open(QIODevice::ReadWrite); + file.close(); + + QVERIFY(pwd.exists("abs_symlink") || createSymbolicLinkW(absSymlink.utf16(),absTarget.utf16(),0x1)); + QVERIFY(pwd.exists(relSymlink) || createSymbolicLinkW(relSymlink.utf16(),relTarget.utf16(),0x1)); + QVERIFY(file.exists()); + + QTest::newRow("absolute dir symlink") << absSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalPath(); + QTest::newRow("relative dir symlink") << relSymlink << true << QDir::fromNativeSeparators(relTarget) << target.canonicalPath(); + QTest::newRow("file in symlink dir") << fileInSymlink << false << "" << target.canonicalPath().append("/file"); + } + { + //File symlinks + QFileInfo target(SRCDIR "tst_qfileinfo.cpp"); + QString absTarget = QDir::toNativeSeparators(target.absoluteFilePath()); + QString absSymlink = QDir::toNativeSeparators(pwd.absolutePath()).append("\\abs_symlink.cpp"); + QString relTarget = QDir::toNativeSeparators(pwd.relativeFilePath(target.absoluteFilePath())); + QString relSymlink = "rel_symlink.cpp"; + QVERIFY(pwd.exists("abs_symlink.cpp") || createSymbolicLinkW(absSymlink.utf16(),absTarget.utf16(),0x0)); + QVERIFY(pwd.exists(relSymlink) || createSymbolicLinkW(relSymlink.utf16(),relTarget.utf16(),0x0)); + + QTest::newRow("absolute file symlink") << absSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalFilePath(); + QTest::newRow("relative file symlink") << relSymlink << true << QDir::fromNativeSeparators(relTarget) << target.canonicalFilePath(); + } + + //Junctions + QString target = "target"; + QString junction = "junction_pwd"; + FileSystem::createNtfsJunction(target, junction); + QFileInfo targetInfo(target); + QTest::newRow("junction_pwd") << junction << true << targetInfo.absoluteFilePath() << targetInfo.canonicalFilePath(); + + QFileInfo fileInJunction(targetInfo.absoluteFilePath().append("/file")); + QFile file(fileInJunction.absoluteFilePath()); + file.open(QIODevice::ReadWrite); + file.close(); + QVERIFY(file.exists()); + QTest::newRow("file in junction") << fileInJunction.absoluteFilePath() << false << "" << fileInJunction.canonicalFilePath(); + + target = QDir::rootPath(); + junction = "junction_root"; + FileSystem::createNtfsJunction(target, junction); + targetInfo.setFile(target); + QTest::newRow("junction_root") << junction << true << targetInfo.absoluteFilePath() << targetInfo.canonicalFilePath(); + + //Mountpoint + wchar_t buffer[MAX_PATH]; + QString rootPath = QDir::toNativeSeparators(QDir::rootPath()); + QVERIFY(GetVolumeNameForVolumeMountPointW(rootPath.utf16(), buffer, MAX_PATH)); + QString rootVolume = QString::fromWCharArray(buffer); + junction = "mountpoint"; + rootVolume.replace("\\\\?\\","\\??\\"); + FileSystem::createNtfsJunction(rootVolume, junction); + QTest::newRow("mountpoint") << junction << true << QDir::fromNativeSeparators(rootPath) << QDir::rootPath(); +} + +void tst_QFileInfo::ntfsJunctionPointsAndSymlinks() +{ + QFETCH(QString, path); + QFETCH(bool, isSymLink); + QFETCH(QString, linkTarget); + QFETCH(QString, canonicalFilePath); + + QFileInfo fi(path); + QCOMPARE(fi.isSymLink(), isSymLink); + QCOMPARE(fi.symLinkTarget(), linkTarget); + QCOMPARE(fi.canonicalFilePath(), canonicalFilePath); +} + void tst_QFileInfo::brokenShortcut() { QString linkName("borkenlink.lnk"); diff --git a/tests/benchmarks/corelib/io/qfileinfo/main.cpp b/tests/benchmarks/corelib/io/qfileinfo/main.cpp index 025787f..b272bda 100644 --- a/tests/benchmarks/corelib/io/qfileinfo/main.cpp +++ b/tests/benchmarks/corelib/io/qfileinfo/main.cpp @@ -43,15 +43,20 @@ #include #include #include +#include #include "private/qfsfileengine_p.h" +#include "../../../../shared/filesystem.h" class qfileinfo : public QObject { Q_OBJECT private slots: void canonicalFileNamePerformance(); - +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + void symLinkTargetPerformanceLNK(); + void symLinkTargetPerformanceMounpoint(); +#endif void initTestCase(); void cleanupTestCase(); public: @@ -78,6 +83,43 @@ void qfileinfo::canonicalFileNamePerformance() } } +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +void qfileinfo::symLinkTargetPerformanceLNK() +{ + QVERIFY(QFile::link("file","link.lnk")); + QFileInfo info("link.lnk"); + info.setCaching(false); + QVERIFY(info.isSymLink()); + QString linkTarget; + QBENCHMARK { + for(int i=0; i<100; i++) + linkTarget = info.readLink(); + } + QVERIFY(QFile::remove("link.lnk")); +} + +void qfileinfo::symLinkTargetPerformanceMounpoint() +{ + wchar_t buffer[MAX_PATH]; + QString rootPath = QDir::toNativeSeparators(QDir::rootPath()); + QVERIFY(GetVolumeNameForVolumeMountPointW(rootPath.utf16(), buffer, MAX_PATH)); + QString rootVolume = QString::fromWCharArray(buffer); + QString mountpoint = "mountpoint"; + rootVolume.replace("\\\\?\\","\\??\\"); + FileSystem::createNtfsJunction(rootVolume, mountpoint); + + QFileInfo info(mountpoint); + info.setCaching(false); + QVERIFY(info.isSymLink()); + QString linkTarget; + QBENCHMARK { + for(int i=0; i<100; i++) + linkTarget = info.readLink(); + } + QVERIFY(QDir().rmdir(mountpoint)); +} +#endif + QTEST_MAIN(qfileinfo) #include "main.moc" diff --git a/tests/shared/filesystem.h b/tests/shared/filesystem.h index 2d46c0d..cc1781e 100644 --- a/tests/shared/filesystem.h +++ b/tests/shared/filesystem.h @@ -48,6 +48,11 @@ #include #include +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +# define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L) +# define REPARSE_MOUNTPOINT_HEADER_SIZE 8 +#endif + struct FileSystem { ~FileSystem() @@ -86,6 +91,59 @@ struct FileSystem } return false; } +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + static void createNtfsJunction(QString target, QString linkName) + { + typedef struct { + DWORD ReparseTag; + DWORD ReparseDataLength; + WORD Reserved; + WORD ReparseTargetLength; + WORD ReparseTargetMaximumLength; + WORD Reserved1; + WCHAR ReparseTarget[1]; + } REPARSE_MOUNTPOINT_DATA_BUFFER, *PREPARSE_MOUNTPOINT_DATA_BUFFER; + + char reparseBuffer[MAX_PATH*3]; + HANDLE hFile; + DWORD returnedLength; + wchar_t fileSystem[MAX_PATH] = L""; + PREPARSE_MOUNTPOINT_DATA_BUFFER reparseInfo = (PREPARSE_MOUNTPOINT_DATA_BUFFER) reparseBuffer; + + QFileInfo junctionInfo(linkName); + linkName = QDir::toNativeSeparators(junctionInfo.absoluteFilePath()); + + GetVolumeInformationW( linkName.left(3).utf16(), NULL, 0, NULL, NULL, NULL, + fileSystem, sizeof(fileSystem)/sizeof(WCHAR)); + if(QString().fromWCharArray(fileSystem) != "NTFS") + QSKIP("This seems not to be an NTFS volume. Junctions are not allowed.",SkipSingle); + + if (!target.startsWith("\\??\\") && !target.startsWith("\\\\?\\")) { + QFileInfo targetInfo(target); + target = QDir::toNativeSeparators(targetInfo.absoluteFilePath()); + target.prepend("\\??\\"); + if(target.endsWith('\\') && target.at(target.length()-2) != ':') + target.chop(1); + } + QDir().mkdir(linkName); + hFile = CreateFileW( linkName.utf16(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, + FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, NULL ); + QVERIFY(hFile != INVALID_HANDLE_VALUE ); + + memset( reparseInfo, 0, sizeof( *reparseInfo )); + reparseInfo->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT; + reparseInfo->ReparseTargetLength = target.size() * sizeof(wchar_t); + reparseInfo->ReparseTargetMaximumLength = reparseInfo->ReparseTargetLength + sizeof(wchar_t); + target.toWCharArray(reparseInfo->ReparseTarget); + reparseInfo->ReparseDataLength = reparseInfo->ReparseTargetLength + 12; + + bool ioc = DeviceIoControl(hFile, FSCTL_SET_REPARSE_POINT, reparseInfo, + reparseInfo->ReparseDataLength + REPARSE_MOUNTPOINT_HEADER_SIZE, + NULL, 0, &returnedLength, NULL); + CloseHandle( hFile ); + QVERIFY(ioc); + } +#endif private: QDir currentDir; -- cgit v0.12 From 20e56eabcb9d8a743952b9b6c3422597631ba7eb Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Fri, 23 Apr 2010 11:03:21 +0200 Subject: Fix for missing wchar_t pointer cast in qfsfileengine_win.cpp This was cause by previous commit 242845a50410e7b97206f6374408a2e53b5c29fb Reviewed-by: Joao --- src/corelib/io/qfsfileengine_win.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 668379f..7d85cb1 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -1298,7 +1298,7 @@ static QString readSymLink(const QString &link) DWORD len; wchar_t buffer[MAX_PATH]; QString volumeName = result.mid(0, matchVolName.matchedLength()).prepend(QLatin1String("\\\\?\\")); - if(GetVolumePathNamesForVolumeNameW(volumeName.utf16(), buffer, MAX_PATH, &len) != 0) + if(GetVolumePathNamesForVolumeNameW((wchar_t*)volumeName.utf16(), buffer, MAX_PATH, &len) != 0) result.replace(0,matchVolName.matchedLength(), QString::fromWCharArray(buffer)); } } -- cgit v0.12 From 4affdc09b88025a93025a60fbecff57ca6ac97b7 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Fri, 23 Apr 2010 16:53:32 +0200 Subject: Use GetProcAddress for GetVolumePathNamesForVolumeNameW This allows to compile also on Windows versions prior XP Reviewed-by: Thiago --- src/corelib/io/qfsfileengine_win.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 7d85cb1..be701dc 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -154,6 +154,8 @@ static TRUSTEE_W worldTrusteeW; typedef BOOL (WINAPI *PtrGetUserProfileDirectoryW)(HANDLE, LPWSTR, LPDWORD); static PtrGetUserProfileDirectoryW ptrGetUserProfileDirectoryW = 0; +typedef BOOL (WINAPI *PtrGetVolumePathNamesForVolumeNameW)(LPCWSTR,LPWSTR,DWORD,PDWORD); +static PtrGetVolumePathNamesForVolumeNameW ptrGetVolumePathNamesForVolumeNameW = 0; QT_END_INCLUDE_NAMESPACE @@ -212,6 +214,9 @@ void QFSFileEnginePrivate::resolveLibs() HINSTANCE userenvHnd = LoadLibrary(L"userenv"); if (userenvHnd) ptrGetUserProfileDirectoryW = (PtrGetUserProfileDirectoryW)GetProcAddress(userenvHnd, "GetUserProfileDirectoryW"); + HINSTANCE kernel32 = LoadLibrary(L"kernel32"); + if(kernel32) + ptrGetVolumePathNamesForVolumeNameW = (PtrGetVolumePathNamesForVolumeNameW)GetProcAddress(kernel32, "GetVolumePathNamesForVolumeNameW"); #endif } } @@ -1293,14 +1298,19 @@ static QString readSymLink(const QString &link) qFree(rdb); CloseHandle(handle); - QRegExp matchVolName(QLatin1String("^Volume\\{([a-z]|[0-9]|-)+\\}\\\\"), Qt::CaseInsensitive); - if(matchVolName.indexIn(result) == 0) { - DWORD len; - wchar_t buffer[MAX_PATH]; - QString volumeName = result.mid(0, matchVolName.matchedLength()).prepend(QLatin1String("\\\\?\\")); - if(GetVolumePathNamesForVolumeNameW((wchar_t*)volumeName.utf16(), buffer, MAX_PATH, &len) != 0) - result.replace(0,matchVolName.matchedLength(), QString::fromWCharArray(buffer)); +#if !defined(QT_NO_LIBRARY) + QFSFileEnginePrivate::resolveLibs(); + if (ptrGetVolumePathNamesForVolumeNameW) { + QRegExp matchVolName(QLatin1String("^Volume\\{([a-z]|[0-9]|-)+\\}\\\\"), Qt::CaseInsensitive); + if(matchVolName.indexIn(result) == 0) { + DWORD len; + wchar_t buffer[MAX_PATH]; + QString volumeName = result.mid(0, matchVolName.matchedLength()).prepend(QLatin1String("\\\\?\\")); + if(ptrGetVolumePathNamesForVolumeNameW((wchar_t*)volumeName.utf16(), buffer, MAX_PATH, &len) != 0) + result.replace(0,matchVolName.matchedLength(), QString::fromWCharArray(buffer)); + } } +#endif } #else Q_UNUSED(link); -- cgit v0.12 From 7eea24f6c71cde7134cfb4b8c936f235da86289d Mon Sep 17 00:00:00 2001 From: ck Date: Mon, 26 Apr 2010 10:27:25 +0200 Subject: Assistant: Fix some merge artifacts. --- tools/assistant/tools/assistant/helpviewer_qtb.cpp | 2 +- tools/assistant/tools/assistant/mainwindow.cpp | 15 ++++++--------- tools/assistant/tools/assistant/openpagesmanager.cpp | 4 +++- tools/assistant/tools/assistant/openpagesmodel.cpp | 3 +++ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.cpp b/tools/assistant/tools/assistant/helpviewer_qtb.cpp index c6bb7a8..78890b9 100644 --- a/tools/assistant/tools/assistant/helpviewer_qtb.cpp +++ b/tools/assistant/tools/assistant/helpviewer_qtb.cpp @@ -188,7 +188,7 @@ void HelpViewer::openLinkInNewTab() if(lastAnchor.isEmpty()) return; - OpenPagesManager::instance()->createNewTab(QUrl(lastAnchor)); + OpenPagesManager::instance()->createPage(QUrl(lastAnchor)); lastAnchor.clear(); } diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp index a9bcd90..9578478 100644 --- a/tools/assistant/tools/assistant/mainwindow.cpp +++ b/tools/assistant/tools/assistant/mainwindow.cpp @@ -418,8 +418,13 @@ void MainWindow::setupActions() QMenu *menu = menuBar()->addMenu(tr("&File")); - m_newTabAction = menu->addAction(tr("New &Tab"), m_centralWidget, SLOT(newTab())); + OpenPagesManager * const openPages = OpenPagesManager::instance(); + m_newTabAction + = menu->addAction(tr("New &Tab"), openPages, SLOT(createPage())); m_newTabAction->setShortcut(QKeySequence::AddTab); + m_closeTabAction = menu->addAction(tr("&Close Tab"), + openPages, SLOT(closeCurrentPage())); + m_closeTabAction->setShortcuts(QKeySequence::Close); menu->addSeparator(); @@ -432,14 +437,6 @@ void MainWindow::setupActions() menu->addAction(globalActions->printAction()); menu->addSeparator(); - OpenPagesManager * const openPages = OpenPagesManager::instance(); - m_newTabAction - = menu->addAction(tr("New &Tab"), openPages, SLOT(createPage())); - m_newTabAction->setShortcut(QKeySequence::AddTab); - m_closeTabAction = menu->addAction(tr("&Close Tab"), - openPages, SLOT(closeCurrentPage())); - m_closeTabAction->setShortcuts(QKeySequence::Close); - QAction *tmp = menu->addAction(QIcon::fromTheme("application-exit"), tr("&Quit"), this, SLOT(close())); tmp->setMenuRole(QAction::QuitRole); diff --git a/tools/assistant/tools/assistant/openpagesmanager.cpp b/tools/assistant/tools/assistant/openpagesmanager.cpp index cd4460a..472a846 100644 --- a/tools/assistant/tools/assistant/openpagesmanager.cpp +++ b/tools/assistant/tools/assistant/openpagesmanager.cpp @@ -42,9 +42,11 @@ #include "centralwidget.h" #include "helpenginewrapper.h" -#include "helpviewer.h" +#if defined(QT_NO_WEBKIT) #include "helpviewer_qtb.h" +#else #include "helpviewer_qwv.h" +#endif // QT_NO_WEBKIT #include "openpagesmodel.h" #include "openpageswidget.h" #include "tracer.h" diff --git a/tools/assistant/tools/assistant/openpagesmodel.cpp b/tools/assistant/tools/assistant/openpagesmodel.cpp index 9e31b84..92ca1ad 100644 --- a/tools/assistant/tools/assistant/openpagesmodel.cpp +++ b/tools/assistant/tools/assistant/openpagesmodel.cpp @@ -41,8 +41,11 @@ #include "openpagesmodel.h" #include "helpenginewrapper.h" +#if defined(QT_NO_WEBKIT) #include "helpviewer_qtb.h" +#else #include "helpviewer_qwv.h" +#endif // QT_NO_WEBKIT #include "tracer.h" #include -- cgit v0.12 From 2c99794e486234580fc0e149c1f176edb57d6565 Mon Sep 17 00:00:00 2001 From: ck Date: Mon, 26 Apr 2010 11:11:46 +0200 Subject: Assistant: Don't display close button when it's not functional. Plus: Show page title in context menu also when right-clicking on the close button. Reviewed-by: kh1 --- tools/assistant/tools/assistant/openpageswidget.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/assistant/tools/assistant/openpageswidget.cpp b/tools/assistant/tools/assistant/openpageswidget.cpp index 648ead8..bbc86c3 100644 --- a/tools/assistant/tools/assistant/openpageswidget.cpp +++ b/tools/assistant/tools/assistant/openpageswidget.cpp @@ -63,7 +63,8 @@ void OpenPagesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt QStyledItemDelegate::paint(painter, option, index); - if (index.column() == 1 && option.state & QStyle::State_MouseOver) { + if (index.column() == 1 && index.model()->rowCount() > 1 + && option.state & QStyle::State_MouseOver) { QIcon icon((option.state & QStyle::State_Selected) ? ":/trolltech/assistant/images/closebutton.png" : ":/trolltech/assistant/images/darkclosebutton.png"); @@ -113,10 +114,12 @@ OpenPagesWidget::~OpenPagesWidget() void OpenPagesWidget::contextMenuRequested(QPoint pos) { - const QModelIndex &index = indexAt(pos); + QModelIndex index = indexAt(pos); if (!index.isValid()) return; + if (index.column() == 1) + index = index.sibling(index.row(), 0); QMenu contextMenu; QAction *closeEditor = contextMenu.addAction(tr("Close %1").arg(index.data() .toString())); -- cgit v0.12