Commit 69102d5f authored by Moritz Molch's avatar Moritz Molch

Improve size calculation

parent ea310b35
......@@ -207,13 +207,13 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
slOpacity->setRange(0.0, 1.0, 2);
slOpacity->setValue(1.0);
slOpacity->setSingleStep(0.05);
slOpacity->setMinimumWidth(sliderWidth);
slOpacity->setMinimumWidth(qMax(sliderWidth, slOpacity->sizeHint().width()));
slOpacity->setFixedHeight(32);
slFlow->setRange(0.0, 1.0, 2);
slFlow->setValue(1.0);
slFlow->setSingleStep(0.05);
slFlow->setMinimumWidth(sliderWidth);
slFlow->setMinimumWidth(qMax(sliderWidth, slFlow->sizeHint().width()));
slFlow->setFixedHeight(32);
slSize->setRange(0, 1000, 2);
......@@ -221,9 +221,9 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
slSize->setSingleStep(1);
slSize->setExponentRatio(3.0);
slSize->setMinimumWidth(sliderWidth);
slSize->setFixedHeight(32);
slSize->setSuffix(" px");
slSize->setMinimumWidth(qMax(sliderWidth, slSize->sizeHint().width()));
slSize->setFixedHeight(32);
m_sliderChooser[i]->chooseWidget(cfg.toolbarSlider(i + 1));
}
......
/* This file is part of the KDE project
* Copyright (c) 2010 Justin Noel <justin@ics.com>
* Copyright (c) 2010 Cyrille Berger <cberger@cberger.net>
* Copyright (c) 2015 Moritz Molch <kde@moritzmolch.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -455,29 +456,33 @@ QSize KisAbstractSliderSpinBox::sizeHint() const
// Some styles use bold font in progressbars
ft.setBold(true);
QFontMetrics fm(ft);
//We need at least 50 pixels or things start to look bad
int w = qMax(fm.width(d->prefix + QString::number(d->maximum) + d->suffix)+qRound(0.2*logicalDpiX()), 50);
QSize hint(w, d->edit->sizeHint().height() + 7);
QSize hint(fm.boundingRect(d->prefix + QString::number(d->maximum) + d->suffix).size());
hint += QSize(4, 2);
if (d->style == KisAbstractSliderSpinBoxPrivate::STYLE_PLASTIQUE) {
hint.setHeight(hint.height() - 6);
// almost all "modern" styles have a margin around controls
if (d->style == KisAbstractSliderSpinBoxPrivate::STYLE_NOQUIRK) {
hint += QSize(4, 6);
}
// The breeze style doesn't seem to need this
if (d->style != KisAbstractSliderSpinBoxPrivate::STYLE_BREEZE) {
//Getting the size of the buttons is a pain as the calcs require a rect
//that is "big enough". We run the calc twice to get the "smallest" buttons
//This code was inspired by QAbstractSpinBox
QSize extra(35, 0);
spinOpts.rect.setSize(hint + extra);
extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &spinOpts,
QStyle::SC_SpinBoxEditField, this).size();
spinOpts.rect.setSize(hint + extra);
extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &spinOpts,
QStyle::SC_SpinBoxEditField, this).size();
hint += extra;
}
//Getting the size of the buttons is a pain as the calcs require a rect
//that is "big enough". We run the calc twice to get the "smallest" buttons
//This code was inspired by QAbstractSpinBox
QSize extra(35, 6);
spinOpts.rect.setSize(hint + extra);
extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &spinOpts,
QStyle::SC_SpinBoxEditField, this).size();
spinOpts.rect.setSize(hint + extra);
extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &spinOpts,
QStyle::SC_SpinBoxEditField, this).size();
hint += extra;
spinOpts.rect = rect();
return style()->sizeFromContents(QStyle::CT_SpinBox, &spinOpts, hint, 0)
spinOpts.rect.setSize(hint);
return style()->sizeFromContents(QStyle::CT_SpinBox, &spinOpts, hint)
.expandedTo(QApplication::globalStrut());
}
......@@ -487,6 +492,11 @@ QSize KisAbstractSliderSpinBox::minimumSizeHint() const
return sizeHint();
}
QSize KisAbstractSliderSpinBox::minimumSize() const
{
return QWidget::minimumSize().expandedTo(minimumSizeHint());
}
QStyleOptionSpinBox KisAbstractSliderSpinBox::spinBoxOptions() const
{
const Q_D(KisAbstractSliderSpinBox);
......
......@@ -50,6 +50,10 @@ public:
void setExponentRatio(qreal dbl);
virtual QSize sizeHint() const;
virtual QSize minimumSizeHint() const;
virtual QSize minimumSize() const;
protected:
virtual void paintEvent(QPaintEvent* e);
virtual void mousePressEvent(QMouseEvent* e);
......@@ -60,9 +64,6 @@ protected:
virtual bool eventFilter(QObject* recv, QEvent* e);
virtual QSize sizeHint() const;
virtual QSize minimumSizeHint() const;
QStyleOptionSpinBox spinBoxOptions() const;
QStyleOptionProgressBar progressBarOptions() const;
......
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