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

Applets

applet.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2007 Robert Knight <robertknight@gmail.com>
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 // Own
00021 #include "applet/applet.h"
00022 
00023 // Qt
00024 #include <QtGui/QAction>
00025 #include <QtGui/QApplication>
00026 #include <QtGui/QGraphicsView>
00027 #include <QtGui/QCheckBox>
00028 #include <QtGui/QVBoxLayout>
00029 #include <QtGui/QLabel>
00030 #include <QtGui/QGraphicsLinearLayout>
00031 
00032 // KDE
00033 #include <KIcon>
00034 #include <KDebug>
00035 #include <KConfigDialog>
00036 #include <KProcess>
00037 
00038 // Plasma
00039 #include <Plasma/IconWidget>
00040 #include <Plasma/Containment>
00041 #include <Plasma/View>
00042 #include <Plasma/ToolTipManager>
00043 
00044 // Local
00045 #include "ui/launcher.h"
00046 #include "core/recentapplications.h"
00047 
00048 class LauncherApplet::Private
00049 {
00050 public:
00051     Private(LauncherApplet *lApplet) : launcher(0), switcher(0), q(lApplet) { }
00052     ~Private() {
00053         delete launcher;
00054     }
00055     void createLauncher();
00056     void initToolTip();
00057 
00058     Kickoff::Launcher *launcher;
00059 
00060     QCheckBox *switchOnHoverCheckBox;
00061     QList<QAction*> actions;
00062     QAction* switcher;
00063     LauncherApplet *q;
00064 };
00065 
00066 void LauncherApplet::Private::createLauncher()
00067 {
00068     if (launcher) {
00069         return;
00070     }
00071 
00072     launcher = new Kickoff::Launcher(q);
00073     launcher->setAttribute(Qt::WA_NoSystemBackground);
00074     launcher->setAutoHide(true);
00075     QObject::connect(launcher, SIGNAL(aboutToHide()), q, SLOT(hidePopup()));
00076     //launcher->resize(launcher->sizeHint());
00077     //QObject::connect(launcher, SIGNAL(aboutToHide()), icon, SLOT(setUnpressed()));
00078     //QObject::connect(launcher, SIGNAL(configNeedsSaving()), q, SIGNAL(configNeedsSaving()));
00079 }
00080 
00081 void LauncherApplet::Private::initToolTip()
00082 {
00083     Plasma::ToolTipContent data(i18n("Kickoff Application Launcher"),
00084                                 i18n("Favorites, applications, computer places, "
00085                                      "recently used items and desktop sessions"),
00086                                 q->popupIcon().pixmap(IconSize(KIconLoader::Desktop)));
00087     Plasma::ToolTipManager::self()->setContent(q, data);
00088 }
00089 
00090 LauncherApplet::LauncherApplet(QObject *parent, const QVariantList &args)
00091         : Plasma::PopupApplet(parent, args),
00092         d(new Private(this))
00093 {
00094     KGlobal::locale()->insertCatalog("plasma_applet_launcher");
00095     setHasConfigurationInterface(true);
00096     setPopupIcon("start-here-kde");
00097 }
00098 
00099 LauncherApplet::~LauncherApplet()
00100 {
00101     delete d;
00102 }
00103 
00104 void LauncherApplet::init()
00105 {
00106     if (KService::serviceByStorageId("kde4-kmenuedit.desktop")) {
00107         QAction* menueditor = new QAction(i18n("Menu Editor"), this);
00108         d->actions.append(menueditor);
00109         connect(menueditor, SIGNAL(triggered(bool)), this, SLOT(startMenuEditor()));
00110     }
00111 
00112     Q_ASSERT(! d->switcher);
00113     d->switcher = new QAction(i18n("Switch to Classic Menu Style"), this);
00114     d->actions.append(d->switcher);
00115     connect(d->switcher, SIGNAL(triggered(bool)), this, SLOT(switchMenuStyle()));
00116 
00117     constraintsEvent(Plasma::ImmutableConstraint);
00118     Plasma::ToolTipManager::self()->registerWidget(this);
00119 }
00120 
00121 void LauncherApplet::constraintsEvent(Plasma::Constraints constraints)
00122 {
00123     if ((constraints & Plasma::ImmutableConstraint) && d->switcher) {
00124         d->switcher->setVisible(immutability() == Plasma::Mutable);
00125     }
00126 }
00127 
00128 void LauncherApplet::switchMenuStyle()
00129 {
00130     if (containment()) {
00131         containment()->addApplet("simplelauncher", QVariantList(), geometry());
00132         destroy();
00133     }
00134 }
00135 
00136 void LauncherApplet::startMenuEditor()
00137 {
00138     KProcess::execute("kmenuedit");
00139 }
00140 
00141 void LauncherApplet::createConfigurationInterface(KConfigDialog *parent)
00142 {
00143     QWidget *widget = new QWidget(parent);
00144     QVBoxLayout *widgetLayout = new QVBoxLayout(widget);
00145     widget->setLayout(widgetLayout);
00146 
00147     d->switchOnHoverCheckBox = new QCheckBox(i18n("Switch tabs on hover"), widget);
00148     widgetLayout->addWidget(d->switchOnHoverCheckBox);
00149 
00150     widgetLayout->addStretch();
00151 
00152     connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
00153     connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
00154     parent->addPage(widget, i18n("General"), icon());
00155 
00156     d->createLauncher();
00157     d->switchOnHoverCheckBox->setChecked(d->launcher->switchTabsOnHover());
00158 }
00159 
00160 void LauncherApplet::popupEvent(bool show)
00161 {
00162     if (show) {
00163         Plasma::ToolTipManager::self()->clearContent(this);
00164         d->launcher->setLauncherOrigin(popupPlacement(), location());
00165         d->createLauncher();
00166     }
00167 }
00168 
00169 void LauncherApplet::toolTipAboutToShow()
00170 {
00171     if (d->launcher->isVisible()) {
00172         Plasma::ToolTipManager::self()->clearContent(this);
00173     } else {
00174         d->initToolTip();
00175     }
00176 }
00177 
00178 void LauncherApplet::configAccepted()
00179 {
00180     bool switchTabsOnHover = d->switchOnHoverCheckBox->isChecked();
00181 
00182     // TODO: should this be moved into Launcher as well? perhaps even the config itself?
00183     KConfigGroup cg = globalConfig();
00184     cg.writeEntry("SwitchTabsOnHover", switchTabsOnHover);
00185     emit configNeedsSaving();
00186 
00187     d->createLauncher();
00188     d->launcher->setSwitchTabsOnHover(switchTabsOnHover);
00189 }
00190 
00191 QList<QAction*> LauncherApplet::contextualActions()
00192 {
00193     return d->actions;
00194 }
00195 
00196 QWidget *LauncherApplet::widget()
00197 {
00198     d->createLauncher();
00199     return d->launcher;
00200 }
00201 
00202 #include "applet.moc"

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