mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
plasma: simulate pressed icon for applets that have Plasma::ItemStatus::NeedsAttentionStatus status
this is only for popup applets, normal (Plasma::Applet-based) applets paint everything and as such should handle status Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
9fb18a72e5
commit
25e28e7076
5 changed files with 47 additions and 32 deletions
|
@ -604,6 +604,16 @@ void PopupApplet::timerEvent(QTimerEvent *event)
|
|||
} else if (event->timerId() == d->showDialogTimer.timerId()) {
|
||||
d->showDialogTimer.stop();
|
||||
d->showDialog();
|
||||
} else if (event->timerId() == d->statusTimer.timerId()) {
|
||||
if (d->icon) {
|
||||
if (d->statusTick <= 0) {
|
||||
d->statusTick++;
|
||||
d->icon->setPressed(true);
|
||||
} else {
|
||||
d->statusTick--;
|
||||
d->icon->setPressed(false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Applet::timerEvent(event);
|
||||
}
|
||||
|
@ -670,13 +680,13 @@ bool PopupApplet::isIconified() const
|
|||
|
||||
PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet)
|
||||
: q(applet),
|
||||
icon(0),
|
||||
widget(0),
|
||||
icon(nullptr),
|
||||
widget(nullptr),
|
||||
popupPlacement(Plasma::FloatingPopup),
|
||||
popupAlignment(Qt::AlignLeft),
|
||||
savedAspectRatio(Plasma::InvalidAspectRatioMode),
|
||||
autohideTimer(0),
|
||||
preShowStatus(UnknownStatus),
|
||||
autohideTimer(nullptr),
|
||||
statusTick(0),
|
||||
popupLostFocus(false),
|
||||
passive(false)
|
||||
{
|
||||
|
@ -685,6 +695,7 @@ PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet)
|
|||
q->setAcceptDrops(true);
|
||||
QObject::disconnect(q, SIGNAL(activate()), static_cast<Applet*>(q), SLOT(setFocus()));
|
||||
QObject::connect(q, SIGNAL(activate()), q, SLOT(appletActivated()));
|
||||
QObject::connect(q, SIGNAL(newStatus(Plasma::ItemStatus)), q, SLOT(statusChange(Plasma::ItemStatus)));
|
||||
QObject::connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)), q, SLOT(iconSizeChanged(int)));
|
||||
}
|
||||
|
||||
|
@ -820,24 +831,27 @@ void PopupAppletPrivate::dialogSizeChanged()
|
|||
|
||||
void PopupAppletPrivate::dialogStatusChanged(bool shown)
|
||||
{
|
||||
q->setStatus(q->status());
|
||||
if (shown) {
|
||||
preShowStatus = q->status();
|
||||
q->setStatus(NeedsAttentionStatus);
|
||||
QObject::connect(q, SIGNAL(newStatus(Plasma::ItemStatus)),
|
||||
q, SLOT(statusChangeWhileShown(Plasma::ItemStatus)),
|
||||
Qt::UniqueConnection);
|
||||
// the dialog is getting attention
|
||||
statusChange(Plasma::ItemStatus::UnknownStatus);
|
||||
} else {
|
||||
QObject::disconnect(q, SIGNAL(newStatus(Plasma::ItemStatus)),
|
||||
q, SLOT(statusChangeWhileShown(Plasma::ItemStatus)));
|
||||
q->setStatus(preShowStatus);
|
||||
// back to needs attention, maybe
|
||||
statusChange(q->status());
|
||||
}
|
||||
|
||||
q->popupEvent(shown);
|
||||
}
|
||||
|
||||
void PopupAppletPrivate::statusChangeWhileShown(Plasma::ItemStatus status)
|
||||
void PopupAppletPrivate::statusChange(Plasma::ItemStatus status)
|
||||
{
|
||||
preShowStatus = status;
|
||||
if (status == Plasma::ItemStatus::NeedsAttentionStatus) {
|
||||
statusTimer.start(500, q);
|
||||
} else {
|
||||
statusTimer.stop();
|
||||
if (icon) {
|
||||
icon->setPressed(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PopupAppletPrivate::createIconWidget()
|
||||
|
|
|
@ -219,7 +219,7 @@ private:
|
|||
Q_PRIVATE_SLOT(d, void updateDialogPosition())
|
||||
Q_PRIVATE_SLOT(d, void appletActivated())
|
||||
Q_PRIVATE_SLOT(d, void iconSizeChanged(int))
|
||||
Q_PRIVATE_SLOT(d, void statusChangeWhileShown(Plasma::ItemStatus status))
|
||||
Q_PRIVATE_SLOT(d, void statusChange(Plasma::ItemStatus status))
|
||||
|
||||
friend class Applet;
|
||||
friend class AppletPrivate;
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
void checkExtenderAppearance(Plasma::FormFactor f);
|
||||
KConfigGroup popupConfigGroup();
|
||||
void appletActivated();
|
||||
void statusChangeWhileShown(Plasma::ItemStatus status);
|
||||
void statusChange(Plasma::ItemStatus status);
|
||||
void createIconWidget();
|
||||
|
||||
|
||||
|
@ -64,10 +64,11 @@ public:
|
|||
QTimer *autohideTimer;
|
||||
QBasicTimer delayedShowTimer;
|
||||
QBasicTimer showDialogTimer;
|
||||
QBasicTimer statusTimer;
|
||||
int statusTick;
|
||||
QPoint clicked;
|
||||
ItemStatus preShowStatus;
|
||||
bool popupLostFocus : 1;
|
||||
bool passive : 1;
|
||||
bool popupLostFocus;
|
||||
bool passive;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
|
|
@ -339,7 +339,7 @@ IconWidget::IconWidget(QGraphicsItem *parent)
|
|||
|
||||
IconWidget::IconWidget(const QString &text, QGraphicsItem *parent)
|
||||
: QGraphicsWidget(parent),
|
||||
d(new IconWidgetPrivate(this))
|
||||
d(new IconWidgetPrivate(this))
|
||||
{
|
||||
d->init();
|
||||
setText(text);
|
||||
|
@ -557,12 +557,12 @@ QSizeF IconWidgetPrivate::iconSizeForWidgetSize(const QStyleOptionGraphicsItem *
|
|||
{
|
||||
setActiveMargins();
|
||||
|
||||
//calculate icon size based on the available space
|
||||
qreal iconWidth;
|
||||
// calculate icon size based on the available space
|
||||
qreal iconWidth = 0.0;
|
||||
|
||||
if (orientation == Qt::Vertical) {
|
||||
qreal heightAvail;
|
||||
//if there is text resize the icon in order to make room for the text
|
||||
// if there is text resize the icon in order to make room for the text
|
||||
if (text.isEmpty() && infoText.isEmpty()) {
|
||||
heightAvail = rect.height();
|
||||
} else {
|
||||
|
@ -1527,7 +1527,7 @@ QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const
|
|||
{
|
||||
d->setActiveMargins();
|
||||
if (d->text.isEmpty() && d->infoText.isEmpty()) {
|
||||
//no text, just the icon size
|
||||
// no text, just the icon size
|
||||
return d->addMargin(QSizeF(iconWidth, iconWidth), IconWidgetPrivate::ItemMargin);
|
||||
}
|
||||
|
||||
|
@ -1553,15 +1553,12 @@ QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const
|
|||
d->horizontalMargin[IconWidgetPrivate::TextMargin].left +
|
||||
d->horizontalMargin[IconWidgetPrivate::TextMargin].right;
|
||||
}
|
||||
|
||||
qreal height;
|
||||
qreal textHeight;
|
||||
|
||||
QStyleOptionGraphicsItem option;
|
||||
option.state = QStyle::State_None;
|
||||
option.rect = QRect(0, 0, width, QWIDGETSIZE_MAX);
|
||||
textHeight = d->displaySizeHint(&option, width).height();
|
||||
qreal textHeight = d->displaySizeHint(&option, width).height();
|
||||
|
||||
qreal height = 0.0;
|
||||
if (d->orientation == Qt::Vertical) {
|
||||
height = iconWidth + textHeight +
|
||||
d->verticalMargin[IconWidgetPrivate::TextMargin].top +
|
||||
|
|
|
@ -294,8 +294,11 @@ Qt::LayoutDirection IconWidgetPrivate::iconDirection(const QStyleOptionGraphicsI
|
|||
|
||||
void IconWidgetPrivate::setActiveMargins()
|
||||
{
|
||||
//sync here itemmargin with contentsrect, not overly pretty but it's where it's more reliable
|
||||
qreal left, top, right, bottom;
|
||||
// sync here item margin with contents rect, not overly pretty but it's where it's more reliable
|
||||
qreal left = 0.0;
|
||||
qreal top = 0.0;
|
||||
qreal right = 0.0;
|
||||
qreal bottom = 0.0;
|
||||
q->getContentsMargins(&left, &top, &right, &bottom);
|
||||
if (left || top || right || bottom) {
|
||||
verticalMargin[ItemMargin].left = horizontalMargin[ItemMargin].left = left;
|
||||
|
|
Loading…
Add table
Reference in a new issue