summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Bache-Wiig <jbache@trolltech.com>2010-03-22 11:03:42 +0100
committerJens Bache-Wiig <jbache@trolltech.com>2010-03-24 15:47:32 +0100
commit2a350684c60fd0225234e77d0a01b01471bc9ea8 (patch)
tree6546b1ec395cec1066a56c833d2f007959b1b60b
parent25214cddf4b52506be07e9897d9b7852d793afc5 (diff)
downloadqt4-tools-2a350684c60fd0225234e77d0a01b01471bc9ea8.tar.gz
Redesigned object and class labels for the Designer propertyeditor
We modified the label so that it gets its own row instead of squeezing it into the tool bar. This layout would usually not have room for more than short labels and looked rather unprofessional when used in Creator. The new label is properly elided. We also added a frame to distinguish it from the dock widget label. Reviewed-by: Friedemann Kleint
-rw-r--r--tools/designer/src/components/propertyeditor/propertyeditor.cpp67
-rw-r--r--tools/designer/src/components/propertyeditor/propertyeditor.h5
2 files changed, 60 insertions, 12 deletions
diff --git a/tools/designer/src/components/propertyeditor/propertyeditor.cpp b/tools/designer/src/components/propertyeditor/propertyeditor.cpp
index 512cc82887..86d7bdf40f 100644
--- a/tools/designer/src/components/propertyeditor/propertyeditor.cpp
+++ b/tools/designer/src/components/propertyeditor/propertyeditor.cpp
@@ -79,6 +79,7 @@
#include <QtGui/QToolButton>
#include <QtGui/QActionGroup>
#include <QtGui/QLabel>
+#include <QtGui/QPainter>
#include <QtCore/QDebug>
#include <QtCore/QTextStream>
@@ -98,6 +99,53 @@ QT_BEGIN_NAMESPACE
// ---------------------------------------------------------------------------------
namespace qdesigner_internal {
+
+// ----------- ElidingLabel
+// QLabel does not support text eliding so we need a helper class
+
+class ElidingLabel : public QWidget
+{
+public:
+ ElidingLabel(const QString &text = QString(), QWidget *parent = 0)
+ : QWidget(parent),
+ m_text(text),
+ m_mode(Qt::ElideRight) {
+ setContentsMargins(3, 2, 3, 2);
+ }
+ QSize sizeHint() const;
+ void paintEvent(QPaintEvent *e);
+ void setText(const QString &text) {
+ m_text = text;
+ updateGeometry();
+ }
+ void setElidemode(Qt::TextElideMode mode) {
+ m_mode = mode;
+ updateGeometry();
+ }
+private:
+ QString m_text;
+ Qt::TextElideMode m_mode;
+};
+
+QSize ElidingLabel::sizeHint() const
+{
+ QSize size = fontMetrics().boundingRect(m_text).size();
+ size += QSize(contentsMargins().left() + contentsMargins().right(),
+ contentsMargins().top() + contentsMargins().bottom());
+ return size;
+}
+
+void ElidingLabel::paintEvent(QPaintEvent *e) {
+ QPainter painter(this);
+ painter.setPen(QColor(0, 0, 0, 60));
+ painter.setBrush(QColor(255, 255, 255, 40));
+ painter.drawRect(rect().adjusted(0, 0, -1, -1));
+ painter.setPen(palette().windowText().color());
+ painter.drawText(contentsRect(), Qt::AlignLeft,
+ fontMetrics().elidedText(m_text, Qt::ElideRight, width(), 0));
+}
+
+
// ----------- PropertyEditor::Strings
PropertyEditor::Strings::Strings() :
@@ -186,7 +234,7 @@ PropertyEditor::PropertyEditor(QDesignerFormEditorInterface *core, QWidget *pare
m_coloringAction(new QAction(createIconSet(QLatin1String("color.png")), tr("Color Groups"), this)),
m_treeAction(new QAction(tr("Tree View"), this)),
m_buttonAction(new QAction(tr("Drop Down Button View"), this)),
- m_classLabel(new QLabel),
+ m_classLabel(new ElidingLabel),
m_sorting(false),
m_coloring(false),
m_brightness(false)
@@ -223,11 +271,6 @@ PropertyEditor::PropertyEditor(QDesignerFormEditorInterface *core, QWidget *pare
actionGroup->addAction(m_buttonAction);
connect(actionGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotViewTriggered(QAction*)));
- QWidget *classWidget = new QWidget;
- QHBoxLayout *l = new QHBoxLayout(classWidget);
- l->setContentsMargins(5, 0, 5, 0);
- l->addWidget(m_classLabel);
-
// Add actions
QActionGroup *addDynamicActionGroup = new QActionGroup(this);
connect(addDynamicActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotAddDynamicProperty(QAction*)));
@@ -269,7 +312,6 @@ PropertyEditor::PropertyEditor(QDesignerFormEditorInterface *core, QWidget *pare
#endif
// Assemble toolbar
QToolBar *toolBar = new QToolBar;
- toolBar->addWidget(classWidget);
toolBar->addWidget(m_filterWidget);
toolBar->addWidget(createDropDownButton(m_addDynamicAction));
toolBar->addAction(m_removeDynamicAction);
@@ -292,6 +334,8 @@ PropertyEditor::PropertyEditor(QDesignerFormEditorInterface *core, QWidget *pare
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(toolBar);
+ layout->addWidget(m_classLabel);
+ layout->addSpacerItem(new QSpacerItem(0,1));
layout->addWidget(m_stackedWidget);
layout->setMargin(0);
layout->setSpacing(0);
@@ -778,9 +822,14 @@ void PropertyEditor::updateToolBarLabel()
className = realClassName(m_object);
}
- QString classLabelText = objectName;
- classLabelText += QLatin1Char('\n');
+ m_classLabel->setVisible(!objectName.isEmpty() || !className.isEmpty());
+ m_classLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+ QString classLabelText;
+ if (!objectName.isEmpty())
+ classLabelText += objectName + QLatin1String(" : ");
classLabelText += className;
+
m_classLabel->setText(classLabelText);
m_classLabel->setToolTip(tr("Object: %1\nClass: %2").arg(objectName).arg(className));
}
diff --git a/tools/designer/src/components/propertyeditor/propertyeditor.h b/tools/designer/src/components/propertyeditor/propertyeditor.h
index 5869c94f3e..f0ea94f221 100644
--- a/tools/designer/src/components/propertyeditor/propertyeditor.h
+++ b/tools/designer/src/components/propertyeditor/propertyeditor.h
@@ -62,9 +62,7 @@ class QtTreePropertyBrowser;
class QtProperty;
class QtVariantProperty;
class QtBrowserItem;
-
class QStackedWidget;
-class QLabel;
namespace qdesigner_internal {
@@ -72,6 +70,7 @@ class StringProperty;
class DesignerPropertyManager;
class DesignerEditorFactory;
class FilterWidget;
+class ElidingLabel;
class QT_PROPERTYEDITOR_EXPORT PropertyEditor: public QDesignerPropertyEditor
{
@@ -186,7 +185,7 @@ private:
QAction *m_coloringAction;
QAction *m_treeAction;
QAction *m_buttonAction;
- QLabel *m_classLabel;
+ ElidingLabel *m_classLabel;
bool m_sorting;
bool m_coloring;