Applets
brandingbutton.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "brandingbutton.h"
00021
00022 #include <QtGui/QPainter>
00023
00024 #include <KConfigGroup>
00025 #include <KDebug>
00026 #include <KStandardDirs>
00027 #include <KRun>
00028
00029 #include <Plasma/Svg>
00030 #include <Plasma/Theme>
00031
00032 namespace Kickoff
00033 {
00034
00035 BrandingButton::BrandingButton(QWidget *parent)
00036 : QToolButton(parent),
00037 m_svg(new Plasma::Svg(this))
00038 {
00039 m_svg->setImagePath("widgets/branding");
00040 m_svg->resize();
00041 checkBranding();
00042 connect(m_svg, SIGNAL(repaintNeeded()), this, SLOT(checkBranding()));
00043 connect(this, SIGNAL(clicked()), SLOT(openHomepage()));
00044 setCursor(Qt::PointingHandCursor);
00045 }
00046
00047 QSize BrandingButton::minimumSizeHint() const
00048 {
00049 return sizeHint();
00050 }
00051
00052 QSize BrandingButton::sizeHint() const
00053 {
00054 return m_size;
00055 }
00056
00057 void BrandingButton::checkBranding()
00058 {
00059 m_doingBranding = m_svg->isValid() && m_svg->hasElement("brilliant");
00060
00061 if (!m_doingBranding) {
00062 m_size = QSize();
00063 return;
00064 }
00065
00066 m_size = m_svg->elementSize("brilliant");
00067 }
00068
00069 void BrandingButton::openHomepage()
00070 {
00071
00072 KUrl home("http://www.kde.org");
00073 QString themePath = KStandardDirs::locate("data", "desktoptheme/" +
00074 Plasma::Theme::defaultTheme()->themeName() +
00075 "/metadata.desktop");
00076 if (!themePath.isEmpty()) {
00077 KConfig c(themePath);
00078 KConfigGroup brandConfig(&c, "Branding");
00079 home = brandConfig.readEntry("homepage", home);
00080 }
00081
00082 new KRun(home, topLevelWidget(), false, false);
00083 }
00084
00085 void BrandingButton::paintEvent(QPaintEvent *event)
00086 {
00087 Q_UNUSED(event);
00088 if (!m_doingBranding) {
00089
00090 return;
00091 }
00092
00093 QPainter p(this);
00094 QSize s = m_svg->elementSize("brilliant");
00095 QRect r = rect();
00096
00097
00098 if (r.width() > s.width()) {
00099 r.setX(r.x() + (r.width() - s.width()) / 2);
00100 }
00101
00102 if (r.height() > s.height()) {
00103 r.setY(r.y() + (r.height() - s.height()) / 2);
00104 }
00105
00106 m_svg->paint(&p, rect(), "brilliant");
00107 }
00108
00109 }
00110
00111 #include "brandingbutton.moc"
00112
00113