Project

General

Profile

Bug #3720 » test.cpp

Max Quatember, 01/08/2015 03:46 PM

 
1
#include	<Wt/WApplication>
2
#include	<Wt/WLabel>
3
#include	<Wt/WBreak>
4
#include	<Wt/WContainerWidget>
5
#include	<Wt/WPopupMenu>
6
#include	<Wt/WPoint>
7
#include	<Wt/WPaintedWidget>
8
#include	<Wt/WPainter>
9

    
10
#include	<boost/test/unit_test.hpp>
11
#include	<boost/lexical_cast.hpp>
12

    
13
namespace
14
{
15
	class Painted 
16
		: public Wt::WPaintedWidget
17
	{
18
		int myI;
19
		int x;
20
	public:
21
		Painted( int i, Wt::WContainerWidget* parent = 0 )
22
			: Wt::WPaintedWidget( parent )
23
			, myI( i )
24
			, x( 0 )
25
		{
26
			mouseWentUp().connect( SLOT( this, Painted::MouseWentUp ) );
27
			mouseWentDown().connect( SLOT( this, Painted::MouseWentDown ) );
28
			mouseMoved().connect( SLOT( this, Painted::MouseMoved ) );
29
		}
30
		virtual void paintEvent( Wt::WPaintDevice* paintDevice )
31
		{
32
			Wt::WPainter painter( paintDevice );
33
			painter.drawText( painter.window(), Wt::AlignCenter | Wt::AlignMiddle, boost::lexical_cast< std::string >( myI + x++ ) );
34
			painter.restore();
35
		}
36
		void MouseWentDown( const Wt::WMouseEvent& e )
37
		{
38
		}
39
		void MouseMoved( const Wt::WMouseEvent& e )
40
		{
41
		}
42
		void MouseWentUp( const Wt::WMouseEvent& e )
43
		{
44
			update();
45
		}
46

    
47
	};	
48

    
49
	class TestToolTip 
50
		: public Wt::WApplication
51
	{
52
	public:
53
		TestToolTip( const Wt::WEnvironment& env )
54
			: Wt::WApplication( env )
55
		{
56
			setCssTheme( "polished" );
57
		    root()->setAttributeValue( "oncontextmenu", "event.cancelBubble = true; event.returnValue = false; return false;" );
58
			root()->mouseWentUp().connect( SLOT( this, TestToolTip::MouseWentUp ) );
59
			root()->mouseWentDown().connect( SLOT( this, TestToolTip::MouseWentDown ) );
60
			root()->mouseMoved().connect( SLOT( this, TestToolTip::MouseMoved ) );
61

    
62
			for( int i = 0; i < 20; ++i )
63
			{
64
				auto x = new Painted( i, root() );
65
				x->resize( 100, 20 );
66
				x->setToolTip( GetTooltipText(), Wt::XHTMLText);
67
				x->doubleClicked().connect( SLOT( this, TestToolTip::DoubleClicked ) );
68
				new Wt::WBreak( root() );
69
			}
70

    
71
		}
72
		void MouseWentDown( const Wt::WMouseEvent& e )
73
		{
74
		}
75
		void MouseMoved( const Wt::WMouseEvent& e )
76
		{
77
		}
78
		void MouseWentUp( const Wt::WMouseEvent& e )
79
		{
80
		}
81
		void DoubleClicked( const Wt::WMouseEvent& e )
82
		{
83
			Wt::WPopupMenu* popup = new Wt::WPopupMenu;
84
			for( int i = 0; i < 20; ++i )
85
				popup->addItem( boost::lexical_cast< std::string >( i ) + " test" );
86
			popup->popup( e );
87
		}
88
		std::string GetTooltipText()
89
		{
90
			return 
91
				"<b>Title of tooltip</b>"
92
				"<br/>"
93
				"<br/>"
94
				"Some text text text text text text text text text text text text text text text<br/>"
95
				;
96
		}
97
	};
98
}
(1-1/2)