Commit 9dd0a108 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Fix the Creator widgets Designer plugin, add DetailsWidgets.

Polish the DetailsWidget for that purpose, add properties,
make it survive without widgets, add a container extension.
parent 9bef75f8
......@@ -3,21 +3,23 @@
#include <QtGui/QGridLayout>
#include <QtCore/QStack>
#include <QtGui/QLabel>
#include <QtGui/QGridLayout>
#include <QtGui/QPainter>
using namespace Utils;
DetailsWidget::DetailsWidget(QWidget *parent)
: QWidget(parent),
m_summaryLabel(new QLabel(this)),
m_detailsButton(new DetailsButton(this)),
m_widget(0),
m_toolWidget(0)
m_toolWidget(0),
m_grid(new QGridLayout(this))
{
m_grid = new QGridLayout(this);
//m_grid->setMargin(0);
m_summaryLabel = new QLabel(this);
m_summaryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_summaryLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_detailsButton = new DetailsButton(this);
m_grid->addWidget(m_summaryLabel, 0, 0, 2, 0);
m_grid->addWidget(m_detailsButton, 1, 2);
......@@ -45,8 +47,8 @@ void DetailsWidget::paintEvent(QPaintEvent *paintEvent)
if (!m_detailsButton->isToggled())
return;
QRect detailsGeometry = m_detailsButton->geometry();
QRect widgetGeometry = m_widget->geometry();
const QRect detailsGeometry = m_detailsButton->geometry();
const QRect widgetGeometry = m_widget ? m_widget->geometry() : QRect(x(), y() + height(), width(), 0);
QPoint tl(detailsGeometry.topLeft());
tl += QPoint(-3, -3);
......@@ -85,29 +87,65 @@ void DetailsWidget::setSummaryText(const QString &text)
m_summaryLabel->setText(text);
}
QString DetailsWidget::summaryText() const
{
return m_summaryLabel->text();
}
bool DetailsWidget::expanded() const
{
return m_detailsButton->isToggled();
}
void DetailsWidget::setExpanded(bool v)
{
if (expanded() != v)
m_detailsButton->animateClick();
}
QWidget *DetailsWidget::widget() const
{
return m_widget;
}
void DetailsWidget::setWidget(QWidget *widget)
{
if (m_widget == widget)
return;
if (m_widget)
if (m_widget) {
m_grid->removeWidget(m_widget);
m_grid->addWidget(widget, 2, 0, 1, 3);
m_widget = widget;
m_widget->setVisible(m_detailsButton->isToggled());
m_widget = 0;
}
if (widget) {
m_grid->addWidget(widget, 2, 0, 1, 3);
m_widget = widget;
m_widget->setVisible(m_detailsButton->isToggled());
}
}
void DetailsWidget::setToolWidget(QWidget *widget)
{
if (m_toolWidget == widget)
return;
if (m_toolWidget)
if (m_toolWidget) {
m_grid->removeWidget(m_toolWidget);
m_grid->addWidget(widget, 1, 1);
m_toolWidget = widget;
m_toolWidget = 0;
}
if (widget) {
m_grid->addWidget(widget, 1, 1);
m_toolWidget = widget;
}
}
QWidget *DetailsWidget::toolWidget() const
{
return m_toolWidget;
}
void DetailsWidget::fixUpLayout()
{
if (!m_widget)
return;
QWidget *parent = m_widget;
QStack<QWidget *> widgets;
while((parent = parent->parentWidget()) && parent && parent->layout()) {
......
......@@ -4,8 +4,11 @@
#include "utils_global.h"
#include <QtGui/QWidget>
#include <QtGui/QLabel>
#include <QtGui/QGridLayout>
QT_BEGIN_NAMESPACE
class QLabel;
class QGridLayout;
QT_END_NAMESPACE
namespace Utils {
class DetailsButton;
......@@ -13,16 +16,30 @@ class DetailsButton;
class QTCREATOR_UTILS_EXPORT DetailsWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString summaryText READ summaryText WRITE setSummaryText DESIGNABLE true)
Q_PROPERTY(bool expanded READ expanded WRITE setExpanded DESIGNABLE true)
public:
DetailsWidget(QWidget *parent = 0);
~DetailsWidget();
void setSummaryText(const QString &text);
QString summaryText() const;
bool expanded() const;
void setExpanded(bool);
void setWidget(QWidget *widget);
QWidget *widget() const;
void setToolWidget(QWidget *widget);
QWidget *toolWidget() const;
protected:
void paintEvent(QPaintEvent *paintEvent);
private slots:
void detailsButtonClicked();
private:
void fixUpLayout();
QLabel *m_summaryLabel;
......
......@@ -63,6 +63,9 @@ public:
QWidget *createWidget(QWidget *parent);
void initialize(QDesignerFormEditorInterface *core);
protected:
bool initialized() const { return m_initialized; }
private:
QString displayName() const;
QString geometryProperty() const;
......
......@@ -31,6 +31,8 @@
#include <QtGui/QMenu>
#include <QtGui/QAction>
#include <QtDesigner/QExtensionManager>
#include <QtDesigner/QDesignerFormEditorInterface>
static const char *groupC = "QtCreator";
......@@ -165,11 +167,125 @@ PathListEditor_CW::PathListEditor_CW(QObject *parent) :
{
}
DetailsButton_CW::DetailsButton_CW(QObject *parent) :
QObject(parent),
CustomWidget<Utils::DetailsButton>
(QLatin1String("<utils/detailsbutton.h>"),
false,
QLatin1String(groupC),
QIcon(),
QLatin1String("Expandable button for 'Details'"))
{
}
DetailsWidget_CW::DetailsWidget_CW(QObject *parent) :
QObject(parent),
CustomWidget<Utils::DetailsWidget>
(QLatin1String("<utils/detailswidget.h>"),
true,
QLatin1String(groupC),
QIcon(),
QLatin1String("Expandable widget for 'Details'. You might need an expandable spacer below."))
{
}
QString DetailsWidget_CW::domXml() const
{
// Expanded from start, else child visibility is wrong
const char *xmlC ="\
<ui language=\"c++\" displayname=\"DetailsWidget\">\
<widget class=\"Utils::DetailsWidget\" name=\"detailsWidget\">\
<property name=\"geometry\">\
<rect><x>0</x><y>0</y><width>160</width><height>80</height></rect>\
</property>\
<property name=\"summaryText\">\
<string>Summary</string>\
</property>\
<property name=\"expanded\">\
<bool>true</bool>\
</property>\
<widget class=\"QWidget\" name=\"detailsContainer\" />\
</widget>\
<customwidgets>\
<customwidget>\
<class>Utils::DetailsWidget</class>\
<addpagemethod>setWidget</addpagemethod>\
</customwidget>\
</customwidgets>\
</ui>";
return QLatin1String(xmlC);
}
void DetailsWidget_CW::initialize(QDesignerFormEditorInterface *core)
{
const bool firstTime = !initialized();
CustomWidget<Utils::DetailsWidget>::initialize(core);
if (firstTime)
if (QExtensionManager *manager = core->extensionManager())
manager->registerExtensions(new DetailsWidgetExtensionFactory(manager), Q_TYPEID(QDesignerContainerExtension));
}
DetailsWidgetContainerExtension::DetailsWidgetContainerExtension(Utils::DetailsWidget *widget, QObject *parent) :
QObject(parent),
m_detailsWidget(widget)
{
}
void DetailsWidgetContainerExtension::addWidget(QWidget *widget)
{
if (m_detailsWidget->widget()) {
qWarning("Cannot add 2nd child to DetailsWidget");
} else {
m_detailsWidget->setWidget(widget);
}
}
int DetailsWidgetContainerExtension::count() const
{
return m_detailsWidget->widget() ? 1 : 0;
}
int DetailsWidgetContainerExtension::currentIndex() const
{
return 0;
}
void DetailsWidgetContainerExtension::insertWidget(int /* index */, QWidget *widget)
{
addWidget(widget);
}
void DetailsWidgetContainerExtension::remove(int /* index */)
{
m_detailsWidget->setWidget(0);
}
void DetailsWidgetContainerExtension::setCurrentIndex(int /* index */)
{
}
QWidget *DetailsWidgetContainerExtension::widget(int /* index */) const
{
return m_detailsWidget->widget();
}
DetailsWidgetExtensionFactory::DetailsWidgetExtensionFactory(QExtensionManager *parent) :
QExtensionFactory(parent)
{
}
QObject *DetailsWidgetExtensionFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const
{
if (Utils::DetailsWidget *dw = qobject_cast<Utils::DetailsWidget*>(object))
if (iid == Q_TYPEID(QDesignerContainerExtension))
return new DetailsWidgetContainerExtension(dw, parent);
return 0;
}
// -------------- WidgetCollection
WidgetCollection::WidgetCollection(QObject *parent) :
QObject(parent)
{
m_plugins.push_back(new NewClassCustomWidget(this));
m_plugins.push_back(new ClassNameValidatingLineEdit_CW(this));
m_plugins.push_back(new FileNameValidatingLineEdit_CW(this));
......@@ -181,6 +297,8 @@ WidgetCollection::WidgetCollection(QObject *parent) :
m_plugins.push_back(new SubmitEditorWidget_CW(this));
m_plugins.push_back(new SubmitFieldWidget_CW(this));
m_plugins.push_back(new PathListEditor_CW(this));
m_plugins.push_back(new DetailsButton_CW(this));
m_plugins.push_back(new DetailsWidget_CW(this));
}
QList<QDesignerCustomWidgetInterface*> WidgetCollection::customWidgets() const
......
......@@ -43,12 +43,20 @@
#include <utils/submiteditorwidget.h>
#include <utils/submitfieldwidget.h>
#include <utils/pathlisteditor.h>
#include <utils/detailsbutton.h>
#include <utils/detailswidget.h>
#include <QtDesigner/QDesignerCustomWidgetCollectionInterface>
#include <QtDesigner/QDesignerContainerExtension>
#include <QtDesigner/QExtensionFactory>
#include <QtCore/qplugin.h>
#include <QtCore/QList>
QT_BEGIN_NAMESPACE
class QExtensionManager;
QT_END_NAMESPACE
// Custom Widgets
class NewClassCustomWidget :
......@@ -163,7 +171,62 @@ public:
explicit PathListEditor_CW(QObject *parent = 0);
};
// Collection
class DetailsButton_CW :
public QObject,
public CustomWidget<Utils::DetailsButton>
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
explicit DetailsButton_CW(QObject *parent = 0);
};
// Details Widget: plugin + simple, hacky container extension that
// accepts only one page.
class DetailsWidget_CW :
public QObject,
public CustomWidget<Utils::DetailsWidget>
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
explicit DetailsWidget_CW(QObject *parent = 0);
QString domXml() const;
void initialize(QDesignerFormEditorInterface *core);
};
class DetailsWidgetContainerExtension: public QObject,
public QDesignerContainerExtension
{
Q_OBJECT
Q_INTERFACES(QDesignerContainerExtension)
public:
explicit DetailsWidgetContainerExtension(Utils::DetailsWidget *widget, QObject *parent);
void addWidget(QWidget *widget);
int count() const;
int currentIndex() const;
void insertWidget(int index, QWidget *widget);
void remove(int index);
void setCurrentIndex(int index);
QWidget *widget(int index) const;
private:
Utils::DetailsWidget *m_detailsWidget;
};
class DetailsWidgetExtensionFactory: public QExtensionFactory
{
Q_OBJECT
public:
explicit DetailsWidgetExtensionFactory(QExtensionManager *parent = 0);
protected:
QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const;
};
// ------------ Collection
class WidgetCollection : public QObject, public QDesignerCustomWidgetCollectionInterface
{
......@@ -175,7 +238,7 @@ public:
virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;
private:
QList<QDesignerCustomWidgetInterface*> m_plugins;
QList<QDesignerCustomWidgetInterface*> m_plugins;
};
#endif // CUSTOMWIDGETS_H
......@@ -19,7 +19,6 @@ linux-* {
QTC_LIBS=$$dirname(QTC_LIBS)
QTC_LIBS=$$dirname(QTC_LIBS)
QTC_LIBS=$$QTC_LIBS/$$IDE_LIBRARY_BASENAME/qtcreator
QTC_LIBS=$$QTC_LIBS/$$IDE_LIBRARY_BASENAME/qtcreator
QMAKE_RPATHDIR *= $$QTC_LIBS
}
......@@ -29,6 +28,7 @@ macx {
CONFIG(debug, debug|release):LIBS += -lUtils_debug
else:LIBS += -lUtils
} else {
message($$QTC_LIBS)
LIBS += -L$$QTC_LIBS -lUtils
}
......
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