forked from qt-creator/qt-creator
Implement Ctrl+Tab/Ctrl+Shift+Tab support to cycle thru open pages.
Reviewed-by: ck
This commit is contained in:
@@ -24,6 +24,7 @@ HEADERS += \
|
|||||||
helpviewer_p.h \
|
helpviewer_p.h \
|
||||||
openpagesmanager.h \
|
openpagesmanager.h \
|
||||||
openpagesmodel.h \
|
openpagesmodel.h \
|
||||||
|
openpagesswicher.h \
|
||||||
openpageswidget.h \
|
openpageswidget.h \
|
||||||
searchwidget.h \
|
searchwidget.h \
|
||||||
xbelsupport.h
|
xbelsupport.h
|
||||||
@@ -43,6 +44,7 @@ SOURCES += \
|
|||||||
helpviewer_qwv.cpp \
|
helpviewer_qwv.cpp \
|
||||||
openpagesmanager.cpp \
|
openpagesmanager.cpp \
|
||||||
openpagesmodel.cpp \
|
openpagesmodel.cpp \
|
||||||
|
openpagesswicher.cpp \
|
||||||
openpageswidget.cpp \
|
openpageswidget.cpp \
|
||||||
searchwidget.cpp \
|
searchwidget.cpp \
|
||||||
xbelsupport.cpp
|
xbelsupport.cpp
|
||||||
|
|||||||
@@ -63,17 +63,17 @@ HelpManager::HelpManager(QObject *parent)
|
|||||||
|
|
||||||
HelpManager::~HelpManager()
|
HelpManager::~HelpManager()
|
||||||
{
|
{
|
||||||
delete m_guiEngine;
|
|
||||||
m_guiEngine = 0;
|
|
||||||
|
|
||||||
delete m_coreEngine;
|
|
||||||
m_coreEngine = 0;
|
|
||||||
|
|
||||||
if (m_bookmarkManager) {
|
if (m_bookmarkManager) {
|
||||||
m_bookmarkManager->saveBookmarks();
|
m_bookmarkManager->saveBookmarks();
|
||||||
delete m_bookmarkManager;
|
delete m_bookmarkManager;
|
||||||
m_bookmarkManager = 0;
|
m_bookmarkManager = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete m_guiEngine;
|
||||||
|
m_guiEngine = 0;
|
||||||
|
|
||||||
|
delete m_coreEngine;
|
||||||
|
m_coreEngine = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
HelpManager& HelpManager::instance()
|
HelpManager& HelpManager::instance()
|
||||||
|
|||||||
@@ -224,31 +224,57 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
action->setText(cmd->action()->text());
|
action->setText(cmd->action()->text());
|
||||||
action->setIcon(cmd->action()->icon());
|
action->setIcon(cmd->action()->icon());
|
||||||
|
|
||||||
if (Core::ActionContainer *advancedMenu =
|
if (Core::ActionContainer *advancedMenu = am->actionContainer(M_EDIT_ADVANCED)) {
|
||||||
am->actionContainer(Core::Constants::M_EDIT_ADVANCED)) {
|
|
||||||
// reuse TextEditor constants to avoid a second pair of menu actions
|
// reuse TextEditor constants to avoid a second pair of menu actions
|
||||||
QAction *a = new QAction(tr("Increase Font Size"), this);
|
action = new QAction(tr("Increase Font Size"), this);
|
||||||
cmd = am->registerAction(a, TextEditor::Constants::INCREASE_FONT_SIZE,
|
cmd = am->registerAction(action, TextEditor::Constants::INCREASE_FONT_SIZE,
|
||||||
modecontext);
|
modecontext);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl++")));
|
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);
|
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
|
||||||
|
|
||||||
a = new QAction(tr("Decrease Font Size"), this);
|
action = new QAction(tr("Decrease Font Size"), this);
|
||||||
cmd = am->registerAction(a, TextEditor::Constants::DECREASE_FONT_SIZE,
|
cmd = am->registerAction(action, TextEditor::Constants::DECREASE_FONT_SIZE,
|
||||||
modecontext);
|
modecontext);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+-")));
|
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);
|
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
|
||||||
|
|
||||||
a = new QAction(tr("Reset Font Size"), this);
|
action = new QAction(tr("Reset Font Size"), this);
|
||||||
cmd = am->registerAction(a, TextEditor::Constants::RESET_FONT_SIZE,
|
cmd = am->registerAction(action, TextEditor::Constants::RESET_FONT_SIZE,
|
||||||
modecontext);
|
modecontext);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+0")));
|
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);
|
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;
|
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
|
||||||
agg->add(m_centralWidget);
|
agg->add(m_centralWidget);
|
||||||
agg->add(new HelpFindSupport(m_centralWidget));
|
agg->add(new HelpFindSupport(m_centralWidget));
|
||||||
|
|||||||
@@ -34,8 +34,10 @@
|
|||||||
#include "helpmanager.h"
|
#include "helpmanager.h"
|
||||||
#include "helpviewer.h"
|
#include "helpviewer.h"
|
||||||
#include "openpagesmodel.h"
|
#include "openpagesmodel.h"
|
||||||
|
#include "openpagesswicher.h"
|
||||||
#include "openpageswidget.h"
|
#include "openpageswidget.h"
|
||||||
|
|
||||||
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QComboBox>
|
#include <QtGui/QComboBox>
|
||||||
#include <QtGui/QTreeView>
|
#include <QtGui/QTreeView>
|
||||||
|
|
||||||
@@ -52,6 +54,7 @@ OpenPagesManager::OpenPagesManager(QObject *parent)
|
|||||||
, m_comboBox(0)
|
, m_comboBox(0)
|
||||||
, m_model(0)
|
, m_model(0)
|
||||||
, m_openPagesWidget(0)
|
, m_openPagesWidget(0)
|
||||||
|
, m_openPagesSwicher(0)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_instance);
|
Q_ASSERT(!m_instance);
|
||||||
|
|
||||||
@@ -70,6 +73,18 @@ OpenPagesManager::OpenPagesManager(QObject *parent)
|
|||||||
m_comboBox->setModel(m_model);
|
m_comboBox->setModel(m_model);
|
||||||
m_comboBox->setMinimumContentsLength(40);
|
m_comboBox->setMinimumContentsLength(40);
|
||||||
connect(m_comboBox, SIGNAL(activated(int)), this, SLOT(setCurrentPage(int)));
|
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()
|
OpenPagesManager &OpenPagesManager::instance()
|
||||||
@@ -153,6 +168,7 @@ void OpenPagesManager::setupInitialPages()
|
|||||||
|
|
||||||
emit pagesChanged();
|
emit pagesChanged();
|
||||||
setCurrentPage(initialPage);
|
setCurrentPage(initialPage);
|
||||||
|
m_openPagesSwicher->selectCurrentPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- public slots
|
// -- public slots
|
||||||
@@ -186,18 +202,16 @@ HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch)
|
|||||||
|
|
||||||
void OpenPagesManager::setCurrentPage(int index)
|
void OpenPagesManager::setCurrentPage(int index)
|
||||||
{
|
{
|
||||||
m_comboBox->setCurrentIndex(index);
|
|
||||||
CentralWidget::instance()->setCurrentPage(m_model->pageAt(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)
|
void OpenPagesManager::setCurrentPage(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
if (index.isValid()) {
|
if (index.isValid())
|
||||||
m_comboBox->setCurrentIndex(index.row());
|
setCurrentPage(index.row());
|
||||||
CentralWidget::instance()->setCurrentPage(m_model->pageAt(index.row()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenPagesManager::closeCurrentPage()
|
void OpenPagesManager::closeCurrentPage()
|
||||||
@@ -230,17 +244,30 @@ void OpenPagesManager::closePagesExcept(const QModelIndex &index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- private
|
void OpenPagesManager::gotoNextPage()
|
||||||
|
|
||||||
void OpenPagesManager::selectCurrentPage()
|
|
||||||
{
|
{
|
||||||
QItemSelectionModel * selModel = m_openPagesWidget->selectionModel();
|
if (!m_openPagesSwicher->isVisible()) {
|
||||||
selModel->clearSelection();
|
m_openPagesSwicher->selectCurrentPage();
|
||||||
selModel->select(m_model->index(CentralWidget::instance()->currentIndex(), 0),
|
m_openPagesSwicher->gotoNextPage();
|
||||||
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
showTwicherOrSelectPage();
|
||||||
m_openPagesWidget->scrollTo(m_openPagesWidget->currentIndex());
|
} else {
|
||||||
|
m_openPagesSwicher->gotoNextPage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenPagesManager::gotoPreviousPage()
|
||||||
|
{
|
||||||
|
if (!m_openPagesSwicher->isVisible()) {
|
||||||
|
m_openPagesSwicher->selectCurrentPage();
|
||||||
|
m_openPagesSwicher->gotoPreviousPage();
|
||||||
|
showTwicherOrSelectPage();
|
||||||
|
} else {
|
||||||
|
m_openPagesSwicher->gotoPreviousPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- private
|
||||||
|
|
||||||
void OpenPagesManager::removePage(int index)
|
void OpenPagesManager::removePage(int index)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_model->rowCount() > 1);
|
Q_ASSERT(m_model->rowCount() > 1);
|
||||||
@@ -249,5 +276,19 @@ void OpenPagesManager::removePage(int index)
|
|||||||
CentralWidget::instance()->removePage(index);
|
CentralWidget::instance()->removePage(index);
|
||||||
|
|
||||||
emit pagesChanged();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ namespace Help {
|
|||||||
|
|
||||||
class HelpViewer;
|
class HelpViewer;
|
||||||
class OpenPagesModel;
|
class OpenPagesModel;
|
||||||
|
class OpenPagesSwicher;
|
||||||
|
class OpenPagesWidget;
|
||||||
|
|
||||||
class OpenPagesManager : public QObject
|
class OpenPagesManager : public QObject
|
||||||
{
|
{
|
||||||
@@ -51,6 +53,7 @@ class OpenPagesManager : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
OpenPagesManager(QObject *parent = 0);
|
OpenPagesManager(QObject *parent = 0);
|
||||||
|
~OpenPagesManager();
|
||||||
|
|
||||||
static OpenPagesManager &instance();
|
static OpenPagesManager &instance();
|
||||||
|
|
||||||
@@ -72,17 +75,21 @@ public slots:
|
|||||||
void closePage(const QModelIndex &index);
|
void closePage(const QModelIndex &index);
|
||||||
void closePagesExcept(const QModelIndex &index);
|
void closePagesExcept(const QModelIndex &index);
|
||||||
|
|
||||||
|
void gotoNextPage();
|
||||||
|
void gotoPreviousPage();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void pagesChanged();
|
void pagesChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void selectCurrentPage();
|
|
||||||
void removePage(int index);
|
void removePage(int index);
|
||||||
|
void showTwicherOrSelectPage() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QComboBox *m_comboBox;
|
QComboBox *m_comboBox;
|
||||||
OpenPagesModel *m_model;
|
OpenPagesModel *m_model;
|
||||||
QTreeView *m_openPagesWidget;
|
OpenPagesWidget *m_openPagesWidget;
|
||||||
|
OpenPagesSwicher *m_openPagesSwicher;
|
||||||
|
|
||||||
static OpenPagesManager *m_instance;
|
static OpenPagesManager *m_instance;
|
||||||
};
|
};
|
||||||
|
|||||||
151
src/plugins/help/openpagesswicher.cpp
Normal file
151
src/plugins/help/openpagesswicher.cpp
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
76
src/plugins/help/openpagesswicher.h
Normal file
76
src/plugins/help/openpagesswicher.h
Normal file
@@ -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
|
||||||
@@ -28,6 +28,8 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "openpageswidget.h"
|
#include "openpageswidget.h"
|
||||||
|
|
||||||
|
#include "centralwidget.h"
|
||||||
#include "openpagesmodel.h"
|
#include "openpagesmodel.h"
|
||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
@@ -80,7 +82,9 @@ void OpenPagesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt
|
|||||||
|
|
||||||
// -- OpenPagesWidget
|
// -- OpenPagesWidget
|
||||||
|
|
||||||
OpenPagesWidget::OpenPagesWidget(OpenPagesModel *model)
|
OpenPagesWidget::OpenPagesWidget(OpenPagesModel *model, QWidget *parent)
|
||||||
|
: QTreeView(parent)
|
||||||
|
, m_allowContextMenu(true)
|
||||||
{
|
{
|
||||||
setModel(model);
|
setModel(model);
|
||||||
setIndentation(0);
|
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
|
// -- private slots
|
||||||
|
|
||||||
void OpenPagesWidget::contextMenuRequested(QPoint pos)
|
void OpenPagesWidget::contextMenuRequested(QPoint pos)
|
||||||
{
|
{
|
||||||
const QModelIndex &index = indexAt(pos);
|
const QModelIndex &index = indexAt(pos);
|
||||||
if (!index.isValid())
|
if (!index.isValid() || !m_allowContextMenu)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QMenu contextMenu;
|
QMenu contextMenu;
|
||||||
|
|||||||
@@ -56,9 +56,12 @@ class OpenPagesWidget : public QTreeView
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenPagesWidget(OpenPagesModel *model);
|
OpenPagesWidget(OpenPagesModel *model, QWidget *parent = 0);
|
||||||
~OpenPagesWidget();
|
~OpenPagesWidget();
|
||||||
|
|
||||||
|
void selectCurrentPage();
|
||||||
|
void allowContextMenu(bool ok);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void setCurrentPage(const QModelIndex &index);
|
void setCurrentPage(const QModelIndex &index);
|
||||||
|
|
||||||
@@ -74,6 +77,7 @@ private:
|
|||||||
bool eventFilter(QObject *obj, QEvent *event);
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_allowContextMenu;
|
||||||
OpenPagesDelegate *m_delegate;
|
OpenPagesDelegate *m_delegate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user