use the focus and over glows for editable mode
svn path=/trunk/KDE/kdelibs/; revision=1027264
This commit is contained in:
parent
d733458a0d
commit
56ac584338
@ -42,7 +42,8 @@ public:
|
|||||||
ComboBoxPrivate(ComboBox *comboBox)
|
ComboBoxPrivate(ComboBox *comboBox)
|
||||||
: q(comboBox),
|
: q(comboBox),
|
||||||
background(0),
|
background(0),
|
||||||
customFont(0)
|
customFont(0),
|
||||||
|
underMouse(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,16 +54,19 @@ public:
|
|||||||
void syncActiveRect();
|
void syncActiveRect();
|
||||||
void syncBorders();
|
void syncBorders();
|
||||||
void animationUpdate(qreal progress);
|
void animationUpdate(qreal progress);
|
||||||
|
void animationFinished(int id);
|
||||||
|
|
||||||
ComboBox *q;
|
ComboBox *q;
|
||||||
|
|
||||||
FrameSvg *background;
|
FrameSvg *background;
|
||||||
|
FrameSvg *lineEditBackground;
|
||||||
int animId;
|
int animId;
|
||||||
bool fadeIn;
|
bool fadeIn;
|
||||||
qreal opacity;
|
qreal opacity;
|
||||||
QRectF activeRect;
|
QRectF activeRect;
|
||||||
Style::Ptr style;
|
Style::Ptr style;
|
||||||
bool customFont;
|
bool customFont;
|
||||||
|
bool underMouse;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ComboBoxPrivate::syncActiveRect()
|
void ComboBoxPrivate::syncActiveRect()
|
||||||
@ -116,6 +120,14 @@ void ComboBoxPrivate::animationUpdate(qreal progress)
|
|||||||
q->update();
|
q->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ComboBoxPrivate::animationFinished(int id)
|
||||||
|
{
|
||||||
|
if (id == animId) {
|
||||||
|
animId = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ComboBox::ComboBox(QGraphicsWidget *parent)
|
ComboBox::ComboBox(QGraphicsWidget *parent)
|
||||||
: QGraphicsProxyWidget(parent),
|
: QGraphicsProxyWidget(parent),
|
||||||
d(new ComboBoxPrivate(this))
|
d(new ComboBoxPrivate(this))
|
||||||
@ -131,10 +143,14 @@ ComboBox::ComboBox(QGraphicsWidget *parent)
|
|||||||
d->background->setImagePath("widgets/button");
|
d->background->setImagePath("widgets/button");
|
||||||
d->background->setCacheAllRenderedFrames(true);
|
d->background->setCacheAllRenderedFrames(true);
|
||||||
d->background->setElementPrefix("normal");
|
d->background->setElementPrefix("normal");
|
||||||
|
d->lineEditBackground = new FrameSvg(this);
|
||||||
|
d->lineEditBackground->setImagePath("widgets/lineedit");
|
||||||
|
d->lineEditBackground->setCacheAllRenderedFrames(true);
|
||||||
|
|
||||||
d->syncBorders();
|
d->syncBorders();
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncBorders()));
|
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncBorders()));
|
||||||
|
connect(Plasma::Animator::self(), SIGNAL(customAnimationFinished(int)), this, SLOT(animationFinished(int)));
|
||||||
d->style = Style::sharedStyle();
|
d->style = Style::sharedStyle();
|
||||||
native->setStyle(d->style.data());
|
native->setStyle(d->style.data());
|
||||||
}
|
}
|
||||||
@ -199,12 +215,36 @@ void ComboBox::paint(QPainter *painter,
|
|||||||
QWidget *widget)
|
QWidget *widget)
|
||||||
{
|
{
|
||||||
if (!styleSheet().isNull() ||
|
if (!styleSheet().isNull() ||
|
||||||
nativeWidget()->isEditable() ||
|
|
||||||
Theme::defaultTheme()->useNativeWidgetStyle()) {
|
Theme::defaultTheme()->useNativeWidgetStyle()) {
|
||||||
QGraphicsProxyWidget::paint(painter, option, widget);
|
QGraphicsProxyWidget::paint(painter, option, widget);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nativeWidget()->isEditable()) {
|
||||||
|
if (d->animId != -1 || hasFocus() || d->underMouse) {
|
||||||
|
if (hasFocus()) {
|
||||||
|
d->lineEditBackground->setElementPrefix("focus");
|
||||||
|
} else {
|
||||||
|
d->lineEditBackground->setElementPrefix("hover");
|
||||||
|
}
|
||||||
|
qreal left, top, right, bottom;
|
||||||
|
d->lineEditBackground->getMargins(left, top, right, bottom);
|
||||||
|
d->lineEditBackground->resizeFrame(size()+QSizeF(left+right, top+bottom));
|
||||||
|
if (qFuzzyCompare(d->opacity, (qreal)1.0)) {
|
||||||
|
d->lineEditBackground->paintFrame(painter, QPoint(-left, -top));
|
||||||
|
} else {
|
||||||
|
QPixmap bufferPixmap = d->lineEditBackground->framePixmap();
|
||||||
|
QPainter buffPainter(&bufferPixmap);
|
||||||
|
buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||||
|
buffPainter.fillRect(bufferPixmap.rect(), QColor(0, 0, 0, 256*d->opacity));
|
||||||
|
buffPainter.end();
|
||||||
|
painter->drawPixmap(bufferPixmap.rect().translated(QPoint(-left, -top)), bufferPixmap, bufferPixmap.rect());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QGraphicsProxyWidget::paint(painter, option, widget);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QPixmap bufferPixmap;
|
QPixmap bufferPixmap;
|
||||||
|
|
||||||
//normal button
|
//normal button
|
||||||
@ -269,8 +309,47 @@ void ComboBox::paint(QPainter *painter,
|
|||||||
QStyle::PE_IndicatorArrowDown, &comboOpt, painter, nativeWidget());
|
QStyle::PE_IndicatorArrowDown, &comboOpt, painter, nativeWidget());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ComboBox::focusInEvent(QFocusEvent *event)
|
||||||
|
{
|
||||||
|
if (nativeWidget()->isEditable() && !d->underMouse) {
|
||||||
|
const int FadeInDuration = 75;
|
||||||
|
|
||||||
|
if (d->animId != -1) {
|
||||||
|
Animator::self()->stopCustomAnimation(d->animId);
|
||||||
|
}
|
||||||
|
d->animId = Animator::self()->customAnimation(
|
||||||
|
40 / (1000 / FadeInDuration), FadeInDuration,
|
||||||
|
Animator::LinearCurve, this, "animationUpdate");
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsProxyWidget::focusInEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComboBox::focusOutEvent(QFocusEvent *event)
|
||||||
|
{
|
||||||
|
if (nativeWidget()->isEditable() && !d->underMouse) {
|
||||||
|
const int FadeOutDuration = 150;
|
||||||
|
|
||||||
|
if (d->animId != -1) {
|
||||||
|
Animator::self()->stopCustomAnimation(d->animId != -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
d->fadeIn = false;
|
||||||
|
d->animId = Animator::self()->customAnimation(
|
||||||
|
40 / (1000 / FadeOutDuration),
|
||||||
|
FadeOutDuration, Animator::LinearCurve, this, "animationUpdate");
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsProxyWidget::focusInEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void ComboBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
void ComboBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
|
d->underMouse = true;
|
||||||
|
if (nativeWidget()->isEditable() && hasFocus()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const int FadeInDuration = 75;
|
const int FadeInDuration = 75;
|
||||||
|
|
||||||
if (d->animId != -1) {
|
if (d->animId != -1) {
|
||||||
@ -287,6 +366,11 @@ void ComboBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
|
|
||||||
void ComboBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void ComboBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
|
d->underMouse = false;
|
||||||
|
if (nativeWidget()->isEditable() && hasFocus()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const int FadeOutDuration = 150;
|
const int FadeOutDuration = 150;
|
||||||
|
|
||||||
if (d->animId != -1) {
|
if (d->animId != -1) {
|
||||||
|
@ -89,6 +89,8 @@ protected:
|
|||||||
void paint(QPainter *painter,
|
void paint(QPainter *painter,
|
||||||
const QStyleOptionGraphicsItem *option,
|
const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
void focusInEvent(QFocusEvent *event);
|
||||||
|
void focusOutEvent(QFocusEvent *event);
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
void changeEvent(QEvent *event);
|
void changeEvent(QEvent *event);
|
||||||
@ -99,6 +101,7 @@ private:
|
|||||||
friend class ComboBoxPrivate;
|
friend class ComboBoxPrivate;
|
||||||
Q_PRIVATE_SLOT(d, void syncBorders())
|
Q_PRIVATE_SLOT(d, void syncBorders())
|
||||||
Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress))
|
Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress))
|
||||||
|
Q_PRIVATE_SLOT(d, void animationFinished(int id))
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
@ -76,6 +76,7 @@ LineEdit::LineEdit(QGraphicsWidget *parent)
|
|||||||
d->style = Plasma::Style::sharedStyle();
|
d->style = Plasma::Style::sharedStyle();
|
||||||
d->background = new Plasma::FrameSvg(this);
|
d->background = new Plasma::FrameSvg(this);
|
||||||
d->background->setImagePath("widgets/lineedit");
|
d->background->setImagePath("widgets/lineedit");
|
||||||
|
d->background->setCacheAllRenderedFrames(true);
|
||||||
|
|
||||||
native->setStyle(d->style.data());
|
native->setStyle(d->style.data());
|
||||||
native->setAttribute(Qt::WA_NoSystemBackground);
|
native->setAttribute(Qt::WA_NoSystemBackground);
|
||||||
|
Loading…
Reference in New Issue
Block a user