Commit edcefd69 authored by kh1's avatar kh1
Browse files

Implement tabless help mode, behaves now like edit mode.

parent a8801d15
This diff is collapsed.
......@@ -30,29 +30,19 @@
#ifndef CENTRALWIDGET_H
#define CENTRALWIDGET_H
#include <QtCore/QUrl>
#include <QtCore/QPoint>
#include <QtCore/QObject>
#include <find/ifindsupport.h>
#include <QtGui/QWidget>
#include <QtGui/QTextDocument>
QT_BEGIN_NAMESPACE
QT_FORWARD_DECLARE_CLASS(QEvent)
QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QStackedWidget)
QT_FORWARD_DECLARE_CLASS(QFocusEvent)
class QEvent;
class QLabel;
class QAction;
class QCheckBox;
class QLineEdit;
class QToolButton;
class QTabWidget;
class QFocusEvent;
QT_END_NAMESPACE
namespace Help {
namespace Internal {
class HelpViewer;
namespace Help {
namespace Internal {
class PrintHelper;
class CentralWidget : public QWidget
......@@ -63,82 +53,71 @@ public:
CentralWidget(QWidget *parent = 0);
~CentralWidget();
static CentralWidget *instance();
bool hasSelection() const;
QUrl currentSource() const;
QString currentTitle() const;
bool isForwardAvailable() const;
bool isBackwardAvailable() const;
QList<QAction*> globalActions() const;
void setGlobalActions(const QList<QAction*> &actions);
HelpViewer *viewerAt(int index) const;
HelpViewer *currentHelpViewer() const;
void activateTab(bool onlyHelpViewer = false);
bool find(const QString &txt, QTextDocument::FindFlags findFlags, bool incremental);
void setLastShownPages();
HelpViewer *helpViewerAtIndex(int index) const;
int indexOf(HelpViewer *viewer) const;
static CentralWidget *instance();
void addPage(HelpViewer *page, bool fromSearch = false);
void removePage(int index);
int currentIndex() const;
void setCurrentPage(HelpViewer *page);
bool find(const QString &txt, Find::IFindSupport::FindFlags findFlags,
bool incremental);
public slots:
void copy();
void home();
void zoomIn();
void zoomOut();
void nextPage();
void resetZoom();
void forward();
void nextPage();
void backward();
void previousPage();
void print();
void pageSetup();
void printPreview();
void setSource(const QUrl &url);
void setSourceInNewTab(const QUrl &url, int zoom = 0);
HelpViewer *newEmptyTab();
void home();
void forward();
void backward();
void showTopicChooser(const QMap<QString, QUrl> &links,
const QString &keyword);
void copy();
void activateTab(int index);
void setSourceFromSearch(const QUrl &url);
void showTopicChooser(const QMap<QString, QUrl> &links, const QString &key);
protected:
void focusInEvent(QFocusEvent *event);
signals:
void currentViewerChanged(int index);
void copyAvailable(bool yes);
void currentViewerChanged();
void sourceChanged(const QUrl &url);
void highlighted(const QString &link);
void forwardAvailable(bool available);
void backwardAvailable(bool available);
void addNewBookmark(const QString &title, const QString &url);
void viewerAboutToBeRemoved(int index);
void viewerRemoved(int index);
private slots:
void newTab();
void closeTab();
void closeTab(int index);
void setTabTitle(const QUrl& url);
void currentPageChanged(int index);
void showTabBarContextMenu(const QPoint &point);
void highlightSearchTerms();
void printPreview(QPrinter *printer);
void handleSourceChanged(const QUrl &url);
private:
void connectSignals();
bool eventFilter(QObject *object, QEvent *e);
void initPrinter();
QString quoteTabTitle(const QString &title) const;
void connectSignals(HelpViewer *page);
bool eventFilter(QObject *object, QEvent *e);
private:
int lastTabPage;
QList<QAction*> globalActionList;
QWidget *findBar;
QTabWidget* tabWidget;
QPrinter *printer;
QStackedWidget *m_stackedWidget;
};
} // namespace Internal
} // namespace Internal
} // namespace Help
#endif // CENTRALWIDGET_H
......@@ -41,25 +41,23 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QTextStream>
#if defined(QT_NO_WEBKIT)
#include <QtGui/QApplication>
#else
#include <QtWebKit/QWebSettings>
#endif
#include <QtGui/QFileDialog>
#include <QtHelp/QHelpEngineCore>
#if !defined(QT_NO_WEBKIT)
#include <QtWebKit/QWebSettings>
#endif
using namespace Help::Internal;
GeneralSettingsPage::GeneralSettingsPage()
{
m_font = qApp->font();
#if !defined(QT_NO_WEBKIT)
QWebSettings* webSettings = QWebSettings::globalSettings();
m_font.setFamily(webSettings->fontFamily(QWebSettings::StandardFont));
m_font.setPointSize(webSettings->fontSize(QWebSettings::DefaultFontSize));
#else
m_font = qApp->font();
#endif
}
......@@ -168,13 +166,8 @@ void GeneralSettingsPage::apply()
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
engine->setCustomValue(QLatin1String("font"), newFont);
#if !defined(QT_NO_WEBKIT)
QWebSettings* webSettings = QWebSettings::globalSettings();
webSettings->setFontFamily(QWebSettings::StandardFont, m_font.family());
webSettings->setFontSize(QWebSettings::DefaultFontSize, m_font.pointSize());
#else
emit fontChanged();
#endif
if (newFont != m_font)
emit fontChanged();
QString homePage = m_ui.homePageLineEdit->text();
if (homePage.isEmpty())
......
......@@ -6,33 +6,46 @@ include(../../qtcreatorplugin.pri)
include(help_dependencies.pri)
CONFIG += help
DEFINES += QT_CLUCENE_SUPPORT \
HELP_LIBRARY
HEADERS += helpplugin.h \
DEFINES += QT_CLUCENE_SUPPORT HELP_LIBRARY
HEADERS += \
centralwidget.h \
docsettingspage.h \
filtersettingspage.h \
generalsettingspage.h \
help_global.h \
helpconstants.h \
helpmode.h \
centralwidget.h \
searchwidget.h \
helpfindsupport.h \
help_global.h \
helpindexfilter.h \
generalsettingspage.h \
xbelsupport.h \
helpmanager.h
helpmanager.h \
helpmode.h \
helpplugin.h \
helpviewer.h \
helpviewer_p.h \
openpagesmanager.h \
openpagesmodel.h \
openpageswidget.h \
searchwidget.h \
xbelsupport.h
SOURCES += helpplugin.cpp \
SOURCES += \
centralwidget.cpp \
docsettingspage.cpp \
filtersettingspage.cpp \
helpmode.cpp \
centralwidget.cpp \
searchwidget.cpp \
generalsettingspage.cpp \
helpfindsupport.cpp \
helpindexfilter.cpp \
generalsettingspage.cpp \
xbelsupport.cpp \
helpmanager.cpp
helpmanager.cpp \
helpmode.cpp \
helpplugin.cpp \
helpviewer.cpp \
helpviewer_qtb.cpp \
helpviewer_qwv.cpp \
openpagesmanager.cpp \
openpagesmodel.cpp \
openpageswidget.cpp \
searchwidget.cpp \
xbelsupport.cpp
FORMS += docsettingspage.ui \
filtersettingspage.ui \
......
......@@ -51,7 +51,7 @@ bool HelpFindSupport::isEnabled() const
Find::IFindSupport::FindFlags HelpFindSupport::supportedFindFlags() const
{
return Find::IFindSupport::FindBackward | Find::IFindSupport::FindCaseSensitively
| Find::IFindSupport::FindWholeWords;
| Find::IFindSupport::FindWholeWords;
}
QString HelpFindSupport::currentFindString() const
......@@ -60,11 +60,7 @@ QString HelpFindSupport::currentFindString() const
HelpViewer *viewer = m_centralWidget->currentHelpViewer();
if (!viewer)
return QString();
#if !defined(QT_NO_WEBKIT)
return viewer->selectedText();
#else
return viewer->textCursor().selectedText();
#endif
}
QString HelpFindSupport::completedFindString() const
......@@ -72,95 +68,58 @@ QString HelpFindSupport::completedFindString() const
return QString();
}
Find::IFindSupport::Result HelpFindSupport::findIncremental(const QString &txt, Find::IFindSupport::FindFlags findFlags)
Find::IFindSupport::Result HelpFindSupport::findIncremental(const QString &txt,
Find::IFindSupport::FindFlags findFlags)
{
QTC_ASSERT(m_centralWidget, return NotFound);
findFlags &= ~Find::IFindSupport::FindBackward;
return m_centralWidget->find(txt, Find::IFindSupport::textDocumentFlagsForFindFlags(findFlags), true)
? Found : NotFound;
return m_centralWidget->find(txt, findFlags, true) ? Found : NotFound;
}
Find::IFindSupport::Result HelpFindSupport::findStep(const QString &txt, Find::IFindSupport::FindFlags findFlags)
Find::IFindSupport::Result HelpFindSupport::findStep(const QString &txt,
Find::IFindSupport::FindFlags findFlags)
{
QTC_ASSERT(m_centralWidget, return NotFound);
return m_centralWidget->find(txt, Find::IFindSupport::textDocumentFlagsForFindFlags(findFlags), false)
? Found : NotFound;
return m_centralWidget->find(txt, findFlags, false) ? Found : NotFound;
}
// -- HelpViewerFindSupport
HelpViewerFindSupport::HelpViewerFindSupport(HelpViewer *viewer)
: m_viewer(viewer)
: m_viewer(viewer)
{
}
Find::IFindSupport::FindFlags HelpViewerFindSupport::supportedFindFlags() const
{
return Find::IFindSupport::FindBackward | Find::IFindSupport::FindCaseSensitively
| Find::IFindSupport::FindWholeWords;
| Find::IFindSupport::FindWholeWords;
}
QString HelpViewerFindSupport::currentFindString() const
{
QTC_ASSERT(m_viewer, return QString());
#if !defined(QT_NO_WEBKIT)
return m_viewer->selectedText();
#else
return QString();
#endif
}
Find::IFindSupport::Result HelpViewerFindSupport::findIncremental(const QString &txt, Find::IFindSupport::FindFlags findFlags)
Find::IFindSupport::Result HelpViewerFindSupport::findIncremental(const QString &txt,
Find::IFindSupport::FindFlags findFlags)
{
QTC_ASSERT(m_viewer, return NotFound);
findFlags &= ~Find::IFindSupport::FindBackward;
return find(txt, findFlags, true) ? Found : NotFound;
}
Find::IFindSupport::Result HelpViewerFindSupport::findStep(const QString &txt, Find::IFindSupport::FindFlags findFlags)
Find::IFindSupport::Result HelpViewerFindSupport::findStep(const QString &txt,
Find::IFindSupport::FindFlags findFlags)
{
QTC_ASSERT(m_viewer, return NotFound);
return find(txt, findFlags, false) ? Found : NotFound;
}
bool HelpViewerFindSupport::find(const QString &txt, Find::IFindSupport::FindFlags findFlags, bool incremental)
bool HelpViewerFindSupport::find(const QString &txt,
Find::IFindSupport::FindFlags findFlags, bool incremental)
{
QTC_ASSERT(m_viewer, return false);
#if !defined(QT_NO_WEBKIT)
Q_UNUSED(incremental)
QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
if (findFlags & Find::IFindSupport::FindBackward)
options |= QWebPage::FindBackward;
if (findFlags & Find::IFindSupport::FindCaseSensitively)
options |= QWebPage::FindCaseSensitively;
bool found = m_viewer->findText(txt, options);
options = QWebPage::HighlightAllOccurrences;
m_viewer->findText(QLatin1String(""), options); // clear first
m_viewer->findText(txt, options); // force highlighting of all other matches
return found;
#else
QTextCursor cursor = m_viewer->textCursor();
QTextDocument *doc = m_viewer->document();
QTextBrowser *browser = qobject_cast<QTextBrowser*>(m_viewer);
if (!browser || !doc || cursor.isNull())
return false;
if (incremental)
cursor.setPosition(cursor.selectionStart());
QTextCursor found = doc->find(txt, cursor, Find::IFindSupport::textDocumentFlagsForFindFlags(findFlags));
if (found.isNull()) {
if ((findFlags&Find::IFindSupport::FindBackward) == 0)
cursor.movePosition(QTextCursor::Start);
else
cursor.movePosition(QTextCursor::End);
found = doc->find(txt, cursor, Find::IFindSupport::textDocumentFlagsForFindFlags(findFlags));
if (found.isNull()) {
return false;
}
}
if (!found.isNull()) {
m_viewer->setTextCursor(found);
}
return true;
#endif
return m_viewer->findText(txt, findFlags, incremental, false);
}
......@@ -34,12 +34,11 @@
#include <find/ifindsupport.h>
class HelpViewer;
namespace Help {
namespace Internal {
class HelpViewer;
class HelpFindSupport : public Find::IFindSupport
{
Q_OBJECT
......
This diff is collapsed.
......@@ -26,6 +26,7 @@
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef HELPPLUGIN_H
#define HELPPLUGIN_H
......@@ -33,14 +34,11 @@
#include <QtCore/QMap>
#include <QtCore/QStringList>
QT_BEGIN_NAMESPACE
class QAction;
class QComboBox;
class QToolBar;
class QUrl;
QT_END_NAMESPACE
class HelpViewer;
QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QComboBox)
QT_FORWARD_DECLARE_CLASS(QToolBar)
QT_FORWARD_DECLARE_CLASS(QToolButton)
QT_FORWARD_DECLARE_CLASS(QUrl)
namespace Core {
class ICore;
......@@ -57,8 +55,10 @@ namespace Internal {
class CentralWidget;
class DocSettingsPage;
class FilterSettingsPage;
class HelpMode;
class GeneralSettingsPage;
class HelpMode;
class HelpViewer;
class OpenPagesManager;
class SearchWidget;
class HelpPlugin : public ExtensionSystem::IPlugin
......@@ -78,14 +78,16 @@ public slots:
private slots:
void modeChanged(Core::IMode *mode);
void activateContext();
void activateIndex();
void activateContents();
void activateSearch();
void activateOpenPages();
void addBookmark();
void updateFilterComboBox();
void filterDocumentation(const QString &customFilter);
void addBookmark();
void addNewBookmark(const QString &title, const QString &url);
void switchToHelpMode();
void switchToHelpMode(const QUrl &source);
......@@ -96,18 +98,14 @@ private slots:
void updateSideBarSource(const QUrl &newUrl);
void fontChanged();
void updateCloseButton();
void setupHelpEngineIfNeeded();
void rebuildViewerComboBox();
void removeViewerFromComboBox(int index);
void updateViewerComboBoxIndex(int index);
private:
void setupUi();
void resetFilter();
void activateHelpMode();
QToolBar *createToolBar();
void connectCentralWidget();
HelpViewer* viewerForContextMode();
void createRightPaneContextViewer();
......@@ -122,18 +120,21 @@ private:
Core::SideBarItem *m_indexItem;
Core::SideBarItem *m_searchItem;
Core::SideBarItem *m_bookmarkItem;
Core::SideBarItem *m_openPagesItem;
DocSettingsPage *m_docSettingsPage;
FilterSettingsPage *m_filterSettingsPage;
GeneralSettingsPage *m_generalSettingsPage;
QComboBox *m_documentsCombo;
QComboBox *m_filterComboBox;
Core::SideBar *m_sideBar;
bool m_firstModeChange;
HelpManager *m_helpManager;
OpenPagesManager *m_openPagesManager;
Core::MiniSplitter *m_splitter;
QToolButton *m_closeButton;
};
} // namespace Internal
......
......@@ -29,6 +29,7 @@
#include "searchwidget.h"
#include "helpmanager.h"
#include "openpagesmanager.h"
#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
......@@ -109,7 +110,7 @@ void SearchWidget::showEvent(QShowEvent *event)
connect(queryWidget, SIGNAL(search()), this, SLOT(search()));
connect(resultWidget, SIGNAL(requestShowLink(QUrl)), this,
SIGNAL(requestShowLink(QUrl)));
SIGNAL(linkActivated(QUrl)));
connect(searchEngine, SIGNAL(searchingStarted()), this,
SLOT(searchingStarted()));
......@@ -179,71 +180,47 @@ bool SearchWidget::eventFilter(QObject* o, QEvent *e)
bool controlPressed = me->modifiers() & Qt::ControlModifier;
if((me->button() == Qt::LeftButton && controlPressed)
|| (me->button() == Qt::MidButton)) {
emit requestShowLinkInNewTab(link);
OpenPagesManager::instance().createPageFromSearch(link);
}
}
}
return QWidget::eventFilter(o,e);
}
void SearchWidget::keyPressEvent(QKeyEvent *keyEvent)
{
if (keyEvent->key() == Qt::Key_Escape)
emit escapePressed();
}
void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
{
QMenu menu;
QPoint point = contextMenuEvent->globalPos();
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
if (!browser)
return;
point = browser->mapFromGlobal(point);
QPoint point = browser->mapFromGlobal(contextMenuEvent->globalPos());
if (!browser->rect().contains(point, true))
return;
QUrl link = browser->anchorAt(point);
QKeySequence keySeq(QKeySequence::Copy);
QAction *copyAction = menu.addAction(tr("&Copy") + QLatin1String("\t") +
keySeq.toString(QKeySequence::NativeText));
copyAction->setEnabled(QTextCursor(browser->textCursor()).hasSelection());
QAction *copyAnchorAction = menu.addAction(tr("Copy &Link Location"));
copyAnchorAction->setEnabled(!link.isEmpty() && link.isValid());
keySeq = QKeySequence(Qt::CTRL);
QAction *newTabAction = menu.addAction(tr("Open Link in New Tab") +
QLatin1String("\t") + keySeq.toString(QKeySequence::NativeText) +
QLatin1String("LMB"));
newTabAction->setEnabled(!link.isEmpty() && link.isValid());
menu.addSeparator();
QAction *openLink = 0;
QAction *openLinkInNewTab = 0;
QAction *copyAnchorAction = 0;
keySeq = QKeySequence::SelectAll;
QAction *selectAllAction = menu.addAction(tr("Select All") +
QLatin1String("\t") + keySeq.toString(QKeySequence::NativeText));
QMenu menu;
QUrl link = browser->anchorAt(point);
if (!link.isEmpty() && link.isValid()) {
if (link.isRelative())
link = browser->source().resolved(link);
openLink = menu.addAction(tr("Open Link"));
openLinkInNewTab = menu.addAction(tr("Open Link as New Page"));
copyAnchorAction = menu.addAction(tr("Copy Link"));
} else if (browser->textCursor().hasSelection()) {
menu.addAction(tr("Copy"), browser, SLOT(copy()));
} else {
menu.addAction(tr("Reload"), browser, SLOT(reload()));
}
QAction *usedAction = menu.exec(mapToGlobal(contextMenuEvent->pos()));
if (usedAction == copyAction) {
QTextCursor cursor = browser->textCursor();
if (!cursor.isNull() && cursor.hasSelection()) {
QString selectedText = cursor.selectedText();