1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "externalhelpwindow.h"
36 #include "centralwidget.h"
37 #include "helpconstants.h"
38 #include "openpagesmanager.h"
40 #include <coreplugin/coreconstants.h>
41 #include <coreplugin/icore.h>
43 #include <QtGui/QAction>
44 #include <QtGui/QHBoxLayout>
45 #include <QtGui/QKeyEvent>
46 #include <QtGui/QStatusBar>
47 #include <QtGui/QToolButton>
49 using namespace Help::Internal;
51 ExternalHelpWindow::ExternalHelpWindow(QWidget *parent)
54 QSettings *settings = Core::ICore::instance()->settings();
55 settings->beginGroup(Help::Constants::ID_MODE_HELP);
57 const QVariant geometry = settings->value(QLatin1String("geometry"));
58 if (geometry.isValid())
59 restoreGeometry(geometry.toByteArray());
65 QAction *action = new QAction(this);
66 action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I));
67 connect(action, SIGNAL(triggered()), this, SIGNAL(activateIndex()));
70 action = new QAction(this);
71 action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C));
72 connect(action, SIGNAL(triggered()), this, SIGNAL(activateContents()));
75 action = new QAction(this);
76 action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Slash));
77 connect(action, SIGNAL(triggered()), this, SIGNAL(activateSearch()));
80 action = new QAction(this);
81 action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B));
82 connect(action, SIGNAL(triggered()), this, SIGNAL(activateBookmarks()));
85 action = new QAction(this);
86 action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_O));
87 connect(action, SIGNAL(triggered()), this, SIGNAL(activateOpenPages()));
90 CentralWidget *centralWidget = CentralWidget::instance();
92 action = new QAction(this);
93 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Plus));
94 connect(action, SIGNAL(triggered()), centralWidget, SLOT(zoomIn()));
97 action = new QAction(this);
98 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Minus));
99 connect(action, SIGNAL(triggered()), centralWidget, SLOT(zoomOut()));
102 action = new QAction(this);
103 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
104 connect(action, SIGNAL(triggered()), this, SIGNAL(addBookmark()));
107 action = new QAction(this);
108 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
109 connect(action, SIGNAL(triggered()), centralWidget, SLOT(copy()));
112 action = new QAction(this);
113 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
114 connect(action, SIGNAL(triggered()), centralWidget, SLOT(print()));
117 action = new QAction(this);
118 action->setShortcut(QKeySequence::Back);
119 action->setEnabled(centralWidget->isBackwardAvailable());
120 connect(action, SIGNAL(triggered()), centralWidget, SLOT(backward()));
121 connect(centralWidget, SIGNAL(backwardAvailable(bool)), action,
122 SLOT(setEnabled(bool)));
124 action = new QAction(this);
125 action->setShortcut(QKeySequence::Forward);
126 action->setEnabled(centralWidget->isForwardAvailable());
127 connect(action, SIGNAL(triggered()), centralWidget, SLOT(forward()));
128 connect(centralWidget, SIGNAL(forwardAvailable(bool)), action,
129 SLOT(setEnabled(bool)));
131 QAction *reset = new QAction(this);
132 connect(reset, SIGNAL(triggered()), centralWidget, SLOT(resetZoom()));
135 QAction *ctrlTab = new QAction(this);
136 connect(ctrlTab, SIGNAL(triggered()), &OpenPagesManager::instance(),
137 SLOT(gotoPreviousPage()));
140 QAction *ctrlShiftTab = new QAction(this);
141 connect(ctrlShiftTab, SIGNAL(triggered()), &OpenPagesManager::instance(),
142 SLOT(gotoNextPage()));
143 addAction(ctrlShiftTab);
145 action = new QAction(QIcon(Core::Constants::ICON_TOGGLE_SIDEBAR),
146 tr("Show Sidebar"), this);
147 connect(action, SIGNAL(triggered()), this, SIGNAL(showHideSidebar()));
150 reset->setShortcut(QKeySequence(Qt::ALT + Qt::Key_0));
151 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_0));
152 ctrlTab->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Tab));
153 ctrlShiftTab->setShortcut(QKeySequence(Qt::ALT + Qt::SHIFT + Qt::Key_Tab));
155 reset->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_0));
156 action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_0));
157 ctrlTab->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Tab));
158 ctrlShiftTab->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab));
161 QToolButton *button = new QToolButton;
162 button->setDefaultAction(action);
164 QStatusBar *statusbar = statusBar();
166 statusbar->setProperty("p_styled", true);
167 statusbar->addPermanentWidget(button);
169 QWidget *w = new QWidget;
170 QHBoxLayout *layout = new QHBoxLayout(w);
171 layout->addStretch(1);
172 statusbar->insertWidget(1, w, 1);
174 installEventFilter(this);
175 setWindowTitle(tr("Qt Creator Offline Help"));
178 ExternalHelpWindow::~ExternalHelpWindow()
182 void ExternalHelpWindow::closeEvent(QCloseEvent *event)
184 QSettings *settings = Core::ICore::instance()->settings();
185 settings->beginGroup(Help::Constants::ID_MODE_HELP);
186 settings->setValue(QLatin1String("geometry"), saveGeometry());
187 settings->endGroup();
189 QMainWindow::closeEvent(event);
192 bool ExternalHelpWindow::eventFilter(QObject *obj, QEvent *event)
195 if (event->type() == QEvent::KeyPress) {
196 QKeyEvent *keyEvent = static_cast<QKeyEvent*> (event);
197 switch (keyEvent->key()) {
199 Core::ICore::instance()->mainWindow()->activateWindow();
205 return QMainWindow::eventFilter(obj, event);