forked from qt-creator/qt-creator
Improve behavior of cpp editor tool bar
The parse context drop down was taking a content based, fixed amount of space in the editor tool bar, without being shrinkable. That was especially bad if you have a long project / target name. When working with a small window / split, the outline drop down would be dropped from the tool bar. This patch makes the parse context drop down shrinkable (with a small minimum size), and gives the outline drop down a slightly higher priority for getting tool bar space. Task-number: QTCREATORBUG-19386 Change-Id: I87e3ee2e411a43b1f398ffd24fe5608e4df02af6 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -134,6 +134,11 @@ ParseContextWidget::ParseContextWidget(ParseContextModel &parseContextModel, QWi
|
|||||||
: QComboBox(parent)
|
: QComboBox(parent)
|
||||||
, m_parseContextModel(parseContextModel)
|
, m_parseContextModel(parseContextModel)
|
||||||
{
|
{
|
||||||
|
setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
|
QSizePolicy policy = sizePolicy();
|
||||||
|
policy.setHorizontalStretch(1);
|
||||||
|
policy.setHorizontalPolicy(QSizePolicy::Maximum);
|
||||||
|
setSizePolicy(policy);
|
||||||
// Set up context menu with a clear action
|
// Set up context menu with a clear action
|
||||||
setContextMenuPolicy(Qt::ActionsContextMenu);
|
setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||||
m_clearPreferredAction = new QAction(tr("Clear Preferred Parse Context"), this);
|
m_clearPreferredAction = new QAction(tr("Clear Preferred Parse Context"), this);
|
||||||
@@ -170,5 +175,16 @@ void ParseContextWidget::syncToModel()
|
|||||||
CppEditorWidget::updateWidgetHighlighting(this, isPreferred);
|
CppEditorWidget::updateWidgetHighlighting(this, isPreferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSize ParseContextWidget::minimumSizeHint() const
|
||||||
|
{
|
||||||
|
// QComboBox always returns the same from sizeHint() and minimumSizeHint().
|
||||||
|
// We want sizeHint() to be the preferred and maximum size
|
||||||
|
// (horizontalPolicy == Maximum), but want it to be shrinkable, which is not the case
|
||||||
|
// if the minimumSizeHint() is the same as sizeHint()
|
||||||
|
QSize size = QComboBox::minimumSizeHint();
|
||||||
|
size.setWidth(120);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ public:
|
|||||||
ParseContextWidget(ParseContextModel &parseContextModel, QWidget *parent);
|
ParseContextWidget(ParseContextModel &parseContextModel, QWidget *parent);
|
||||||
void syncToModel();
|
void syncToModel();
|
||||||
|
|
||||||
|
QSize minimumSizeHint() const final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ParseContextModel &m_parseContextModel;
|
ParseContextModel &m_parseContextModel;
|
||||||
QAction *m_clearPreferredAction = nullptr;
|
QAction *m_clearPreferredAction = nullptr;
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ CppEditorOutline::CppEditorOutline(TextEditor::TextEditorWidget *editorWidget)
|
|||||||
m_combo->setMinimumContentsLength(22);
|
m_combo->setMinimumContentsLength(22);
|
||||||
QSizePolicy policy = m_combo->sizePolicy();
|
QSizePolicy policy = m_combo->sizePolicy();
|
||||||
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
||||||
|
policy.setHorizontalStretch(2);
|
||||||
m_combo->setSizePolicy(policy);
|
m_combo->setSizePolicy(policy);
|
||||||
m_combo->setMaxVisibleItems(40);
|
m_combo->setMaxVisibleItems(40);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user