Commit 8011a164 authored by hjk's avatar hjk Committed by Eike Ziller
Browse files

EditorManager: OpenEditorsView: Remove unneeded one-cell layout



Change-Id: I063b00779e5acbfb307308d2107616990f0da010
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 1011a486
...@@ -207,7 +207,6 @@ FORMS += dialogs/newdialog.ui \ ...@@ -207,7 +207,6 @@ FORMS += dialogs/newdialog.ui \
actionmanager/commandmappings.ui \ actionmanager/commandmappings.ui \
dialogs/saveitemsdialog.ui \ dialogs/saveitemsdialog.ui \
dialogs/openwithdialog.ui \ dialogs/openwithdialog.ui \
editormanager/openeditorsview.ui \
generalsettings.ui \ generalsettings.ui \
dialogs/externaltoolconfig.ui \ dialogs/externaltoolconfig.ui \
variablechooser.ui \ variablechooser.ui \
......
...@@ -208,7 +208,6 @@ QtcPlugin { ...@@ -208,7 +208,6 @@ QtcPlugin {
"editormanager/openeditorsmodel.h", "editormanager/openeditorsmodel.h",
"editormanager/openeditorsview.cpp", "editormanager/openeditorsview.cpp",
"editormanager/openeditorsview.h", "editormanager/openeditorsview.h",
"editormanager/openeditorsview.ui",
"editormanager/openeditorswindow.cpp", "editormanager/openeditorswindow.cpp",
"editormanager/openeditorswindow.h", "editormanager/openeditorswindow.h",
"editormanager/systemeditor.cpp", "editormanager/systemeditor.cpp",
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#include <coreplugin/actionmanager/command.h> #include <coreplugin/actionmanager/command.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QApplication>
#include <QGridLayout>
#include <QTimer> #include <QTimer>
#include <QMenu> #include <QMenu>
#include <QPainter> #include <QPainter>
...@@ -48,6 +50,7 @@ ...@@ -48,6 +50,7 @@
#include <QStyleOption> #include <QStyleOption>
#include <QHeaderView> #include <QHeaderView>
#include <QKeyEvent> #include <QKeyEvent>
#include <QTreeView>
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include <qmacstyle_mac.h> #include <qmacstyle_mac.h>
#endif #endif
...@@ -96,37 +99,36 @@ void OpenEditorsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o ...@@ -96,37 +99,36 @@ void OpenEditorsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
OpenEditorsWidget::OpenEditorsWidget() OpenEditorsWidget::OpenEditorsWidget()
{ {
m_ui.setupUi(this);
setWindowTitle(tr("Open Documents")); setWindowTitle(tr("Open Documents"));
setWindowIcon(QIcon(QLatin1String(Constants::ICON_DIR))); setWindowIcon(QIcon(QLatin1String(Constants::ICON_DIR)));
setFocusProxy(m_ui.editorList); setUniformRowHeights(true);
m_ui.editorList->viewport()->setAttribute(Qt::WA_Hover); viewport()->setAttribute(Qt::WA_Hover);
m_ui.editorList->setItemDelegate((m_delegate = new OpenEditorsDelegate(this))); setItemDelegate((m_delegate = new OpenEditorsDelegate(this)));
m_ui.editorList->header()->hide(); header()->hide();
m_ui.editorList->setIndentation(0); setIndentation(0);
m_ui.editorList->setTextElideMode(Qt::ElideMiddle); setTextElideMode(Qt::ElideMiddle);
m_ui.editorList->setFrameStyle(QFrame::NoFrame); setFrameStyle(QFrame::NoFrame);
m_ui.editorList->setAttribute(Qt::WA_MacShowFocusRect, false); setAttribute(Qt::WA_MacShowFocusRect, false);
EditorManager *em = EditorManager::instance(); EditorManager *em = EditorManager::instance();
m_ui.editorList->setModel(em->openedEditorsModel()); setModel(em->openedEditorsModel());
m_ui.editorList->setSelectionMode(QAbstractItemView::SingleSelection); setSelectionMode(QAbstractItemView::SingleSelection);
m_ui.editorList->setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionBehavior(QAbstractItemView::SelectRows);
m_ui.editorList->header()->setStretchLastSection(false); header()->setStretchLastSection(false);
m_ui.editorList->header()->setResizeMode(0, QHeaderView::Stretch); header()->setResizeMode(0, QHeaderView::Stretch);
m_ui.editorList->header()->setResizeMode(1, QHeaderView::Fixed); header()->setResizeMode(1, QHeaderView::Fixed);
m_ui.editorList->header()->resizeSection(1, 16); header()->resizeSection(1, 16);
m_ui.editorList->setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
m_ui.editorList->installEventFilter(this); installEventFilter(this);
m_ui.editorList->viewport()->installEventFilter(this); viewport()->installEventFilter(this);
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateCurrentItem(Core::IEditor*))); this, SLOT(updateCurrentItem(Core::IEditor*)));
connect(m_ui.editorList, SIGNAL(clicked(QModelIndex)), connect(this, SIGNAL(clicked(QModelIndex)),
this, SLOT(handleClicked(QModelIndex))); this, SLOT(handleClicked(QModelIndex)));
connect(m_ui.editorList, SIGNAL(pressed(QModelIndex)), connect(this, SIGNAL(pressed(QModelIndex)),
this, SLOT(handlePressed(QModelIndex))); this, SLOT(handlePressed(QModelIndex)));
connect(m_ui.editorList, SIGNAL(customContextMenuRequested(QPoint)), connect(this, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(contextMenuRequested(QPoint))); this, SLOT(contextMenuRequested(QPoint)));
} }
...@@ -137,37 +139,37 @@ OpenEditorsWidget::~OpenEditorsWidget() ...@@ -137,37 +139,37 @@ OpenEditorsWidget::~OpenEditorsWidget()
void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor) void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor)
{ {
if (!editor) { if (!editor) {
m_ui.editorList->clearSelection(); clearSelection();
return; return;
} }
EditorManager *em = EditorManager::instance(); EditorManager *em = EditorManager::instance();
m_ui.editorList->setCurrentIndex(em->openedEditorsModel()->indexOf(editor)); setCurrentIndex(em->openedEditorsModel()->indexOf(editor));
m_ui.editorList->selectionModel()->select(m_ui.editorList->currentIndex(), selectionModel()->select(currentIndex(),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
m_ui.editorList->scrollTo(m_ui.editorList->currentIndex()); scrollTo(currentIndex());
} }
bool OpenEditorsWidget::eventFilter(QObject *obj, QEvent *event) bool OpenEditorsWidget::eventFilter(QObject *obj, QEvent *event)
{ {
if (obj == m_ui.editorList && event->type() == QEvent::KeyPress if (obj == this && event->type() == QEvent::KeyPress
&& m_ui.editorList->currentIndex().isValid()) { && currentIndex().isValid()) {
QKeyEvent *ke = static_cast<QKeyEvent*>(event); QKeyEvent *ke = static_cast<QKeyEvent*>(event);
if ((ke->key() == Qt::Key_Return if ((ke->key() == Qt::Key_Return
|| ke->key() == Qt::Key_Enter) || ke->key() == Qt::Key_Enter)
&& ke->modifiers() == 0) { && ke->modifiers() == 0) {
activateEditor(m_ui.editorList->currentIndex()); activateEditor(currentIndex());
return true; return true;
} else if ((ke->key() == Qt::Key_Delete } else if ((ke->key() == Qt::Key_Delete
|| ke->key() == Qt::Key_Backspace) || ke->key() == Qt::Key_Backspace)
&& ke->modifiers() == 0) { && ke->modifiers() == 0) {
closeEditor(m_ui.editorList->currentIndex()); closeEditor(currentIndex());
} }
} else if (obj == m_ui.editorList->viewport() } else if (obj == viewport()
&& event->type() == QEvent::MouseButtonRelease) { && event->type() == QEvent::MouseButtonRelease) {
QMouseEvent * me = static_cast<QMouseEvent*>(event); QMouseEvent * me = static_cast<QMouseEvent*>(event);
if (me->button() == Qt::MiddleButton if (me->button() == Qt::MiddleButton
&& me->modifiers() == Qt::NoModifier) { && me->modifiers() == Qt::NoModifier) {
QModelIndex index = m_ui.editorList->indexAt(me->pos()); QModelIndex index = indexAt(me->pos());
if (index.isValid()) { if (index.isValid()) {
closeEditor(index); closeEditor(index);
return true; return true;
...@@ -193,7 +195,7 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index) ...@@ -193,7 +195,7 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index)
// work around a bug in itemviews where the delegate wouldn't get the QStyle::State_MouseOver // work around a bug in itemviews where the delegate wouldn't get the QStyle::State_MouseOver
QPoint cursorPos = QCursor::pos(); QPoint cursorPos = QCursor::pos();
QWidget *vp = m_ui.editorList->viewport(); QWidget *vp = viewport();
QMouseEvent e(QEvent::MouseMove, vp->mapFromGlobal(cursorPos), cursorPos, Qt::NoButton, 0, 0); QMouseEvent e(QEvent::MouseMove, vp->mapFromGlobal(cursorPos), cursorPos, Qt::NoButton, 0, 0);
QCoreApplication::sendEvent(vp, &e); QCoreApplication::sendEvent(vp, &e);
} }
...@@ -201,7 +203,7 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index) ...@@ -201,7 +203,7 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index)
void OpenEditorsWidget::activateEditor(const QModelIndex &index) void OpenEditorsWidget::activateEditor(const QModelIndex &index)
{ {
m_ui.editorList->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
EditorManager::instance()->activateEditorForIndex(index, EditorManager::ModeSwitch); EditorManager::instance()->activateEditorForIndex(index, EditorManager::ModeSwitch);
} }
...@@ -215,11 +217,11 @@ void OpenEditorsWidget::closeEditor(const QModelIndex &index) ...@@ -215,11 +217,11 @@ void OpenEditorsWidget::closeEditor(const QModelIndex &index)
void OpenEditorsWidget::contextMenuRequested(QPoint pos) void OpenEditorsWidget::contextMenuRequested(QPoint pos)
{ {
QMenu contextMenu; QMenu contextMenu;
QModelIndex editorIndex = m_ui.editorList->indexAt(pos); QModelIndex editorIndex = indexAt(pos);
EditorManager::instance()->addCloseEditorActions(&contextMenu, editorIndex); EditorManager::instance()->addCloseEditorActions(&contextMenu, editorIndex);
contextMenu.addSeparator(); contextMenu.addSeparator();
EditorManager::instance()->addNativeDirActions(&contextMenu, editorIndex); EditorManager::instance()->addNativeDirActions(&contextMenu, editorIndex);
contextMenu.exec(m_ui.editorList->mapToGlobal(pos)); contextMenu.exec(mapToGlobal(pos));
} }
/// ///
......
...@@ -30,11 +30,10 @@ ...@@ -30,11 +30,10 @@
#ifndef OPENEDITORSVIEW_H #ifndef OPENEDITORSVIEW_H
#define OPENEDITORSVIEW_H #define OPENEDITORSVIEW_H
#include "ui_openeditorsview.h"
#include <coreplugin/inavigationwidgetfactory.h> #include <coreplugin/inavigationwidgetfactory.h>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QTreeView>
namespace Core { namespace Core {
class IEditor; class IEditor;
...@@ -43,8 +42,6 @@ namespace Internal { ...@@ -43,8 +42,6 @@ namespace Internal {
class OpenEditorsDelegate : public QStyledItemDelegate class OpenEditorsDelegate : public QStyledItemDelegate
{ {
Q_OBJECT
public: public:
explicit OpenEditorsDelegate(QObject *parent = 0); explicit OpenEditorsDelegate(QObject *parent = 0);
...@@ -54,7 +51,7 @@ public: ...@@ -54,7 +51,7 @@ public:
mutable QModelIndex pressedIndex; mutable QModelIndex pressedIndex;
}; };
class OpenEditorsWidget : public QWidget class OpenEditorsWidget : public QTreeView
{ {
Q_OBJECT Q_OBJECT
...@@ -74,8 +71,6 @@ private: ...@@ -74,8 +71,6 @@ private:
void activateEditor(const QModelIndex &index); void activateEditor(const QModelIndex &index);
void closeEditor(const QModelIndex &index); void closeEditor(const QModelIndex &index);
Ui::OpenEditorsView m_ui;
QWidget *m_widget;
OpenEditorsDelegate *m_delegate; OpenEditorsDelegate *m_delegate;
}; };
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Core::Internal::OpenEditorsView</class>
<widget class="QWidget" name="Core::Internal::OpenEditorsView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>263</width>
<height>217</height>
</rect>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTreeView" name="editorList">
<property name="uniformRowHeights">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment