forked from qt-creator/qt-creator
Utils::NavigationTreeView is created - as a base class for any Navigation Widget (Side Bar) tree view
Merge-request: 2167 Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
committed by
Kai Koehne
parent
ae8192ad5a
commit
5af6f15f7c
79
src/libs/utils/navigationtreeview.cpp
Normal file
79
src/libs/utils/navigationtreeview.cpp
Normal file
@@ -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
|
||||||
63
src/libs/utils/navigationtreeview.h
Normal file
63
src/libs/utils/navigationtreeview.h
Normal file
@@ -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
|
||||||
@@ -41,7 +41,8 @@ SOURCES += reloadpromptutils.cpp \
|
|||||||
changeset.cpp \
|
changeset.cpp \
|
||||||
filterlineedit.cpp \
|
filterlineedit.cpp \
|
||||||
faketooltip.cpp \
|
faketooltip.cpp \
|
||||||
htmldocextractor.cpp
|
htmldocextractor.cpp \
|
||||||
|
navigationtreeview.cpp
|
||||||
win32 {
|
win32 {
|
||||||
SOURCES += abstractprocess_win.cpp \
|
SOURCES += abstractprocess_win.cpp \
|
||||||
consoleprocess_win.cpp \
|
consoleprocess_win.cpp \
|
||||||
@@ -95,7 +96,8 @@ HEADERS += utils_global.h \
|
|||||||
changeset.h \
|
changeset.h \
|
||||||
filterlineedit.h \
|
filterlineedit.h \
|
||||||
faketooltip.h \
|
faketooltip.h \
|
||||||
htmldocextractor.h
|
htmldocextractor.h \
|
||||||
|
navigationtreeview.h
|
||||||
FORMS += filewizardpage.ui \
|
FORMS += filewizardpage.ui \
|
||||||
projectintropage.ui \
|
projectintropage.ui \
|
||||||
newclasswidget.ui \
|
newclasswidget.ui \
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ NavigationWidget::NavigationWidget(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
d_ptr->ui = new Ui::NavigationWidget;
|
d_ptr->ui = new Ui::NavigationWidget;
|
||||||
d_ptr->ui->setupUi(this);
|
d_ptr->ui->setupUi(this);
|
||||||
d_ptr->ui->treeView->setIndentation(d_ptr->ui->treeView->indentation() * 9/10);
|
|
||||||
|
|
||||||
// tree model
|
// tree model
|
||||||
d_ptr->treeModel = new TreeItemModel(this);
|
d_ptr->treeModel = new TreeItemModel(this);
|
||||||
|
|||||||
@@ -21,19 +21,10 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="treeView">
|
<widget class="Utils::NavigationTreeView" name="treeView">
|
||||||
<property name="frameShape">
|
|
||||||
<enum>QFrame::NoFrame</enum>
|
|
||||||
</property>
|
|
||||||
<property name="editTriggers">
|
<property name="editTriggers">
|
||||||
<set>QAbstractItemView::NoEditTriggers</set>
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="textElideMode">
|
|
||||||
<enum>Qt::ElideNone</enum>
|
|
||||||
</property>
|
|
||||||
<property name="uniformRowHeights">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="headerHidden">
|
<property name="headerHidden">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
@@ -41,6 +32,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>Utils::NavigationTreeView</class>
|
||||||
|
<extends>QTreeView</extends>
|
||||||
|
<header>utils/navigationtreeview.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
@@ -18,16 +18,11 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CppOutlineTreeView::CppOutlineTreeView(QWidget *parent) :
|
CppOutlineTreeView::CppOutlineTreeView(QWidget *parent) :
|
||||||
QTreeView(parent)
|
Utils::NavigationTreeView(parent)
|
||||||
{
|
{
|
||||||
// see also QmlJSOutlineTreeView
|
// see also QmlJSOutlineTreeView
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
setFrameStyle(QFrame::NoFrame);
|
|
||||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
||||||
setUniformRowHeights(true);
|
|
||||||
setHeaderHidden(true);
|
setHeaderHidden(true);
|
||||||
setTextElideMode(Qt::ElideNone);
|
|
||||||
setIndentation(20);
|
|
||||||
setExpandsOnDoubleClick(false);
|
setExpandsOnDoubleClick(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "cppeditor.h"
|
#include "cppeditor.h"
|
||||||
|
|
||||||
|
#include <utils/navigationtreeview.h>
|
||||||
#include <texteditor/ioutlinewidget.h>
|
#include <texteditor/ioutlinewidget.h>
|
||||||
|
|
||||||
#include <QtGui/QSortFilterProxyModel>
|
#include <QtGui/QSortFilterProxyModel>
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CppOutlineTreeView : public QTreeView
|
class CppOutlineTreeView : public Utils::NavigationTreeView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/navigationtreeview.h>
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
@@ -57,14 +58,12 @@ namespace {
|
|||||||
bool debug = false;
|
bool debug = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProjectTreeView : public QTreeView
|
class ProjectTreeView : public Utils::NavigationTreeView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProjectTreeView()
|
ProjectTreeView()
|
||||||
{
|
{
|
||||||
setEditTriggers(QAbstractItemView::EditKeyPressed);
|
setEditTriggers(QAbstractItemView::EditKeyPressed);
|
||||||
setFrameStyle(QFrame::NoFrame);
|
|
||||||
setIndentation(indentation() * 9/10);
|
|
||||||
{
|
{
|
||||||
QHeaderView *treeHeader = header();
|
QHeaderView *treeHeader = header();
|
||||||
treeHeader->setVisible(false);
|
treeHeader->setVisible(false);
|
||||||
@@ -72,41 +71,8 @@ public:
|
|||||||
treeHeader->setStretchLastSection(true);
|
treeHeader->setStretchLastSection(true);
|
||||||
}
|
}
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
setUniformRowHeights(true);
|
|
||||||
setTextElideMode(Qt::ElideNone);
|
|
||||||
// setExpandsOnDoubleClick(false);
|
// 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
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -17,16 +17,11 @@ namespace QmlJSEditor {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
QmlJSOutlineTreeView::QmlJSOutlineTreeView(QWidget *parent) :
|
QmlJSOutlineTreeView::QmlJSOutlineTreeView(QWidget *parent) :
|
||||||
QTreeView(parent)
|
Utils::NavigationTreeView(parent)
|
||||||
{
|
{
|
||||||
// see also CppOutlineTreeView
|
// see also CppOutlineTreeView
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
setFrameStyle(QFrame::NoFrame);
|
|
||||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
||||||
setUniformRowHeights(true);
|
|
||||||
setHeaderHidden(true);
|
setHeaderHidden(true);
|
||||||
setTextElideMode(Qt::ElideNone);
|
|
||||||
setIndentation(20);
|
|
||||||
setExpandsOnDoubleClick(false);
|
setExpandsOnDoubleClick(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "qmljseditor.h"
|
#include "qmljseditor.h"
|
||||||
|
|
||||||
|
#include <utils/navigationtreeview.h>
|
||||||
#include <texteditor/ioutlinewidget.h>
|
#include <texteditor/ioutlinewidget.h>
|
||||||
|
|
||||||
#include <QtGui/QTreeView>
|
#include <QtGui/QTreeView>
|
||||||
@@ -19,7 +20,7 @@ class Editor;
|
|||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class QmlJSOutlineTreeView : public QTreeView
|
class QmlJSOutlineTreeView : public Utils::NavigationTreeView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user