diff --git a/src/plugins/help/help.pro b/src/plugins/help/help.pro index c8164485c8ce1f8a586a3e8761e8aff730da7c1d..56e1668f0f1914103b1409eb2edcab9fa95abd7f 100644 --- a/src/plugins/help/help.pro +++ b/src/plugins/help/help.pro @@ -24,6 +24,7 @@ HEADERS += \ helpviewer_p.h \ openpagesmanager.h \ openpagesmodel.h \ + openpagesswicher.h \ openpageswidget.h \ searchwidget.h \ xbelsupport.h @@ -43,6 +44,7 @@ SOURCES += \ helpviewer_qwv.cpp \ openpagesmanager.cpp \ openpagesmodel.cpp \ + openpagesswicher.cpp \ openpageswidget.cpp \ searchwidget.cpp \ xbelsupport.cpp diff --git a/src/plugins/help/helpmanager.cpp b/src/plugins/help/helpmanager.cpp index 2cac288d94fbe877f3c2f45a4907d8a2cef23e4c..300d313e0cd9df542ccacc0ca61a5f83ce022c3c 100644 --- a/src/plugins/help/helpmanager.cpp +++ b/src/plugins/help/helpmanager.cpp @@ -63,17 +63,17 @@ HelpManager::HelpManager(QObject *parent) HelpManager::~HelpManager() { - delete m_guiEngine; - m_guiEngine = 0; - - delete m_coreEngine; - m_coreEngine = 0; - if (m_bookmarkManager) { m_bookmarkManager->saveBookmarks(); delete m_bookmarkManager; m_bookmarkManager = 0; } + + delete m_guiEngine; + m_guiEngine = 0; + + delete m_coreEngine; + m_coreEngine = 0; } HelpManager& HelpManager::instance() diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index fa4958889890bb1c849cca202dfb75fcd5af62a7..7c93195653ac132ae1e6d00238994b7742c3ebba 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -224,31 +224,57 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) action->setText(cmd->action()->text()); action->setIcon(cmd->action()->icon()); - if (Core::ActionContainer *advancedMenu = - am->actionContainer(Core::Constants::M_EDIT_ADVANCED)) { + if (Core::ActionContainer *advancedMenu = am->actionContainer(M_EDIT_ADVANCED)) { // reuse TextEditor constants to avoid a second pair of menu actions - QAction *a = new QAction(tr("Increase Font Size"), this); - cmd = am->registerAction(a, TextEditor::Constants::INCREASE_FONT_SIZE, + action = new QAction(tr("Increase Font Size"), this); + cmd = am->registerAction(action, TextEditor::Constants::INCREASE_FONT_SIZE, modecontext); cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl++"))); - connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(zoomIn())); + connect(action, SIGNAL(triggered()), m_centralWidget, SLOT(zoomIn())); advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT); - a = new QAction(tr("Decrease Font Size"), this); - cmd = am->registerAction(a, TextEditor::Constants::DECREASE_FONT_SIZE, + action = new QAction(tr("Decrease Font Size"), this); + cmd = am->registerAction(action, TextEditor::Constants::DECREASE_FONT_SIZE, modecontext); cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+-"))); - connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(zoomOut())); + connect(action, SIGNAL(triggered()), m_centralWidget, SLOT(zoomOut())); advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT); - a = new QAction(tr("Reset Font Size"), this); - cmd = am->registerAction(a, TextEditor::Constants::RESET_FONT_SIZE, + action = new QAction(tr("Reset Font Size"), this); + cmd = am->registerAction(action, TextEditor::Constants::RESET_FONT_SIZE, modecontext); cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+0"))); - connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(resetZoom())); + connect(action, SIGNAL(triggered()), m_centralWidget, SLOT(resetZoom())); advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT); } + if (Core::ActionContainer *windowMenu = am->actionContainer(M_WINDOW)) { + // reuse EditorManager constants to avoid a second pair of menu actions + action = new QAction(QApplication::tr("EditorManager", + "Next Open Document in History"), this); + Core::Command *ctrlTab = am->registerAction(action, GOTOPREVINHISTORY, + modecontext); // Goto Previous In History Action + windowMenu->addAction(ctrlTab, Core::Constants::G_WINDOW_NAVIGATE); + connect(action, SIGNAL(triggered()), &OpenPagesManager::instance(), + SLOT(gotoPreviousPage())); + + action = new QAction(QApplication::tr("EditorManager", + "Previous Open Document in History"), this); + Core::Command *ctrlShiftTab = am->registerAction(action, GOTONEXTINHISTORY, + modecontext); // Goto Next In History Action + windowMenu->addAction(ctrlShiftTab, Core::Constants::G_WINDOW_NAVIGATE); + connect(action, SIGNAL(triggered()), &OpenPagesManager::instance(), + SLOT(gotoNextPage())); + +#ifdef Q_WS_MAC + ctrlTab->setDefaultKeySequence(QKeySequence(tr("Alt+Tab"))); + ctrlShiftTab->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+Tab"))); +#else + ctrlTab->setDefaultKeySequence(QKeySequence(tr("Ctrl+Tab"))); + ctrlShiftTab->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+Tab"))); +#endif + } + Aggregation::Aggregate *agg = new Aggregation::Aggregate; agg->add(m_centralWidget); agg->add(new HelpFindSupport(m_centralWidget)); diff --git a/src/plugins/help/openpagesmanager.cpp b/src/plugins/help/openpagesmanager.cpp index 1b9290814971fa28b68339a45585003a98df402d..10591c6c00f259e98961128ca4383125db76dc74 100644 --- a/src/plugins/help/openpagesmanager.cpp +++ b/src/plugins/help/openpagesmanager.cpp @@ -34,8 +34,10 @@ #include "helpmanager.h" #include "helpviewer.h" #include "openpagesmodel.h" +#include "openpagesswicher.h" #include "openpageswidget.h" +#include <QtGui/QApplication> #include <QtGui/QComboBox> #include <QtGui/QTreeView> @@ -52,6 +54,7 @@ OpenPagesManager::OpenPagesManager(QObject *parent) , m_comboBox(0) , m_model(0) , m_openPagesWidget(0) + , m_openPagesSwicher(0) { Q_ASSERT(!m_instance); @@ -70,6 +73,18 @@ OpenPagesManager::OpenPagesManager(QObject *parent) m_comboBox->setModel(m_model); m_comboBox->setMinimumContentsLength(40); connect(m_comboBox, SIGNAL(activated(int)), this, SLOT(setCurrentPage(int))); + + m_openPagesSwicher = new OpenPagesSwicher(m_model); + connect(m_openPagesSwicher, SIGNAL(closePage(QModelIndex)), this, + SLOT(closePage(QModelIndex))); + connect(m_openPagesSwicher, SIGNAL(setCurrentPage(QModelIndex)), this, + SLOT(setCurrentPage(QModelIndex))); +} + +OpenPagesManager ::~OpenPagesManager() +{ + m_instance = 0; + delete m_openPagesSwicher; } OpenPagesManager &OpenPagesManager::instance() @@ -153,6 +168,7 @@ void OpenPagesManager::setupInitialPages() emit pagesChanged(); setCurrentPage(initialPage); + m_openPagesSwicher->selectCurrentPage(); } // -- public slots @@ -186,18 +202,16 @@ HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch) void OpenPagesManager::setCurrentPage(int index) { - m_comboBox->setCurrentIndex(index); CentralWidget::instance()->setCurrentPage(m_model->pageAt(index)); - selectCurrentPage(); // update the selection inside the tree view + m_comboBox->setCurrentIndex(index); + m_openPagesWidget->selectCurrentPage(); } void OpenPagesManager::setCurrentPage(const QModelIndex &index) { - if (index.isValid()) { - m_comboBox->setCurrentIndex(index.row()); - CentralWidget::instance()->setCurrentPage(m_model->pageAt(index.row())); - } + if (index.isValid()) + setCurrentPage(index.row()); } void OpenPagesManager::closeCurrentPage() @@ -230,17 +244,30 @@ void OpenPagesManager::closePagesExcept(const QModelIndex &index) } } -// -- private +void OpenPagesManager::gotoNextPage() +{ + if (!m_openPagesSwicher->isVisible()) { + m_openPagesSwicher->selectCurrentPage(); + m_openPagesSwicher->gotoNextPage(); + showTwicherOrSelectPage(); + } else { + m_openPagesSwicher->gotoNextPage(); + } +} -void OpenPagesManager::selectCurrentPage() +void OpenPagesManager::gotoPreviousPage() { - QItemSelectionModel * 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()); + if (!m_openPagesSwicher->isVisible()) { + m_openPagesSwicher->selectCurrentPage(); + m_openPagesSwicher->gotoPreviousPage(); + showTwicherOrSelectPage(); + } else { + m_openPagesSwicher->gotoPreviousPage(); + } } +// -- private + void OpenPagesManager::removePage(int index) { Q_ASSERT(m_model->rowCount() > 1); @@ -249,5 +276,19 @@ void OpenPagesManager::removePage(int index) CentralWidget::instance()->removePage(index); emit pagesChanged(); - selectCurrentPage(); // update the selection inside the tree view + m_openPagesWidget->selectCurrentPage(); +} + +void OpenPagesManager::showTwicherOrSelectPage() const +{ + if (QApplication::keyboardModifiers() != Qt::NoModifier) { + const int width = CentralWidget::instance()->width(); + const int height = CentralWidget::instance()->height(); + const QPoint p(CentralWidget::instance()->mapToGlobal(QPoint(0, 0))); + m_openPagesSwicher->move((width - m_openPagesSwicher->width()) / 2 + p.x(), + (height - m_openPagesSwicher->height()) / 2 + p.y()); + m_openPagesSwicher->setVisible(true); + } else { + m_openPagesSwicher->selectAndHide(); + } } diff --git a/src/plugins/help/openpagesmanager.h b/src/plugins/help/openpagesmanager.h index aa1303a2ce94642ae079887212dca12d38fa8e78..e1d21530b8b8c95ac816077793038fb0dceef6f3 100644 --- a/src/plugins/help/openpagesmanager.h +++ b/src/plugins/help/openpagesmanager.h @@ -44,6 +44,8 @@ namespace Help { class HelpViewer; class OpenPagesModel; +class OpenPagesSwicher; +class OpenPagesWidget; class OpenPagesManager : public QObject { @@ -51,6 +53,7 @@ class OpenPagesManager : public QObject public: OpenPagesManager(QObject *parent = 0); + ~OpenPagesManager(); static OpenPagesManager &instance(); @@ -72,17 +75,21 @@ public slots: void closePage(const QModelIndex &index); void closePagesExcept(const QModelIndex &index); + void gotoNextPage(); + void gotoPreviousPage(); + signals: void pagesChanged(); private: - void selectCurrentPage(); void removePage(int index); + void showTwicherOrSelectPage() const; private: QComboBox *m_comboBox; OpenPagesModel *m_model; - QTreeView *m_openPagesWidget; + OpenPagesWidget *m_openPagesWidget; + OpenPagesSwicher *m_openPagesSwicher; static OpenPagesManager *m_instance; }; diff --git a/src/plugins/help/openpagesswicher.cpp b/src/plugins/help/openpagesswicher.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a52a701514ef5ded74d8609503cc1a43757f5e9f --- /dev/null +++ b/src/plugins/help/openpagesswicher.cpp @@ -0,0 +1,151 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** 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 "openpagesswicher.h" + +#include "centralwidget.h" +#include "openpagesmodel.h" +#include "openpageswidget.h" + +#include <QtCore/QEvent> + +#include <QtGui/QKeyEvent> + +using namespace Help::Internal; + +const int gMargin = 4; +const int gWidth = 300; +const int gHeight = 200; + +OpenPagesSwicher::OpenPagesSwicher(OpenPagesModel *model) + : QWidget(0, Qt::Popup) + , m_openPagesModel(model) +{ + resize(gWidth, gHeight); + + m_openPagesWidget = new OpenPagesWidget(m_openPagesModel, this); + + m_openPagesWidget->allowContextMenu(false); + m_openPagesWidget->installEventFilter(this); + m_openPagesWidget->setTextElideMode(Qt::ElideMiddle); + m_openPagesWidget->setGeometry(gMargin, gMargin, gWidth - 2 * gMargin, + gHeight - 2 * gMargin); + + connect(m_openPagesWidget, SIGNAL(closePage(QModelIndex)), this, + SIGNAL(closePage(QModelIndex))); + connect(m_openPagesWidget, SIGNAL(setCurrentPage(QModelIndex)), this, + SIGNAL(setCurrentPage(QModelIndex))); +} + +OpenPagesSwicher::~OpenPagesSwicher() +{ +} + +void OpenPagesSwicher::gotoNextPage() +{ + selectPageUpDown(-1); +} + +void OpenPagesSwicher::gotoPreviousPage() +{ + selectPageUpDown(1); +} + +void OpenPagesSwicher::selectAndHide() +{ + setVisible(false); + emit setCurrentPage(m_openPagesWidget->currentIndex()); +} + +void OpenPagesSwicher::selectCurrentPage() +{ + m_openPagesWidget->selectCurrentPage(); +} + +void OpenPagesSwicher::setVisible(bool visible) +{ + QWidget::setVisible(visible); + if (visible) + setFocus(); +} + +void OpenPagesSwicher::focusInEvent(QFocusEvent *event) +{ + Q_UNUSED(event) + m_openPagesWidget->setFocus(); +} + +bool OpenPagesSwicher::eventFilter(QObject *object, QEvent *event) +{ + if (object == m_openPagesWidget) { + if (event->type() == QEvent::KeyPress) { + QKeyEvent *ke = static_cast<QKeyEvent*>(event); + if (ke->key() == Qt::Key_Escape) { + setVisible(false); + return true; + } + + const int key = ke->key(); + if (key == Qt::Key_Return || key == Qt::Key_Enter || key == Qt::Key_Space) { + emit setCurrentPage(m_openPagesWidget->currentIndex()); + return true; + } + } else if (event->type() == QEvent::KeyRelease) { + QKeyEvent *ke = static_cast<QKeyEvent*>(event); + if (ke->modifiers() == 0 + /*HACK this is to overcome some event inconsistencies between platforms*/ + || (ke->modifiers() == Qt::AltModifier + && (ke->key() == Qt::Key_Alt || ke->key() == -1))) { + selectAndHide(); + } + } + } + return QWidget::eventFilter(object, event); +} + +void OpenPagesSwicher::selectPageUpDown(int summand) +{ + const int pageCount = m_openPagesModel->rowCount(); + if (pageCount < 2) + return; + + const QModelIndexList &list = m_openPagesWidget->selectionModel()->selectedIndexes(); + if (list.isEmpty()) + return; + + QModelIndex index = list.first(); + if (!index.isValid()) + return; + + index = m_openPagesModel->index((index.row() + summand + pageCount) % pageCount, 0); + if (index.isValid()) { + m_openPagesWidget->setCurrentIndex(index); + m_openPagesWidget->scrollTo(index, QAbstractItemView::PositionAtCenter); + } +} diff --git a/src/plugins/help/openpagesswicher.h b/src/plugins/help/openpagesswicher.h new file mode 100644 index 0000000000000000000000000000000000000000..7aaf0fda2b348af5e30565c18cf47d9d20daf980 --- /dev/null +++ b/src/plugins/help/openpagesswicher.h @@ -0,0 +1,76 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** 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 OPENPAGESSWICHER_H +#define OPENPAGESSWICHER_H + +#include <QtGui/QWidget> + +QT_FORWARD_DECLARE_CLASS(QModelIndex) + +namespace Help { + namespace Internal { + +class OpenPagesModel; +class OpenPagesWidget; + +class OpenPagesSwicher : public QWidget +{ + Q_OBJECT + +public: + OpenPagesSwicher(OpenPagesModel *model); + ~OpenPagesSwicher(); + + void gotoNextPage(); + void gotoPreviousPage(); + + void selectAndHide(); + void selectCurrentPage(); + + void setVisible(bool visible); + void focusInEvent(QFocusEvent *event); + bool eventFilter(QObject *object, QEvent *event); + +signals: + void closePage(const QModelIndex &index); + void setCurrentPage(const QModelIndex &index); + +private: + void selectPageUpDown(int summand); + +private: + OpenPagesModel *m_openPagesModel; + OpenPagesWidget *m_openPagesWidget; +}; + + } // namespace Internal +} // namespace Help + +#endif // OPENPAGESSWICHER_H diff --git a/src/plugins/help/openpageswidget.cpp b/src/plugins/help/openpageswidget.cpp index 3d19778261251bc2c3140903d83c37b1ac526246..ae539224fefccc5da2cb57c5d487c8a17b7b8196 100644 --- a/src/plugins/help/openpageswidget.cpp +++ b/src/plugins/help/openpageswidget.cpp @@ -28,6 +28,8 @@ **************************************************************************/ #include "openpageswidget.h" + +#include "centralwidget.h" #include "openpagesmodel.h" #include <QtGui/QApplication> @@ -80,7 +82,9 @@ void OpenPagesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt // -- OpenPagesWidget -OpenPagesWidget::OpenPagesWidget(OpenPagesModel *model) +OpenPagesWidget::OpenPagesWidget(OpenPagesModel *model, QWidget *parent) + : QTreeView(parent) + , m_allowContextMenu(true) { setModel(model); setIndentation(0); @@ -116,12 +120,26 @@ OpenPagesWidget::~OpenPagesWidget() { } +void OpenPagesWidget::selectCurrentPage() +{ + QItemSelectionModel * const selModel = selectionModel(); + selModel->clearSelection(); + selModel->select(model()->index(CentralWidget::instance()->currentIndex(), 0), + QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + scrollTo(currentIndex()); +} + +void OpenPagesWidget::allowContextMenu(bool ok) +{ + m_allowContextMenu = ok; +} + // -- private slots void OpenPagesWidget::contextMenuRequested(QPoint pos) { const QModelIndex &index = indexAt(pos); - if (!index.isValid()) + if (!index.isValid() || !m_allowContextMenu) return; QMenu contextMenu; diff --git a/src/plugins/help/openpageswidget.h b/src/plugins/help/openpageswidget.h index ad7a5535464118feb44173313c65ed37e598981c..5a951ff071b468a3ea7ca6b51208d6a648aa9505 100644 --- a/src/plugins/help/openpageswidget.h +++ b/src/plugins/help/openpageswidget.h @@ -56,9 +56,12 @@ class OpenPagesWidget : public QTreeView Q_OBJECT public: - OpenPagesWidget(OpenPagesModel *model); + OpenPagesWidget(OpenPagesModel *model, QWidget *parent = 0); ~OpenPagesWidget(); + void selectCurrentPage(); + void allowContextMenu(bool ok); + signals: void setCurrentPage(const QModelIndex &index); @@ -74,6 +77,7 @@ private: bool eventFilter(QObject *obj, QEvent *event); private: + bool m_allowContextMenu; OpenPagesDelegate *m_delegate; };