- Added a factory class analogous to QUiLoader for plasma widgets. It
it not currently compiled, and does not yet support loading of full forms. Note that this shows up that the APIs defined by the widgets are still woefully inconsistent. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=708875
This commit is contained in:
parent
cec28bebac
commit
2e506845e9
123
uiloader.cpp
Normal file
123
uiloader.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 2007 Richard J. Moore <rich@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 "uiloader.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
#include "widgets/widget.h"
|
||||
#include "widgets/layout.h"
|
||||
|
||||
#include "widgets/checkbox.h"
|
||||
#include "widgets/flash.h"
|
||||
#include "widgets/icon.h"
|
||||
#include "widgets/label.h"
|
||||
#include "widgets/pushbutton.h"
|
||||
#include "widgets/radiobutton.h"
|
||||
#include "widgets/rectangle.h"
|
||||
|
||||
#include "widgets/hboxlayout.h"
|
||||
#include "widgets/vboxlayout.h"
|
||||
#include "widgets/flowlayout.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class UiLoader::Private
|
||||
{
|
||||
public:
|
||||
QStringList widgets;
|
||||
QStringList layouts;
|
||||
};
|
||||
|
||||
UiLoader::UiLoader( QObject *parent )
|
||||
: d( new Private() )
|
||||
{
|
||||
d->widgets
|
||||
<< "CheckBox"
|
||||
<< "Flash"
|
||||
<< "Icon"
|
||||
<< "Label"
|
||||
<< "PushButton"
|
||||
<< "RadioButton"
|
||||
<< "Rectangle";
|
||||
|
||||
d->layouts
|
||||
<< "VBoxLayout"
|
||||
<< "HBoxLayout"
|
||||
<< "FlowLayout";
|
||||
}
|
||||
|
||||
UiLoader::~UiLoader()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
QStringList UiLoader::availableWidgets() const
|
||||
{
|
||||
return d->widgets;
|
||||
}
|
||||
|
||||
Widget *UiLoader::createWidget( const QString &className, QGraphicsItem *parent, QObject *parentObject )
|
||||
{
|
||||
if ( className == QString("CheckBox") ) {
|
||||
return new CheckBox( parent );
|
||||
}
|
||||
else if ( className == QString("Flash") ) {
|
||||
return new Flash( parent );
|
||||
}
|
||||
else if ( className == QString("Icon") ) {
|
||||
return new Icon( parent );
|
||||
}
|
||||
else if ( className == QString("Label") ) {
|
||||
// return new Label( parent ); // Constructor here requires a Widget
|
||||
}
|
||||
else if ( className == QString("PushButton") ) {
|
||||
// return new PushButton( parent ); // Constructor here requires a Widget
|
||||
}
|
||||
else if ( className == QString("RadioButton") ) {
|
||||
return new RadioButton( parent );
|
||||
}
|
||||
else if ( className == QString("Rectangle") ) {
|
||||
// return new Rectangle( parent ); // Constructor here requires a Widget
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QStringList UiLoader::availableLayouts() const
|
||||
{
|
||||
return d->layouts;
|
||||
}
|
||||
|
||||
Layout *UiLoader::createLayout( const QString &className, LayoutItem *parent )
|
||||
{
|
||||
if ( className == QString("HBoxLayout") ) {
|
||||
return new HBoxLayout( parent );
|
||||
}
|
||||
else if ( className == QString("VBoxLayout") ) {
|
||||
return new VBoxLayout( parent );
|
||||
}
|
||||
else if ( className == QString("FlowLayout") ) {
|
||||
return new FlowLayout( parent );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
61
uiloader.h
Normal file
61
uiloader.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2007 Richard J. Moore <rich@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 PLASMA_UILOADER_H
|
||||
#define PLASMA_UILOADER_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QGraphicsItem;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Widget;
|
||||
class Layout;
|
||||
class LayoutItem;
|
||||
|
||||
/**
|
||||
* Dynamically create plasma Widgets and Layouts.
|
||||
*
|
||||
* @author Richard J. Moore, <rich@kde.org>
|
||||
*/
|
||||
class PLASMA_EXPORT UiLoader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UiLoader( QObject *parent = 0 );
|
||||
virtual ~UiLoader();
|
||||
|
||||
QStringList availableWidgets() const;
|
||||
Widget *createWidget( const QString &className, QGraphicsItem *parent=0, QObject *parentObject = 0 );
|
||||
|
||||
QStringList availableLayouts() const;
|
||||
Layout *createLayout( const QString &className, LayoutItem *parent );
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private *const d;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif // PLASMA_UILOADER_H
|
Loading…
Reference in New Issue
Block a user