示例#1
0
文件: StyleLayout.C 项目: ReWeb3D/wt
WWidget *StyleLayout::wGridLayout()
{
  WContainerWidget *result = new WContainerWidget();
  topic("WGridLayout", result);

  addText(tr("layout-WGridLayout"), result);

  WContainerWidget *container;

  container = new WContainerWidget(result);
  container->resize(WLength::Auto, 400);
  container->setStyleClass("yellow-box");
  WGridLayout *grid = new WGridLayout();
  container->setLayout(grid);

  for (int row = 0; row < 3; ++row) {
    for (int column = 0; column < 4; ++column) {
      WText *t = addText(tr("grid-item").arg(row).arg(column));
      if (row == 1 || column == 1 || column == 2)
	t->setStyleClass("blue-box");
      else
	t->setStyleClass("green-box");
      grid->addWidget(t, row, column);
    }
  }

  grid->setRowStretch(1, 1);
  grid->setColumnStretch(1, 1);
  grid->setColumnStretch(2, 1);

  return result;
}
示例#2
0
/*
 * The env argument contains information about the new session, and
 * the initial request. It must be passed to the WApplication
 * constructor so it is typically also an argument for your custom
 * application constructor.
*/
DataAnalyzer::DataAnalyzer(const WEnvironment& env)
  : WApplication(env)
{
  setTitle(WString::fromUTF8("行车数据管理平台",true));
  WContainerWidget *w = new WContainerWidget(root());
  w->resize(WLength::Auto, WLength::Auto);
  HomeUI* home = new HomeUI(w);
  w->addWidget(home);
  root()->addWidget(w);
  setLocale(WT_LOCALE("cn"));
  WMessageResourceBundle* pTranslate = new WMessageResourceBundle();
  pTranslate->use(appRoot()+"resources/auth");
  setLocalizedStrings(pTranslate);
  useStyleSheet("resources/analyzer.css");
  log("info") << "constructed" ;
}
示例#3
0
文件: EventsDemo.C 项目: 913862627/wt
WWidget *EventsDemo::wMouseEvent()
{
  WContainerWidget *result = new WContainerWidget();

  topic("WMouseEvent", result);
  addText(tr("events-WMouseEvent"), result);
  WContainerWidget *c = new WContainerWidget(result);
  WHBoxLayout *hlayout = new WHBoxLayout;
  c->setLayout(hlayout);
  WContainerWidget *l = new WContainerWidget;
  WContainerWidget *r = new WContainerWidget;
  new WText("clicked<br/>doubleClicked<br/>mouseWentOut<br/>mouseWentOver",
	    l);
  new WText("mouseWentDown<br/>mouseWentUp<br/>mouseMoved<br/>mouseWheel", r);
  hlayout->addWidget(l);
  hlayout->addWidget(r);
  c->resize(600, 300);
  l->decorationStyle().setBackgroundColor(Wt::gray);
  r->decorationStyle().setBackgroundColor(Wt::gray);
  // prevent that firefox interprets drag as drag&drop action
  l->setStyleClass("unselectable");
  r->setStyleClass("unselectable");
  l->clicked().connect(this, &EventsDemo::showClicked);
  l->doubleClicked().connect(this, &EventsDemo::showDoubleClicked);
  l->mouseWentOut().connect(this, &EventsDemo::showMouseWentOut);
  l->mouseWentOver().connect(this, &EventsDemo::showMouseWentOver);
  r->mouseMoved().connect(this, &EventsDemo::showMouseMoved);
  r->mouseWentUp().connect(this, &EventsDemo::showMouseWentUp);
  r->mouseWentDown().connect(this, &EventsDemo::showMouseWentDown);
  r->mouseWheel().connect(this, &EventsDemo::showMouseWheel);
  r->mouseWheel().preventDefaultAction(true);

  l->setAttributeValue
    ("oncontextmenu",
     "event.cancelBubble = true; event.returnValue = false; return false;");
  r->setAttributeValue
    ("oncontextmenu",
     "event.cancelBubble = true; event.returnValue = false; return false;");

  new WBreak(result);
  new WText("Last event: ", result);
  mouseEventType_ = new WText(result);
  new WBreak(result);
  mouseEventDescription_ = new WText(result);

  return result;
}
示例#4
0
文件: StyleLayout.C 项目: ReWeb3D/wt
WWidget *StyleLayout::wBorderLayout()
{
  WContainerWidget *result = new WContainerWidget();
  topic("WBorderLayout", result);

  addText(tr("layout-WBorderLayout"), result);

  WContainerWidget *container;

  container = new WContainerWidget(result);
  container->resize(WLength::Auto, 400);
  container->setStyleClass("yellow-box");
  WBorderLayout *layout = new WBorderLayout();
  container->setLayout(layout);

  WText *item;

  item = addText(tr("borderlayout-item").arg("North"));
  item->setStyleClass("green-box");
  layout->addWidget(item, WBorderLayout::North);

  item = addText(tr("borderlayout-item").arg("West"));
  item->setStyleClass("green-box");
  layout->addWidget(item, WBorderLayout::West);

  item = addText(tr("borderlayout-item").arg("East"));
  item->setStyleClass("green-box");
  layout->addWidget(item, WBorderLayout::East);

  item = addText(tr("borderlayout-item").arg("South"));
  item->setStyleClass("green-box");
  layout->addWidget(item, WBorderLayout::South);

  item = addText(tr("borderlayout-item").arg("Center"));
  item->setStyleClass("green-box");
  layout->addWidget(item, WBorderLayout::Center);

  return result;
}
示例#5
0
文件: StyleLayout.C 项目: ReWeb3D/wt
WWidget *StyleLayout::wBoxLayout()
{
  WContainerWidget *result = new WContainerWidget();
  topic("WHBoxLayout", "WVBoxLayout", result);

  addText(tr("layout-WBoxLayout"), result);

  WContainerWidget *container;
  WText *item;
  WHBoxLayout *hbox;
  WVBoxLayout *vbox;

  /*
   * first hbox
   */
  container = new WContainerWidget(result);
  container->setStyleClass("yellow-box");
  hbox = new WHBoxLayout();
  container->setLayout(hbox);

  item = addText(tr("layout-item1"));
  item->setStyleClass("green-box");
  hbox->addWidget(item);
  
  item = addText(tr("layout-item2"));
  item->setStyleClass("blue-box");
  hbox->addWidget(item);

  addText(tr("layout-WBoxLayout-stretch"), result);

  /*
   * second hbox
   */
  container = new WContainerWidget(result);
  container->setStyleClass("yellow-box");
  hbox = new WHBoxLayout();
  container->setLayout(hbox);

  item = addText(tr("layout-item1"));
  item->setStyleClass("green-box");
  hbox->addWidget(item, 1);
  
  item = addText(tr("layout-item2"));
  item->setStyleClass("blue-box");
  hbox->addWidget(item);

  addText(tr("layout-WBoxLayout-vbox"), result);

  /*
   * first vbox
   */
  container = new WContainerWidget(result);
  container->resize(150, 150);
  container->setStyleClass("yellow-box centered");
  vbox = new WVBoxLayout();
  container->setLayout(vbox);

  item = addText(tr("layout-item1"));
  item->setStyleClass("green-box");
  vbox->addWidget(item);
  
  item = addText(tr("layout-item2"));
  item->setStyleClass("blue-box");
  vbox->addWidget(item);

  /*
   * second vbox
   */
  container = new WContainerWidget(result);
  container->resize(150, 150);
  container->setStyleClass("yellow-box centered");
  vbox = new WVBoxLayout();
  container->setLayout(vbox);

  item = addText(tr("layout-item1"));
  item->setStyleClass("green-box");
  vbox->addWidget(item, 1);
  
  item = addText(tr("layout-item2"));
  item->setStyleClass("blue-box");
  vbox->addWidget(item);

  addText(tr("layout-WBoxLayout-nested"), result);

  /*
   * nested boxes
   */
  container = new WContainerWidget(result);
  container->resize(200, 200);
  container->setStyleClass("yellow-box centered");

  vbox = new WVBoxLayout();
  container->setLayout(vbox);

  item = addText(tr("layout-item1"));
  item->setStyleClass("green-box");
  vbox->addWidget(item, 1);

  hbox = new WHBoxLayout();
  vbox->addLayout(hbox);

  item = addText(tr("layout-item2"));
  item->setStyleClass("green-box");
  hbox->addWidget(item);

  item = addText(tr("layout-item3"));
  item->setStyleClass("blue-box");
  hbox->addWidget(item);

  return result;
}
示例#6
0
文件: lesson11.cpp 项目: ReWeb3D/wt
void WebGLDemo::main(){


    glContainer_ = new WContainerWidget(root());
    glContainer_->resize(500, 500);
    glContainer_->setInline(false);

    root()->addWidget(new WBreak());
    root()->addWidget(new WText("Rotate with mouse and zoom with scroll"));
    root()->addWidget(new WBreak());

    root()->addWidget(new WText(" "));
    root()->addWidget(new WBreak());
    root()->addWidget(new WText("LIGHT DIRECTION"));
    root()->addWidget(new WBreak());
    root()->addWidget(new WText("X : "));
    lightDirX = new WLineEdit("-1.0",root());
    root()->addWidget(new WText(" Y : "));
    lightDirY = new WLineEdit("-1.0",root());
    root()->addWidget(new WText(" Z : "));
    lightDirZ = new WLineEdit("-1.0",root());

    root()->addWidget(new WBreak());
    root()->addWidget(new WText(" "));
    root()->addWidget(new WBreak());
    root()->addWidget(new WText("LIGHT COLOR"));
    root()->addWidget(new WBreak());

    root()->addWidget(new WText("R : "));
    lightColR = new WLineEdit("0.8",root());
    root()->addWidget(new WText(" G : "));
    lightColG = new WLineEdit("0.8",root());
    root()->addWidget(new WText(" B : "));
    lightColB = new WLineEdit("0.8",root());

    root()->addWidget(new WBreak());
    root()->addWidget(new WText(" "));
    root()->addWidget(new WBreak());
    root()->addWidget(new WText("AMBIENT LIGHT COLOR"));
    root()->addWidget(new WBreak());
    root()->addWidget(new WText("R : "));
    ambLightColR = new WLineEdit("0.2",root());
    root()->addWidget(new WText(" G : "));
    ambLightColG = new WLineEdit("0.2",root());
    root()->addWidget(new WText(" B : "));
    ambLightColB = new WLineEdit("0.2",root());




    lightDirX->keyWentUp().connect(this,&WebGLDemo::eventKeyWentUp);
    lightDirY->keyWentUp().connect(this,&WebGLDemo::eventKeyWentUp);
    lightDirZ->keyWentUp().connect(this,&WebGLDemo::eventKeyWentUp);

    lightColR->keyWentUp().connect(this,&WebGLDemo::eventKeyWentUp);
    lightColG->keyWentUp().connect(this,&WebGLDemo::eventKeyWentUp);
    lightColB->keyWentUp().connect(this,&WebGLDemo::eventKeyWentUp);

    ambLightColR->keyWentUp().connect(this,&WebGLDemo::eventKeyWentUp);
    ambLightColG->keyWentUp().connect(this,&WebGLDemo::eventKeyWentUp);
    ambLightColB->keyWentUp().connect(this,&WebGLDemo::eventKeyWentUp);

    updateShaders();

    this->globalKeyWentDown().connect(this,&WebGLDemo::eventKeyWentDown);

}
示例#7
0
DetailManipulation::DetailManipulation(bool enhance, WContainerWidget *parent)
	: WContainerWidget(parent), onlySmooth(!enhance)
{

	resize(WLength::Auto, WLength::Auto);

	// Image bar
	prepareInputImages();
	WContainerWidget *imageBar = new WContainerWidget;
	WVBoxLayout *imageBarLayout = new WVBoxLayout();
	for (size_t i = 0; i < inputImages.size(); ++i) {
		WImage *img = inputImages[i]->getOriginalImage();
		img->setStyleClass("image_button");
		img->resize(160, 120);
		img->setAttributeValue("onMouseOver", "this.width=192; this.height=144;");
		img->setAttributeValue("onMouseOut", "this.width=160; this.height=120;");
		img->clicked().connect(
				boost::bind(&DetailManipulation::selectImage,
							this,
							i
							)
		);
		imageBarLayout->addWidget(img);
	}
	imageBar->resize(200, WLength::Auto);
	imageBar->setLayout(imageBarLayout);
	selectedImageId = 0;

	// Main component
	imageTab = new WTabWidget();
	imageTab->addTab(inputImages[selectedImageId]->getOriginalImage(), "Original");
	if (onlySmooth) {
		imageTab->addTab(new WImage(smoothedResult[selectedImageId].second), smoothedResult[selectedImageId].first);
	}
	else {
		imageTab->addTab(new WImage(enhancedResult[selectedImageId].second), enhancedResult[selectedImageId].first);
	}
	imageTab->resize(600, WLength::Auto);


	WGridLayout *controllerLayout = new WGridLayout();
	WSlider *rSlider = new WSlider(Wt::Vertical);
	rSlider->setRange(SLIDER_MINIMUM, SLIDER_MAXIMUM);
	rSlider->setTickPosition(Wt::WSlider::TicksBothSides);
	WDoubleSpinBox *rSpinBox = new WDoubleSpinBox();
	rSpinBox->setMinimum(R_MINIMUM);
	rSpinBox->setMaximum(R_MAXIMUM);
	rSlider->sliderMoved().connect(
			boost::bind(&DetailManipulation::changeDoubleSpinBoxValue,
						this,
						rSpinBox,
						true,
						_1)
	);
	rSpinBox->valueChanged().connect(
			boost::bind(&DetailManipulation::changeSliderValue,
						this,
						rSlider,
						1.f/(R_MAXIMUM-R_MINIMUM),
						_1)
	);
	controllerLayout->addWidget(rSlider, 2, 0, 6, 1);
	controllerLayout->addWidget(rSpinBox, 9, 0);
	controllerLayout->addWidget(new WText("radius"), 10, 0);


	WSlider *epsSlider = new WSlider(Wt::Vertical);
	epsSlider->setMinimum(SLIDER_MINIMUM);
	epsSlider->setMaximum(SLIDER_MAXIMUM);
	epsSlider->setRange(SLIDER_MINIMUM, SLIDER_MAXIMUM);
	epsSlider->setTickPosition(WSlider::TicksBothSides);
	WDoubleSpinBox *epsSpinBox = new WDoubleSpinBox();
	epsSpinBox->setMinimum(EPS_MINIMUM);
	epsSpinBox->setMaximum(EPS_MAXIMUM);
	epsSlider->sliderMoved().connect(
			boost::bind(&DetailManipulation::changeDoubleSpinBoxValue,
						this,
						epsSpinBox,
						false,
						_1)
	);
	epsSpinBox->valueChanged().connect(
			boost::bind(&DetailManipulation::changeSliderValue,
						this,
						epsSlider,
						1.f/(EPS_MAXIMUM-EPS_MINIMUM),
						_1)
	);
	controllerLayout->addWidget(epsSlider, 2, 1, 6, 1);
	controllerLayout->addWidget(epsSpinBox, 9, 1);
	controllerLayout->addWidget(new WText("epsilon"), 10, 1);

	WPushButton *apply = new WPushButton("Apply");
	apply->clicked().connect(
			boost::bind(&DetailManipulation::applyEnhancement,
					this,
					rSpinBox,
					epsSpinBox
					)
	);
	controllerLayout->addWidget(apply, 1, 0, 1, 2);


	WContainerWidget *controller = new WContainerWidget();
	controller->resize(120, WLength::Auto);
	controller->setLayout(controllerLayout);


	WBorderLayout *mainLayout = new WBorderLayout(this);
	mainLayout->addWidget(imageBar, WBorderLayout::West);
	mainLayout->addWidget(imageTab, WBorderLayout::Center);
	mainLayout->addWidget(controller, WBorderLayout::East);
	//setLayout(mainLayout, Wt::AlignTop | Wt::AlignJustify);
	/*
		doJavaScript(
			    "(function () { \
						     var imageTags = document.getElementsByClassName(\"image_button\"); \
						     for (var i=0; image=imageTags[i]; ++i) { \
						         if (image.width>200 && image.height>0) { \
						             image.width = 192;  \
						         } \
						     }\
				 })();"
		);*/

}
示例#8
0
文件: WSlider.C 项目: StevenFarley/wt
void PaintedSlider::updateState()
{
  bool rtl = WApplication::instance()->layoutDirection() == RightToLeft;

  std::string resourcesURL = WApplication::resourcesUrl();

  Orientation o = slider_->orientation();

  handle_->setStyleClass("handle");

  if (o == Horizontal) {
    handle_->resize(HANDLE_WIDTH, h());
    handle_->setOffsets(0, Top);
  } else {
    handle_->resize(w(), HANDLE_WIDTH);
    handle_->setOffsets(0, Left);
  }

  double l = o == Horizontal ? w() : h();
  double pixelsPerUnit = (l - HANDLE_WIDTH) / range();

  std::string dir;
  if (o == Horizontal)
    dir = rtl ? "right" : "left";
  else
    dir = "top";
  std::string u = (o == Horizontal ? "x" : "y");
  std::string U = (o == Horizontal ? "X" : "Y");
  std::string maxS = boost::lexical_cast<std::string>(l - HANDLE_WIDTH);
  std::string ppU = boost::lexical_cast<std::string>(pixelsPerUnit);
  std::string minimumS = boost::lexical_cast<std::string>(slider_->minimum());
  std::string maximumS = boost::lexical_cast<std::string>(slider_->maximum());

  std::string width = boost::lexical_cast<std::string>(w());
  std::string horizontal = boost::lexical_cast<std::string>(o == Horizontal);

  /*
   * Note: cancelling the mouseDown event prevents the selection behaviour
   */
  std::string mouseDownJS = 
    """obj.setAttribute('down', " WT_CLASS ".widgetCoordinates(obj, event)."
    + u + "); "
    WT_CLASS ".cancelEvent(event);";

  // = 'u' position relative to background, corrected for slider
  std::string computeD =
    ""  "var objh = " + handle_->jsRef() + ","
    ""      "objb = " + jsRef() + ","
    ""      "page_u = WT.pageCoordinates(event)." + u + ","
    ""      "widget_page_u = WT.widgetPageCoordinates(objb)." + u + ","
    ""      "pos = page_u - widget_page_u,"
    ""      "rtl = " + boost::lexical_cast<std::string>(rtl) + ","
    ""      "horizontal = " + horizontal + ";"
    ""  "if (rtl && horizontal)"
    ""  "  pos = " + width + " - pos;"
    ""  "var d = pos - down;";
  

  std::string mouseMovedJS = 
    """var down = obj.getAttribute('down');"
    """var WT = " WT_CLASS ";"
    """if (down != null && down != '') {"
    + computeD +
    ""  "d = Math.max(0, Math.min(d, " + maxS + "));"
    ""  "var v = Math.round(d/" + ppU + ");"
    ""  "var intd = v*" + ppU + ";"
    ""  "if (Math.abs(WT.pxself(objh, '" + dir + "') - intd) > 1) {"
    ""    "objh.style." + dir + " = intd + 'px';" +
    slider_->sliderMoved().createCall(o == Horizontal ? "v + " + minimumS
				      : maximumS + " - v") + 
    ""  "}"
    """}";

  std::string mouseUpJS = 
    """var down = obj.getAttribute('down');"
    """var WT = " WT_CLASS ";"
    """if (down != null && down != '') {"
    + computeD +
    """d += " + boost::lexical_cast<std::string>(HANDLE_WIDTH / 2) + ";" +
    sliderReleased_.createCall("d") + 
    ""  "obj.removeAttribute('down');"
    """}";

  bool enabled = !slider_->isDisabled();
  
  mouseDownJS_.setJavaScript(std::string("function(obj, event) {") 
			     + (enabled ? mouseDownJS : "") 
			     + "}");
  mouseMovedJS_.setJavaScript(std::string("function(obj, event) {") 
			      + (enabled ? mouseMovedJS : "") 
			      + "}");
  mouseUpJS_.setJavaScript(std::string("function(obj, event) {") 
			   + (enabled ? mouseUpJS : "") 
			   + "}");

  update();
  updateSliderPosition();
}