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

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 \
actionmanager/commandmappings.ui \
dialogs/saveitemsdialog.ui \
dialogs/openwithdialog.ui \
editormanager/openeditorsview.ui \
generalsettings.ui \
dialogs/externaltoolconfig.ui \
variablechooser.ui \
......
......@@ -208,7 +208,6 @@ QtcPlugin {
"editormanager/openeditorsmodel.h",
"editormanager/openeditorsview.cpp",
"editormanager/openeditorsview.h",
"editormanager/openeditorsview.ui",
"editormanager/openeditorswindow.cpp",
"editormanager/openeditorswindow.h",
"editormanager/systemeditor.cpp",
......
......@@ -41,6 +41,8 @@
#include <coreplugin/actionmanager/command.h>
#include <utils/qtcassert.h>
#include <QApplication>
#include <QGridLayout>
#include <QTimer>
#include <QMenu>
#include <QPainter>
......@@ -48,6 +50,7 @@
#include <QStyleOption>
#include <QHeaderView>
#include <QKeyEvent>
#include <QTreeView>
#ifdef Q_OS_MAC
#include <qmacstyle_mac.h>
#endif
......@@ -96,37 +99,36 @@ void OpenEditorsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
OpenEditorsWidget::OpenEditorsWidget()
{
m_ui.setupUi(this);
setWindowTitle(tr("Open Documents"));
setWindowIcon(QIcon(QLatin1String(Constants::ICON_DIR)));
setFocusProxy(m_ui.editorList);
m_ui.editorList->viewport()->setAttribute(Qt::WA_Hover);
m_ui.editorList->setItemDelegate((m_delegate = new OpenEditorsDelegate(this)));
m_ui.editorList->header()->hide();
m_ui.editorList->setIndentation(0);
m_ui.editorList->setTextElideMode(Qt::ElideMiddle);
m_ui.editorList->setFrameStyle(QFrame::NoFrame);
m_ui.editorList->setAttribute(Qt::WA_MacShowFocusRect, false);
setUniformRowHeights(true);
viewport()->setAttribute(Qt::WA_Hover);
setItemDelegate((m_delegate = new OpenEditorsDelegate(this)));
header()->hide();
setIndentation(0);
setTextElideMode(Qt::ElideMiddle);
setFrameStyle(QFrame::NoFrame);
setAttribute(Qt::WA_MacShowFocusRect, false);
EditorManager *em = EditorManager::instance();
m_ui.editorList->setModel(em->openedEditorsModel());
m_ui.editorList->setSelectionMode(QAbstractItemView::SingleSelection);
m_ui.editorList->setSelectionBehavior(QAbstractItemView::SelectRows);
m_ui.editorList->header()->setStretchLastSection(false);
m_ui.editorList->header()->setResizeMode(0, QHeaderView::Stretch);
m_ui.editorList->header()->setResizeMode(1, QHeaderView::Fixed);
m_ui.editorList->header()->resizeSection(1, 16);
m_ui.editorList->setContextMenuPolicy(Qt::CustomContextMenu);
m_ui.editorList->installEventFilter(this);
m_ui.editorList->viewport()->installEventFilter(this);
setModel(em->openedEditorsModel());
setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
header()->setStretchLastSection(false);
header()->setResizeMode(0, QHeaderView::Stretch);
header()->setResizeMode(1, QHeaderView::Fixed);
header()->resizeSection(1, 16);
setContextMenuPolicy(Qt::CustomContextMenu);
installEventFilter(this);
viewport()->installEventFilter(this);
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateCurrentItem(Core::IEditor*)));
connect(m_ui.editorList, SIGNAL(clicked(QModelIndex)),
connect(this, SIGNAL(clicked(QModelIndex)),
this, SLOT(handleClicked(QModelIndex)));
connect(m_ui.editorList, SIGNAL(pressed(QModelIndex)),
connect(this, SIGNAL(pressed(QModelIndex)),
this, SLOT(handlePressed(QModelIndex)));
connect(m_ui.editorList, SIGNAL(customContextMenuRequested(QPoint)),
connect(this, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(contextMenuRequested(QPoint)));
}
......@@ -137,37 +139,37 @@ OpenEditorsWidget::~OpenEditorsWidget()
void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor)
{
if (!editor) {
m_ui.editorList->clearSelection();
clearSelection();
return;
}
EditorManager *em = EditorManager::instance();
m_ui.editorList->setCurrentIndex(em->openedEditorsModel()->indexOf(editor));
m_ui.editorList->selectionModel()->select(m_ui.editorList->currentIndex(),
setCurrentIndex(em->openedEditorsModel()->indexOf(editor));
selectionModel()->select(currentIndex(),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
m_ui.editorList->scrollTo(m_ui.editorList->currentIndex());
scrollTo(currentIndex());
}
bool OpenEditorsWidget::eventFilter(QObject *obj, QEvent *event)
{
if (obj == m_ui.editorList && event->type() == QEvent::KeyPress
&& m_ui.editorList->currentIndex().isValid()) {
if (obj == this && event->type() == QEvent::KeyPress
&& currentIndex().isValid()) {
QKeyEvent *ke = static_cast<QKeyEvent*>(event);
if ((ke->key() == Qt::Key_Return
|| ke->key() == Qt::Key_Enter)
&& ke->modifiers() == 0) {
activateEditor(m_ui.editorList->currentIndex());
activateEditor(currentIndex());
return true;
} else if ((ke->key() == Qt::Key_Delete
|| ke->key() == Qt::Key_Backspace)
&& 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) {
QMouseEvent * me = static_cast<QMouseEvent*>(event);
if (me->button() == Qt::MiddleButton
&& me->modifiers() == Qt::NoModifier) {
QModelIndex index = m_ui.editorList->indexAt(me->pos());
QModelIndex index = indexAt(me->pos());
if (index.isValid()) {
closeEditor(index);
return true;
......@@ -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
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);
QCoreApplication::sendEvent(vp, &e);
}
......@@ -201,7 +203,7 @@ void OpenEditorsWidget::handleClicked(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);
}
......@@ -215,11 +217,11 @@ void OpenEditorsWidget::closeEditor(const QModelIndex &index)
void OpenEditorsWidget::contextMenuRequested(QPoint pos)
{
QMenu contextMenu;
QModelIndex editorIndex = m_ui.editorList->indexAt(pos);
QModelIndex editorIndex = indexAt(pos);
EditorManager::instance()->addCloseEditorActions(&contextMenu, editorIndex);
contextMenu.addSeparator();
EditorManager::instance()->addNativeDirActions(&contextMenu, editorIndex);
contextMenu.exec(m_ui.editorList->mapToGlobal(pos));
contextMenu.exec(mapToGlobal(pos));
}
///
......
......@@ -30,11 +30,10 @@
#ifndef OPENEDITORSVIEW_H
#define OPENEDITORSVIEW_H
#include "ui_openeditorsview.h"
#include <coreplugin/inavigationwidgetfactory.h>
#include <QStyledItemDelegate>
#include <QTreeView>
namespace Core {
class IEditor;
......@@ -43,8 +42,6 @@ namespace Internal {
class OpenEditorsDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit OpenEditorsDelegate(QObject *parent = 0);
......@@ -54,7 +51,7 @@ public:
mutable QModelIndex pressedIndex;
};
class OpenEditorsWidget : public QWidget
class OpenEditorsWidget : public QTreeView
{
Q_OBJECT
......@@ -74,8 +71,6 @@ private:
void activateEditor(const QModelIndex &index);
void closeEditor(const QModelIndex &index);
Ui::OpenEditorsView m_ui;
QWidget *m_widget;
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