diff --git a/src/libs/utils/itemviews.cpp b/src/libs/utils/itemviews.cpp new file mode 100644 index 00000000000..c6b4f5cfb29 --- /dev/null +++ b/src/libs/utils/itemviews.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "itemviews.h" + +/*! + \class Utils::TreeView + + \brief The TreeView adds setActivationMode to QTreeView + to allow for single click/double click behavior on + platforms where the default is different. Use with care. + + Also adds sane keyboard navigation for mac. + */ + +/*! + \class Utils::TreeWidget + + \brief The TreeWidget adds setActivationMode to QTreeWidget + to allow for single click/double click behavior on + platforms where the default is different. Use with care. + + Also adds sane keyboard navigation for mac. + */ + +/*! + \class Utils::ListView + + \brief The ListView adds setActivationMode to QListView + to allow for single click/double click behavior on + platforms where the default is different. Use with care. + + Also adds sane keyboard navigation for mac. + */ + +/*! + \class Utils::ListWidget + + \brief The ListWidget adds setActivationMode to QListWidget + to allow for single click/double click behavior on + platforms where the default is different. Use with care. + + Also adds sane keyboard navigation for mac. + */ diff --git a/src/libs/utils/itemviews.h b/src/libs/utils/itemviews.h new file mode 100644 index 00000000000..cd570cc2a5d --- /dev/null +++ b/src/libs/utils/itemviews.h @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef TREEVIEW_H +#define TREEVIEW_H + +#include "utils_global.h" + +static const char activationModeC[] = "ActivationMode"; + +#include +#include +#include +#include + +#include + + +namespace Utils { + +enum ActivationMode { + DoubleClickActivation = 0, + SingleClickActivation = 1, + PlatformDefaultActivation = 2 +}; + +template +class View : public BaseT +{ +public: + View(QWidget *parent = 0) + : BaseT(parent) + {} + void setActivationMode(ActivationMode mode) + { + if (mode == PlatformDefaultActivation) + BaseT::setProperty(activationModeC, QVariant()); + else + BaseT::setProperty(activationModeC, QVariant(bool(mode))); + } + + ActivationMode activationMode() const + { + QVariant v = BaseT::property(activationModeC); + if (!v.isValid()) + return PlatformDefaultActivation; + return v.toBool() ? SingleClickActivation : DoubleClickActivation; + } + + void keyPressEvent(QKeyEvent *event) + { + // Note: This always eats the event + // whereas QAbstractItemView never eats it + if ((event->key() == Qt::Key_Return + || event->key() == Qt::Key_Enter) + && event->modifiers() == 0 + && BaseT::currentIndex().isValid() + && BaseT::state() != QAbstractItemView::EditingState) { + emit BaseT::activated(BaseT::currentIndex()); + return; + } + BaseT::keyPressEvent(event); + } + +}; + +class QTCREATOR_UTILS_EXPORT TreeView : public View +{ + Q_OBJECT +public: + TreeView(QWidget *parent = 0) + : View(parent) + {} +}; + +class QTCREATOR_UTILS_EXPORT TreeWidget : public View +{ + Q_OBJECT +public: + TreeWidget(QWidget *parent = 0) + : View(parent) + {} +}; + +class QTCREATOR_UTILS_EXPORT ListView : public View +{ + Q_OBJECT +public: + ListView(QWidget *parent = 0) + : View(parent) + {} +}; + +class QTCREATOR_UTILS_EXPORT ListWidget : public View +{ + Q_OBJECT +public: + ListWidget(QWidget *parent = 0) + : View(parent) + {} +}; + + +} + +#endif // TREEVIEW_H diff --git a/src/libs/utils/navigationtreeview.cpp b/src/libs/utils/navigationtreeview.cpp index d1d645e66bf..5c91f80486d 100644 --- a/src/libs/utils/navigationtreeview.cpp +++ b/src/libs/utils/navigationtreeview.cpp @@ -49,7 +49,7 @@ namespace Utils { NavigationTreeView::NavigationTreeView(QWidget *parent) - : QTreeView(parent) + : TreeView(parent) { setFrameStyle(QFrame::NoFrame); setIndentation(indentation() * 9/10); @@ -70,34 +70,19 @@ NavigationTreeView::NavigationTreeView(QWidget *parent) void NavigationTreeView::focusInEvent(QFocusEvent *event) { if (event->reason() != Qt::PopupFocusReason) - QTreeView::focusInEvent(event); + TreeView::focusInEvent(event); } void NavigationTreeView::focusOutEvent(QFocusEvent *event) { if (event->reason() != Qt::PopupFocusReason) - QTreeView::focusOutEvent(event); + TreeView::focusOutEvent(event); } void NavigationTreeView::resizeEvent(QResizeEvent *event) { header()->setMinimumSectionSize(viewport()->width()); - QTreeView::resizeEvent(event); + TreeView::resizeEvent(event); } -#ifdef Q_OS_MAC -void NavigationTreeView::keyPressEvent(QKeyEvent *event) -{ - if ((event->key() == Qt::Key_Return - || event->key() == Qt::Key_Enter) - && event->modifiers() == 0 - && currentIndex().isValid() - && state() != QAbstractItemView::EditingState) { - emit activated(currentIndex()); - return; - } - QTreeView::keyPressEvent(event); -} -#endif - } // namespace Utils diff --git a/src/libs/utils/navigationtreeview.h b/src/libs/utils/navigationtreeview.h index b8303834d59..f9846f3dff3 100644 --- a/src/libs/utils/navigationtreeview.h +++ b/src/libs/utils/navigationtreeview.h @@ -32,11 +32,11 @@ #include "utils_global.h" -#include +#include "itemviews.h" namespace Utils { -class QTCREATOR_UTILS_EXPORT NavigationTreeView : public QTreeView +class QTCREATOR_UTILS_EXPORT NavigationTreeView : public Utils::TreeView { Q_OBJECT public: @@ -46,10 +46,6 @@ protected: void focusInEvent(QFocusEvent *event); void focusOutEvent(QFocusEvent *event); void resizeEvent(QResizeEvent *event); - -#ifdef Q_OS_MAC - void keyPressEvent(QKeyEvent *event); -#endif }; } // Utils diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 67025e67a49..f634d596cff 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -87,7 +87,8 @@ SOURCES += $$PWD/environment.cpp \ $$PWD/ansiescapecodehandler.cpp \ $$PWD/execmenu.cpp \ $$PWD/completinglineedit.cpp \ - $$PWD/winutils.cpp + $$PWD/winutils.cpp \ + $$PWD/itemviews.cpp win32:SOURCES += $$PWD/consoleprocess_win.cpp else:SOURCES += $$PWD/consoleprocess_unix.cpp @@ -178,7 +179,8 @@ HEADERS += \ $$PWD/execmenu.h \ $$PWD/completinglineedit.h \ $$PWD/logging.h \ - $$PWD/winutils.h + $$PWD/winutils.h \ + $$PWD/itemviews.h FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 0714e853d25..da9ca7cac24 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -99,6 +99,8 @@ QtcLibrary { "htmldocextractor.h", "ipaddresslineedit.cpp", "ipaddresslineedit.h", + "itemviews.cpp", + "itemviews.h", "iwelcomepage.cpp", "iwelcomepage.h", "json.cpp", diff --git a/src/plugins/coreplugin/manhattanstyle.cpp b/src/plugins/coreplugin/manhattanstyle.cpp index d5d7875b6e7..39c2615df72 100644 --- a/src/plugins/coreplugin/manhattanstyle.cpp +++ b/src/plugins/coreplugin/manhattanstyle.cpp @@ -360,6 +360,13 @@ int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const case QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren: ret = true; break; + case QStyle::SH_ItemView_ActivateItemOnSingleClick: + // default depends on the style + if (widget) { + QVariant activationMode = widget->property("ActivationMode"); + if (activationMode.isValid()) + ret = activationMode.toBool(); + } default: break; }