mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-24 02:42:50 +00:00
plasma: remove unused plasmacomponents types
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
9e1808ec97
commit
5199756c8c
11 changed files with 0 additions and 1318 deletions
|
@ -2,10 +2,7 @@ project(plasmacomponents)
|
|||
|
||||
set(plasmacomponents_SRCS
|
||||
plasmacomponentsplugin.cpp
|
||||
qrangemodel.cpp
|
||||
enums.cpp
|
||||
qmenu.cpp
|
||||
qmenuitem.cpp
|
||||
../core/declarativeitemcontainer.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -24,20 +24,6 @@
|
|||
|
||||
#include <QtDeclarative/qdeclarative.h>
|
||||
|
||||
class DialogStatus : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(Status)
|
||||
|
||||
public:
|
||||
enum Status {
|
||||
Opening,
|
||||
Open,
|
||||
Closing,
|
||||
Closed
|
||||
};
|
||||
};
|
||||
|
||||
class PageStatus : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
@ -18,10 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "plasmacomponentsplugin.h"
|
||||
#include "qrangemodel.h"
|
||||
#include "enums.h"
|
||||
#include "qmenu.h"
|
||||
#include "qmenuitem.h"
|
||||
|
||||
#include <QtDeclarative/qdeclarative.h>
|
||||
#include <QtDeclarative/QDeclarativeEngine>
|
||||
|
@ -34,63 +31,10 @@
|
|||
|
||||
Q_EXPORT_PLUGIN(PlasmaComponentsPlugin)
|
||||
|
||||
class BKSingleton
|
||||
{
|
||||
public:
|
||||
EngineBookKeeping self;
|
||||
};
|
||||
K_GLOBAL_STATIC(BKSingleton, privateBKSelf)
|
||||
|
||||
EngineBookKeeping::EngineBookKeeping()
|
||||
{
|
||||
}
|
||||
|
||||
EngineBookKeeping *EngineBookKeeping::self()
|
||||
{
|
||||
return &privateBKSelf->self;
|
||||
}
|
||||
|
||||
QDeclarativeEngine *EngineBookKeeping::engine() const
|
||||
{
|
||||
//for components creation, any engine will do, as long is valid
|
||||
if (m_engines.isEmpty()) {
|
||||
kWarning() << "No engines found, this should never happen";
|
||||
return 0;
|
||||
} else {
|
||||
return m_engines.values().first();
|
||||
}
|
||||
}
|
||||
|
||||
void EngineBookKeeping::insertEngine(QDeclarativeEngine *engine)
|
||||
{
|
||||
connect(engine, SIGNAL(destroyed(QObject *)),
|
||||
this, SLOT(engineDestroyed(QObject *)));
|
||||
m_engines.insert(engine);
|
||||
}
|
||||
|
||||
void EngineBookKeeping::engineDestroyed(QObject *deleted)
|
||||
{
|
||||
m_engines.remove(static_cast<QDeclarativeEngine *>(deleted));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PlasmaComponentsPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri)
|
||||
{
|
||||
QDeclarativeExtensionPlugin::initializeEngine(engine, uri);
|
||||
EngineBookKeeping::self()->insertEngine(engine);
|
||||
}
|
||||
|
||||
void PlasmaComponentsPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
Q_ASSERT(uri == QLatin1String("org.kde.plasma.components"));
|
||||
|
||||
qmlRegisterType<QMenuProxy>(uri, 0, 1, "Menu");
|
||||
qmlRegisterType<QMenuItem>(uri, 0, 1, "MenuItem");
|
||||
|
||||
qmlRegisterType<Plasma::QRangeModel>(uri, 0, 1, "RangeModel");
|
||||
|
||||
qmlRegisterUncreatableType<DialogStatus>(uri, 0, 1, "DialogStatus", "");
|
||||
qmlRegisterUncreatableType<PageStatus>(uri, 0, 1, "PageStatus", "");
|
||||
}
|
||||
|
||||
|
|
|
@ -25,32 +25,12 @@
|
|||
|
||||
#include <QDeclarativeEngine>
|
||||
#include <QDeclarativeItem>
|
||||
class PlasmaComponentsPlugin;
|
||||
|
||||
class EngineBookKeeping : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EngineBookKeeping();
|
||||
static EngineBookKeeping *self();
|
||||
|
||||
void insertEngine(QDeclarativeEngine *engine);
|
||||
QDeclarativeEngine *engine() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void engineDestroyed(QObject *deleted);
|
||||
|
||||
private:
|
||||
QSet <QDeclarativeEngine*> m_engines;
|
||||
};
|
||||
|
||||
class PlasmaComponentsPlugin : public QDeclarativeExtensionPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void initializeEngine(QDeclarativeEngine *engine, const char *uri);
|
||||
void registerTypes(const char *uri);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,307 +0,0 @@
|
|||
/*
|
||||
* Copyright 2011 Viranch Mehta <viranch.mehta@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "qmenu.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QDesktopWidget>
|
||||
#include <QtGui/qgraphicsitem.h>
|
||||
#include <QtGui/qmenu.h>
|
||||
#include <QGraphicsView>
|
||||
#include <QDeclarativeItem>
|
||||
|
||||
#include "plasmacomponentsplugin.h"
|
||||
QMenuProxy::QMenuProxy (QObject *parent)
|
||||
: QObject(parent),
|
||||
m_status(DialogStatus::Closed)
|
||||
{
|
||||
m_menu = new QMenu(0);
|
||||
connect(m_menu, SIGNAL(triggered(QAction *)),
|
||||
this, SLOT(itemTriggered(QAction *)));
|
||||
connect(m_menu, SIGNAL(aboutToHide()), SLOT(markAsClosed()));
|
||||
}
|
||||
|
||||
QMenuProxy::~QMenuProxy()
|
||||
{
|
||||
delete m_menu;
|
||||
}
|
||||
|
||||
QDeclarativeListProperty<QMenuItem> QMenuProxy::content()
|
||||
{
|
||||
return QDeclarativeListProperty<QMenuItem>(this, m_items);
|
||||
}
|
||||
|
||||
int QMenuProxy::actionCount() const
|
||||
{
|
||||
return m_items.count();
|
||||
}
|
||||
|
||||
QMenuItem *QMenuProxy::action(int index) const
|
||||
{
|
||||
return m_items.at(index);
|
||||
}
|
||||
|
||||
DialogStatus::Status QMenuProxy::status() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
|
||||
QObject *QMenuProxy::visualParent() const
|
||||
{
|
||||
return m_visualParent.data();
|
||||
}
|
||||
|
||||
void QMenuProxy::setVisualParent(QObject *parent)
|
||||
{
|
||||
if (m_visualParent.data() == parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
//if the old parent was a QAction, disconnect the menu from it
|
||||
QAction *action = qobject_cast<QAction *>(m_visualParent.data());
|
||||
if (action) {
|
||||
action->setMenu(0);
|
||||
m_menu->clear();
|
||||
}
|
||||
//if parent is a QAction, become a submenu
|
||||
action = qobject_cast<QAction *>(parent);
|
||||
if (action) {
|
||||
action->setMenu(m_menu);
|
||||
m_menu->clear();
|
||||
foreach(QMenuItem* item, m_items) {
|
||||
m_menu->addAction(item);
|
||||
}
|
||||
m_menu->updateGeometry();
|
||||
}
|
||||
|
||||
m_visualParent = parent;
|
||||
emit visualParentChanged();
|
||||
}
|
||||
|
||||
bool QMenuProxy::event(QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::ChildAdded: {
|
||||
QChildEvent *ce = static_cast<QChildEvent *>(event);
|
||||
QMenuItem *mi = qobject_cast<QMenuItem *>(ce->child());
|
||||
//FIXME: linear complexity here
|
||||
if (mi && !m_items.contains(mi)) {
|
||||
m_menu->addAction(mi);
|
||||
m_items << mi;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case QEvent::ChildRemoved: {
|
||||
QChildEvent *ce = static_cast<QChildEvent *>(event);
|
||||
QMenuItem *mi = qobject_cast<QMenuItem *>(ce->child());
|
||||
|
||||
//FIXME: linear complexity here
|
||||
if (mi) {
|
||||
m_menu->removeAction(mi);
|
||||
m_items.removeAll(mi);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QObject::event(event);
|
||||
}
|
||||
|
||||
void QMenuProxy::clearMenuItems()
|
||||
{
|
||||
qDeleteAll(m_items);
|
||||
m_items.clear();
|
||||
}
|
||||
|
||||
void QMenuProxy::addMenuItem(const QString &text)
|
||||
{
|
||||
QMenuItem *item = new QMenuItem(this);
|
||||
item->setText(text);
|
||||
m_menu->addAction(item);
|
||||
m_items << item;
|
||||
}
|
||||
|
||||
void QMenuProxy::addMenuItem(QMenuItem *item)
|
||||
{
|
||||
m_menu->addAction(item);
|
||||
m_items << item;
|
||||
}
|
||||
|
||||
void QMenuProxy::itemTriggered(QAction *action)
|
||||
{
|
||||
QMenuItem *item = qobject_cast<QMenuItem *>(action);
|
||||
if (item) {
|
||||
emit triggered(item);
|
||||
int index = m_items.indexOf(item);
|
||||
if (index > -1) {
|
||||
emit triggeredIndex(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QMenuProxy::open(int x, int y)
|
||||
{
|
||||
m_menu->clear();
|
||||
foreach(QMenuItem* item, m_items) {
|
||||
m_menu->addAction (item);
|
||||
}
|
||||
|
||||
QPoint screenPos;
|
||||
|
||||
QGraphicsObject *parentItem;
|
||||
if (m_visualParent) {
|
||||
parentItem = qobject_cast<QGraphicsObject *>(m_visualParent.data());
|
||||
} else {
|
||||
parentItem = qobject_cast<QGraphicsObject *>(parent());
|
||||
}
|
||||
|
||||
if (!parentItem || !parentItem->scene()) {
|
||||
m_menu->popup(QPoint(0, 0));
|
||||
m_status = DialogStatus::Open;
|
||||
emit statusChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QGraphicsView*> views = parentItem->scene()->views();
|
||||
|
||||
if (views.size() < 1) {
|
||||
m_menu->popup(QPoint(0, 0));
|
||||
m_status = DialogStatus::Open;
|
||||
emit statusChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
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(parentItem->sceneBoundingRect()) ||
|
||||
v->sceneRect().contains(parentItem->scenePos())) {
|
||||
if (v->isActiveWindow()) {
|
||||
found = v;
|
||||
} else {
|
||||
possibleFind = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
view = found ? found : possibleFind;
|
||||
}
|
||||
|
||||
if (view) {
|
||||
screenPos = view->mapToGlobal(view->mapFromScene(parentItem->scenePos()+ QPoint(x, y)));
|
||||
} else {
|
||||
screenPos = QApplication::activeWindow()->mapToGlobal(QPoint(x, y));
|
||||
}
|
||||
|
||||
m_menu->popup(screenPos);
|
||||
m_status = DialogStatus::Open;
|
||||
emit statusChanged();
|
||||
}
|
||||
|
||||
void QMenuProxy::open()
|
||||
{
|
||||
m_menu->clear();
|
||||
|
||||
foreach(QMenuItem* item, m_items) {
|
||||
m_menu->addAction (item);
|
||||
}
|
||||
m_menu->updateGeometry();
|
||||
|
||||
QGraphicsObject *parentItem;
|
||||
if (m_visualParent) {
|
||||
parentItem = qobject_cast<QGraphicsObject *>(m_visualParent.data());
|
||||
} else {
|
||||
parentItem = qobject_cast<QGraphicsObject *>(parent());
|
||||
}
|
||||
|
||||
if (!parentItem || !parentItem->scene()) {
|
||||
m_menu->popup(QPoint(0, 0));
|
||||
m_status = DialogStatus::Open;
|
||||
emit statusChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QGraphicsView*> views = parentItem->scene()->views();
|
||||
|
||||
if (views.size() < 1) {
|
||||
m_menu->popup(QPoint(0, 0));
|
||||
m_status = DialogStatus::Open;
|
||||
emit statusChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
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(parentItem->sceneBoundingRect()) ||
|
||||
v->sceneRect().contains(parentItem->scenePos())) {
|
||||
if (v->isActiveWindow()) {
|
||||
found = v;
|
||||
} else {
|
||||
possibleFind = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
view = found ? found : possibleFind;
|
||||
}
|
||||
|
||||
if (!view) {
|
||||
m_menu->popup(QPoint(0, 0));
|
||||
m_status = DialogStatus::Open;
|
||||
emit statusChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
const QRect avail = QApplication::desktop()->availableGeometry(view);
|
||||
QPoint menuPos = view->mapToGlobal(view->mapFromScene(parentItem->scenePos()+QPoint(0, parentItem->boundingRect().height())));
|
||||
|
||||
if (menuPos.y() + m_menu->sizeHint().height() > avail.bottom()) {
|
||||
menuPos = view->mapToGlobal(view->mapFromScene(parentItem->scenePos() - QPoint(0, m_menu->sizeHint().height())));
|
||||
}
|
||||
|
||||
m_menu->popup(menuPos);
|
||||
m_status = DialogStatus::Open;
|
||||
emit statusChanged();
|
||||
}
|
||||
|
||||
void QMenuProxy::close()
|
||||
{
|
||||
m_menu->hide();
|
||||
}
|
||||
|
||||
void QMenuProxy::markAsClosed()
|
||||
{
|
||||
m_status = DialogStatus::Closed;
|
||||
emit statusChanged();
|
||||
}
|
||||
|
||||
#include "moc_qmenu.cpp"
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Copyright 2011 Viranch Mehta <viranch.mehta@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef QMENU_PROXY_H
|
||||
#define QMENU_PROXY_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMenu>
|
||||
#include <QtDeclarative/qdeclarativelist.h>
|
||||
#include "qmenuitem.h"
|
||||
#include "enums.h"
|
||||
|
||||
#include <QDeclarativeItem>
|
||||
|
||||
class QMenuProxy : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QDeclarativeListProperty<QMenuItem> content READ content CONSTANT)
|
||||
Q_CLASSINFO("DefaultProperty", "content")
|
||||
|
||||
/**
|
||||
* the visualParent is used to position the menu. it can be an item on the scene, like a button (that will open the menu on clicked) or another menuitem (in this case this will be a submenu)
|
||||
*/
|
||||
Q_PROPERTY(QObject *visualParent READ visualParent WRITE setVisualParent NOTIFY visualParentChanged())
|
||||
Q_PROPERTY(DialogStatus::Status status READ status NOTIFY statusChanged)
|
||||
|
||||
public:
|
||||
QMenuProxy(QObject *parent = 0);
|
||||
~QMenuProxy();
|
||||
|
||||
QDeclarativeListProperty<QMenuItem> content();
|
||||
int actionCount() const;
|
||||
QMenuItem *action(int) const;
|
||||
DialogStatus::Status status() const;
|
||||
|
||||
QObject *visualParent() const;
|
||||
void setVisualParent(QObject *parent);
|
||||
|
||||
Q_INVOKABLE void open(int x, int y);
|
||||
Q_INVOKABLE void open();
|
||||
Q_INVOKABLE void close();
|
||||
Q_INVOKABLE void clearMenuItems();
|
||||
Q_INVOKABLE void addMenuItem(const QString &text);
|
||||
Q_INVOKABLE void addMenuItem(QMenuItem *item);
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event);
|
||||
|
||||
Q_SIGNALS:
|
||||
void statusChanged();
|
||||
void visualParentChanged();
|
||||
void triggered(QMenuItem *item);
|
||||
void triggeredIndex(int index);
|
||||
|
||||
private Q_SLOTS:
|
||||
void itemTriggered(QAction *item);
|
||||
void markAsClosed();
|
||||
|
||||
private:
|
||||
QList<QMenuItem*> m_items;
|
||||
QMenu *m_menu;
|
||||
DialogStatus::Status m_status;
|
||||
QWeakPointer<QObject> m_visualParent;
|
||||
};
|
||||
|
||||
#endif //QMENU_PROXY_H
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2011 Viranch Mehta <viranch.mehta@gmail.com> *
|
||||
* *
|
||||
* 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) any later version. *
|
||||
* *
|
||||
* 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qmenuitem.h"
|
||||
|
||||
QMenuItem::QMenuItem(QObject *parent)
|
||||
: QAction(parent)
|
||||
{
|
||||
connect(this, SIGNAL(triggered(bool)), this, SIGNAL(clicked()));
|
||||
}
|
||||
|
||||
#include "moc_qmenuitem.cpp"
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2011 Viranch Mehta <viranch.mehta@gmail.com> *
|
||||
* *
|
||||
* 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) any later version. *
|
||||
* *
|
||||
* 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QMENUITEM_H
|
||||
#define QMENUITEM_H
|
||||
|
||||
#include <QAction>
|
||||
#include <QObject>
|
||||
|
||||
class QMenuItem : public QAction
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/**
|
||||
* The parent object
|
||||
*/
|
||||
Q_PROPERTY(QObject *parent READ parent WRITE setParent)
|
||||
|
||||
/**
|
||||
* If true, the menu item will behave like a separator
|
||||
*/
|
||||
Q_PROPERTY(bool separator READ isSeparator WRITE setSeparator)
|
||||
|
||||
public:
|
||||
QMenuItem(QObject *parent = 0);
|
||||
|
||||
Q_SIGNALS:
|
||||
void clicked();
|
||||
};
|
||||
|
||||
#endif // QMENUITEM_H
|
||||
|
|
@ -1,534 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Components project.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\class QRangeModel
|
||||
\brief The QRangeModel class, helps users to build components that depend
|
||||
on some value and/or position to be in a certain range previously defined
|
||||
|
||||
With this class, the user sets a value range and a position range, which
|
||||
represent the valid values/positions the model can assume. It is worth telling
|
||||
that the value property always has priority over the position property. A nice use
|
||||
case, would be a Slider implementation with the help of QRangeModel. If the user sets
|
||||
a value range to [0,100], a position range to [50,100] and sets the value
|
||||
to 80, the equivalent position would be 90. After that, if the user decides to
|
||||
resize the slider, the value would be the same, but the knob position would
|
||||
be updated due to the new position range.
|
||||
|
||||
\ingroup qt-components
|
||||
*/
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "qrangemodel.h"
|
||||
#include "qrangemodel_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
QRangeModelPrivate::QRangeModelPrivate(QRangeModel *qq)
|
||||
: q_ptr(qq)
|
||||
{
|
||||
}
|
||||
|
||||
QRangeModelPrivate::~QRangeModelPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void QRangeModelPrivate::init()
|
||||
{
|
||||
minimum = 0;
|
||||
maximum = 99;
|
||||
stepSize = 0;
|
||||
value = 0;
|
||||
pos = 0;
|
||||
posatmin = 0;
|
||||
posatmax = 0;
|
||||
inverted = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
Calculates the position that is going to be seen outside by the component
|
||||
that is using QRangeModel. It takes into account the \l stepSize,
|
||||
\l positionAtMinimum, \l positionAtMaximum properties
|
||||
and \a position that is passed as parameter.
|
||||
*/
|
||||
|
||||
qreal QRangeModelPrivate::publicPosition(qreal position) const
|
||||
{
|
||||
// Calculate the equivalent stepSize for the position property.
|
||||
const qreal min = effectivePosAtMin();
|
||||
const qreal max = effectivePosAtMax();
|
||||
const qreal valueRange = maximum - minimum;
|
||||
const qreal positionValueRatio = valueRange ? (max - min) / valueRange : 0;
|
||||
const qreal positionStep = stepSize * positionValueRatio;
|
||||
|
||||
if (positionStep == 0)
|
||||
return (min < max) ? qBound(min, position, max) : qBound(max, position, min);
|
||||
|
||||
const int stepSizeMultiplier = (position - min) / positionStep;
|
||||
|
||||
// Test whether value is below minimum range
|
||||
if (stepSizeMultiplier < 0)
|
||||
return min;
|
||||
|
||||
qreal leftEdge = (stepSizeMultiplier * positionStep) + min;
|
||||
qreal rightEdge = ((stepSizeMultiplier + 1) * positionStep) + min;
|
||||
|
||||
if (min < max) {
|
||||
leftEdge = qMin(leftEdge, max);
|
||||
rightEdge = qMin(rightEdge, max);
|
||||
} else {
|
||||
leftEdge = qMax(leftEdge, max);
|
||||
rightEdge = qMax(rightEdge, max);
|
||||
}
|
||||
|
||||
if (qAbs(leftEdge - position) <= qAbs(rightEdge - position))
|
||||
return leftEdge;
|
||||
return rightEdge;
|
||||
}
|
||||
|
||||
/*!
|
||||
Calculates the value that is going to be seen outside by the component
|
||||
that is using QRangeModel. It takes into account the \l stepSize,
|
||||
\l minimumValue, \l maximumValue properties
|
||||
and \a value that is passed as parameter.
|
||||
*/
|
||||
|
||||
qreal QRangeModelPrivate::publicValue(qreal value) const
|
||||
{
|
||||
// It is important to do value-within-range check this
|
||||
// late (as opposed to during setPosition()). The reason is
|
||||
// QML bindings; a position that is initially invalid because it lays
|
||||
// outside the range, might become valid later if the range changes.
|
||||
|
||||
if (stepSize == 0)
|
||||
return qBound(minimum, value, maximum);
|
||||
|
||||
const int stepSizeMultiplier = (value - minimum) / stepSize;
|
||||
|
||||
// Test whether value is below minimum range
|
||||
if (stepSizeMultiplier < 0)
|
||||
return minimum;
|
||||
|
||||
const qreal leftEdge = qMin(maximum, (stepSizeMultiplier * stepSize) + minimum);
|
||||
const qreal rightEdge = qMin(maximum, ((stepSizeMultiplier + 1) * stepSize) + minimum);
|
||||
const qreal middle = (leftEdge + rightEdge) / 2;
|
||||
|
||||
return (value <= middle) ? leftEdge : rightEdge;
|
||||
}
|
||||
|
||||
/*!
|
||||
Checks if the \l value or \l position, that is seen by the user, has changed and emits the changed signal if it
|
||||
has changed.
|
||||
*/
|
||||
|
||||
void QRangeModelPrivate::emitValueAndPositionIfChanged(const qreal oldValue, const qreal oldPosition)
|
||||
{
|
||||
Q_Q(QRangeModel);
|
||||
|
||||
// Effective value and position might have changed even in cases when e.g. d->value is
|
||||
// unchanged. This will be the case when operating with values outside range:
|
||||
const qreal newValue = q->value();
|
||||
const qreal newPosition = q->position();
|
||||
if (!qFuzzyCompare(newValue, oldValue))
|
||||
emit q->valueChanged(newValue);
|
||||
if (!qFuzzyCompare(newPosition, oldPosition))
|
||||
emit q->positionChanged(newPosition);
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs a QRangeModel with \a parent
|
||||
*/
|
||||
|
||||
QRangeModel::QRangeModel(QObject *parent)
|
||||
: QObject(parent), d_ptr(new QRangeModelPrivate(this))
|
||||
{
|
||||
Q_D(QRangeModel);
|
||||
d->init();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Constructs a QRangeModel with private class pointer \a dd and \a parent
|
||||
*/
|
||||
|
||||
QRangeModel::QRangeModel(QRangeModelPrivate &dd, QObject *parent)
|
||||
: QObject(parent), d_ptr(&dd)
|
||||
{
|
||||
Q_D(QRangeModel);
|
||||
d->init();
|
||||
}
|
||||
|
||||
/*!
|
||||
Destroys the QRangeModel
|
||||
*/
|
||||
|
||||
QRangeModel::~QRangeModel()
|
||||
{
|
||||
delete d_ptr;
|
||||
d_ptr = 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the range of valid positions, that \l position can assume externally, with
|
||||
\a min and \a max.
|
||||
Such range is represented by \l positionAtMinimum and \l positionAtMaximum
|
||||
*/
|
||||
|
||||
void QRangeModel::setPositionRange(qreal min, qreal max)
|
||||
{
|
||||
Q_D(QRangeModel);
|
||||
|
||||
bool emitPosAtMinChanged = !qFuzzyCompare(min, d->posatmin);
|
||||
bool emitPosAtMaxChanged = !qFuzzyCompare(max, d->posatmax);
|
||||
|
||||
if (!(emitPosAtMinChanged || emitPosAtMaxChanged))
|
||||
return;
|
||||
|
||||
const qreal oldPosition = position();
|
||||
d->posatmin = min;
|
||||
d->posatmax = max;
|
||||
|
||||
// When a new positionRange is defined, the position property must be updated based on the value property.
|
||||
// For instance, imagine that you have a valueRange of [0,100] and a position range of [20,100],
|
||||
// if a user set the value to 50, the position would be 60. If this positionRange is updated to [0,100], then
|
||||
// the new position, based on the value (50), will be 50.
|
||||
// If the newPosition is different than the old one, it must be updated, in order to emit
|
||||
// the positionChanged signal.
|
||||
d->pos = d->equivalentPosition(d->value);
|
||||
|
||||
if (emitPosAtMinChanged)
|
||||
emit positionAtMinimumChanged(d->posatmin);
|
||||
if (emitPosAtMaxChanged)
|
||||
emit positionAtMaximumChanged(d->posatmax);
|
||||
|
||||
d->emitValueAndPositionIfChanged(value(), oldPosition);
|
||||
}
|
||||
/*!
|
||||
Sets the range of valid values, that \l value can assume externally, with
|
||||
\a min and \a max. The range has the following constraint: \a min must be less or equal \a max
|
||||
Such range is represented by \l minimumValue and \l maximumValue
|
||||
*/
|
||||
|
||||
void QRangeModel::setRange(qreal min, qreal max)
|
||||
{
|
||||
Q_D(QRangeModel);
|
||||
|
||||
bool emitMinimumChanged = !qFuzzyCompare(min, d->minimum);
|
||||
bool emitMaximumChanged = !qFuzzyCompare(max, d->maximum);
|
||||
|
||||
if (!(emitMinimumChanged || emitMaximumChanged))
|
||||
return;
|
||||
|
||||
const qreal oldValue = value();
|
||||
const qreal oldPosition = position();
|
||||
|
||||
d->minimum = min;
|
||||
d->maximum = qMax(min, max);
|
||||
|
||||
// Update internal position if it was changed. It can occurs if internal value changes, due to range update
|
||||
d->pos = d->equivalentPosition(d->value);
|
||||
|
||||
if (emitMinimumChanged)
|
||||
emit minimumChanged(d->minimum);
|
||||
if (emitMaximumChanged)
|
||||
emit maximumChanged(d->maximum);
|
||||
|
||||
d->emitValueAndPositionIfChanged(oldValue, oldPosition);
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QRangeModel::minimumValue
|
||||
\brief the minimum value that \l value can assume
|
||||
|
||||
This property's default value is 0
|
||||
*/
|
||||
|
||||
void QRangeModel::setMinimum(qreal min)
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
setRange(min, d->maximum);
|
||||
}
|
||||
|
||||
qreal QRangeModel::minimum() const
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
return d->minimum;
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QRangeModel::maximumValue
|
||||
\brief the maximum value that \l value can assume
|
||||
|
||||
This property's default value is 99
|
||||
*/
|
||||
|
||||
void QRangeModel::setMaximum(qreal max)
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
// if the new maximum value is smaller than
|
||||
// minimum, update minimum too
|
||||
setRange(qMin(d->minimum, max), max);
|
||||
}
|
||||
|
||||
qreal QRangeModel::maximum() const
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
return d->maximum;
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QRangeModel::stepSize
|
||||
\brief the value that is added to the \l value and \l position property
|
||||
|
||||
Example: If a user sets a range of [0,100] and stepSize
|
||||
to 30, the valid values that are going to be seen externally would be: 0, 30, 60, 90, 100.
|
||||
*/
|
||||
|
||||
void QRangeModel::setStepSize(qreal stepSize)
|
||||
{
|
||||
Q_D(QRangeModel);
|
||||
|
||||
stepSize = qMax(qreal(0.0), stepSize);
|
||||
if (qFuzzyCompare(stepSize, d->stepSize))
|
||||
return;
|
||||
|
||||
const qreal oldValue = value();
|
||||
const qreal oldPosition = position();
|
||||
d->stepSize = stepSize;
|
||||
|
||||
emit stepSizeChanged(d->stepSize);
|
||||
d->emitValueAndPositionIfChanged(oldValue, oldPosition);
|
||||
}
|
||||
|
||||
qreal QRangeModel::stepSize() const
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
return d->stepSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a valid position, respecting the \l positionAtMinimum,
|
||||
\l positionAtMaximum and the \l stepSize properties.
|
||||
Such calculation is based on the parameter \a value (which is valid externally).
|
||||
*/
|
||||
|
||||
qreal QRangeModel::positionForValue(qreal value) const
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
|
||||
const qreal unconstrainedPosition = d->equivalentPosition(value);
|
||||
return d->publicPosition(unconstrainedPosition);
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QRangeModel::position
|
||||
\brief the current position of the model
|
||||
|
||||
Represents a valid external position, based on the \l positionAtMinimum,
|
||||
\l positionAtMaximum and the \l stepSize properties.
|
||||
The user can set it internally with a position, that is not within the current position range,
|
||||
since it can become valid if the user changes the position range later.
|
||||
*/
|
||||
|
||||
qreal QRangeModel::position() const
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
|
||||
// Return the internal position but observe boundaries and
|
||||
// stepSize restrictions.
|
||||
return d->publicPosition(d->pos);
|
||||
}
|
||||
|
||||
void QRangeModel::setPosition(qreal newPosition)
|
||||
{
|
||||
Q_D(QRangeModel);
|
||||
|
||||
if (qFuzzyCompare(newPosition, d->pos))
|
||||
return;
|
||||
|
||||
const qreal oldPosition = position();
|
||||
const qreal oldValue = value();
|
||||
|
||||
// Update position and calculate new value
|
||||
d->pos = newPosition;
|
||||
d->value = d->equivalentValue(d->pos);
|
||||
d->emitValueAndPositionIfChanged(oldValue, oldPosition);
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QRangeModel::positionAtMinimum
|
||||
\brief the minimum value that \l position can assume
|
||||
|
||||
This property's default value is 0
|
||||
*/
|
||||
|
||||
void QRangeModel::setPositionAtMinimum(qreal min)
|
||||
{
|
||||
Q_D(QRangeModel);
|
||||
setPositionRange(min, d->posatmax);
|
||||
}
|
||||
|
||||
qreal QRangeModel::positionAtMinimum() const
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
return d->posatmin;
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QRangeModel::positionAtMaximum
|
||||
\brief the maximum value that \l position can assume
|
||||
|
||||
This property's default value is 0
|
||||
*/
|
||||
|
||||
void QRangeModel::setPositionAtMaximum(qreal max)
|
||||
{
|
||||
Q_D(QRangeModel);
|
||||
setPositionRange(d->posatmin, max);
|
||||
}
|
||||
|
||||
qreal QRangeModel::positionAtMaximum() const
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
return d->posatmax;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a valid value, respecting the \l minimumValue,
|
||||
\l maximumValue and the \l stepSize properties.
|
||||
Such calculation is based on the parameter \a position (which is valid externally).
|
||||
*/
|
||||
|
||||
qreal QRangeModel::valueForPosition(qreal position) const
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
|
||||
const qreal unconstrainedValue = d->equivalentValue(position);
|
||||
return d->publicValue(unconstrainedValue);
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QRangeModel::value
|
||||
\brief the current value of the model
|
||||
|
||||
Represents a valid external value, based on the \l minimumValue,
|
||||
\l maximumValue and the \l stepSize properties.
|
||||
The user can set it internally with a value, that is not within the current range,
|
||||
since it can become valid if the user changes the range later.
|
||||
*/
|
||||
|
||||
qreal QRangeModel::value() const
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
|
||||
// Return internal value but observe boundaries and
|
||||
// stepSize restrictions
|
||||
return d->publicValue(d->value);
|
||||
}
|
||||
|
||||
void QRangeModel::setValue(qreal newValue)
|
||||
{
|
||||
Q_D(QRangeModel);
|
||||
|
||||
if (qFuzzyCompare(newValue, d->value))
|
||||
return;
|
||||
|
||||
const qreal oldValue = value();
|
||||
const qreal oldPosition = position();
|
||||
|
||||
// Update relative value and position
|
||||
d->value = newValue;
|
||||
d->pos = d->equivalentPosition(d->value);
|
||||
d->emitValueAndPositionIfChanged(oldValue, oldPosition);
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QRangeModel::inverted
|
||||
\brief the model is inverted or not
|
||||
|
||||
The model can be represented with an inverted behavior, e.g. when \l value assumes
|
||||
the maximum value (represented by \l maximumValue) the \l position will be at its
|
||||
minimum (represented by \l positionAtMinimum).
|
||||
*/
|
||||
|
||||
void QRangeModel::setInverted(bool inverted)
|
||||
{
|
||||
Q_D(QRangeModel);
|
||||
if (inverted == d->inverted)
|
||||
return;
|
||||
|
||||
d->inverted = inverted;
|
||||
emit invertedChanged(d->inverted);
|
||||
|
||||
// After updating the internal value, the position property can change.
|
||||
setPosition(d->equivalentPosition(d->value));
|
||||
}
|
||||
|
||||
bool QRangeModel::inverted() const
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
return d->inverted;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the \l value to \l minimumValue.
|
||||
*/
|
||||
|
||||
void QRangeModel::toMinimum()
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
setValue(d->minimum);
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the \l value to \l maximumValue.
|
||||
*/
|
||||
|
||||
void QRangeModel::toMaximum()
|
||||
{
|
||||
Q_D(const QRangeModel);
|
||||
setValue(d->maximum);
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#include "moc_qrangemodel.cpp"
|
|
@ -1,126 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Components project.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QRANGEMODEL_H
|
||||
#define QRANGEMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class QRangeModelPrivate;
|
||||
|
||||
class QRangeModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged USER true)
|
||||
Q_PROPERTY(qreal minimumValue READ minimum WRITE setMinimum NOTIFY minimumChanged)
|
||||
Q_PROPERTY(qreal maximumValue READ maximum WRITE setMaximum NOTIFY maximumChanged)
|
||||
Q_PROPERTY(qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged)
|
||||
Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged)
|
||||
Q_PROPERTY(qreal positionAtMinimum READ positionAtMinimum WRITE setPositionAtMinimum NOTIFY positionAtMinimumChanged)
|
||||
Q_PROPERTY(qreal positionAtMaximum READ positionAtMaximum WRITE setPositionAtMaximum NOTIFY positionAtMaximumChanged)
|
||||
Q_PROPERTY(bool inverted READ inverted WRITE setInverted NOTIFY invertedChanged)
|
||||
|
||||
public:
|
||||
QRangeModel(QObject *parent = 0);
|
||||
virtual ~QRangeModel();
|
||||
|
||||
void setRange(qreal min, qreal max);
|
||||
void setPositionRange(qreal min, qreal max);
|
||||
|
||||
void setStepSize(qreal stepSize);
|
||||
qreal stepSize() const;
|
||||
|
||||
void setMinimum(qreal min);
|
||||
qreal minimum() const;
|
||||
|
||||
void setMaximum(qreal max);
|
||||
qreal maximum() const;
|
||||
|
||||
void setPositionAtMinimum(qreal posAtMin);
|
||||
qreal positionAtMinimum() const;
|
||||
|
||||
void setPositionAtMaximum(qreal posAtMax);
|
||||
qreal positionAtMaximum() const;
|
||||
|
||||
void setInverted(bool inverted);
|
||||
bool inverted() const;
|
||||
|
||||
qreal value() const;
|
||||
qreal position() const;
|
||||
|
||||
Q_INVOKABLE qreal valueForPosition(qreal position) const;
|
||||
Q_INVOKABLE qreal positionForValue(qreal value) const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void toMinimum();
|
||||
void toMaximum();
|
||||
void setValue(qreal value);
|
||||
void setPosition(qreal position);
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged(qreal value);
|
||||
void positionChanged(qreal position);
|
||||
|
||||
void stepSizeChanged(qreal stepSize);
|
||||
|
||||
void invertedChanged(bool inverted);
|
||||
|
||||
void minimumChanged(qreal min);
|
||||
void maximumChanged(qreal max);
|
||||
void positionAtMinimumChanged(qreal min);
|
||||
void positionAtMaximumChanged(qreal max);
|
||||
|
||||
protected:
|
||||
QRangeModel(QRangeModelPrivate &dd, QObject *parent);
|
||||
QRangeModelPrivate* d_ptr;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QRangeModel)
|
||||
Q_DECLARE_PRIVATE(QRangeModel)
|
||||
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#endif // QRANGEMODEL_H
|
|
@ -1,97 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Components project on Qt Labs.
|
||||
**
|
||||
** No Commercial Usage
|
||||
** This file contains pre-release code and may not be distributed.
|
||||
** You may use this file in accordance with the terms and conditions contained
|
||||
** in the Technology Preview License Agreement accompanying this package.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QRANGEMODEL_P_H
|
||||
#define QRANGEMODEL_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt Components API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qrangemodel.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class QRangeModelPrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QRangeModel)
|
||||
public:
|
||||
QRangeModelPrivate(QRangeModel *qq);
|
||||
virtual ~QRangeModelPrivate();
|
||||
|
||||
void init();
|
||||
|
||||
qreal posatmin, posatmax;
|
||||
qreal minimum, maximum, stepSize, pos, value;
|
||||
|
||||
uint inverted : 1;
|
||||
|
||||
QRangeModel *q_ptr;
|
||||
|
||||
inline qreal effectivePosAtMin() const {
|
||||
return inverted ? posatmax : posatmin;
|
||||
}
|
||||
|
||||
inline qreal effectivePosAtMax() const {
|
||||
return inverted ? posatmin : posatmax;
|
||||
}
|
||||
|
||||
inline qreal equivalentPosition(qreal value) const {
|
||||
// Return absolute position from absolute value
|
||||
const qreal valueRange = maximum - minimum;
|
||||
if (valueRange == 0)
|
||||
return effectivePosAtMin();
|
||||
|
||||
const qreal scale = (effectivePosAtMax() - effectivePosAtMin()) / valueRange;
|
||||
return (value - minimum) * scale + effectivePosAtMin();
|
||||
}
|
||||
|
||||
inline qreal equivalentValue(qreal pos) const {
|
||||
// Return absolute value from absolute position
|
||||
const qreal posRange = effectivePosAtMax() - effectivePosAtMin();
|
||||
if (posRange == 0)
|
||||
return minimum;
|
||||
|
||||
const qreal scale = (maximum - minimum) / posRange;
|
||||
return (pos - effectivePosAtMin()) * scale + minimum;
|
||||
}
|
||||
|
||||
qreal publicPosition(qreal position) const;
|
||||
qreal publicValue(qreal value) const;
|
||||
void emitValueAndPositionIfChanged(const qreal oldValue, const qreal oldPosition);
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#endif // QRANGEMODEL_P_H
|
Loading…
Add table
Reference in a new issue