Commit 3270cae2 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Remove dead code

parent 9bcb1cc1
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright 2013 Vishesh Handa <me@vhanda.in>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "applet.h"
#include "configwidget.h"
#include <KGlobal>
#include <KStandardDirs>
#include <KConfigDialog>
#include <KLocale>
#include <QDeclarativeContext>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QApplication>
#include <QDesktopWidget>
Applet::Applet(QObject* parent, const QVariantList& args): PopupApplet(parent, args)
{
setPopupIcon("nepomuk");
KGlobal::locale()->insertCatalog("milou");
}
Applet::~Applet()
{
}
void Applet::init()
{
m_declarativeWidget = new Plasma::DeclarativeWidget(this);
QDeclarativeContext* rootContext = m_declarativeWidget->engine()->rootContext();
rootContext->setContextProperty("plasmoid", this);
QString qmlFile = KGlobal::dirs()->findResource("data", "plasma/plasmoids/org.kde.milou/contents/ui/main.qml");
m_declarativeWidget->setQmlPath(qmlFile);
Plasma::Applet::init();
}
QGraphicsWidget* Applet::graphicsWidget()
{
return m_declarativeWidget;
}
void Applet::createConfigurationInterface(KConfigDialog* parent)
{
ConfigWidget* widget = new ConfigWidget();
parent->addPage(widget, i18n("Search Results"), icon());
connect(widget, SIGNAL(changed()), parent, SLOT(settingsModified()));
// The order matters. The config widget should be saved first
connect(parent, SIGNAL(applyClicked()), widget, SLOT(saveSettings()));
connect(parent, SIGNAL(okClicked()), widget, SLOT(saveSettings()));
connect(parent, SIGNAL(applyClicked()), this, SIGNAL(settingsChanged()));
connect(parent, SIGNAL(okClicked()), this, SIGNAL(settingsChanged()));
}
void Applet::popupEvent(bool show)
{
emit popupEventSignal(show);
}
bool Applet::isTopEdge() const
{
return location() == Plasma::TopEdge;
}
bool Applet::isBottomEdge() const
{
return location() == Plasma::BottomEdge;
}
bool Applet::isShown() const
{
return isPopupShowing();
}
// Copied adapted from kde-workspace/libs/plasmagenericshell/widgetexplorer/widgetexplorer.cpp
QPoint Applet::tooltipPosition(QGraphicsObject* item, int tipWidth, int tipHeight)
{
if (!item) {
return QPoint();
}
// Find view
if (!item->scene()) {
return QPoint();
}
QList<QGraphicsView*> views = item->scene()->views();
if (views.isEmpty()) {
return QPoint();
}
QGraphicsView *view = 0;
if (views.size() == 1) {
view = views[0];
} else {
QGraphicsView *found = 0;
QGraphicsView *possibleFind = 0;
foreach (QGraphicsView *v, views) {
if (v->sceneRect().intersects(item->sceneBoundingRect()) ||
v->sceneRect().contains(item->scenePos())) {
if (v->isActiveWindow()) {
found = v;
} else {
possibleFind = v;
}
}
}
view = found ? found : possibleFind;
}
if (!view) {
return QPoint();
}
// Compute tip pos
QRect itemRect(
view->mapToGlobal(view->mapFromScene(item->scenePos())),
item->boundingRect().size().toSize());
const int margin = 10;
QPoint pos;
pos.setY(itemRect.top() - tipHeight/2 + itemRect.height()/2);
pos.setX(itemRect.right() + margin);
// Choose left edge if no space on right edge
const QRect avail = QApplication::desktop()->availableGeometry(view);
if (pos.x() + tipWidth > avail.right()) {
// HACK: The tipWidth doesn't seem to accurately reflect the actual width
// Hence the extra -25 to make it look good.
pos.setX(itemRect.left() - tipWidth - margin - 25);
}
// HACK: The +30 is to account for other margins
QRect finalRect(pos.x(), pos.y(), tipWidth, tipHeight + 30);
if (finalRect.bottom() > avail.bottom()) {
int diff = finalRect.bottom() - avail.bottom();
finalRect.moveTop(finalRect.top() - diff);
}
return QPoint(finalRect.x(), finalRect.y());
}
#include "applet.moc"
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright 2013 Vishesh Handa <me@vhanda.in>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef APPLET_H
#define APPLET_H
#include <Plasma/PopupApplet>
#include <Plasma/DeclarativeWidget>
class Applet : public Plasma::PopupApplet
{
Q_OBJECT
public:
Applet(QObject* parent, const QVariantList& args);
virtual ~Applet();
virtual void init();
virtual QGraphicsWidget* graphicsWidget();
virtual void createConfigurationInterface(KConfigDialog* parent);
Q_INVOKABLE QPoint tooltipPosition(QGraphicsObject* item, int tipWidth, int tipHeight);
public Q_SLOTS:
bool isTopEdge() const;
bool isBottomEdge() const;
bool isShown() const;
Q_SIGNALS:
void popupEventSignal(bool shown);
void settingsChanged();
protected:
virtual void popupEvent(bool show);
private:
Plasma::DeclarativeWidget* m_declarativeWidget;
};
K_EXPORT_PLASMA_APPLET(milou_applet, Applet)
#endif // APPLET_H
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright 2013 Vishesh Handa <me@vhanda.in>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "configwidget.h"
#include <KIcon>
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <QLabel>
#include <QVBoxLayout>
#include <QListWidgetItem>
ConfigWidget::ConfigWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
{
m_listWidget = new QListWidget(this);
m_listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
m_listWidget->setDragDropMode(QAbstractItemView::InternalMove);
m_listWidget->setAlternatingRowColors(true);
connect(m_listWidget, SIGNAL(itemChanged(QListWidgetItem*)),
this, SIGNAL(changed()));
connect(m_listWidget->model(), SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)),
this, SIGNAL(changed()));
KConfig config("milourc");
KConfigGroup generalGroup = config.group("General");
int numTypes = generalGroup.readEntry("NumTypes", 0);
for (int i=0; i<numTypes; i++) {
KConfigGroup group = config.group("Type-" + QString::number(i));
QString name = group.readEntry("Name", QString());
QString icon = group.readEntry("Icon", QString());
bool enabled = group.readEntry("Enabled", true);
QListWidgetItem* item = new QListWidgetItem(name, m_listWidget);
item->setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
item->setIcon(KIcon(icon));
}
QLabel* label = new QLabel(i18n("Only the selected components are shown in the search results"));
label->setAlignment(Qt::AlignHCenter);
label->setWordWrap(true);
QLabel* label2 = new QLabel(i18n("Drag categories to change the order in which results appear"));
QFont fo = label2->font();
fo.setBold(true);
label2->setFont(fo);
label2->setAlignment(Qt::AlignHCenter);
label2->setWordWrap(true);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(label);
layout->addWidget(label2);
layout->addWidget(m_listWidget);
}
ConfigWidget::~ConfigWidget()
{
}
void ConfigWidget::saveSettings()
{
KConfig config("milourc");
int size = m_listWidget->count();
for(int i=0; i<size; i++) {
QListWidgetItem* item = m_listWidget->item(i);
KConfigGroup group = config.group("Type-" + QString::number(i));
group.writeEntry("Name", item->text());
group.writeEntry("Icon", item->icon().name());
group.writeEntry("Enabled", (item->checkState() == Qt::Checked));
}
}
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright 2013 Vishesh Handa <me@vhanda.in>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CONFIGWIDGET_H
#define CONFIGWIDGET_H
#include <QListWidget>
class ConfigWidget : public QWidget
{
Q_OBJECT
public:
explicit ConfigWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
virtual ~ConfigWidget();
public Q_SLOTS:
void saveSettings();
Q_SIGNALS:
void changed();
private:
QListWidget* m_listWidget;
};
#endif // CONFIGWIDGET_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment