Icon troubles + countdown in new plasmoid
Aaron J. Seigo
aseigo at kde.org
Fri Nov 14 07:37:54 CET 2008
On Thursday 13 November 2008, Tarah Wheeler wrote:
> How do I specify that I want to use my own icon (as opposed to the one in
> KIcon which provides a default document icon) for the image? I tried using
>
> the relative directory like this in the .cpp:
> : Plasma::Applet(parent, args),
>
> m_svg(this),
> m_icon("../icon.png")
that would a relative path to where plasma's working directory is (which
probably isn't where that png is =).
so. there are two ways to do this, but in both cases you will want to install
the image.
a) install it as an icon. do this in your CMakeLists.txt:
kde4_install_icons(${DATA_INSTALL_DIR}/plasma/icons)
though this will only work when it's run from inside plasma without more code
in your applet. probably not what you want.
b) don't bother with KIcon (you have just the one png anyways, right? =) and
load it using QImage + KStandardDirs. you'll still need to install it, but now
you can do:
install(FILES icon.png DESTINATION
${DATA_INSTALL_DIR}/plasma/plasmoids/<yourplasmoidname>)
that will install it in a place you can now find it using:
QString iconPath = KGlobal::dirs()->locate("data",
"plasma/plasmoids/<yourplasmoidname>/icon.png);
m_icon.load(iconPath); // m_icon would be a QImage or QPixmap in this case
i'd recommend (b): it's easier. =) you can also install custom svg's into the
plasma theme and get scalable wonderfulness.
what this does teach me is that we really need:
* nice cmake macros to install plasma data for applet
* Package support for c++ applets so you can simply bundle all your data into
a Plasma::Package and then do things like package()->filePath("icon");
evidently we have more work ahead of us :)
> Second, how would I go about replacing the regular text with a countdown
> (with a prespecified value set in the future)?
easiest way is to use a QTimer; let's say you wanted it to countdown every
second
m_timer = new QTimer(1000, this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(decrementCountdown()));
then in your applet, define a slot called decrementCountdown() and in there do
something like:
void decrementCountdown()
{
if (m_count == 0) {
m_timer->stop();
return;
}
--m_count;
if (m_count) {
m_label->setText(i18nc("One second left!", "%1 seconds left",
m_count));
} else {
m_label->setText(i18n("Your time is up!"));
}
}
the i18nc there is "internationalize, with a count", which lets the
translators do their job properly.
> If there are any tutorials or walkthroughs other than the beginning one
> I've already done, I'd be glad to know about them.
just what's on techbase right now, sadly.
--
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA EE75 D6B7 2EB1 A7F1 DB43
KDE core developer sponsored by Qt Software
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/plasma-devel/attachments/20081113/72bf4ac8/attachment.sig
More information about the Plasma-devel
mailing list