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