• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

brandingbutton.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2008 Aaron Seigo <aseigo@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
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     //FIXME: 4.3 .. add a brandingConfig to Theme
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         //kDebug() << "bad branding svg!";
00090         return;
00091     }
00092 
00093     QPainter p(this);
00094     QSize s = m_svg->elementSize("brilliant");
00095     QRect r = rect();
00096 
00097     // center ourselves in the full rect
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 } // namespace KickOff
00110 
00111 #include "brandingbutton.moc"
00112 
00113 

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal