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 \
|
||||
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 \
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user