More improvements of text editor tool bar

Make line/column label always visible, and move context drop down to the
right, so it vanishes first. Reduce the minimum size and stretch of the
outline drop down, so the context drop down doesn't vanish too early
either.

Task-number: QTCREATORBUG-15218
Task-number: QTCREATORBUG-19386
Change-Id: Ie2ced1cb62a27a0129438f5605d5711bfac50cd0
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-04-23 17:03:50 +02:00
parent a09bc8d7fa
commit a8aa4bbb31
3 changed files with 17 additions and 11 deletions

View File

@@ -220,9 +220,6 @@ void CppEditorWidget::finalizeInitialization()
d->m_cppSelectionChanger.onCursorPositionChanged(textCursor());
});
// Toolbar: Outline/Overview combo box
insertExtraToolBarWidget(TextEditorWidget::Left, d->m_cppEditorOutline->widget());
// Toolbar: Parse context
ParseContextModel &parseContextModel = cppEditorDocument()->parseContextModel();
d->m_parseContextWidget = new ParseContextWidget(parseContextModel, this);
@@ -233,6 +230,10 @@ void CppEditorWidget::finalizeInitialization()
this, [this](bool areMultipleAvailable) {
d->m_parseContextAction->setVisible(areMultipleAvailable);
});
// Toolbar: Outline/Overview combo box
insertExtraToolBarWidget(TextEditorWidget::Left, d->m_cppEditorOutline->widget());
// clang-format on
// Toolbar: '#' Button
// TODO: Make "Additional Preprocessor Directives" also useful with Clang Code Model.

View File

@@ -109,10 +109,9 @@ CppEditorOutline::CppEditorOutline(TextEditor::TextEditorWidget *editorWidget)
// Set up combo box
m_combo->setModel(m_proxyModel);
m_combo->setMinimumContentsLength(22);
m_combo->setMinimumContentsLength(13);
QSizePolicy policy = m_combo->sizePolicy();
policy.setHorizontalPolicy(QSizePolicy::Expanding);
policy.setHorizontalStretch(2);
m_combo->setSizePolicy(policy);
m_combo->setMaxVisibleItems(40);

View File

@@ -607,11 +607,11 @@ public:
public:
TextEditorWidget *q;
QWidget *m_toolBarWidget = nullptr;
QToolBar *m_toolBar = nullptr;
QWidget *m_stretchWidget = nullptr;
LineColumnLabel *m_cursorPositionLabel = nullptr;
FixedSizeClickLabel *m_fileEncodingLabel = nullptr;
QAction *m_cursorPositionLabelAction = nullptr;
QAction *m_fileEncodingLabelAction = nullptr;
bool m_contentsChanged = false;
@@ -799,21 +799,27 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent)
m_extraArea = new TextEditExtraArea(q);
m_extraArea->setMouseTracking(true);
auto toolBarLayout = new QHBoxLayout;
toolBarLayout->setContentsMargins(0, 0, 0, 0);
toolBarLayout->setSpacing(0);
m_toolBarWidget = new QWidget;
m_toolBarWidget->setLayout(toolBarLayout);
m_stretchWidget = new QWidget;
m_stretchWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_toolBar = new QToolBar;
m_toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
m_toolBar->addWidget(m_stretchWidget);
m_toolBarWidget->layout()->addWidget(m_toolBar);
m_cursorPositionLabel = new LineColumnLabel(q);
const int spacing = q->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) / 2;
m_cursorPositionLabel->setContentsMargins(spacing, 0, spacing, 0);
m_toolBarWidget->layout()->addWidget(m_cursorPositionLabel);
m_fileEncodingLabel = new FixedSizeClickLabel;
m_fileEncodingLabel->setContentsMargins(spacing, 0, spacing, 0);
m_cursorPositionLabelAction = m_toolBar->addWidget(m_cursorPositionLabel);
m_fileEncodingLabelAction = m_toolBar->addWidget(m_fileEncodingLabel);
m_extraSelections.reserve(NExtraSelectionKinds);
}
@@ -822,7 +828,7 @@ TextEditorWidgetPrivate::~TextEditorWidgetPrivate()
QObject::disconnect(m_document.data(), &TextDocument::markRemoved,
this, &TextEditorWidgetPrivate::markRemoved);
q->disconnect(this);
delete m_toolBar;
delete m_toolBarWidget;
delete m_highlightScrollBarController;
}
@@ -7808,7 +7814,7 @@ IDocument *BaseTextEditor::document()
QWidget *BaseTextEditor::toolBar()
{
return editorWidget()->d->m_toolBar;
return editorWidget()->d->m_toolBarWidget;
}
QAction * TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side,
@@ -7821,7 +7827,7 @@ QAction * TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side
}
if (side == Right)
return d->m_toolBar->insertWidget(d->m_cursorPositionLabelAction, widget);
return d->m_toolBar->insertWidget(d->m_fileEncodingLabelAction, widget);
else
return d->m_toolBar->insertWidget(d->m_toolBar->actions().constFirst(), widget);
}