Commit 292db7a5 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.propertyEditor: allow collapsing

parent 9c45d8b8
......@@ -51,6 +51,8 @@
#include "siblingcombobox.h"
#include "propertyeditortransaction.h"
#include <coreplugin/sidebar.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QFileSystemWatcher>
......@@ -65,11 +67,15 @@
#include <private/qdeclarativemetatype_p.h>
#include <QMessageBox>
#include <QApplication>
#include <QGraphicsOpacityEffect>
#include <QToolBar>
enum {
debug = false
};
const int collapseButtonOffset = 114;
namespace QmlDesigner {
PropertyEditor::NodeType::NodeType(PropertyEditor *propertyEditor) :
......@@ -181,11 +187,15 @@ void PropertyEditor::NodeType::setup(const QmlObjectNode &fxObjectNode, const QS
m_backendAnchorBinding.setup(QmlItemNode(fxObjectNode.modelNode()));
ctxt->setContextProperty("anchorBackend", &m_backendAnchorBinding);
QApplication::processEvents();
ctxt->setContextProperty("transaction", m_propertyEditorTransaction.data());
QApplication::processEvents();
ctxt->setContextProperty("backendValues", &m_backendValuesPropertyMap);
QApplication::processEvents();
ctxt->setContextProperty("specificsUrl", QVariant(qmlSpecificsFile));
QApplication::processEvents();
ctxt->setContextProperty("stateName", QVariant(stateName));
QApplication::processEvents();
ctxt->setContextProperty("propertyCount", QVariant(fxObjectNode.modelNode().properties().count()));
ctxt->setContextProperty("isBaseState", QVariant(fxObjectNode.isInBaseState()));
ctxt->setContextProperty("selectionChanged", QVariant(false));
......@@ -235,7 +245,8 @@ PropertyEditor::PropertyEditor(QWidget *parent) :
m_parent(parent),
m_updateShortcut(0),
m_timerId(0),
m_stackedWidget(new QStackedWidget(parent)),
m_stackedWidget(new StackedWidget(parent)),
m_collapseButton(new CollapseButton(m_stackedWidget)),
m_currentType(0),
m_locked(false)
{
......@@ -247,6 +258,14 @@ PropertyEditor::PropertyEditor(QWidget *parent) :
QString styleSheet = QLatin1String(file.readAll());
m_stackedWidget->setStyleSheet(styleSheet);
m_stackedWidget->setMinimumWidth(360);
m_collapseButton->raise();
m_collapseButton->show();
connect(m_collapseButton, SIGNAL(expand()), this, SLOT(expand()));
connect(m_collapseButton, SIGNAL(collapse()), this, SLOT(collapse()));
connect(m_stackedWidget, SIGNAL(resized()), this, SLOT(updateCollapseButton()));
m_stackedWidget->insertWidget(0, new QWidget(m_stackedWidget));
static bool declarativeTypesRegistered = false;
if (!declarativeTypesRegistered) {
......@@ -290,8 +309,6 @@ void PropertyEditor::setupPane(const QString &typeName)
m_stackedWidget->addWidget(type->m_view);
m_typeHash.insert(qmlFile.toString(), type);
m_stackedWidget->setCurrentWidget(type->m_view);
} else {
QDeclarativeContext *ctxt = type->m_view->rootContext();
ctxt->setContextProperty("finishedNotify", QVariant(false) );
......@@ -299,6 +316,7 @@ void PropertyEditor::setupPane(const QString &typeName)
type->initialSetup(typeName, qmlSpecificsFile, this);
ctxt->setContextProperty("finishedNotify", QVariant(true) );
}
m_stackedWidget->setCurrentWidget(type->m_view);
}
void PropertyEditor::changeValue(const QString &propertyName)
......@@ -444,6 +462,76 @@ void PropertyEditor::changeExpression(const QString &name)
}
}
void PropertyEditor::expand()
{
m_stackedWidget->setMinimumWidth(360);
m_stackedWidget->setMaximumWidth(1000);
m_stackedWidget->parentWidget()->layout()->update();
QWidget * parentWidget = m_stackedWidget->parentWidget();
QWidget *childWidget = m_stackedWidget;
while (parentWidget) {
if (Core::SideBar *sideBar = qobject_cast<Core::SideBar*>(parentWidget)) {
childWidget->setMaximumWidth(2000);
QList<QComboBox*> list = sideBar->findChildren<QComboBox*>();
foreach (QComboBox* box, list) {
if (qobject_cast<QToolBar*>(box->parentWidget()))
box->parentWidget()->show();
}
sideBar->refresh();
sideBar->update();
break;
}
childWidget = parentWidget;
parentWidget = parentWidget->parentWidget();
}
m_collapseButton->move(0, m_stackedWidget->height() - collapseButtonOffset);
resetView();
}
void PropertyEditor::collapse()
{
m_stackedWidget->setCurrentIndex(0);
m_stackedWidget->setMinimumWidth(0);
QWidget * parentWidget = m_stackedWidget->parentWidget();
QWidget *childWidget = m_stackedWidget;
while (parentWidget) {
if (Core::SideBar *sideBar = qobject_cast<Core::SideBar*>(parentWidget)) {
childWidget->setMaximumWidth(22);
QSplitter* parentSplitter = qobject_cast<QSplitter*>(sideBar->parentWidget());
QList<int> s = sideBar->sizes();
s.removeLast();
s.append(25);
parentSplitter->setSizes(s);
parentSplitter->refresh();
parentSplitter->update();
QApplication::processEvents();
QList<QComboBox*> list = sideBar->findChildren<QComboBox*>();
foreach (QComboBox* box, list) {
if (qobject_cast<QToolBar*>(box->parentWidget())) {
box->parentWidget()->hide();
}
}
break;
}
childWidget = parentWidget;
parentWidget = parentWidget->parentWidget();
}
m_collapseButton->raise();
m_stackedWidget->parentWidget()->layout()->activate();
m_collapseButton->move(0, m_stackedWidget->height() - collapseButtonOffset + 20);
}
void PropertyEditor::updateCollapseButton()
{
m_collapseButton->move(0, m_stackedWidget->height() - collapseButtonOffset + 20);
m_collapseButton->update();
}
void PropertyEditor::otherPropertyChanged(const QmlObjectNode &fxObjectNode, const QString &propertyName)
{
QmlModelView::otherPropertyChanged(fxObjectNode, propertyName);
......@@ -486,7 +574,7 @@ void PropertyEditor::setQmlDir(const QString &qmlDir)
void PropertyEditor::delayedResetView()
{
if (m_timerId == 0)
m_timerId = startTimer(20);
m_timerId = startTimer(500);
}
void PropertyEditor::timerEvent(QTimerEvent *timerEvent)
......@@ -501,6 +589,9 @@ void PropertyEditor::resetView()
if (model() == 0)
return;
if (m_collapseButton->isCollapsed())
return;
if (debug)
qDebug() << "________________ RELOADING PROPERTY EDITOR QML _______________________";
......@@ -551,6 +642,9 @@ void PropertyEditor::resetView()
m_stackedWidget->setCurrentWidget(type->m_view);
m_collapseButton->raise();
m_collapseButton->move(0, m_stackedWidget->height() - collapseButtonOffset);
QDeclarativeContext *ctxt = type->m_view->rootContext();
ctxt->setContextProperty("finishedNotify", QVariant(true));
ctxt->setContextProperty("selectionChanged", QVariant(false));
......@@ -775,5 +869,45 @@ QString PropertyEditor::locateQmlFile(const QString &relativePath) const
return QString();
}
CollapseButton::CollapseButton(QWidget *parent) : QWidget(parent), m_collapsed(false), m_hovered(false),
m_pixmap_normal(":/qmldesigner/images/collapse-button-normal.png"),
m_pixmap_normal_mirrored(":/qmldesigner/images/collapse-button-normal-mirrored.png"),
m_pixmap_hover_mirrored(":/qmldesigner/images/collapse-button-hover-mirrored.png"),
m_pixmap_hover(":/qmldesigner/images/collapse-button-hover.png")
{
setFixedWidth(20);
setFixedHeight(81);
setMouseTracking(true);
setAttribute(Qt::WA_TranslucentBackground, true);
QGraphicsOpacityEffect* graphicsOpacityEffect = new QGraphicsOpacityEffect(this);
setGraphicsEffect(graphicsOpacityEffect);
graphicsOpacityEffect->setOpacity(0.4);
setToolTip(QLatin1String("Properties"));
}
void CollapseButton::setOpacity(qreal opacity)
{
qobject_cast<QGraphicsOpacityEffect*>(graphicsEffect())->setOpacity(opacity);
}
void CollapseButton::paintEvent(QPaintEvent *event)
{
QWidget::paintEvent(event);
QPainter p(this);
if (m_hovered) {
if (m_collapsed)
p.drawPixmap(0,0, m_pixmap_hover_mirrored);
else
p.drawPixmap(0,0, m_pixmap_hover);
} else {
if (m_collapsed)
p.drawPixmap(0,0, m_pixmap_normal_mirrored);
else
p.drawPixmap(0,0, m_pixmap_normal);
}
}
} //QmlDesigner
......@@ -34,6 +34,7 @@
#include <QDeclarativeView>
#include <QHash>
#include <QDeclarativePropertyMap>
#include <QStackedWidget>
#include "qmlanchorbindingproxy.h"
......@@ -45,6 +46,8 @@ QT_END_NAMESPACE
namespace QmlDesigner {
class PropertyEditorTransaction;
class CollapseButton;
class StackedWidget;
class PropertyEditor: public QmlModelView
{
......@@ -109,6 +112,9 @@ private slots:
void reloadQml();
void changeValue(const QString &name);
void changeExpression(const QString &name);
void expand();
void collapse();
void updateCollapseButton();
private: //functions
QString qmlFileName(const NodeMetaInfo &nodeInfo) const;
......@@ -126,13 +132,86 @@ private: //variables
QWidget *m_parent;
QShortcut *m_updateShortcut;
int m_timerId;
QStackedWidget* m_stackedWidget;
StackedWidget* m_stackedWidget;
CollapseButton *m_collapseButton;
QString m_qmlDir;
QHash<QString, NodeType *> m_typeHash;
NodeType *m_currentType;
bool m_locked;
};
class StackedWidget : public QStackedWidget
{
Q_OBJECT
public:
StackedWidget(QWidget *parent = 0) : QStackedWidget(parent) {}
signals:
void resized();
protected:
void resizeEvent(QResizeEvent * event)
{
QStackedWidget::resizeEvent(event);
emit resized();
}
};
class CollapseButton : public QWidget
{
Q_OBJECT
public:
CollapseButton(QWidget *parent = 0);
bool isCollapsed() const
{ return m_collapsed; }
signals:
void expand();
void collapse();
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *e)
{
if (m_collapsed) {
m_collapsed = false;
emit expand();
} else {
m_collapsed = true;
emit collapse();
}
update();
}
void enterEvent ( QEvent *)
{
m_hovered = true;
setOpacity(0.9);
update();
}
void leaveEvent ( QEvent *)
{
m_hovered = false;
setOpacity(0.4);
update();
}
void setOpacity(qreal opacity);
private:
bool m_collapsed;
bool m_hovered;
QPixmap m_pixmap_normal;
QPixmap m_pixmap_hover;
QPixmap m_pixmap_normal_mirrored;
QPixmap m_pixmap_hover_mirrored;
};
}
#endif // QmlPropertyView_h
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