Skip to content
Permalink
Browse files

fix #295121: crazy behaviour of the colorLabel

Rewrite ColorLabel to be a child of QPushButton instead of QFrame. The reason is that QFrame doesn't implement MouseClickEvent. That led to the issues when opening the colour picker widget on mousePressEvent.

I have to move `Awl::ColorLabel` `else if` statement checks above the `QPushButton` ones, because the latter set incorrect connects for the `ColorLabel` which inherits `QPushButton` now.
  • Loading branch information...
anatoly-os committed Oct 2, 2019
1 parent 2cf1cf7 commit 578d4a965980bce7c7958b6fa88cd7b7c4d502e6
@@ -26,10 +26,10 @@ namespace Awl {
//---------------------------------------------------------

ColorLabel::ColorLabel(QWidget* parent)
: QFrame (parent)
: QPushButton(parent)
{
_color = Qt::blue;
_pixmap = 0;
connect(this, &QPushButton::clicked, this, &ColorLabel::colorButtonClicked);
setFlat(true);
}

ColorLabel::~ColorLabel()
@@ -74,20 +74,19 @@ QSize ColorLabel::sizeHint() const
void ColorLabel::paintEvent(QPaintEvent* ev)
{
QPainter p(this);
int fw = frameWidth();
QRect r(frameRect().adjusted(fw, fw, -2*fw, -2*fw));
if (_pixmap)
p.drawTiledPixmap(r, *_pixmap);
p.drawTiledPixmap(rect(), *_pixmap);
else
p.fillRect(r, _color);
QFrame::paintEvent(ev);
p.fillRect(rect(), _color);

QPushButton::paintEvent(ev);
}

//---------------------------------------------------------
// mousePressEvent
//---------------------------------------------------------

void ColorLabel::mousePressEvent(QMouseEvent*)
void ColorLabel::colorButtonClicked(bool)
{
if (_pixmap)
return;
@@ -103,6 +102,5 @@ void ColorLabel::mousePressEvent(QMouseEvent*)
}
}
}

} // namespace Awl

}
// namespace Awl
@@ -26,18 +26,20 @@ namespace Awl {
// ColorLabel
//---------------------------------------------------------

class ColorLabel : public QFrame {
class ColorLabel : public QPushButton {
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor)

QColor _color;
QPixmap* _pixmap;
QColor _color = Qt::blue;
QPixmap* _pixmap = nullptr;

virtual void paintEvent(QPaintEvent*);
virtual void mousePressEvent(QMouseEvent*);


signals:
void colorChanged(QColor);

public slots:
void colorButtonClicked(bool);

public:
ColorLabel(QWidget* parent = 0);
@@ -302,9 +302,6 @@
<property name="toolTip">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
<item row="1" column="0">
@@ -927,7 +924,7 @@
<customwidgets>
<customwidget>
<class>Awl::ColorLabel</class>
<extends>QFrame</extends>
<extends>QPushButton</extends>
<header>awl/colorlabel.h</header>
<container>1</container>
</customwidget>
@@ -97,9 +97,6 @@
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
</layout>
@@ -923,7 +920,7 @@
<customwidgets>
<customwidget>
<class>Awl::ColorLabel</class>
<extends>QFrame</extends>
<extends>QPushButton</extends>
<header>awl/colorlabel.h</header>
<container>1</container>
</customwidget>
@@ -10202,9 +10202,6 @@
</property>
<item row="0" column="1">
<widget class="Awl::ColorLabel" name="textStyleFrameForeground">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
<item row="2" column="0">
@@ -10291,9 +10288,6 @@
</item>
<item row="1" column="1">
<widget class="Awl::ColorLabel" name="textStyleFrameBackground">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
<item row="3" column="2">
@@ -10355,9 +10349,6 @@
</item>
<item row="6" column="1">
<widget class="Awl::ColorLabel" name="textStyleColor">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
<item row="7" column="1">
@@ -10519,7 +10510,7 @@
<customwidgets>
<customwidget>
<class>Awl::ColorLabel</class>
<extends>QFrame</extends>
<extends>QPushButton</extends>
<header>awl/colorlabel.h</header>
<container>1</container>
</customwidget>
@@ -68,12 +68,12 @@ QVariant InspectorBase::getValue(const InspectorItem& ii) const
val = cb->itemData(val).toInt();
v = val;
}
else if (qobject_cast<Awl::ColorLabel*>(w))
v = static_cast<Awl::ColorLabel*>(w)->color();
else if (qobject_cast<QCheckBox*>(w) || qobject_cast<QPushButton*>(w) || qobject_cast<QToolButton*>(w))
v = w->property("checked");
else if (qobject_cast<QLineEdit*>(w))
v = w->property("text");
else if (qobject_cast<Awl::ColorLabel*>(w))
v = static_cast<Awl::ColorLabel*>(w)->color();
else if (qobject_cast<Ms::AlignSelect*>(w))
v = int(static_cast<Ms::AlignSelect*>(w)->align());
else if (qobject_cast<Ms::FontStyleSelect*>(w))
@@ -218,14 +218,14 @@ void InspectorBase::setValue(const InspectorItem& ii, QVariant val)
}
else if (qobject_cast<QCheckBox*>(w))
static_cast<QCheckBox*>(w)->setChecked(val.toBool());
else if (qobject_cast<Awl::ColorLabel*>(w))
static_cast<Awl::ColorLabel*>(w)->setColor(val.value<QColor>());
else if (qobject_cast<QPushButton*>(w))
static_cast<QPushButton*>(w)->setChecked(val.toBool());
else if (qobject_cast<QToolButton*>(w))
static_cast<QToolButton*>(w)->setChecked(val.toBool());
else if (qobject_cast<QLineEdit*>(w))
static_cast<QLineEdit*>(w)->setText(val.toString());
else if (qobject_cast<Awl::ColorLabel*>(w))
static_cast<Awl::ColorLabel*>(w)->setColor(val.value<QColor>());
else if (qobject_cast<Ms::AlignSelect*>(w))
static_cast<Ms::AlignSelect*>(w)->setAlign(Align(val.toInt()));
else if (qobject_cast<Ms::FontStyleSelect*>(w))
@@ -575,14 +575,14 @@ void InspectorBase::mapSignals(const std::vector<InspectorItem>& il, const std::
connect(qobject_cast<QComboBox*>(w), QOverload<int>::of(&QComboBox::currentIndexChanged), [=] { valueChanged(i); });
else if (qobject_cast<QCheckBox*>(w))
connect(qobject_cast<QCheckBox*>(w), QOverload<bool>::of(&QCheckBox::toggled), [=] { valueChanged(i); });
else if (qobject_cast<Awl::ColorLabel*>(w))
connect(qobject_cast<Awl::ColorLabel*>(w), QOverload<QColor>::of(&Awl::ColorLabel::colorChanged), [=] { valueChanged(i); });
else if (qobject_cast<QPushButton*>(w))
connect(qobject_cast<QPushButton*>(w), QOverload<bool>::of(&QPushButton::toggled), [=] { valueChanged(i); });
else if (qobject_cast<QToolButton*>(w))
connect(qobject_cast<QToolButton*>(w), QOverload<bool>::of(&QToolButton::toggled), [=] { valueChanged(i); });
else if (qobject_cast<QLineEdit*>(w))
connect(qobject_cast<QLineEdit*>(w), QOverload<const QString&>::of(&QLineEdit::textChanged), [=] { valueChanged(i); });
else if (qobject_cast<Awl::ColorLabel*>(w))
connect(qobject_cast<Awl::ColorLabel*>(w), QOverload<QColor>::of(&Awl::ColorLabel::colorChanged), [=] { valueChanged(i); });
else if (qobject_cast<Ms::AlignSelect*>(w))
connect(qobject_cast<Ms::AlignSelect*>(w), QOverload<Align>::of(&Ms::AlignSelect::alignChanged), [=] { valueChanged(i); });
else if (qobject_cast<Ms::FontStyleSelect*>(w))
@@ -205,12 +205,6 @@
<property name="accessibleName">
<string>Color</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
</layout>
@@ -348,7 +342,7 @@
</customwidget>
<customwidget>
<class>Awl::ColorLabel</class>
<extends>QFrame</extends>
<extends>QPushButton</extends>
<header>awl/colorlabel.h</header>
<container>1</container>
</customwidget>
@@ -83,9 +83,6 @@
<property name="accessibleName">
<string>Color</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
<item row="1" column="0">
@@ -136,7 +133,7 @@
<customwidgets>
<customwidget>
<class>Awl::ColorLabel</class>
<extends>QFrame</extends>
<extends>QPushButton</extends>
<header>awl/colorlabel.h</header>
<container>1</container>
</customwidget>
@@ -139,9 +139,6 @@
<property name="accessibleName">
<string>Line color</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
<item row="5" column="1">
@@ -379,7 +376,7 @@
</customwidget>
<customwidget>
<class>Awl::ColorLabel</class>
<extends>QFrame</extends>
<extends>QPushButton</extends>
<header>awl/colorlabel.h</header>
<container>1</container>
</customwidget>
@@ -278,9 +278,6 @@
<property name="accessibleName">
<string>Border color</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
<item row="0" column="2">
@@ -414,9 +411,6 @@
<property name="accessibleName">
<string>Highlight color</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
<item row="0" column="0">
@@ -568,7 +562,7 @@
</customwidget>
<customwidget>
<class>Awl::ColorLabel</class>
<extends>QFrame</extends>
<extends>QPushButton</extends>
<header>awl/colorlabel.h</header>
<container>1</container>
</customwidget>
@@ -522,7 +522,7 @@
<customwidgets>
<customwidget>
<class>Awl::ColorLabel</class>
<extends>QFrame</extends>
<extends>QPushButton</extends>
<header>awl/colorlabel.h</header>
<container>1</container>
</customwidget>
@@ -909,9 +909,6 @@
<property name="accessibleDescription">
<string>Opens a dialog for selecting the background color</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
</layout>
@@ -1021,9 +1018,6 @@
<property name="accessibleDescription">
<string>Opens a dialog for selecting the paper color</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
<item row="2" column="1">
@@ -4151,7 +4145,7 @@ Adjusting latency can help synchronize your MIDI hardware with MuseScore's inter
<customwidgets>
<customwidget>
<class>Awl::ColorLabel</class>
<extends>QFrame</extends>
<extends>QPushButton</extends>
<header>awl/colorlabel.h</header>
<container>1</container>
</customwidget>

0 comments on commit 578d4a9

Please sign in to comment.
You can’t perform that action at this time.