not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / applets / kickoff / ui / brandingbutton.cpp
blobe2e2a0d7b97e44036ec3dc8e197cba956d030fd1
1 /*
2 Copyright 2008 Aaron Seigo <aseigo@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "brandingbutton.h"
22 #include <QtGui/QPainter>
24 #include <KConfigGroup>
25 #include <KDebug>
26 #include <KStandardDirs>
27 #include <KRun>
29 #include <Plasma/Svg>
30 #include <Plasma/Theme>
32 namespace Kickoff
35 BrandingButton::BrandingButton(QWidget *parent)
36 : QToolButton(parent),
37 m_svg(new Plasma::Svg(this))
39 m_svg->setImagePath("widgets/branding");
40 m_svg->resize();
41 checkBranding();
42 connect(m_svg, SIGNAL(repaintNeeded()), this, SLOT(checkBranding()));
43 connect(this, SIGNAL(clicked()), SLOT(openHomepage()));
44 setCursor(Qt::PointingHandCursor);
47 QSize BrandingButton::minimumSizeHint() const
49 return sizeHint();
52 QSize BrandingButton::sizeHint() const
54 return m_size;
57 void BrandingButton::checkBranding()
59 m_doingBranding = m_svg->isValid() && m_svg->hasElement("brilliant");
61 if (!m_doingBranding) {
62 m_size = QSize();
63 return;
66 m_size = m_svg->elementSize("brilliant");
69 void BrandingButton::openHomepage()
71 //FIXME: 4.3 .. add a brandingConfig to Theme
72 KUrl home("http://www.kde.org");
73 QString themePath = KStandardDirs::locate("data", "desktoptheme/" +
74 Plasma::Theme::defaultTheme()->themeName() +
75 "/metadata.desktop");
76 if (!themePath.isEmpty()) {
77 KConfig c(themePath);
78 KConfigGroup brandConfig(&c, "Branding");
79 home = brandConfig.readEntry("homepage", home);
82 new KRun(home, topLevelWidget(), false, false);
85 void BrandingButton::paintEvent(QPaintEvent *event)
87 Q_UNUSED(event);
88 if (!m_doingBranding) {
89 //kDebug() << "bad branding svg!";
90 return;
93 QPainter p(this);
94 QSize s = m_svg->elementSize("brilliant");
95 QRect r = rect();
97 // center ourselves in the full rect
98 if (r.width() > s.width()) {
99 r.setX(r.x() + (r.width() - s.width()) / 2);
102 if (r.height() > s.height()) {
103 r.setY(r.y() + (r.height() - s.height()) / 2);
106 m_svg->paint(&p, rect(), "brilliant");
109 } // namespace KickOff
111 #include "brandingbutton.moc"