diff --git a/src/libs/utils/navigationtreeview.cpp b/src/libs/utils/navigationtreeview.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0974bccaaa0ad95ddb73b9d90bb458e5e66e6d92 --- /dev/null +++ b/src/libs/utils/navigationtreeview.cpp @@ -0,0 +1,79 @@ +/************************************************************************** +** +** 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 "navigationtreeview.h" + +#include <QtGui/QFocusEvent> + +#ifdef Q_WS_MAC +#include <QtGui/QKeyEvent> +#endif + +namespace Utils { + +NavigationTreeView::NavigationTreeView(QWidget *parent) + : QTreeView(parent) +{ + setFrameStyle(QFrame::NoFrame); + setIndentation(indentation() * 9/10); + setUniformRowHeights(true); + setTextElideMode(Qt::ElideNone); + setAttribute(Qt::WA_MacShowFocusRect, false); +} + +// This is a workaround to stop Qt from redrawing the project tree every +// time the user opens or closes a menu when it has focus. Would be nicer to +// fix it in Qt. +void NavigationTreeView::focusInEvent(QFocusEvent *event) +{ + if (event->reason() != Qt::PopupFocusReason) + QTreeView::focusInEvent(event); +} + +void NavigationTreeView::focusOutEvent(QFocusEvent *event) +{ + if (event->reason() != Qt::PopupFocusReason) + QTreeView::focusOutEvent(event); +} + +#ifdef Q_WS_MAC +void NavigationTreeView::keyPressEvent(QKeyEvent *event) +{ + if ((event->key() == Qt::Key_Return + || event->key() == Qt::Key_Enter) + && event->modifiers() == 0 + && currentIndex().isValid()) { + emit activated(currentIndex()); + return; + } + QTreeView::keyPressEvent(event); +} +#endif + +} // namespace Utils diff --git a/src/libs/utils/navigationtreeview.h b/src/libs/utils/navigationtreeview.h new file mode 100644 index 0000000000000000000000000000000000000000..697fed10124e94ae4f1fd340f2d52d986963f629 --- /dev/null +++ b/src/libs/utils/navigationtreeview.h @@ -0,0 +1,63 @@ +/************************************************************************** +** +** 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 NAVIGATIONTREEVIEW_H +#define NAVIGATIONTREEVIEW_H + +#include "utils_global.h" + +#include <QtGui/QTreeView> + +namespace Utils { + +/*! + \class NavigationTreeView + \sa Core::NavigationView, Core::INavigationWidgetFactory + + General TreeView for any Side Bar widget. Common initialization etc, e.g. Mac specific behaviour. + */ + +class QTCREATOR_UTILS_EXPORT NavigationTreeView : public QTreeView +{ + Q_OBJECT +public: + NavigationTreeView(QWidget *parent = 0); + +protected: + void focusInEvent(QFocusEvent *event); + void focusOutEvent(QFocusEvent *event); + +#ifdef Q_WS_MAC + void keyPressEvent(QKeyEvent *event); +#endif +}; + +} // Utils + +#endif // NAVIGATIONTREEVIEW_H diff --git a/src/libs/utils/utils.pro b/src/libs/utils/utils.pro index a189b6725083f21ff0b9234db75b8cfd268a8c64..582286884c3f057f40b5f8889bc4c42722352c00 100644 --- a/src/libs/utils/utils.pro +++ b/src/libs/utils/utils.pro @@ -41,7 +41,8 @@ SOURCES += reloadpromptutils.cpp \ changeset.cpp \ filterlineedit.cpp \ faketooltip.cpp \ - htmldocextractor.cpp + htmldocextractor.cpp \ + navigationtreeview.cpp win32 { SOURCES += abstractprocess_win.cpp \ consoleprocess_win.cpp \ @@ -95,7 +96,8 @@ HEADERS += utils_global.h \ changeset.h \ filterlineedit.h \ faketooltip.h \ - htmldocextractor.h + htmldocextractor.h \ + navigationtreeview.h FORMS += filewizardpage.ui \ projectintropage.ui \ newclasswidget.ui \ diff --git a/src/plugins/classview/classviewnavigationwidget.cpp b/src/plugins/classview/classviewnavigationwidget.cpp index a90a58fa823253a49ca125d134a51a7d4aa06914..8420284d818e9d2fc14dad433c7a59bbfc0f18fc 100644 --- a/src/plugins/classview/classviewnavigationwidget.cpp +++ b/src/plugins/classview/classviewnavigationwidget.cpp @@ -76,7 +76,6 @@ NavigationWidget::NavigationWidget(QWidget *parent) : { d_ptr->ui = new Ui::NavigationWidget; d_ptr->ui->setupUi(this); - d_ptr->ui->treeView->setIndentation(d_ptr->ui->treeView->indentation() * 9/10); // tree model d_ptr->treeModel = new TreeItemModel(this); diff --git a/src/plugins/classview/classviewnavigationwidget.ui b/src/plugins/classview/classviewnavigationwidget.ui index d9ba960515e25c0aecb75ecd47b44dde72dd0fa0..0b0bf55a50f053bc31b0178df6d4dc5acf9c3866 100644 --- a/src/plugins/classview/classviewnavigationwidget.ui +++ b/src/plugins/classview/classviewnavigationwidget.ui @@ -21,19 +21,10 @@ <number>0</number> </property> <item> - <widget class="QTreeView" name="treeView"> - <property name="frameShape"> - <enum>QFrame::NoFrame</enum> - </property> + <widget class="Utils::NavigationTreeView" name="treeView"> <property name="editTriggers"> <set>QAbstractItemView::NoEditTriggers</set> </property> - <property name="textElideMode"> - <enum>Qt::ElideNone</enum> - </property> - <property name="uniformRowHeights"> - <bool>true</bool> - </property> <property name="headerHidden"> <bool>true</bool> </property> @@ -41,6 +32,13 @@ </item> </layout> </widget> + <customwidgets> + <customwidget> + <class>Utils::NavigationTreeView</class> + <extends>QTreeView</extends> + <header>utils/navigationtreeview.h</header> + </customwidget> + </customwidgets> <resources/> <connections/> </ui> diff --git a/src/plugins/cppeditor/cppoutline.cpp b/src/plugins/cppeditor/cppoutline.cpp index 4e9fcfdbdaf6ed21b44cd7f1ae81b3c62a841e2d..14d8b0b9e9301de0e8cb01fcb6333b9b86f9965f 100644 --- a/src/plugins/cppeditor/cppoutline.cpp +++ b/src/plugins/cppeditor/cppoutline.cpp @@ -18,16 +18,11 @@ enum { }; CppOutlineTreeView::CppOutlineTreeView(QWidget *parent) : - QTreeView(parent) + Utils::NavigationTreeView(parent) { // see also QmlJSOutlineTreeView setFocusPolicy(Qt::NoFocus); - setFrameStyle(QFrame::NoFrame); - setAttribute(Qt::WA_MacShowFocusRect, false); - setUniformRowHeights(true); setHeaderHidden(true); - setTextElideMode(Qt::ElideNone); - setIndentation(20); setExpandsOnDoubleClick(false); } diff --git a/src/plugins/cppeditor/cppoutline.h b/src/plugins/cppeditor/cppoutline.h index d007b9689de001d03db487328b17d2ecbe317f4d..a9f2e65e0fbc705002ed53bdbc8c6b06334636fb 100644 --- a/src/plugins/cppeditor/cppoutline.h +++ b/src/plugins/cppeditor/cppoutline.h @@ -3,6 +3,7 @@ #include "cppeditor.h" +#include <utils/navigationtreeview.h> #include <texteditor/ioutlinewidget.h> #include <QtGui/QSortFilterProxyModel> @@ -11,7 +12,7 @@ namespace CppEditor { namespace Internal { -class CppOutlineTreeView : public QTreeView +class CppOutlineTreeView : public Utils::NavigationTreeView { Q_OBJECT public: diff --git a/src/plugins/projectexplorer/projecttreewidget.cpp b/src/plugins/projectexplorer/projecttreewidget.cpp index 56495cf6394352f86f0812e78d2ec13e947f035e..d6fd7a5f62c55d417aaaa9afc9f2128aafd35d96 100644 --- a/src/plugins/projectexplorer/projecttreewidget.cpp +++ b/src/plugins/projectexplorer/projecttreewidget.cpp @@ -38,6 +38,7 @@ #include <coreplugin/icore.h> #include <coreplugin/editormanager/editormanager.h> #include <utils/qtcassert.h> +#include <utils/navigationtreeview.h> #include <QtCore/QDebug> #include <QtCore/QSettings> @@ -57,14 +58,12 @@ namespace { bool debug = false; } -class ProjectTreeView : public QTreeView +class ProjectTreeView : public Utils::NavigationTreeView { public: ProjectTreeView() { setEditTriggers(QAbstractItemView::EditKeyPressed); - setFrameStyle(QFrame::NoFrame); - setIndentation(indentation() * 9/10); { QHeaderView *treeHeader = header(); treeHeader->setVisible(false); @@ -72,41 +71,8 @@ public: treeHeader->setStretchLastSection(true); } setContextMenuPolicy(Qt::CustomContextMenu); - setUniformRowHeights(true); - setTextElideMode(Qt::ElideNone); // setExpandsOnDoubleClick(false); - setAttribute(Qt::WA_MacShowFocusRect, false); } - -protected: - // This is a workaround to stop Qt from redrawing the project tree every - // time the user opens or closes a menu when it has focus. Would be nicer to - // fix it in Qt. - void focusInEvent(QFocusEvent *event) - { - if (event->reason() != Qt::PopupFocusReason) - QTreeView::focusInEvent(event); - } - - void focusOutEvent(QFocusEvent *event) - { - if (event->reason() != Qt::PopupFocusReason) - QTreeView::focusOutEvent(event); - } - -#ifdef Q_WS_MAC - void keyPressEvent(QKeyEvent *event) - { - if ((event->key() == Qt::Key_Return - || event->key() == Qt::Key_Enter) - && event->modifiers() == 0 - && currentIndex().isValid()) { - emit activated(currentIndex()); - return; - } - QTreeView::keyPressEvent(event); - } -#endif }; /*! diff --git a/src/plugins/qmljseditor/qmljsoutline.cpp b/src/plugins/qmljseditor/qmljsoutline.cpp index 7831670eec72410e9e11e836cd9f15de773b3708..c349dfc9ed9d04edb610c461e1f8a21cef11c64d 100644 --- a/src/plugins/qmljseditor/qmljsoutline.cpp +++ b/src/plugins/qmljseditor/qmljsoutline.cpp @@ -17,16 +17,11 @@ namespace QmlJSEditor { namespace Internal { QmlJSOutlineTreeView::QmlJSOutlineTreeView(QWidget *parent) : - QTreeView(parent) + Utils::NavigationTreeView(parent) { // see also CppOutlineTreeView setFocusPolicy(Qt::NoFocus); - setFrameStyle(QFrame::NoFrame); - setAttribute(Qt::WA_MacShowFocusRect, false); - setUniformRowHeights(true); setHeaderHidden(true); - setTextElideMode(Qt::ElideNone); - setIndentation(20); setExpandsOnDoubleClick(false); } diff --git a/src/plugins/qmljseditor/qmljsoutline.h b/src/plugins/qmljseditor/qmljsoutline.h index 15221210cb94e211e351c529708597ffd31b5220..27c2e4f8d408edc68a1d56dc8de5b62407f4eef4 100644 --- a/src/plugins/qmljseditor/qmljsoutline.h +++ b/src/plugins/qmljseditor/qmljsoutline.h @@ -3,6 +3,7 @@ #include "qmljseditor.h" +#include <utils/navigationtreeview.h> #include <texteditor/ioutlinewidget.h> #include <QtGui/QTreeView> @@ -19,7 +20,7 @@ class Editor; namespace QmlJSEditor { namespace Internal { -class QmlJSOutlineTreeView : public QTreeView +class QmlJSOutlineTreeView : public Utils::NavigationTreeView { Q_OBJECT public: