summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-06-03 02:34:39 +0200
committerQt Continuous Integration System <qt-info@nokia.com>2010-06-03 02:34:39 +0200
commitb1f9fcb175f99dd4eb3b7804c1e1e0d1421e549a (patch)
tree8bf606069e1ff3bda85fc5be0adf4dfc3d2308bb
parent9d3324118b49b18899242e36dc9d58ddc03d6cb5 (diff)
parent43576edf79b85b3d254db02dba3f08dcd327c0e4 (diff)
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1: Backport open pages switcher from Qt Creator. Remove in-page switcher. Add missing trace, small cleanup.
-rw-r--r--tools/assistant/tools/assistant/assistant.pro6
-rw-r--r--tools/assistant/tools/assistant/helpviewer.cpp33
-rw-r--r--tools/assistant/tools/assistant/helpviewer.h3
-rw-r--r--tools/assistant/tools/assistant/helpviewer_p.h30
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qtb.cpp7
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qwv.cpp11
-rw-r--r--tools/assistant/tools/assistant/mainwindow.cpp13
-rw-r--r--tools/assistant/tools/assistant/openpagesmanager.cpp106
-rw-r--r--tools/assistant/tools/assistant/openpagesmanager.h44
-rw-r--r--tools/assistant/tools/assistant/openpagesswitcher.cpp194
-rw-r--r--tools/assistant/tools/assistant/openpagesswitcher.h85
-rw-r--r--tools/assistant/tools/assistant/openpageswidget.cpp35
-rw-r--r--tools/assistant/tools/assistant/openpageswidget.h4
13 files changed, 446 insertions, 125 deletions
diff --git a/tools/assistant/tools/assistant/assistant.pro b/tools/assistant/tools/assistant/assistant.pro
index af306a551b..97d88dc1b1 100644
--- a/tools/assistant/tools/assistant/assistant.pro
+++ b/tools/assistant/tools/assistant/assistant.pro
@@ -47,7 +47,8 @@ HEADERS += aboutdialog.h \
openpagesmodel.h \
globalactions.h \
openpageswidget.h \
- openpagesmanager.h
+ openpagesmanager.h \
+ openpagesswitcher.h
win32:HEADERS += remotecontrol_win.h
SOURCES += aboutdialog.cpp \
@@ -78,7 +79,8 @@ SOURCES += aboutdialog.cpp \
openpagesmodel.cpp \
globalactions.cpp \
openpageswidget.cpp \
- openpagesmanager.cpp
+ openpagesmanager.cpp \
+ openpagesswitcher.cpp
contains(QT_CONFIG, webkit) {
SOURCES += helpviewer_qwv.cpp
} else {
diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp
index 81870a93cc..a448dd4f27 100644
--- a/tools/assistant/tools/assistant/helpviewer.cpp
+++ b/tools/assistant/tools/assistant/helpviewer.cpp
@@ -51,7 +51,6 @@
#include <QtCore/QTemporaryFile>
#include <QtCore/QUrl>
-#include <QtGui/QComboBox>
#include <QtGui/QDesktopServices>
#include <QtGui/QMouseEvent>
@@ -109,6 +108,12 @@ struct ExtensionMap {
{ 0, 0 }
};
+HelpViewer::~HelpViewer()
+{
+ TRACE_OBJ
+ delete d;
+}
+
bool HelpViewer::isLocalUrl(const QUrl &url)
{
TRACE_OBJ
@@ -208,30 +213,4 @@ bool HelpViewer::handleForwardBackwardMouseButtons(QMouseEvent *event)
return false;
}
-bool HelpViewer::openPagesListRequested(const QMouseEvent *event) const
-{
- return event->buttons() == Qt::RightButton
- && event->modifiers() == Qt::ControlModifier;
-}
-
-bool HelpViewer::openPagesListRequested(const QContextMenuEvent *event) const
-{
- return event->reason() == QContextMenuEvent::Mouse
- && event->modifiers() == Qt::ControlModifier;
-}
-
-void HelpViewer::showOpenPagesList(const QPoint &pos)
-{
- QComboBox * const openPagesBox = d->openPagesBox(this);
- openPagesBox->move(pos);
- openPagesBox->setCurrentIndex(CentralWidget::instance()->currentIndex());
- openPagesBox->showPopup();
-}
-
-HelpViewer::~HelpViewer()
-{
- TRACE_OBJ
- delete d;
-}
-
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h
index 1f897d9ec4..847b0ca584 100644
--- a/tools/assistant/tools/assistant/helpviewer.h
+++ b/tools/assistant/tools/assistant/helpviewer.h
@@ -145,9 +145,6 @@ private:
void contextMenuEvent(QContextMenuEvent *event);
QVariant loadResource(int type, const QUrl &name);
bool handleForwardBackwardMouseButtons(QMouseEvent *e);
- bool openPagesListRequested(const QMouseEvent *event) const;
- bool openPagesListRequested(const QContextMenuEvent *event) const;
- void showOpenPagesList(const QPoint &pos);
private:
HelpViewerPrivate *d;
diff --git a/tools/assistant/tools/assistant/helpviewer_p.h b/tools/assistant/tools/assistant/helpviewer_p.h
index 2bd4e16c5e..277290530b 100644
--- a/tools/assistant/tools/assistant/helpviewer_p.h
+++ b/tools/assistant/tools/assistant/helpviewer_p.h
@@ -47,11 +47,9 @@
#include "openpagesmanager.h"
#include <QtCore/QObject>
-#include <QtGui/QComboBox>
#ifdef QT_NO_WEBKIT
#include <QtGui/QTextBrowser>
#endif
-#include <QtGui/QTreeView>
QT_BEGIN_NAMESPACE
@@ -69,7 +67,6 @@ public:
HelpViewerPrivate()
#endif
{
- m_openPagesBox = 0;
}
#ifdef QT_NO_WEBKIT
@@ -98,25 +95,8 @@ public:
CentralWidget::instance()->setSource(lastAnchor);
lastAnchor.clear();
}
-#endif // QT_NO_WEBKIT
-
- QComboBox *openPagesBox(QWidget *parent = 0)
- {
- if (!m_openPagesBox) {
- m_openPagesBox = new QComboBox(parent);
- m_openPagesBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
- m_openPagesBox->setModel(OpenPagesManager::instance()
- ->openPagesWidget()->model());
- connect(m_openPagesBox, SIGNAL(activated(int)), this,
- SLOT(switchToPage(int)));
- }
-
- return m_openPagesBox;
- }
public slots:
-
-#ifdef QT_NO_WEBKIT
void openLink()
{
openLink(false);
@@ -132,16 +112,6 @@ public:
bool forceFont;
QString lastAnchor;
#endif // QT_NO_WEBKIT
-
-private slots:
-
- void switchToPage(int row)
- {
- OpenPagesManager::instance()->setCurrentPage(row);
- }
-
-private:
- QComboBox *m_openPagesBox;
};
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.cpp b/tools/assistant/tools/assistant/helpviewer_qtb.cpp
index 98eb59f087..f6b5022660 100644
--- a/tools/assistant/tools/assistant/helpviewer_qtb.cpp
+++ b/tools/assistant/tools/assistant/helpviewer_qtb.cpp
@@ -298,10 +298,6 @@ void HelpViewer::mousePressEvent(QMouseEvent *e)
if (handleForwardBackwardMouseButtons(e))
return;
#endif
- if (openPagesListRequested(e)) {
- showOpenPagesList(e->pos());
- return;
- }
QTextBrowser::mousePressEvent(e);
}
@@ -346,9 +342,6 @@ void HelpViewer::contextMenuEvent(QContextMenuEvent *event)
{
TRACE_OBJ
- if (openPagesListRequested(event))
- return;
-
QMenu menu(QString(), 0);
QUrl link;
QAction *copyAnchorAction = 0;
diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.cpp b/tools/assistant/tools/assistant/helpviewer_qwv.cpp
index 869789b9f0..f61d6d4eb2 100644
--- a/tools/assistant/tools/assistant/helpviewer_qwv.cpp
+++ b/tools/assistant/tools/assistant/helpviewer_qwv.cpp
@@ -243,7 +243,8 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *,
// -- HelpViewer
HelpViewer::HelpViewer(qreal zoom, QWidget *parent)
- : QWebView(parent), d(new HelpViewerPrivate)
+ : QWebView(parent)
+ , d(new HelpViewerPrivate)
{
TRACE_OBJ
setAcceptDrops(false);
@@ -432,11 +433,6 @@ void HelpViewer::mousePressEvent(QMouseEvent *event)
return;
#endif
- if (openPagesListRequested(event)) {
- showOpenPagesList(event->pos());
- return;
- }
-
if (HelpPage *currentPage = static_cast<HelpPage*> (page())) {
currentPage->m_pressedButtons = event->buttons();
currentPage->m_keyboardModifiers = event->modifiers();
@@ -481,8 +477,7 @@ bool HelpViewer::eventFilter(QObject *obj, QEvent *event)
void HelpViewer::contextMenuEvent(QContextMenuEvent *event)
{
TRACE_OBJ
- if (!openPagesListRequested(event))
- QWebView::contextMenuEvent(event);
+ QWebView::contextMenuEvent(event);
}
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp
index ca10d381cf..e4362018bb 100644
--- a/tools/assistant/tools/assistant/mainwindow.cpp
+++ b/tools/assistant/tools/assistant/mainwindow.cpp
@@ -79,6 +79,7 @@
#include <QtGui/QMenuBar>
#include <QtGui/QMessageBox>
#include <QtGui/QProgressBar>
+#include <QtGui/QShortcut>
#include <QtGui/QStatusBar>
#include <QtGui/QToolBar>
#include <QtGui/QToolButton>
@@ -516,6 +517,18 @@ void MainWindow::setupActions()
tmp->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Alt+Left"))
<< QKeySequence(Qt::CTRL + Qt::Key_PageUp));
+#ifdef Q_WS_MAC
+ QShortcut *sct = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_Tab), this);
+ connect(sct, SIGNAL(activated()), openPages, SLOT(nextPageWithSwitcher()));
+ sct = new QShortcut(QKeySequence(Qt::ALT + Qt::SHIFT + Qt::Key_Tab), this);
+ connect(sct, SIGNAL(activated()), openPages, SLOT(previousPageWithSwitcher()));
+#else
+ QShortcut *sct = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Tab), this);
+ connect(sct, SIGNAL(activated()), openPages, SLOT(nextPageWithSwitcher()));
+ sct = new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab), this);
+ connect(sct, SIGNAL(activated()), openPages, SLOT(previousPageWithSwitcher()));
+#endif
+
BookmarkManager::instance()->takeBookmarksMenu(menuBar()->addMenu(tr("&Bookmarks")));
menu = menuBar()->addMenu(tr("&Help"));
diff --git a/tools/assistant/tools/assistant/openpagesmanager.cpp b/tools/assistant/tools/assistant/openpagesmanager.cpp
index b6005e8a5c..6b08c466e9 100644
--- a/tools/assistant/tools/assistant/openpagesmanager.cpp
+++ b/tools/assistant/tools/assistant/openpagesmanager.cpp
@@ -38,20 +38,25 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
#include "openpagesmanager.h"
-
+
#include "centralwidget.h"
#include "helpenginewrapper.h"
#include "helpviewer.h"
#include "openpagesmodel.h"
+#include "openpagesswitcher.h"
#include "openpageswidget.h"
#include "tracer.h"
#include "../shared/collectionconfiguration.h"
+#include <QtGui/QApplication>
#include <QtGui/QTreeView>
-
+
QT_BEGIN_NAMESPACE
+OpenPagesManager *OpenPagesManager::m_instance = 0;
+
OpenPagesManager *OpenPagesManager::createInstance(QObject *parent,
bool defaultCollection, const QUrl &cmdLineUrl)
{
@@ -70,25 +75,43 @@ OpenPagesManager *OpenPagesManager::instance()
OpenPagesManager::OpenPagesManager(QObject *parent, bool defaultCollection,
const QUrl &cmdLineUrl)
- : QObject(parent), m_model(new OpenPagesModel(this)),
- m_openPagesWidget(new OpenPagesWidget(m_model))
+ : QObject(parent)
+ , m_model(new OpenPagesModel(this))
+ , m_openPagesWidget(0)
+ , m_openPagesSwitcher(0)
{
TRACE_OBJ
+ m_openPagesWidget = new OpenPagesWidget(m_model);
+ m_openPagesWidget->setFrameStyle(QFrame::NoFrame);
connect(m_openPagesWidget, SIGNAL(setCurrentPage(QModelIndex)), this,
SLOT(setCurrentPage(QModelIndex)));
connect(m_openPagesWidget, SIGNAL(closePage(QModelIndex)), this,
SLOT(closePage(QModelIndex)));
connect(m_openPagesWidget, SIGNAL(closePagesExcept(QModelIndex)), this,
SLOT(closePagesExcept(QModelIndex)));
+
+ m_openPagesSwitcher = new OpenPagesSwitcher(m_model);
+ connect(m_openPagesSwitcher, SIGNAL(closePage(QModelIndex)), this,
+ SLOT(closePage(QModelIndex)));
+ connect(m_openPagesSwitcher, SIGNAL(setCurrentPage(QModelIndex)), this,
+ SLOT(setCurrentPage(QModelIndex)));
+
setupInitialPages(defaultCollection, cmdLineUrl);
}
-
+
+OpenPagesManager ::~OpenPagesManager()
+{
+ TRACE_OBJ
+ m_instance = 0;
+ delete m_openPagesSwitcher;
+}
+
int OpenPagesManager::pageCount() const
{
TRACE_OBJ
return m_model->rowCount();
}
-
+
void OpenPagesManager::setupInitialPages(bool defaultCollection,
const QUrl &cmdLineUrl)
{
@@ -145,6 +168,7 @@ void OpenPagesManager::setupInitialPages(bool defaultCollection,
for (int i = 0; i < m_model->rowCount(); ++i)
CentralWidget::instance()->addPage(m_model->pageAt(i));
setCurrentPage(initialPage);
+ m_openPagesSwitcher->selectCurrentPage();
}
HelpViewer *OpenPagesManager::createPage()
@@ -181,11 +205,13 @@ HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch)
HelpViewer *OpenPagesManager::createNewPageFromSearch(const QUrl &url)
{
+ TRACE_OBJ
return createPage(url, true);
}
void OpenPagesManager::closePage(const QModelIndex &index)
{
+ TRACE_OBJ
if (index.isValid())
removePage(index.row());
}
@@ -200,13 +226,12 @@ void OpenPagesManager::reloadPages(const QString &nameSpace)
{
TRACE_OBJ
closeOrReloadPages(nameSpace, true);
- selectCurrentPage();
+ m_openPagesWidget->selectCurrentPage();
}
void OpenPagesManager::closeOrReloadPages(const QString &nameSpace, bool tryReload)
{
TRACE_OBJ
-
for (int i = m_model->rowCount() - 1; i >= 0; --i) {
HelpViewer *page = m_model->pageAt(i);
if (page->source().host() != nameSpace)
@@ -232,27 +257,15 @@ bool OpenPagesManager::pagesOpenForNamespace(const QString &nameSpace) const
void OpenPagesManager::setCurrentPage(const QModelIndex &index)
{
TRACE_OBJ
- if (!index.isValid())
- return;
- HelpViewer * const page = m_model->pageAt(index.row());
- CentralWidget::instance()->setCurrentPage(page);
+ if (index.isValid())
+ setCurrentPage(index.row());
}
void OpenPagesManager::setCurrentPage(int index)
{
TRACE_OBJ
CentralWidget::instance()->setCurrentPage(m_model->pageAt(index));
- selectCurrentPage();
-}
-
-void OpenPagesManager::selectCurrentPage()
-{
- TRACE_OBJ
- QItemSelectionModel * const 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());
+ m_openPagesWidget->selectCurrentPage();
}
void OpenPagesManager::removePage(int index)
@@ -260,7 +273,7 @@ void OpenPagesManager::removePage(int index)
TRACE_OBJ
CentralWidget::instance()->removePage(index);
m_model->removePage(index);
- selectCurrentPage();
+ m_openPagesWidget->selectCurrentPage();
}
@@ -282,25 +295,66 @@ void OpenPagesManager::closePagesExcept(const QModelIndex &index)
QAbstractItemView *OpenPagesManager::openPagesWidget() const
{
+ TRACE_OBJ
return m_openPagesWidget;
}
void OpenPagesManager::nextPage()
{
+ TRACE_OBJ
nextOrPreviousPage(1);
}
+void OpenPagesManager::nextPageWithSwitcher()
+{
+ TRACE_OBJ
+ if (!m_openPagesSwitcher->isVisible()) {
+ m_openPagesSwitcher->selectCurrentPage();
+ m_openPagesSwitcher->gotoNextPage();
+ showSwitcherOrSelectPage();
+ } else {
+ m_openPagesSwitcher->gotoNextPage();
+ }
+}
+
void OpenPagesManager::previousPage()
{
+ TRACE_OBJ
nextOrPreviousPage(-1);
}
+void OpenPagesManager::previousPageWithSwitcher()
+{
+ TRACE_OBJ
+ if (!m_openPagesSwitcher->isVisible()) {
+ m_openPagesSwitcher->selectCurrentPage();
+ m_openPagesSwitcher->gotoPreviousPage();
+ showSwitcherOrSelectPage();
+ } else {
+ m_openPagesSwitcher->gotoPreviousPage();
+ }
+}
+
void OpenPagesManager::nextOrPreviousPage(int offset)
{
+ TRACE_OBJ
setCurrentPage((CentralWidget::instance()->currentIndex() + offset
- + m_model->rowCount()) % m_model->rowCount());
+ + m_model->rowCount()) % m_model->rowCount());
}
-OpenPagesManager *OpenPagesManager::m_instance = 0;
+void OpenPagesManager::showSwitcherOrSelectPage() const
+{
+ TRACE_OBJ
+ 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_openPagesSwitcher->move((width - m_openPagesSwitcher->width()) / 2 + p.x(),
+ (height - m_openPagesSwitcher->height()) / 2 + p.y());
+ m_openPagesSwitcher->setVisible(true);
+ } else {
+ m_openPagesSwitcher->selectAndHide();
+ }
+}
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/openpagesmanager.h b/tools/assistant/tools/assistant/openpagesmanager.h
index 5e7a9afb0d..56a1ce74ee 100644
--- a/tools/assistant/tools/assistant/openpagesmanager.h
+++ b/tools/assistant/tools/assistant/openpagesmanager.h
@@ -41,27 +41,28 @@
#ifndef OPENPAGESMANAGER_H
#define OPENPAGESMANAGER_H
-
+
#include <QtCore/QObject>
-
+
QT_BEGIN_NAMESPACE
class QAbstractItemView;
class QModelIndex;
class QUrl;
-
+
class HelpViewer;
class OpenPagesModel;
+class OpenPagesSwitcher;
class OpenPagesWidget;
-
+
class OpenPagesManager : public QObject
- {
+{
Q_OBJECT
- public:
+public:
static OpenPagesManager *createInstance(QObject *parent,
- bool defaultCollection, const QUrl &cmdLineUrl);
+ bool defaultCollection, const QUrl &cmdLineUrl);
static OpenPagesManager *instance();
-
+
bool pagesOpenForNamespace(const QString &nameSpace) const;
void closePages(const QString &nameSpace);
void reloadPages(const QString &nameSpace);
@@ -71,13 +72,16 @@ class OpenPagesManager : public QObject
int pageCount() const;
void setCurrentPage(int index);
- public slots:
+public slots:
HelpViewer *createPage(const QUrl &url, bool fromSearch = false);
HelpViewer *createNewPageFromSearch(const QUrl &url);
HelpViewer *createPage();
void closeCurrentPage();
+
void nextPage();
+ void nextPageWithSwitcher();
void previousPage();
+ void previousPageWithSwitcher();
private slots:
void setCurrentPage(const QModelIndex &index);
@@ -86,19 +90,23 @@ private slots:
private:
OpenPagesManager(QObject *parent, bool defaultCollection,
- const QUrl &cmdLineUrl);
+ const QUrl &cmdLineUrl);
+ ~OpenPagesManager();
+
void setupInitialPages(bool defaultCollection, const QUrl &cmdLineUrl);
void closeOrReloadPages(const QString &nameSpace, bool tryReload);
- void selectCurrentPage();
void removePage(int index);
+
void nextOrPreviousPage(int offset);
-
- OpenPagesModel *m_model;
- OpenPagesWidget *m_openPagesWidget;
+ void showSwitcherOrSelectPage() const;
+
+ OpenPagesModel *m_model;
+ OpenPagesWidget *m_openPagesWidget;
+ OpenPagesSwitcher *m_openPagesSwitcher;
+
+ static OpenPagesManager *m_instance;
+};
- static OpenPagesManager *m_instance;
- };
-
QT_END_NAMESPACE
-
+
#endif // OPENPAGESMANAGER_H
diff --git a/tools/assistant/tools/assistant/openpagesswitcher.cpp b/tools/assistant/tools/assistant/openpagesswitcher.cpp
new file mode 100644
index 0000000000..d4b7d82229
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesswitcher.cpp
@@ -0,0 +1,194 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "openpagesswitcher.h"
+
+#include "centralwidget.h"
+#include "openpagesmodel.h"
+#include "openpageswidget.h"
+#include "tracer.h"
+
+#include <QtCore/QEvent>
+
+#include <QtGui/QKeyEvent>
+#include <QtGui/QVBoxLayout>
+
+QT_BEGIN_NAMESPACE
+
+const int gWidth = 300;
+const int gHeight = 200;
+
+OpenPagesSwitcher::OpenPagesSwitcher(OpenPagesModel *model)
+ : QFrame(0, Qt::Popup)
+ , m_openPagesModel(model)
+{
+ TRACE_OBJ
+ resize(gWidth, gHeight);
+
+ m_openPagesWidget = new OpenPagesWidget(m_openPagesModel);
+
+ // We disable the frame on this list view and use a QFrame around it instead.
+ // This improves the look with QGTKStyle.
+#ifndef Q_WS_MAC
+ setFrameStyle(m_openPagesWidget->frameStyle());
+#endif
+ m_openPagesWidget->setFrameStyle(QFrame::NoFrame);
+
+ m_openPagesWidget->allowContextMenu(false);
+ m_openPagesWidget->installEventFilter(this);
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->setMargin(0);
+ layout->addWidget(m_openPagesWidget);
+
+ connect(m_openPagesWidget, SIGNAL(closePage(QModelIndex)), this,
+ SIGNAL(closePage(QModelIndex)));
+ connect(m_openPagesWidget, SIGNAL(setCurrentPage(QModelIndex)), this,
+ SIGNAL(setCurrentPage(QModelIndex)));
+}
+
+OpenPagesSwitcher::~OpenPagesSwitcher()
+{
+ TRACE_OBJ
+}
+
+void OpenPagesSwitcher::gotoNextPage()
+{
+ TRACE_OBJ
+ selectPageUpDown(1);
+}
+
+void OpenPagesSwitcher::gotoPreviousPage()
+{
+ TRACE_OBJ
+ selectPageUpDown(-1);
+}
+
+void OpenPagesSwitcher::selectAndHide()
+{
+ TRACE_OBJ
+ setVisible(false);
+ emit setCurrentPage(m_openPagesWidget->currentIndex());
+}
+
+void OpenPagesSwitcher::selectCurrentPage()
+{
+ TRACE_OBJ
+ m_openPagesWidget->selectCurrentPage();
+}
+
+void OpenPagesSwitcher::setVisible(bool visible)
+{
+ TRACE_OBJ
+ QWidget::setVisible(visible);
+ if (visible)
+ setFocus();
+}
+
+void OpenPagesSwitcher::focusInEvent(QFocusEvent *event)
+{
+ TRACE_OBJ
+ Q_UNUSED(event)
+ m_openPagesWidget->setFocus();
+}
+
+bool OpenPagesSwitcher::eventFilter(QObject *object, QEvent *event)
+{
+ TRACE_OBJ
+ 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;
+ }
+
+ Qt::KeyboardModifier modifier = Qt::ControlModifier;
+#ifdef Q_WS_MAC
+ modifier = Qt::AltModifier;
+#endif
+ if (key == Qt::Key_Backtab
+ && (ke->modifiers() == (modifier | Qt::ShiftModifier)))
+ gotoPreviousPage();
+ else if (key == Qt::Key_Tab && (ke->modifiers() == modifier))
+ gotoNextPage();
+ } 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 OpenPagesSwitcher::selectPageUpDown(int summand)
+{
+ TRACE_OBJ
+ 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);
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/openpagesswitcher.h b/tools/assistant/tools/assistant/openpagesswitcher.h
new file mode 100644
index 0000000000..e27db6bd6e
--- /dev/null
+++ b/tools/assistant/tools/assistant/openpagesswitcher.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Assistant module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef OPENPAGESSWITCHER_H
+#define OPENPAGESSWITCHER_H
+
+#include <QtGui/QFrame>
+
+QT_BEGIN_NAMESPACE
+
+class OpenPagesModel;
+class OpenPagesWidget;
+class QModelIndex;
+
+class OpenPagesSwitcher : public QFrame
+{
+ Q_OBJECT
+
+public:
+ OpenPagesSwitcher(OpenPagesModel *model);
+ ~OpenPagesSwitcher();
+
+ 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;
+};
+
+QT_END_NAMESPACE
+
+#endif // OPENPAGESSWITCHER_H
diff --git a/tools/assistant/tools/assistant/openpageswidget.cpp b/tools/assistant/tools/assistant/openpageswidget.cpp
index d702c2813a..a68da23d70 100644
--- a/tools/assistant/tools/assistant/openpageswidget.cpp
+++ b/tools/assistant/tools/assistant/openpageswidget.cpp
@@ -41,7 +41,9 @@
#include "openpageswidget.h"
+#include "centralwidget.h"
#include "openpagesmodel.h"
+#include "tracer.h"
#include <QtGui/QApplication>
#include <QtGui/QHeaderView>
@@ -57,13 +59,15 @@
QT_BEGIN_NAMESPACE
OpenPagesDelegate::OpenPagesDelegate(QObject *parent)
- : QStyledItemDelegate(parent)
+ : QStyledItemDelegate(parent)
{
+ TRACE_OBJ
}
void OpenPagesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
+ TRACE_OBJ
if (option.state & QStyle::State_MouseOver) {
if ((QApplication::mouseButtons() & Qt::LeftButton) == 0)
pressedIndex = QModelIndex();
@@ -87,14 +91,16 @@ void OpenPagesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt
}
}
+// -- OpenPagesWidget
OpenPagesWidget::OpenPagesWidget(OpenPagesModel *model)
+ : m_allowContextMenu(true)
{
+ TRACE_OBJ
setModel(model);
setIndentation(0);
setItemDelegate((m_delegate = new OpenPagesDelegate(this)));
- setFrameStyle(QFrame::NoFrame);
setTextElideMode(Qt::ElideMiddle);
setAttribute(Qt::WA_MacShowFocusRect, false);
@@ -122,12 +128,30 @@ OpenPagesWidget::OpenPagesWidget(OpenPagesModel *model)
OpenPagesWidget::~OpenPagesWidget()
{
+ TRACE_OBJ
+}
+
+void OpenPagesWidget::selectCurrentPage()
+{
+ TRACE_OBJ
+ 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)
+{
+ TRACE_OBJ
+ m_allowContextMenu = ok;
}
void OpenPagesWidget::contextMenuRequested(QPoint pos)
{
+ TRACE_OBJ
QModelIndex index = indexAt(pos);
- if (!index.isValid())
+ if (!index.isValid() || !m_allowContextMenu)
return;
if (index.column() == 1)
@@ -152,6 +176,7 @@ void OpenPagesWidget::contextMenuRequested(QPoint pos)
void OpenPagesWidget::handlePressed(const QModelIndex &index)
{
+ TRACE_OBJ
if (index.column() == 0)
emit setCurrentPage(index);
@@ -161,7 +186,8 @@ void OpenPagesWidget::handlePressed(const QModelIndex &index)
void OpenPagesWidget::handleClicked(const QModelIndex &index)
{
- // implemented here to handle the funky close button and to work around a
+ TRACE_OBJ
+ // implemented here to handle the funky close button and to work around a
// bug in item views where the delegate wouldn't get the QStyle::State_MouseOver
if (index.column() == 1) {
if (model()->rowCount() > 1)
@@ -177,6 +203,7 @@ void OpenPagesWidget::handleClicked(const QModelIndex &index)
bool OpenPagesWidget::eventFilter(QObject *obj, QEvent *event)
{
+ TRACE_OBJ
if (obj == this && event->type() == QEvent::KeyPress) {
if (currentIndex().isValid()) {
QKeyEvent *ke = static_cast<QKeyEvent*>(event);
diff --git a/tools/assistant/tools/assistant/openpageswidget.h b/tools/assistant/tools/assistant/openpageswidget.h
index 46c0022afe..4b972f3d4c 100644
--- a/tools/assistant/tools/assistant/openpageswidget.h
+++ b/tools/assistant/tools/assistant/openpageswidget.h
@@ -67,6 +67,9 @@ public:
OpenPagesWidget(OpenPagesModel *model);
~OpenPagesWidget();
+ void selectCurrentPage();
+ void allowContextMenu(bool ok);
+
signals:
void setCurrentPage(const QModelIndex &index);
void closePage(const QModelIndex &index);
@@ -80,6 +83,7 @@ private slots:
private:
bool eventFilter(QObject *obj, QEvent *event);
+ bool m_allowContextMenu;
OpenPagesDelegate *m_delegate;
};