* implement checkState and fix const'ness of the method signature
* implement updated * add setChecked(bool) svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=693544
This commit is contained in:
parent
cfe59991ba
commit
bf6fba2b27
@ -99,7 +99,6 @@ void CheckBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if (d->hasMouse) {
|
if (d->hasMouse) {
|
||||||
|
|
||||||
options.state |= QStyle::State_MouseOver;
|
options.state |= QStyle::State_MouseOver;
|
||||||
options.state |= QStyle::State_HasFocus;
|
options.state |= QStyle::State_HasFocus;
|
||||||
options.state |= QStyle::State_Sunken;
|
options.state |= QStyle::State_Sunken;
|
||||||
@ -107,11 +106,16 @@ void CheckBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||||||
options.state |= QStyle::State_On;
|
options.state |= QStyle::State_On;
|
||||||
}
|
}
|
||||||
widget-> style()->drawControl(QStyle::CE_CheckBox, &options, painter, widget);
|
widget-> style()->drawControl(QStyle::CE_CheckBox, &options, painter, widget);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::updated(const QString&, const DataEngine::Data&)
|
void CheckBox::updated(const QString&, const DataEngine::Data& data)
|
||||||
{
|
{
|
||||||
|
foreach (const QVariant& variant, data) {
|
||||||
|
if (variant.canConvert(QVariant::Bool)) {
|
||||||
|
setChecked(variant.toBool());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::setText(const QString& text)
|
void CheckBox::setText(const QString& text)
|
||||||
@ -152,9 +156,9 @@ void CheckBox::setHeight(int h)
|
|||||||
void CheckBox::setWidth(int w)
|
void CheckBox::setWidth(int w)
|
||||||
{
|
{
|
||||||
if (!(w >= d->maxWidth)) {
|
if (!(w >= d->maxWidth)) {
|
||||||
prepareGeometryChange ();
|
prepareGeometryChange ();
|
||||||
d->width = w;
|
d->width = w;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,9 +170,9 @@ QSize CheckBox::size() const
|
|||||||
void CheckBox::setSize(const QSize &s)
|
void CheckBox::setSize(const QSize &s)
|
||||||
{
|
{
|
||||||
prepareGeometryChange ();
|
prepareGeometryChange ();
|
||||||
if (!d->maxWidth >= s.width() ) {
|
if (!d->maxWidth >= s.width() ) {
|
||||||
d->width = s.width();
|
d->width = s.width();
|
||||||
}
|
}
|
||||||
d->height = s.height();
|
d->height = s.height();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -178,18 +182,28 @@ void CheckBox::setMaximumWidth(int w)
|
|||||||
d->maxWidth= w;
|
d->maxWidth= w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::CheckState CheckBox::checkState() const
|
||||||
|
{
|
||||||
|
return d->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckBox::setChecked(bool checked)
|
||||||
|
{
|
||||||
|
d->state = checked ? Qt::Checked : Qt::Unchecked;
|
||||||
|
}
|
||||||
|
|
||||||
void CheckBox::setCheckState(Qt::CheckState state)
|
void CheckBox::setCheckState(Qt::CheckState state)
|
||||||
{
|
{
|
||||||
d->state = state;
|
d->state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::mouseMoveEvent (QGraphicsSceneMouseEvent * event)
|
void CheckBox::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
|
||||||
{
|
{
|
||||||
event->accept();
|
event->accept();
|
||||||
d->hasMouse= false;
|
d->hasMouse= false;
|
||||||
|
|
||||||
}
|
}
|
||||||
void CheckBox::mousePressEvent ( QGraphicsSceneMouseEvent * event )
|
|
||||||
|
void CheckBox::mousePressEvent(QGraphicsSceneMouseEvent * event)
|
||||||
{
|
{
|
||||||
event->accept();
|
event->accept();
|
||||||
d->down = true;
|
d->down = true;
|
||||||
@ -197,24 +211,23 @@ void CheckBox::mousePressEvent ( QGraphicsSceneMouseEvent * event )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CheckBox::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
|
void CheckBox::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
|
||||||
{
|
{
|
||||||
event->accept();
|
event->accept();
|
||||||
|
|
||||||
if (d->hasMouse) {
|
if (d->hasMouse) {
|
||||||
if (d->state == Qt::Checked) {
|
if (d->state == Qt::Checked) {
|
||||||
d->state = Qt::Unchecked;
|
d->state = Qt::Unchecked;
|
||||||
} else {
|
} else {
|
||||||
d->state = Qt::Checked;
|
d->state = Qt::Checked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
emit clicked();
|
emit clicked();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CheckBox::hoverMoveEvent ( QGraphicsSceneHoverEvent * event )
|
void CheckBox::hoverMoveEvent(QGraphicsSceneHoverEvent * event)
|
||||||
{
|
{
|
||||||
event->accept();
|
event->accept();
|
||||||
d->hasMouse= true;
|
d->hasMouse= true;
|
||||||
|
@ -53,7 +53,8 @@ class PLASMA_EXPORT CheckBox : public QObject, public QGraphicsItem
|
|||||||
void setWidth(int width);
|
void setWidth(int width);
|
||||||
void setHeight(int height);
|
void setHeight(int height);
|
||||||
void setMaximumWidth(int maxwidth);
|
void setMaximumWidth(int maxwidth);
|
||||||
Qt::CheckState CheckState();
|
Qt::CheckState checkState() const;
|
||||||
|
void setChecked(bool checked);
|
||||||
void setCheckState(Qt::CheckState state);
|
void setCheckState(Qt::CheckState state);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user