|
@@ -19,6 +19,7 @@
|
|
=========================================================================*/
|
|
=========================================================================*/
|
|
|
|
|
|
// Qt includes
|
|
// Qt includes
|
|
|
|
+#include <QApplication>
|
|
#include <QColorDialog>
|
|
#include <QColorDialog>
|
|
#include <QDebug>
|
|
#include <QDebug>
|
|
#include <QIcon>
|
|
#include <QIcon>
|
|
@@ -46,6 +47,7 @@ public:
|
|
QColor Color;
|
|
QColor Color;
|
|
bool DisplayColorName;
|
|
bool DisplayColorName;
|
|
ctkColorPickerButton::ColorDialogOptions DialogOptions;
|
|
ctkColorPickerButton::ColorDialogOptions DialogOptions;
|
|
|
|
+ mutable QSize CachedSizeHint;
|
|
};
|
|
};
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
@@ -158,7 +160,9 @@ void ctkColorPickerButton::setDisplayColorName(bool displayColorName)
|
|
{
|
|
{
|
|
Q_D(ctkColorPickerButton);
|
|
Q_D(ctkColorPickerButton);
|
|
d->DisplayColorName = displayColorName;
|
|
d->DisplayColorName = displayColorName;
|
|
|
|
+ d->CachedSizeHint = QSize();
|
|
this->update();
|
|
this->update();
|
|
|
|
+ this->updateGeometry();
|
|
}
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
@@ -211,7 +215,7 @@ void ctkColorPickerButton::paintEvent(QPaintEvent *)
|
|
Q_D(ctkColorPickerButton);
|
|
Q_D(ctkColorPickerButton);
|
|
QStylePainter p(this);
|
|
QStylePainter p(this);
|
|
QStyleOptionButton option;
|
|
QStyleOptionButton option;
|
|
- initStyleOption(&option);
|
|
|
|
|
|
+ this->initStyleOption(&option);
|
|
if (d->DisplayColorName)
|
|
if (d->DisplayColorName)
|
|
{
|
|
{
|
|
option.text = d->Color.name();
|
|
option.text = d->Color.name();
|
|
@@ -219,3 +223,31 @@ void ctkColorPickerButton::paintEvent(QPaintEvent *)
|
|
option.icon = d->Icon;
|
|
option.icon = d->Icon;
|
|
p.drawControl(QStyle::CE_PushButton, option);
|
|
p.drawControl(QStyle::CE_PushButton, option);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
|
+QSize ctkColorPickerButton::sizeHint()const
|
|
|
|
+{
|
|
|
|
+ Q_D(const ctkColorPickerButton);
|
|
|
|
+ if (d->DisplayColorName || !this->text().isEmpty())
|
|
|
|
+ {
|
|
|
|
+ return this->QPushButton::sizeHint();
|
|
|
|
+ }
|
|
|
|
+ if (d->CachedSizeHint.isValid())
|
|
|
|
+ {
|
|
|
|
+ return d->CachedSizeHint;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QStyleOptionButton pushButtonOpt;
|
|
|
|
+ this->initStyleOption(&pushButtonOpt);
|
|
|
|
+ QStyleOptionToolButton opt;
|
|
|
|
+ (&opt)->QStyleOption::operator=(pushButtonOpt);
|
|
|
|
+ opt.arrowType = Qt::NoArrow;
|
|
|
|
+ opt.icon = d->Icon;
|
|
|
|
+ int iconSize = this->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
|
|
|
+ opt.iconSize = QSize(iconSize, iconSize);
|
|
|
|
+ opt.rect.setSize(opt.iconSize); // PM_MenuButtonIndicator depends on the height
|
|
|
|
+ d->CachedSizeHint = this->style()->sizeFromContents(
|
|
|
|
+ QStyle::CT_ToolButton, &opt, opt.iconSize, this).
|
|
|
|
+ expandedTo(QApplication::globalStrut());
|
|
|
|
+ return d->CachedSizeHint;
|
|
|
|
+}
|