Project

General

Profile

Feature #836 ยป PngImage.cpp

Max Quatember, 05/25/2011 11:38 AM

 
namespace
{
class Painted
: public Wt::WPaintedWidget
{
int myI;
public:
Painted( int i, Wt::WContainerWidget* parent = 0 )
: Wt::WPaintedWidget( parent )
, myI( i )
{
}
virtual void paintEvent( Wt::WPaintDevice* paintDevice )
{
Wt::WPainter painter( paintDevice );
painter.drawText( painter.window(), Wt::AlignCenter, boost::lexical_cast< std::string >( myI ) );
painter.restore();
}
};

class PaintedWidgets
: public Wt::WContainerWidget
{
public:
PaintedWidgets()
: Wt::WContainerWidget( 0 )
{
for( int i = 0; i < 1000; ++i )
{
auto painted = new Painted( i );
//painted->setPreferredMethod( Wt::WPaintedWidget::InlineSvgVml );
painted->setPreferredMethod( Wt::WPaintedWidget::PngImage );
painted->resize( 100, 20 );
addWidget( painted );
}
}
~PaintedWidgets()
{
}
};

class TestTabMemory
: public Wt::WApplication
{
public:
Wt::WTabWidget* myTab;
TestTabMemory( const Wt::WEnvironment& env )
: Wt::WApplication( env )
{
InitLogging( boost::log::trivial::info );
auto add = new Wt::WPushButton( "add", root() );
add->clicked().connect( SLOT( this, TestTabMemory::Add ) );
auto remove = new Wt::WPushButton( "remove", root() );
remove->clicked().connect( SLOT( this, TestTabMemory::Remove ) );
new Wt::WBreak( root() );
myTab = new Wt::WTabWidget( root() );
myTab->resize( 1000, 1000 );
}
void Add()
{
auto i = myTab->count();
myTab->addTab( new PaintedWidgets(), boost::lexical_cast< std::string >( i ) );
myTab->setCurrentIndex( i );
}
void Remove()
{
if( myTab->count() > 0 )
myTab->removeTab( myTab->widget( 0 ) );
}
};
}
    (1-1/1)