aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/views/msliderview.cpp17
-rw-r--r--src/views/msliderview_p.h2
-rw-r--r--src/views/style/msliderstyle.h10
3 files changed, 28 insertions, 1 deletions
diff --git a/src/views/msliderview.cpp b/src/views/msliderview.cpp
index 40e96b0b..a4608ff1 100644
--- a/src/views/msliderview.cpp
+++ b/src/views/msliderview.cpp
@@ -246,6 +246,7 @@ MSliderIndicator::MSliderIndicator(bool isMinMax, QGraphicsItem *parent) :
MWidget(parent),
label(0),
image(0),
+ fixedWidth(0),
layout(0)
{
layout = new QGraphicsAnchorLayout;
@@ -264,6 +265,7 @@ MSliderIndicator::MSliderIndicator(bool isMinMax, QGraphicsItem *parent) :
image->setObjectName("MSliderImage");
layout->addAnchor(layout, Qt::AnchorVerticalCenter, label, Qt::AnchorVerticalCenter);
+ layout->addAnchor(layout, Qt::AnchorHorizontalCenter, label, Qt::AnchorHorizontalCenter);
layout->addAnchor(layout, Qt::AnchorVerticalCenter, image, Qt::AnchorVerticalCenter);
label->resize(0, 0);
@@ -400,13 +402,23 @@ QSizeF MSliderIndicator::sizeHint(Qt::SizeHint which, const QSizeF &constraint)
}
if (label && !label->text().isEmpty()) {
- width = qMax(width, label->sizeHint(Qt::PreferredSize).width());
+ if (fixedWidth) {
+ width = fixedWidth;
+ } else {
+ width = qMax(width, label->sizeHint(Qt::PreferredSize).width());
+ }
height = qMax(height, label->sizeHint(Qt::PreferredSize).height());
}
return QSizeF(width, height);
}
+void MSliderIndicator::setLabelFixedWidth(const qreal width)
+{
+ fixedWidth = width;
+ updateGeometry();
+}
+
MSliderHandleIndicator::MSliderHandleIndicator(QGraphicsItem* parent) :
MWidget(parent),
arrowPos(0),
@@ -1682,6 +1694,9 @@ void MSliderView::applyStyle()
d->horizontalPolicy->setSpacing(style()->grooveMargin());
d->verticalPolicy->setSpacing(style()->grooveMargin());
+ d->minIndicator->setLabelFixedWidth(style()->minLabelFixedWidth());
+ d->maxIndicator->setLabelFixedWidth(style()->maxLabelFixedWidth());
+
d->updateOrientation();
//only to reposition slider handle
diff --git a/src/views/msliderview_p.h b/src/views/msliderview_p.h
index a2a890ce..32f87880 100644
--- a/src/views/msliderview_p.h
+++ b/src/views/msliderview_p.h
@@ -108,6 +108,7 @@ public:
void setLabelStyleName(const QString &stylename);
void setText(const QString &text);
void setImage(const QString &id);
+ void setLabelFixedWidth(const qreal width);
bool isEmpty() const;
@@ -118,6 +119,7 @@ private:
MLabel *label;
MImageWidget *image;
QString imageName;
+ qreal fixedWidth;
QGraphicsAnchorLayout *layout;
diff --git a/src/views/style/msliderstyle.h b/src/views/style/msliderstyle.h
index 58ec49c4..ed8d647e 100644
--- a/src/views/style/msliderstyle.h
+++ b/src/views/style/msliderstyle.h
@@ -176,6 +176,16 @@ class M_VIEWS_EXPORT MSliderStyle : public MWidgetStyle
\brief Style name of the indicator label
*/
M_STYLE_ATTRIBUTE(QString, indicatorStyleName, IndicatorStyleName)
+ /*!
+ \property MSlider::minLabelFixedWidth
+ \brief Fixed width of the minimum label of the slider, if not empty
+ */
+ M_STYLE_ATTRIBUTE(qreal, minLabelFixedWidth, MinLabelFixedWidth)
+ /*!
+ \property MSlider::maxLabelFixedWidth
+ \brief Fixed width of the maximum label of the slider, if not empty
+ */
+ M_STYLE_ATTRIBUTE(qreal, maxLabelFixedWidth, MaxLabelFixedWidth)
};
class M_VIEWS_EXPORT MSliderStyleContainer : public MWidgetStyleContainer