diff options
author | Jens Bache-Wiig <jbache@trolltech.com> | 2010-03-22 10:03:42 (GMT) |
---|---|---|
committer | Jens Bache-Wiig <jbache@trolltech.com> | 2010-03-24 14:47:32 (GMT) |
commit | 2a350684c60fd0225234e77d0a01b01471bc9ea8 (patch) | |
tree | 6546b1ec395cec1066a56c833d2f007959b1b60b /tools/designer/src/components/propertyeditor/propertyeditor.cpp | |
parent | 25214cddf4b52506be07e9897d9b7852d793afc5 (diff) | |
download | Qt-2a350684c60fd0225234e77d0a01b01471bc9ea8.zip Qt-2a350684c60fd0225234e77d0a01b01471bc9ea8.tar.gz Qt-2a350684c60fd0225234e77d0a01b01471bc9ea8.tar.bz2 |
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
Diffstat (limited to 'tools/designer/src/components/propertyeditor/propertyeditor.cpp')
-rw-r--r-- | tools/designer/src/components/propertyeditor/propertyeditor.cpp | 67 |
1 files changed, 58 insertions, 9 deletions
diff --git a/tools/designer/src/components/propertyeditor/propertyeditor.cpp b/tools/designer/src/components/propertyeditor/propertyeditor.cpp index 512cc82..86d7bdf 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)); } |