From 597ceed2c42afd2a14145eedb960114ab7b1495c Mon Sep 17 00:00:00 2001 From: kh1 <qt-info@nokia.com> Date: Wed, 4 Aug 2010 15:34:25 +0200 Subject: [PATCH] Make the side bar able to hide, implement missing shortcuts. Reviewed-by: ck --- src/plugins/help/externalhelpwindow.cpp | 87 +++++++++++++++++++++++++ src/plugins/help/externalhelpwindow.h | 11 ++++ src/plugins/help/helpplugin.cpp | 42 +++++++++--- src/plugins/help/helpplugin.h | 2 + src/plugins/help/openpagesswitcher.cpp | 10 +++ 5 files changed, 143 insertions(+), 9 deletions(-) diff --git a/src/plugins/help/externalhelpwindow.cpp b/src/plugins/help/externalhelpwindow.cpp index 36e0113d418..edc2a2dc840 100644 --- a/src/plugins/help/externalhelpwindow.cpp +++ b/src/plugins/help/externalhelpwindow.cpp @@ -28,11 +28,19 @@ **************************************************************************/ #include "externalhelpwindow.h" + +#include "centralwidget.h" #include "helpconstants.h" +#include "openpagesmanager.h" +#include <coreplugin/coreconstants.h> #include <coreplugin/icore.h> +#include <QtGui/QAction> +#include <QtGui/QHBoxLayout> #include <QtGui/QKeyEvent> +#include <QtGui/QStatusBar> +#include <QtGui/QToolButton> using namespace Help::Internal; @@ -49,7 +57,86 @@ ExternalHelpWindow::ExternalHelpWindow(QWidget *parent) resize(640, 480); settings->endGroup(); + + QAction *action = new QAction(this); + action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I)); + connect(action, SIGNAL(triggered()), this, SIGNAL(activateIndex())); + addAction(action); + + action = new QAction(this); + action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C)); + connect(action, SIGNAL(triggered()), this, SIGNAL(activateContents())); + addAction(action); + + action = new QAction(this); + action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Slash)); + connect(action, SIGNAL(triggered()), this, SIGNAL(activateSearch())); + addAction(action); + + action = new QAction(this); + action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B)); + connect(action, SIGNAL(triggered()), this, SIGNAL(activateBookmarks())); + addAction(action); + + action = new QAction(this); + action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_O)); + connect(action, SIGNAL(triggered()), this, SIGNAL(activateOpenPages())); + addAction(action); + + action = new QAction(this); + action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Plus)); + connect(action, SIGNAL(triggered()), CentralWidget::instance(), SLOT(zoomIn())); + addAction(action); + + action = new QAction(this); + action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Minus)); + connect(action, SIGNAL(triggered()), CentralWidget::instance(), SLOT(zoomOut())); + addAction(action); + + action = new QAction(this); + action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_0)); + connect(action, SIGNAL(triggered()), CentralWidget::instance(), SLOT(resetZoom())); + addAction(action); + + QAction *ctrlTab = new QAction(this); + connect(ctrlTab, SIGNAL(triggered()), &OpenPagesManager::instance(), + SLOT(gotoPreviousPage())); + addAction(ctrlTab); + + QAction *ctrlShiftTab = new QAction(this); + connect(ctrlShiftTab, SIGNAL(triggered()), &OpenPagesManager::instance(), + SLOT(gotoNextPage())); + addAction(ctrlShiftTab); + + action = new QAction(QIcon(Core::Constants::ICON_TOGGLE_SIDEBAR), + tr("Show Sidebar"), this); + connect(action, SIGNAL(triggered()), this, SIGNAL(showHideSidebar())); + +#ifdef Q_WS_MAC + action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_0)); + ctrlTab->setShortcut(QKeySequence(tr("Alt+Tab"))); + ctrlShiftTab->setShortcut(QKeySequence(tr("Alt+Shift+Tab"))); +#else + action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_0)); + ctrlTab->setShortcut(QKeySequence(tr("Ctrl+Tab"))); + ctrlShiftTab->setShortcut(QKeySequence(tr("Ctrl+Shift+Tab"))); +#endif + + QToolButton *button = new QToolButton; + button->setDefaultAction(action); + + QStatusBar *statusbar = statusBar(); + statusbar->show(); + statusbar->setProperty("p_styled", true); + statusbar->addPermanentWidget(button); + + QWidget *w = new QWidget; + QHBoxLayout *layout = new QHBoxLayout(w); + layout->addStretch(1); + statusbar->insertWidget(1, w, 1); + installEventFilter(this); + setWindowTitle(tr("Qt Creator Offline Help")); } ExternalHelpWindow::~ExternalHelpWindow() diff --git a/src/plugins/help/externalhelpwindow.h b/src/plugins/help/externalhelpwindow.h index f96117f01fb..8dd72e21850 100644 --- a/src/plugins/help/externalhelpwindow.h +++ b/src/plugins/help/externalhelpwindow.h @@ -33,16 +33,27 @@ #include <QtGui/QMainWindow> QT_FORWARD_DECLARE_CLASS(QCloseEvent) +QT_FORWARD_DECLARE_CLASS(QToolButton) namespace Help { namespace Internal { class ExternalHelpWindow : public QMainWindow { + Q_OBJECT + public: ExternalHelpWindow(QWidget *parent = 0); virtual ~ExternalHelpWindow(); +signals: + void activateIndex(); + void activateContents(); + void activateSearch(); + void activateBookmarks(); + void activateOpenPages(); + void showHideSidebar(); + protected: void closeEvent(QCloseEvent *event); bool eventFilter(QObject *obj, QEvent *event); diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index dc6fa523ae2..9d549a2f911 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -117,8 +117,7 @@ HelpPlugin::HelpPlugin() m_bookmarkItem(0), m_sideBar(0), m_firstModeChange(true), - m_oldMode(0), - m_externalWindow(new ExternalHelpWindow(0)) + m_oldMode(0) { } @@ -208,7 +207,8 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) connect(action, SIGNAL(triggered()), this, SLOT(addBookmark())); // Add Contents, Index, and Context menu items and a separator to the Help menu - action = new QAction(QIcon::fromTheme(QLatin1String("help-contents")), tr(SB_CONTENTS), this); + action = new QAction(QIcon::fromTheme(QLatin1String("help-contents")), + tr(SB_CONTENTS), this); cmd = am->registerAction(action, QLatin1String("Help.Contents"), globalcontext); am->actionContainer(M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP); connect(action, SIGNAL(triggered()), this, SLOT(activateContents())); @@ -324,6 +324,7 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) connect(m_core->modeManager(), SIGNAL(currentModeChanged(Core::IMode*, Core::IMode*)), this, SLOT(modeChanged(Core::IMode*, Core::IMode*))); + m_externalWindow = new ExternalHelpWindow; if (contextHelpOption() == Help::Constants::ExternalHelpAlways) { m_mode = new HelpMode(new QWidget); m_mode->setEnabled(false); @@ -334,9 +335,6 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) } addAutoReleasedObject(m_mode); m_mode->setContext(modecontext); - - connect(Core::ICore::instance(), SIGNAL(coreAboutToClose()), - m_externalWindow, SLOT(close())); return true; } @@ -561,8 +559,8 @@ void HelpPlugin::createRightPaneContextViewer() Core::Context(Constants::C_HELP_SIDEBAR), this)); QAction *copy = new QAction(this); - Core::Command *cmd = m_core->actionManager()->registerAction(copy, Core::Constants::COPY, - Core::Context(Constants::C_HELP_SIDEBAR)); + Core::Command *cmd = m_core->actionManager()->registerAction(copy, + Core::Constants::COPY, Core::Context(Constants::C_HELP_SIDEBAR)); copy->setText(cmd->action()->text()); copy->setIcon(cmd->action()->icon()); @@ -600,14 +598,21 @@ void HelpPlugin::slotHideRightPane() Core::RightPaneWidget::instance()->setShown(false); } +void HelpPlugin::showHideSidebar() +{ + m_sideBar->setVisible(!m_sideBar->isVisible()); +} + void HelpPlugin::showExternalWindow() { bool firstTime = m_firstModeChange; setup(); m_externalWindow->show(); m_externalWindow->activateWindow(); - if (firstTime) + if (firstTime) { + connectExternalHelpWindow(); Core::ICore::instance()->mainWindow()->activateWindow(); + } } void HelpPlugin::modeChanged(Core::IMode *mode, Core::IMode *old) @@ -707,6 +712,7 @@ void HelpPlugin::contextHelpOptionChanged() m_mode->setEnabled(true); m_externalWindow->close(); + m_sideBar->setVisible(true); } } } @@ -1005,4 +1011,22 @@ int HelpPlugin::contextHelpOption() const Help::Constants::SideBySideIfPossible).toInt(); } +void HelpPlugin::connectExternalHelpWindow() +{ + connect(Core::ICore::instance(), SIGNAL(coreAboutToClose()), + m_externalWindow, SLOT(close())); + connect(m_externalWindow, SIGNAL(activateIndex()), this, + SLOT(activateIndex())); + connect(m_externalWindow, SIGNAL(activateContents()), this, + SLOT(activateContents())); + connect(m_externalWindow, SIGNAL(activateSearch()), this, + SLOT(activateSearch())); + connect(m_externalWindow, SIGNAL(activateBookmarks()), this, + SLOT(activateBookmarks())); + connect(m_externalWindow, SIGNAL(activateOpenPages()), this, + SLOT(activateOpenPages())); + connect(m_externalWindow, SIGNAL(showHideSidebar()), this, + SLOT(showHideSidebar())); +} + Q_EXPORT_PLUGIN(HelpPlugin) diff --git a/src/plugins/help/helpplugin.h b/src/plugins/help/helpplugin.h index 8ba4457b778..08171f1aabb 100644 --- a/src/plugins/help/helpplugin.h +++ b/src/plugins/help/helpplugin.h @@ -91,6 +91,7 @@ private slots: void switchToHelpMode(); void switchToHelpMode(const QUrl &source); void slotHideRightPane(); + void showHideSidebar(); void updateSideBarSource(); void updateSideBarSource(const QUrl &newUrl); @@ -114,6 +115,7 @@ private: void setup(); int contextHelpOption() const; + void connectExternalHelpWindow(); private: HelpMode *m_mode; diff --git a/src/plugins/help/openpagesswitcher.cpp b/src/plugins/help/openpagesswitcher.cpp index 9cdf4bfacf2..9c5705c5f5b 100644 --- a/src/plugins/help/openpagesswitcher.cpp +++ b/src/plugins/help/openpagesswitcher.cpp @@ -124,6 +124,16 @@ bool OpenPagesSwitcher::eventFilter(QObject *object, QEvent *event) emit setCurrentPage(m_openPagesWidget->currentIndex()); return true; } + + Qt::KeyboardModifier modifier = Qt::ControlModifier; +#ifdef Q_WS_MAC + modifier = Qt::AltModifier; +#endif + if (key == Qt::Key_Backtab + && (ke->modifiers() == (modifier | Qt::ShiftModifier))) + gotoNextPage(); + else if (key == Qt::Key_Tab && (ke->modifiers() == modifier)) + gotoPreviousPage(); } else if (event->type() == QEvent::KeyRelease) { QKeyEvent *ke = static_cast<QKeyEvent*>(event); if (ke->modifiers() == 0 -- GitLab