Commit 70b70770 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Fixed layout issues in some editor toolbars

Cleaned up some hacky code in the process.

Done-with: Tobias Hunger
parent b3169701
......@@ -465,7 +465,7 @@ TextEditor::BaseTextEditor *CPPEditorWidget::createEditor()
return editable;
}
void CPPEditorWidget::createToolBar(CPPEditor *editable)
void CPPEditorWidget::createToolBar(CPPEditor *editor)
{
m_outlineCombo = new QComboBox;
m_outlineCombo->setMinimumContentsLength(22);
......@@ -528,10 +528,7 @@ void CPPEditorWidget::createToolBar(CPPEditor *editable)
connect(m_semanticHighlighter, SIGNAL(changed(CppEditor::Internal::SemanticInfo)),
this, SLOT(updateSemanticInfo(CppEditor::Internal::SemanticInfo)));
QToolBar *toolBar = static_cast<QToolBar*>(editable->toolBar());
QList<QAction*> actions = toolBar->actions();
QWidget *w = toolBar->widgetForAction(actions.first());
static_cast<QHBoxLayout*>(w->layout())->insertWidget(0, m_outlineCombo, 1);
editor->insertExtraToolBarWidget(TextEditor::BaseTextEditor::Left, m_outlineCombo);
}
void CPPEditorWidget::paste()
......
......@@ -106,6 +106,7 @@ public:
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(3, 0, 3, 0);
layout->setSpacing(2);
m_patience->setToolTip(tr("Use the patience algorithmn for calculating the diff"));
m_patience->setText(tr("Patience"));
......@@ -236,6 +237,7 @@ public:
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(3, 0, 3, 0);
layout->setSpacing(2);
m_prettyFormat->setToolTip(tr("Select the pretty printing format"));
m_prettyFormat->addItem(tr("oneline"), QLatin1String("oneline"));
......@@ -247,6 +249,7 @@ public:
m_prettyFormat->addItem(tr("raw"), QLatin1String("raw"));
layout->addWidget(m_prettyFormat);
m_prettyFormat->setCurrentIndex(m_settings->showPrettyFormat);
m_prettyFormat->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
connect(m_prettyFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(testForArgumentsChanged()));
}
......@@ -304,6 +307,7 @@ public:
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(3, 0, 3, 0);
layout->setSpacing(2);
m_omitDate = new QToolButton;
m_omitDate->setToolTip(tr("Do not show the date a change was made in the output"));
......
......@@ -274,7 +274,7 @@ TextEditor::BaseTextEditor *GLSLTextEditorWidget::createEditor()
return editable;
}
void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editable)
void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editor)
{
m_outlineCombo = new QComboBox;
m_outlineCombo->setMinimumContentsLength(22);
......@@ -295,10 +295,7 @@ void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editable)
policy.setHorizontalPolicy(QSizePolicy::Expanding);
m_outlineCombo->setSizePolicy(policy);
QToolBar *toolBar = static_cast<QToolBar*>(editable->toolBar());
QList<QAction*> actions = toolBar->actions();
toolBar->insertWidget(actions.first(), m_outlineCombo);
editor->insertExtraToolBarWidget(TextEditor::BaseTextEditor::Left, m_outlineCombo);
}
bool GLSLTextEditorWidget::event(QEvent *e)
......
......@@ -1222,7 +1222,7 @@ TextEditor::BaseTextEditor *QmlJSTextEditorWidget::createEditor()
return editable;
}
void QmlJSTextEditorWidget::createToolBar(QmlJSEditorEditable *editable)
void QmlJSTextEditorWidget::createToolBar(QmlJSEditorEditable *editor)
{
m_outlineCombo = new QComboBox;
m_outlineCombo->setMinimumContentsLength(22);
......@@ -1247,10 +1247,7 @@ void QmlJSTextEditorWidget::createToolBar(QmlJSEditorEditable *editable)
connect(file(), SIGNAL(changed()), this, SLOT(updateFileName()));
QToolBar *toolBar = static_cast<QToolBar*>(editable->toolBar());
QList<QAction*> actions = toolBar->actions();
toolBar->insertWidget(actions.first(), m_outlineCombo);
editor->insertExtraToolBarWidget(TextEditor::BaseTextEditor::Left, m_outlineCombo);
}
TextEditor::BaseTextEditorWidget::Link QmlJSTextEditorWidget::findLinkAt(const QTextCursor &cursor, bool /*resolveTarget*/)
......
......@@ -5775,17 +5775,13 @@ BaseTextEditor::BaseTextEditor(BaseTextEditorWidget *editor)
m_cursorPositionLabel = new Utils::LineColumnLabel;
QHBoxLayout *l = new QHBoxLayout;
QWidget *w = new QWidget;
l->setMargin(0);
l->setContentsMargins(5, 0, 5, 0);
// l->addStretch(0);
l->addWidget(m_cursorPositionLabel);
w->setLayout(l);
m_stretchWidget = new QWidget;
m_stretchWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_toolBar = new QToolBar;
m_toolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
m_toolBar->addWidget(w);
m_toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
m_toolBar->addWidget(m_stretchWidget);
m_cursorPositionLabelAction = m_toolBar->addWidget(m_cursorPositionLabel);
connect(editor, SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition()));
}
......@@ -5801,6 +5797,21 @@ QWidget *BaseTextEditor::toolBar()
return m_toolBar;
}
void BaseTextEditor::insertExtraToolBarWidget(BaseTextEditor::Side side,
QWidget *widget)
{
if (widget->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag) {
if (m_stretchWidget)
m_stretchWidget->deleteLater();
m_stretchWidget = 0;
}
if (side == Right)
m_toolBar->insertWidget(m_cursorPositionLabelAction, widget);
else
m_toolBar->insertWidget(m_toolBar->actions().first(), widget);
}
int BaseTextEditor::find(const QString &) const
{
return 0;
......
......@@ -567,6 +567,9 @@ public:
bool restoreState(const QByteArray &state) { return e->restoreState(state); }
QWidget *toolBar();
enum Side { Left, Right };
void insertExtraToolBarWidget(Side side, QWidget *widget);
// ITextEditor
int find(const QString &string) const;
int currentLine() const;
......@@ -609,6 +612,8 @@ private:
BaseTextEditorWidget *e;
mutable QString m_contextHelpId;
QToolBar *m_toolBar;
QWidget *m_stretchWidget;
QAction *m_cursorPositionLabelAction;
Utils::LineColumnLabel *m_cursorPositionLabel;
};
......
......@@ -120,39 +120,31 @@ class VCSBaseDiffEditor : public VCSBaseEditor
{
public:
VCSBaseDiffEditor(VCSBaseEditorWidget *, const VCSBaseEditorParameters *type);
~VCSBaseDiffEditor();
virtual QWidget *toolBar() { return m_toolBar; }
QComboBox *diffFileBrowseComboBox() const { return m_diffFileBrowseComboBox; }
private:
QToolBar *m_toolBar;
QComboBox *m_diffFileBrowseComboBox;
};
VCSBaseDiffEditor::VCSBaseDiffEditor(VCSBaseEditorWidget *w, const VCSBaseEditorParameters *type) :
VCSBaseEditor(w, type),
m_toolBar(new QToolBar),
m_diffFileBrowseComboBox(new QComboBox(m_toolBar))
m_diffFileBrowseComboBox(new QComboBox)
{
m_diffFileBrowseComboBox->setMinimumContentsLength(20);
// Make the combo box prefer to expand
QSizePolicy policy = m_diffFileBrowseComboBox->sizePolicy();
policy.setHorizontalPolicy(QSizePolicy::Expanding);
m_diffFileBrowseComboBox->setSizePolicy(policy);
m_toolBar->addWidget(m_diffFileBrowseComboBox);
}
VCSBaseDiffEditor::~VCSBaseDiffEditor()
{
delete m_toolBar;
insertExtraToolBarWidget(Left, m_diffFileBrowseComboBox);
}
// ----------- VCSBaseEditorPrivate
struct VCSBaseEditorPrivate
struct VCSBaseEditorWidgetPrivate
{
VCSBaseEditorPrivate(const VCSBaseEditorParameters *type);
VCSBaseEditorWidgetPrivate(const VCSBaseEditorParameters *type);
const VCSBaseEditorParameters *m_parameters;
......@@ -167,17 +159,17 @@ struct VCSBaseEditorPrivate
QString m_annotatePreviousRevisionTextFormat;
QString m_copyRevisionTextFormat;
bool m_fileLogAnnotateEnabled;
QToolBar *m_toolBar;
TextEditor::BaseTextEditor *m_editor;
QWidget *m_configurationWidget;
};
VCSBaseEditorPrivate::VCSBaseEditorPrivate(const VCSBaseEditorParameters *type) :
VCSBaseEditorWidgetPrivate::VCSBaseEditorWidgetPrivate(const VCSBaseEditorParameters *type) :
m_parameters(type),
m_cursorLine(-1),
m_annotateRevisionTextFormat(VCSBaseEditorWidget::tr("Annotate \"%1\"")),
m_copyRevisionTextFormat(VCSBaseEditorWidget::tr("Copy \"%1\"")),
m_fileLogAnnotateEnabled(false),
m_toolBar(0),
m_editor(0),
m_configurationWidget(0)
{
}
......@@ -185,7 +177,7 @@ VCSBaseEditorPrivate::VCSBaseEditorPrivate(const VCSBaseEditorParameters *type)
// ------------ VCSBaseEditor
VCSBaseEditorWidget::VCSBaseEditorWidget(const VCSBaseEditorParameters *type, QWidget *parent)
: BaseTextEditorWidget(parent),
d(new VCSBaseEditorPrivate(type))
d(new VCSBaseEditorWidgetPrivate(type))
{
if (VCSBase::Constants::Internal::debug)
qDebug() << "VCSBaseEditor::VCSBaseEditor" << type->type << type->id;
......@@ -334,7 +326,7 @@ TextEditor::BaseTextEditor *VCSBaseEditorWidget::createEditor()
} else {
editor = new VCSBaseEditor(this, d->m_parameters);
}
d->m_toolBar = qobject_cast<QToolBar *>(editor->toolBar());
d->m_editor = editor;
// Pass on signals.
connect(this, SIGNAL(describeRequested(QString,QString)),
......@@ -842,20 +834,12 @@ QString VCSBaseEditorWidget::getTitleId(const QString &workingDirectory,
bool VCSBaseEditorWidget::setConfigurationWidget(QWidget *w)
{
if (!d->m_toolBar || d->m_configurationWidget)
if (!d->m_editor || d->m_configurationWidget)
return false;
d->m_configurationWidget = w;
if (contentType() == AnnotateOutput) {
QList<QAction *> actions = d->m_toolBar->actions();
Q_ASSERT(actions.count() >= 1);
QWidget *spacer = new QWidget(d->m_toolBar);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
QAction *configAction = d->m_toolBar->insertWidget(actions.at(0), w);
d->m_toolBar->insertWidget(configAction, spacer);
} else {
d->m_toolBar->addWidget(w);
}
d->m_editor->insertExtraToolBarWidget(TextEditor::BaseTextEditor::Right, w);
return true;
}
......
......@@ -52,7 +52,7 @@ namespace Core {
namespace VCSBase {
struct VCSBaseEditorPrivate;
struct VCSBaseEditorWidgetPrivate;
class DiffHighlighter;
class BaseAnnotationHighlighter;
......@@ -248,7 +248,7 @@ private:
QAction *createAnnotateAction(const QString &change, bool previous = false);
QAction *createCopyRevisionAction(const QString &change);
VCSBaseEditorPrivate *d;
VCSBaseEditorWidgetPrivate *d;
};
} // namespace VCSBase
......
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