OSDN Git Service

9dc1435a2c6a1448cb23235393f8c8fbaae175a5
[qt-creator-jp/qt-creator-jp.git] / src / plugins / help / externalhelpwindow.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "externalhelpwindow.h"
35
36 #include "centralwidget.h"
37 #include "helpconstants.h"
38 #include "openpagesmanager.h"
39
40 #include <coreplugin/coreconstants.h>
41 #include <coreplugin/icore.h>
42
43 #include <QtGui/QAction>
44 #include <QtGui/QHBoxLayout>
45 #include <QtGui/QKeyEvent>
46 #include <QtGui/QStatusBar>
47 #include <QtGui/QToolButton>
48
49 using namespace Help::Internal;
50
51 ExternalHelpWindow::ExternalHelpWindow(QWidget *parent)
52     : QMainWindow(parent)
53 {
54     QSettings *settings = Core::ICore::instance()->settings();
55     settings->beginGroup(Help::Constants::ID_MODE_HELP);
56
57     const QVariant geometry = settings->value(QLatin1String("geometry"));
58     if (geometry.isValid())
59         restoreGeometry(geometry.toByteArray());
60     else
61         resize(640, 480);
62
63     settings->endGroup();
64
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()));
68     addAction(action);
69
70     action = new QAction(this);
71     action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C));
72     connect(action, SIGNAL(triggered()), this, SIGNAL(activateContents()));
73     addAction(action);
74
75     action = new QAction(this);
76     action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Slash));
77     connect(action, SIGNAL(triggered()), this, SIGNAL(activateSearch()));
78     addAction(action);
79
80     action = new QAction(this);
81     action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B));
82     connect(action, SIGNAL(triggered()), this, SIGNAL(activateBookmarks()));
83     addAction(action);
84
85     action = new QAction(this);
86     action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_O));
87     connect(action, SIGNAL(triggered()), this, SIGNAL(activateOpenPages()));
88     addAction(action);
89
90     CentralWidget *centralWidget = CentralWidget::instance();
91
92     action = new QAction(this);
93     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Plus));
94     connect(action, SIGNAL(triggered()), centralWidget, SLOT(zoomIn()));
95     addAction(action);
96
97     action = new QAction(this);
98     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Minus));
99     connect(action, SIGNAL(triggered()), centralWidget, SLOT(zoomOut()));
100     addAction(action);
101
102     action = new QAction(this);
103     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
104     connect(action, SIGNAL(triggered()), this, SIGNAL(addBookmark()));
105     addAction(action);
106
107     action = new QAction(this);
108     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
109     connect(action, SIGNAL(triggered()), centralWidget, SLOT(copy()));
110     addAction(action);
111
112     action = new QAction(this);
113     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
114     connect(action, SIGNAL(triggered()), centralWidget, SLOT(print()));
115     addAction(action);
116
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)));
123
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)));
130
131     QAction *reset = new QAction(this);
132     connect(reset, SIGNAL(triggered()), centralWidget, SLOT(resetZoom()));
133     addAction(reset);
134
135     QAction *ctrlTab = new QAction(this);
136     connect(ctrlTab, SIGNAL(triggered()), &OpenPagesManager::instance(),
137         SLOT(gotoPreviousPage()));
138     addAction(ctrlTab);
139
140     QAction *ctrlShiftTab = new QAction(this);
141     connect(ctrlShiftTab, SIGNAL(triggered()), &OpenPagesManager::instance(),
142         SLOT(gotoNextPage()));
143     addAction(ctrlShiftTab);
144
145     action = new QAction(QIcon(Core::Constants::ICON_TOGGLE_SIDEBAR),
146         tr("Show Sidebar"), this);
147     connect(action, SIGNAL(triggered()), this, SIGNAL(showHideSidebar()));
148
149 #ifdef Q_WS_MAC
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));
154 #else
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));
159 #endif
160
161     QToolButton *button = new QToolButton;
162     button->setDefaultAction(action);
163
164     QStatusBar *statusbar = statusBar();
165     statusbar->show();
166     statusbar->setProperty("p_styled", true);
167     statusbar->addPermanentWidget(button);
168
169     QWidget *w = new QWidget;
170     QHBoxLayout *layout = new QHBoxLayout(w);
171     layout->addStretch(1);
172     statusbar->insertWidget(1, w, 1);
173
174     installEventFilter(this);
175     setWindowTitle(tr("Qt Creator Offline Help"));
176 }
177
178 ExternalHelpWindow::~ExternalHelpWindow()
179 {
180 }
181
182 void ExternalHelpWindow::closeEvent(QCloseEvent *event)
183 {
184     QSettings *settings = Core::ICore::instance()->settings();
185     settings->beginGroup(Help::Constants::ID_MODE_HELP);
186     settings->setValue(QLatin1String("geometry"), saveGeometry());
187     settings->endGroup();
188
189     QMainWindow::closeEvent(event);
190 }
191
192 bool ExternalHelpWindow::eventFilter(QObject *obj, QEvent *event)
193 {
194     if (obj == this) {
195         if (event->type() == QEvent::KeyPress) {
196             QKeyEvent *keyEvent = static_cast<QKeyEvent*> (event);
197             switch (keyEvent->key()) {
198                 case Qt::Key_Escape:
199                     Core::ICore::instance()->mainWindow()->activateWindow();
200                 default:
201                     break;
202             }
203         }
204     }
205     return QMainWindow::eventFilter(obj, event);
206 }