Commit 0fd5e4e9 authored by Lasse Holmstedt's avatar Lasse Holmstedt
Browse files

Removed extra toolbar from quick designer, improved settings page

parent da221819
......@@ -28,6 +28,8 @@
**************************************************************************/
#include "formeditorwidget.h"
#include "qmldesignerplugin.h"
#include "designersettings.h"
#include <QWheelEvent>
#include <cmath>
......@@ -42,7 +44,6 @@
#include <formeditorgraphicsview.h>
#include <formeditorscene.h>
#include <formeditorview.h>
#include "numberseriesaction.h"
namespace QmlDesigner {
......@@ -82,14 +83,8 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view)
// addActions(m_toolActionGroup->actions());
// upperActions.append(m_toolActionGroup->actions());
QAction *separatorAction = new QAction(this);
separatorAction->setSeparator(true);
// addAction(separatorAction);
// upperActions.append(separatorAction);
QActionGroup *layoutActionGroup = new QActionGroup(this);
layoutActionGroup->setExclusive(true);
layoutActionGroup->setExclusive(false);
m_snappingAction = layoutActionGroup->addAction("Toogle Snapping (Press Key E)");
m_snappingAction->setShortcut(Qt::Key_E);
m_snappingAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
......@@ -106,17 +101,10 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view)
m_snappingAndAnchoringAction->setVisible(false);
m_snappingAndAnchoringAction->setIcon(QPixmap(":/icon/layout/snapping_and_anchoring.png"));
m_noSnappingAction = layoutActionGroup->addAction("Toogle Snapping And Anchoring (Press Key T)");
m_noSnappingAction->setShortcut(Qt::Key_T);
m_noSnappingAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
m_noSnappingAction->setCheckable(true);
m_noSnappingAction->setChecked(false);
m_noSnappingAction->setIcon(QPixmap(":/icon/layout/no_snapping.png"));
addActions(layoutActionGroup->actions());
upperActions.append(layoutActionGroup->actions());
separatorAction = new QAction(this);
QAction *separatorAction = new QAction(this);
separatorAction->setSeparator(true);
addAction(separatorAction);
upperActions.append(separatorAction);
......@@ -142,9 +130,9 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view)
upperActions.append(m_selectOnlyContentItemsAction.data());
ToolBox *upperToolBox = new ToolBox(this);
upperToolBox->setActions(upperActions);
fillLayout->addWidget(upperToolBox);
m_toolBox = new ToolBox(this);
fillLayout->addWidget(m_toolBox.data());
m_toolBox->setLeftSideActions(upperActions);
m_graphicsView = new FormEditorGraphicsView(this);
fillLayout->addWidget(m_graphicsView.data());
......@@ -157,36 +145,11 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view)
QList<QAction*> lowerActions;
m_zoomAction = new ZoomAction(toolActionGroup());
m_zoomAction = new ZoomAction(m_toolActionGroup.data());
connect(m_zoomAction.data(), SIGNAL(zoomLevelChanged(double)), SLOT(setZoomLevel(double)));
addAction(m_zoomAction.data());
lowerActions.append(m_zoomAction.data());
QActionGroup *layoutMarginActionGroup = new QActionGroup(this);
m_snappingMarginAction = new NumberSeriesAction(layoutMarginActionGroup);
m_snappingMarginAction->addEntry(tr("no margins (0)"), 0);
m_snappingMarginAction->addEntry(tr("small margin (2)"), 2);
m_snappingMarginAction->addEntry(tr("medium margin (6)"), 6);
m_snappingMarginAction->addEntry(tr("large margin (10)"), 10);
m_snappingMarginAction->setCurrentEntryIndex(2);
layoutMarginActionGroup->addAction(m_snappingMarginAction.data());
m_snappingSpacingAction = new NumberSeriesAction(layoutMarginActionGroup);
m_snappingSpacingAction->addEntry(tr("no spacing (0)"), 0);
m_snappingSpacingAction->addEntry(tr("small spacing (2)"), 2);
m_snappingSpacingAction->addEntry(tr("medium spacing (4)"), 4);
m_snappingSpacingAction->addEntry(tr("large spacing (6)"), 6);
m_snappingSpacingAction->setCurrentEntryIndex(1);
layoutMarginActionGroup->addAction(m_snappingSpacingAction.data());
addActions(layoutMarginActionGroup->actions());
lowerActions.append(layoutMarginActionGroup->actions());
m_lowerToolBox = new ToolBox(this);
lowerToolBox()->setActions(lowerActions);
fillLayout->addWidget(lowerToolBox());
upperActions.append(m_zoomAction.data());
m_toolBox->addRightSideAction(m_zoomAction.data());
}
void FormEditorWidget::enterEvent(QEvent *event)
......@@ -198,6 +161,7 @@ void FormEditorWidget::enterEvent(QEvent *event)
void FormEditorWidget::changeTransformTool(bool checked)
{
if (checked)
m_formEditorView->changeToTransformTools();
}
......@@ -275,19 +239,21 @@ QActionGroup *FormEditorWidget::toolActionGroup() const
return m_toolActionGroup.data();
}
ToolBox *FormEditorWidget::lowerToolBox() const
ToolBox *FormEditorWidget::toolBox() const
{
return m_lowerToolBox.data();
return m_toolBox.data();
}
double FormEditorWidget::spacing() const
{
return m_snappingSpacingAction->currentValue().toDouble();
DesignerSettings settings = Internal::BauhausPlugin::pluginInstance()->settings();
return settings.itemSpacing;
}
double FormEditorWidget::margins() const
{
return m_snappingMarginAction->currentValue().toDouble();
DesignerSettings settings = Internal::BauhausPlugin::pluginInstance()->settings();
return settings.snapMargin;
}
void FormEditorWidget::setFeedbackNode(const QmlItemNode &node)
......
......@@ -43,7 +43,6 @@ class FormEditorView;
class FormEditorScene;
class FormEditorGraphicsView;
class ToolBox;
class NumberSeriesAction;
class QmlItemNode;
......@@ -62,7 +61,7 @@ public:
QAction *snappingAndAnchoringAction() const;
void setScene(FormEditorScene *scene);
ToolBox *lowerToolBox() const;
ToolBox *toolBox() const;
double spacing() const;
double margins() const;
......@@ -84,15 +83,13 @@ private:
QWeakPointer<FormEditorView> m_formEditorView;
QWeakPointer<FormEditorGraphicsView> m_graphicsView;
QWeakPointer<ZoomAction> m_zoomAction;
QWeakPointer<ToolBox> m_toolBox;
QWeakPointer<QAction> m_anchorToolAction;
QWeakPointer<QAction> m_transformToolAction;
QWeakPointer<QActionGroup> m_toolActionGroup;
QWeakPointer<ToolBox> m_lowerToolBox;
QWeakPointer<QAction> m_snappingAction;
QWeakPointer<QAction> m_snappingAndAnchoringAction;
QWeakPointer<QAction> m_noSnappingAction;
QWeakPointer<NumberSeriesAction> m_snappingMarginAction;
QWeakPointer<NumberSeriesAction> m_snappingSpacingAction;
QWeakPointer<QAction> m_showBoundingRectAction;
QWeakPointer<QAction> m_selectOnlyContentItemsAction;
};
......
......@@ -28,6 +28,7 @@
**************************************************************************/
#include "toolbox.h"
#include "utils/styledbar.h"
#include <QToolBar>
#include <QHBoxLayout>
......@@ -38,49 +39,59 @@
namespace QmlDesigner {
ToolBox::ToolBox(QWidget *parentWidget)
: QWidget(parentWidget),
m_toolBar(new QToolBar("Sidebar", this))
: Utils::StyledBar(parentWidget),
m_leftToolBar(new QToolBar("LeftSidebar", this)),
m_rightToolBar(new QToolBar("RightSidebar", this))
{
QHBoxLayout *fillLayout = new QHBoxLayout(this);
fillLayout->setMargin(0);
setLayout(fillLayout);
//setContentsMargins(4, 12, 4, 4);
fillLayout->setSpacing(0);
m_toolBar->setFloatable(true);
m_toolBar->setMovable(true);
m_toolBar->setOrientation(Qt::Horizontal);
m_toolBar->setIconSize(QSize(24, 24));
fillLayout->addWidget(m_toolBar);
m_leftToolBar->setFloatable(true);
m_leftToolBar->setMovable(true);
m_leftToolBar->setOrientation(Qt::Horizontal);
m_leftToolBar->setIconSize(QSize(24, 24));
QToolBar *stretchToolbar = new QToolBar(this);
stretchToolbar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
// QPalette toolPalette(palette());
// QColor newColor(palette().color(QPalette::Window));
// newColor.setAlphaF(0.7);
// toolPalette.setColor(QPalette::Window, newColor);
// setPalette(toolPalette);
// setBackgroundRole(QPalette::Window);
// setAutoFillBackground(true);
// setAttribute(Qt::WA_NoSystemBackground, true);
m_rightToolBar->setOrientation(Qt::Horizontal);
m_rightToolBar->setIconSize(QSize(24, 24));
fillLayout->addWidget(m_leftToolBar);
fillLayout->addWidget(stretchToolbar);
fillLayout->addWidget(m_rightToolBar);
setLayout(fillLayout);
}
void ToolBox::setLeftSideActions(const QList<QAction*> &actions)
{
m_leftToolBar->clear();
m_leftToolBar->addActions(actions);
resize(sizeHint());
}
void ToolBox::setActions(const QList<QAction*> &actions)
void ToolBox::setRightSideActions(const QList<QAction*> &actions)
{
m_toolBar->clear();
m_toolBar->addActions(actions);
m_rightToolBar->clear();
m_rightToolBar->addActions(actions);
resize(sizeHint());
}
void ToolBox::addAction(QAction *action)
void ToolBox::addLeftSideAction(QAction *action)
{
m_toolBar->addAction(action);
m_leftToolBar->addAction(action);
}
void ToolBox::addRightSideAction(QAction *action)
{
m_rightToolBar->addAction(action);
}
QList<QAction*> ToolBox::actions() const
{
return m_toolBar->actions();
return QList<QAction*>() << m_leftToolBar->actions() << m_rightToolBar->actions();
}
} // namespace QmlDesigner
......@@ -30,7 +30,7 @@
#ifndef TOOLBOX_H
#define TOOLBOX_H
#include <QWidget>
#include "utils/styledbar.h"
QT_BEGIN_NAMESPACE
class QToolBar;
......@@ -38,16 +38,19 @@ QT_END_NAMESPACE
namespace QmlDesigner {
class ToolBox : public QWidget
class ToolBox : public Utils::StyledBar
{
public:
ToolBox(QWidget *parentWidget);
void setActions(const QList<QAction*> &actions);
void addAction(QAction *action);
void setLeftSideActions(const QList<QAction*> &actions);
void setRightSideActions(const QList<QAction*> &actions);
void addLeftSideAction(QAction *action);
void addRightSideAction(QAction *action);
QList<QAction*> actions() const;
private:
QToolBar *m_toolBar;
QToolBar *m_leftToolBar;
QToolBar *m_rightToolBar;
};
} // namespace QmlDesigner
......
......@@ -347,7 +347,7 @@ void DesignDocumentController::loadCurrentModel()
m_d->componentAction = new ComponentAction(m_d->formEditorView->widget());
m_d->componentAction->setModel(m_d->model.data());
connect(m_d->componentAction.data(), SIGNAL(currentComponentChanged(ModelNode)), SLOT(changeCurrentModelTo(ModelNode)));
m_d->formEditorView->widget()->lowerToolBox()->addAction(m_d->componentAction.data());
m_d->formEditorView->widget()->toolBox()->addAction(m_d->componentAction.data());
}
// Disable switching between in file components for the time being
m_d->componentAction->setVisible(false);
......
......@@ -62,7 +62,7 @@ public:
QString fileName() const
{ return m_fileName.toString(); }
void setText(const QString &text)
void setText(const QString &/*text*/)
{
}
......
......@@ -35,27 +35,22 @@
using namespace QmlDesigner;
static const char *snapToGridKey = "SnapToGrid";
static const char *showBoundingRectanglesKey = "ShowBoundingRectangles";
static const char *onlyShowItemsWithContentsKey = "OnlyShowItemsWithContents";
DesignerSettings::DesignerSettings()
: snapToGrid(false)
, showBoundingRectangles(false)
, onlyShowItemsWithContents(false)
, openDesignMode(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT)
: openDesignMode(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT)
{}
void DesignerSettings::fromSettings(QSettings *settings)
{
settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_SETTINGS_GROUP));
settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_DESIGNER_SETTINGS_GROUP));
snapToGrid = settings->value(QLatin1String(snapToGridKey), false).toBool();
showBoundingRectangles = settings->value(
QLatin1String(showBoundingRectanglesKey), false).toBool();
onlyShowItemsWithContents = settings->value(
QLatin1String(onlyShowItemsWithContentsKey), false).toBool();
openDesignMode = settings->value(
QLatin1String(QmlDesigner::Constants::QML_OPENDESIGNMODE_SETTINGS_KEY),
bool(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT)).toBool();
itemSpacing = settings->value(
QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), QVariant(0)).toInt();
snapMargin = settings->value(
QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), QVariant(0)).toInt();
settings->endGroup();
settings->endGroup();
}
......@@ -64,20 +59,18 @@ void DesignerSettings::toSettings(QSettings *settings) const
{
settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_SETTINGS_GROUP));
settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_DESIGNER_SETTINGS_GROUP));
settings->setValue(QLatin1String(snapToGridKey), snapToGrid);
settings->setValue(QLatin1String(showBoundingRectanglesKey),
showBoundingRectangles);
settings->setValue(QLatin1String(onlyShowItemsWithContentsKey),
onlyShowItemsWithContents);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_OPENDESIGNMODE_SETTINGS_KEY), openDesignMode);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_ITEMSPACING_KEY), itemSpacing);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), snapMargin);
settings->endGroup();
settings->endGroup();
}
bool DesignerSettings::equals(const DesignerSettings &other) const
{
return snapToGrid == other.snapToGrid
&& showBoundingRectangles == other.showBoundingRectangles
&& onlyShowItemsWithContents == other.onlyShowItemsWithContents
&& openDesignMode == other.openDesignMode;
return openDesignMode == other.openDesignMode
&& snapMargin == other.snapMargin
&& itemSpacing == other.itemSpacing;
}
......@@ -47,11 +47,9 @@ public:
void toSettings(QSettings *) const;
bool equals(const DesignerSettings &other) const;
bool snapToGrid;
bool showBoundingRectangles;
bool onlyShowItemsWithContents;
bool openDesignMode;
int itemSpacing;
int snapMargin;
};
inline bool operator==(const DesignerSettings &s1, const DesignerSettings &s2)
......
......@@ -52,6 +52,8 @@ const char * const FORM_MIMETYPE = "application/x-qmldesigner";
const char * const QML_SETTINGS_GROUP = "QML";
const char * const QML_DESIGNER_SETTINGS_GROUP = "Designer";
const char * const QML_OPENDESIGNMODE_SETTINGS_KEY = "OpenDesignMode";
const char * const QML_ITEMSPACING_KEY = "ItemSpacing";
const char * const QML_SNAPMARGIN_KEY = "SnapMargin";
enum { QML_OPENDESIGNMODE_DEFAULT = 1 };
namespace Internal {
......
......@@ -49,29 +49,25 @@ SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
DesignerSettings SettingsPageWidget::settings() const
{
DesignerSettings ds;
ds.snapToGrid = m_ui.snapToGridCheckbox->isChecked();
ds.showBoundingRectangles = m_ui.showBoundingRectanglesCheckbox->isChecked();
ds.onlyShowItemsWithContents =
m_ui.onlyShowItemsWithContentsCheckBox->isChecked();
ds.openDesignMode = m_ui.editorModeComboBox->currentIndex() == EditModeDesign;
ds.itemSpacing = m_ui.spinItemSpacing->value();
ds.snapMargin = m_ui.spinSnapMargin->value();
return ds;
}
void SettingsPageWidget::setSettings(const DesignerSettings &s)
{
m_ui.snapToGridCheckbox->setChecked(s.snapToGrid);
m_ui.showBoundingRectanglesCheckbox->setChecked(s.showBoundingRectangles);
m_ui.onlyShowItemsWithContentsCheckBox->setChecked(s.onlyShowItemsWithContents);
m_ui.editorModeComboBox->setCurrentIndex(s.openDesignMode ? EditModeDesign : EditModeEdit);
m_ui.spinItemSpacing->setValue(s.itemSpacing);
m_ui.spinSnapMargin->setValue(s.snapMargin);
}
QString SettingsPageWidget::searchKeywords() const
{
QString rc;
QTextStream(&rc)
<< m_ui.snapToGridCheckbox->text()
<< ' ' << m_ui.showBoundingRectanglesCheckbox->text()
<< ' ' << m_ui.onlyShowItemsWithContentsCheckBox->text();
<< ' ' << m_ui.snapMarginLabel
<< ' ' << m_ui.itemSpacingLabel;
rc.remove(QLatin1Char('&'));
return rc;
}
......
......@@ -6,36 +6,142 @@
<rect>
<x>0</x>
<y>0</y>
<width>494</width>
<height>467</height>
<width>433</width>
<height>428</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="2" colspan="3">
<widget class="QCheckBox" name="snapToGridCheckbox">
<property name="text">
<string>&amp;Snap to guides</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="showBoundingRectanglesCheckbox">
<property name="text">
<string>Show &amp;bounding rectangles</string>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Files</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="editorModeLabel">
<property name="text">
<string>Open file in:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="editorModeComboBox">
<item>
<property name="text">
<string>Design mode</string>
</property>
</item>
<item>
<property name="text">
<string>Edit mode</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="onlyShowItemsWithContentsCheckBox">
<property name="text">
<string>Only select items with content</string>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Snapping</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<property name="margin">
<number>9</number>
</property>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<property name="horizontalSpacing">
<number>20</number>
</property>
<item row="0" column="1">
<widget class="QLabel" name="itemSpacingLabel">
<property name="text">
<string>Item spacing</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinItemSpacing">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>50</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="snapMarginLabel">
<property name="text">
<string>Snap margin</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QSpinBox" name="spinSnapMargin">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>