File: GraphicsWidgets.C

package info (click to toggle)
witty 3.1.2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 45,512 kB
  • ctags: 35,832
  • sloc: cpp: 69,469; ansic: 66,945; xml: 4,383; sh: 594; perl: 108; makefile: 106
file content (90 lines) | stat: -rw-r--r-- 2,247 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright (C) 2008 Emweb bvba
 *
 * See the LICENSE file for terms of use.
 */

#include "GraphicsWidgets.h"
#include "PaintExample.h"
#include "PaintBrush.h"

#include <Wt/WText>
#include <Wt/WGlobal>
#include <Wt/WCssDecorationStyle>
#include <Wt/WBorder>
#include <Wt/WBreak>
#include <Wt/WPushButton>

GraphicsWidgets::GraphicsWidgets(EventDisplayer *ed)
  : ControlsWidget(ed, true)
{
  colorMapper_ = new WSignalMapper<WColor >();

  topic("WPaintedWidget", this);
  new WText(tr("graphics-intro"), this);
}

GraphicsWidgets::~GraphicsWidgets()
{
  delete colorMapper_;
}

void GraphicsWidgets::populateSubMenu(WMenu *menu)
{
  menu->addItem("Emweb logo example", emwebLogo());
  menu->addItem("Paintbrush example", paintbrush());
}

WWidget* GraphicsWidgets::emwebLogo()
{
  WContainerWidget *result = new WContainerWidget();

  topic("WPaintedWidget", result);
  
  new PaintExample(result, false);
  
  return result;
}

WWidget* GraphicsWidgets::paintbrush()
{
  WContainerWidget *result = new WContainerWidget();
  
  topic("WPaintedWidget", result);

  new WText(tr("graphics-paintbrush"), result);

  WTable* layout = new WTable(result);

  PaintBrush* canvas = new PaintBrush(710, 400, layout->elementAt(0,0));
  canvas->decorationStyle().setBorder(WBorder(WBorder::Solid));

  new WText("Color chooser:", layout->elementAt(0,1));
  WTable* colorTable = new WTable(layout->elementAt(0,1));
  addColor(colorTable, 0, 0, WColor(black));
  addColor(colorTable, 0, 1, WColor(red));
  addColor(colorTable, 1, 0, WColor(green));
  addColor(colorTable, 1, 1, WColor(blue));
  new WBreak(layout->elementAt(0,1));
  WPushButton* clearButton = new WPushButton("Clear", layout->elementAt(0,1));
  clearButton->clicked().connect(SLOT(canvas, PaintBrush::clear));
  layout->elementAt(0,1)->setPadding(3);

  colorMapper_->mapped().connect(SLOT(canvas, PaintBrush::setColor));
  
  return result;
}


void GraphicsWidgets::addColor(WTable* table, 
			       int row, 
			       int column, 
			       const WColor& color)
{
  table->elementAt(row, column)
    ->decorationStyle().setBackgroundColor(color);
  table->elementAt(row, column)
    ->resize(15, 15);

  colorMapper_->mapConnect(table->elementAt(row, column)->clicked(), color);
}