Refresh Icons in Mode Manager

12 views
Skip to first unread message

Carel Combrink

unread,
Jul 24, 2013, 6:32:20 AM7/24/13
to qtil...@googlegroups.com
Hi,

How would I go about refreshing the icons for the different modes. 

At the moment I am trying to create a mode that shows the status of the application. When there is an error in the application I want to overlay a small error icon over the current mode icon (this could also apply to the "Session Log" Mode).

Is there perhaps already a way that this can be done or how can I proceed.

Built in support for this would be very nice, but if not I would just like to refresh the icon.

Regards

Jaco Naude

unread,
Jul 24, 2013, 11:03:06 PM7/24/13
to qtil...@googlegroups.com
Hi

The IMode interface has two functions related to mode icons:
- modeIcon() used to retrieve the icon to show.
- setModeIcon(), which can be used to set the icon of the mode. Note that the implementation of IMode needs to manually re-implement this function if the mode need to allow changing of its icon. By default, the function does nothing. The "Session Log" mode supports changing of its icon, thus it has an implementation of this function. 

However, the ModeManager only gets the icon when its initialized. Therefore you need to call setModeIcon() before initializing the mode manager. To support your request, support must be added to allow the mode implementation to emit a signal to notify that its icon changed, and the ModeManager needs to connect to this. However, because the IMode interface does not inherit QObject we cannot add such a signal on the interface itself. I suggest that a modeIconChanged() virtual abstract function needs to be added. All modes must implement it as a signal, even if they don't re-implement setModeIcon().

This would mean that all application's which implement IMode must be updated to add this signal. However, I think it might be a worthwhile change for the next Qtilities release (v1.5). What do you think? An alternative would be to add a function on ModeManager which tells it to refresh the icon for a given IMode interface, maybe a better approach?

In terms of doing the overlay, something like the following should work to overlay something in the bottom left corner for example:

    QPixmap pixmap(my_mode->modeIcon().pixmap(48,48));
    QPixmap result(48, 48);
    result.fill(Qt::transparent);

    QPainter painter(&result);
    painter.drawPixmap(0, 0, pixmap);

    QPixmap overlay("path_to_overlay_image");
    painter.drawPixmap(result.width()-1-overlay.width(), result.height()-1-overlay.height(), overlay);

    my_mode->setModeIcon(QIcon(result));

I won't be able to add built-in support for the Session Log mode at the moment, but would support you if you want to give it a try.

Cheers,
Jaco



--
--
To post to this group, send email to qtil...@googlegroups.com
To unsubscribe from this group, send email to
qtilities+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/qtilities?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Qtilities" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qtilities+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Carel Combrink

unread,
Aug 1, 2013, 6:08:19 AM8/1/13
to qtil...@googlegroups.com
Jaco,

However, the ModeManager only gets the icon when its initialized. Therefore you need to call setModeIcon() before initializing the mode manager. To support your request, support must be added to allow the mode implementation to emit a signal to notify that its icon changed, and the ModeManager needs to connect to this. However, because the IMode interface does not inherit QObject we cannot add such a signal on the interface itself. I suggest that a modeIconChanged() virtual abstract function needs to be added. All modes must implement it as a signal, even if they don't re-implement setModeIcon().

I support something like this. Perhaps an alternative to change the IMode interface is to have the manager check if a signal with a specific signature like "void modeIconChanged()"  exists on the mode and if it does it connects to it. To enforce this signature it might be worth while to add a virtual function to the IMode base but not make it pure virtual. 

The QStyle does something similar for the standardIcon() function to preserve binary compatibility (although this is for calling a slot, not connecting a signal). 

An alternative would be to add a function on ModeManager which tells it to refresh the icon for a given IMode interface, maybe a better approach?
 
I do not think that this is a good solution. The reason for this is because the way that the manager and modes work. Since a mode does not always know what manager it belongs to, and a mode can belong to different managers at the same time, this might complicate it a bit to get the correct manager(s) and update all of them for the specified mode. 

I will attempt something in the line of suggestion 1 if and when I have time. If I get something working I will let you know.

Regards,
Carel

Jaco Naude

unread,
Aug 1, 2013, 6:45:46 AM8/1/13
to qtil...@googlegroups.com
Hi Carel

Please see https://github.com/JPNaude/Qtilities/issues/96. I've create the issue for it. I will start on the Mode Manager side using the first approach we discussed. I will first focus on support for icons to change when they need to. The pixmap overlays can then be done later and use this functionality.

Cheers
Jaco


--
Reply all
Reply to author
Forward
0 new messages