plasma-framework/widgets/tests/testLayouts.cpp

71 lines
1.9 KiB
C++
Raw Normal View History

#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <KUniqueApplication>
#include <KCmdLineArgs>
#include <KCmdLineOptions>
#include <KAboutData>
#include <KIcon>
#include "plasma/layouts/boxlayout.h"
#include "plasma/widgets/pushbutton.h"
#include "plasma/widgets/lineedit.h"
#include "plasma/widgets/widget.h"
#include "plasma/widgets/label.h"
int main(int argc, char **argv)
{
KAboutData aboutData( QByteArray("test"), 0, ki18n("test"),
KDE_VERSION_STRING, ki18n("test"), KAboutData::License_BSD,
ki18n("test") );
KCmdLineArgs::init(argc, argv, &aboutData);
KApplication app;
QGraphicsView view;
QGraphicsScene scene;
view.setScene(&scene);
Plasma::VBoxLayout *widgetLayout = new Plasma::VBoxLayout(0);
widgetLayout->setGeometry( QRectF(0.0, 0.0, 400.0, 700.0) );
Plasma::HBoxLayout *h1 = new Plasma::HBoxLayout( 0 );
Plasma::HBoxLayout *h2 = new Plasma::HBoxLayout( 0 );
widgetLayout->addItem( h1 );
widgetLayout->addItem( h2 );
// should be first row
Plasma::PushButton *pushOne = new Plasma::PushButton("pushbutton one");
h1->addItem(pushOne);
scene.addItem(pushOne);
Plasma::LineEdit *editOne = new Plasma::LineEdit;
h1->addItem(editOne);
scene.addItem(editOne);
Plasma::Label *labelOne = new Plasma::Label( 0 );
labelOne->setText( "hello world 1" );
h1->addItem(labelOne);
scene.addItem(labelOne);
// should be second row
Plasma::PushButton *pushTwo = new Plasma::PushButton("pushbutton two");
h2->addItem(pushTwo);
scene.addItem(pushTwo);
This breaks the existing Plasma applet API, see the contentSize() comments below. * New Flow Layout. This provides simple icon view-esque layout of items. Useful for icons for documents , applications or other tasks on the desktop for example. Supports non-equally sized items. Works well when used with the LayoutAnimator class to animate insertions and removals. * Re-wrote BoxLayout and removed old HBoxLayout,VBoxLayout classes which had a lot of code duplication. BoxLayout class now takes a direction argument in the constructor, ala. QBoxLayout. New BoxLayout class actually takes minimumSize() , maximumSize() of items into account. The Qt layout code for box and grid layouts is surprisingly sophisticated, so the results from BoxLayout probably will not be as good in certain situations but it should do for the panel. New BoxLayout also has support for LayoutAnimator * Fix Plasma::HBoxLayout and Plasma::VBoxLayout to use margin() rather than spacing() for the distance from the top and left margins respectively. * Fix Plasma::Applet::contentSize() to return the actual content size rather than a size hint. Added a new method contentSizeHint() which applets use to provide a hint about suitable content size. Existing implementations of contentSize() in applets need to be renamed to contentSizeHint(). The arguments and return type are the same as before. * Install the LayoutAnimator header so that applets can use it svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=707275
2007-09-01 14:34:22 +02:00
Plasma::LineEdit *editTwo = new Plasma::LineEdit;
h2->addItem(editTwo);
scene.addItem(editTwo);
This breaks the existing Plasma applet API, see the contentSize() comments below. * New Flow Layout. This provides simple icon view-esque layout of items. Useful for icons for documents , applications or other tasks on the desktop for example. Supports non-equally sized items. Works well when used with the LayoutAnimator class to animate insertions and removals. * Re-wrote BoxLayout and removed old HBoxLayout,VBoxLayout classes which had a lot of code duplication. BoxLayout class now takes a direction argument in the constructor, ala. QBoxLayout. New BoxLayout class actually takes minimumSize() , maximumSize() of items into account. The Qt layout code for box and grid layouts is surprisingly sophisticated, so the results from BoxLayout probably will not be as good in certain situations but it should do for the panel. New BoxLayout also has support for LayoutAnimator * Fix Plasma::HBoxLayout and Plasma::VBoxLayout to use margin() rather than spacing() for the distance from the top and left margins respectively. * Fix Plasma::Applet::contentSize() to return the actual content size rather than a size hint. Added a new method contentSizeHint() which applets use to provide a hint about suitable content size. Existing implementations of contentSize() in applets need to be renamed to contentSizeHint(). The arguments and return type are the same as before. * Install the LayoutAnimator header so that applets can use it svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=707275
2007-09-01 14:34:22 +02:00
Plasma::Label *labelTwo = new Plasma::Label( 0 );
labelTwo->setText( "hello world 2" );
h2->addItem(labelTwo);
scene.addItem(labelTwo);
widgetLayout->updateGeometry();
view.show();
return app.exec();
}