Ejemplo n.º 1
0
void SquareRootElement::layout( const AttributeManager* am )
{
    RowElement::layout( am );

    kDebug(39001) << "Width: " << width();
    kDebug(39001) << "Height: " << height();

    double thinSpace = am->layoutSpacing( this );
    double linethickness = 1;
    double symbolHeight = baseLine();
    if( height() > symbolHeight*1.3 ) symbolHeight = height();
    symbolHeight += thinSpace;
    double tickWidth = symbolHeight / 3.0;

    // Set the sqrt dimensions 
    setWidth( tickWidth + width() + thinSpace );
    setHeight( height() + thinSpace );
    setBaseLine( baseLine() + thinSpace );
   
    // Adapt the children's positions to the new offset
    QPointF childOffset( tickWidth + thinSpace, thinSpace );
    foreach( BasicElement* element, childElements() )
        element->setOrigin( element->origin() + childOffset );

    // Draw the sqrt symbol into a QPainterPath as buffer
    m_rootSymbol = QPainterPath();
    m_rootSymbol.moveTo( linethickness, 2.0 * symbolHeight / 3.0 );
    m_rootSymbol.lineTo( 0 + tickWidth/2.0, symbolHeight-linethickness/2 );
    m_rootSymbol.lineTo( 0 + tickWidth, linethickness/2 );
    m_rootSymbol.lineTo( width() - linethickness/2, linethickness/2 );

}
Ejemplo n.º 2
0
void SquareRootElement::layout( const AttributeManager* am )
{
    RowElement::layout( am );

    qreal thinSpace = am->layoutSpacing( this );
    qreal symbolHeight = baseLine();
    if( height() > symbolHeight*1.3 ) symbolHeight = height();
    symbolHeight += thinSpace;
    qreal tickWidth = symbolHeight / 3.0;

    m_lineThickness = am->lineThickness(this);

    // Set the sqrt dimensions 
    QPointF childOffset( tickWidth + thinSpace, thinSpace + m_lineThickness );

    setWidth( width() + childOffset.x());
    setHeight( height() + childOffset.y());
    setBaseLine( baseLine() + childOffset.y());

    // Adapt the children's positions to the new offset
    foreach( BasicElement* element, childElements() )
        element->setOrigin( element->origin() + childOffset );

    QRectF rect = childrenBoundingRect();
    rect.translate(childOffset);
    setChildrenBoundingRect(rect);

    // Draw the sqrt symbol into a QPainterPath as buffer
    m_rootSymbol = QPainterPath();
    m_rootSymbol.moveTo( m_lineThickness, 2.0 * symbolHeight / 3.0 );
    m_rootSymbol.lineTo( 0 + tickWidth/2.0, symbolHeight-m_lineThickness/2 );
    m_rootSymbol.lineTo( 0 + tickWidth, m_lineThickness/2 );
    m_rootSymbol.lineTo( width() - m_lineThickness/2, m_lineThickness/2 );

}
Ejemplo n.º 3
0
bool FixedElement::moveHorSituation(FormulaCursor& newcursor, FormulaCursor& oldcursor, int pos1, int pos2) {
    if ((newcursor.position()/2==pos1 && newcursor.direction()==MoveUp) ||
        (newcursor.position()/2==pos2 && newcursor.direction()==MoveDown) ||
        (newcursor.position()==2*pos1 && newcursor.direction()==MoveLeft) ||
        (newcursor.position()==2*pos2+1 && newcursor.direction()==MoveRight) ) {
        return false;
    }
    switch (newcursor.direction()) {
    case MoveLeft:
        if (newcursor.position()==2*pos2+1) {
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos2]);
        } else {
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos1]);
        }
        break;
    case MoveRight:
        if (newcursor.position()==2*pos1) {
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos1]);
        } else {
            newcursor.moveTo(newcursor.currentElement()->childElements()[pos2]);
        }
        break;
    case MoveUp:
    case MoveDown:
        return newcursor.moveCloseTo(childElements()[newcursor.direction()==MoveUp ? pos1 : pos2],oldcursor);
    case NoDirection:
        break;
    }
    return true;
}
Ejemplo n.º 4
0
std::shared_ptr<raytracer::Primitive> Surface::toRaytracer(raytracer::Scene* scene) const {
  auto primitive = toRaytracerPrimitive();
  if (!primitive) {
    return primitive;
  }
  
  if (material()) {
    primitive->setMaterial(material()->toRaytracerMaterial());
  }
  
  if (childElements().size() > 0) {
    auto composite = std::dynamic_pointer_cast<raytracer::Composite>(primitive);
    if (!composite) {
      composite = std::make_shared<raytracer::Composite>();
      composite->add(primitive);
    }
    
    for (const auto& child : childElements()) {
      if (Surface* surface = qobject_cast<Surface*>(child)) {
        if (surface->visible())
          composite->add(surface->toRaytracer(scene));
      } else if (Light* light = qobject_cast<Light*>(child)) {
        if (light->visible())
          scene->addLight(light->toRaytracer());
      }
    }
    
    if (auto grid = std::dynamic_pointer_cast<raytracer::Grid>(composite)) {
      grid->setup();
    }

    return applyTransform(composite);
  } else {
    return applyTransform(primitive);
  }
}
Ejemplo n.º 5
0
QLineF TableRowElement::cursorLine ( int position ) const
{
    TableElement* parentTable = static_cast<TableElement*>( parentElement() );
    QPointF top=absoluteBoundingRect().topLeft();
    qreal hOffset = 0;
    if( childElements().isEmpty() ) {
        // center cursor in elements that have no children
        top += QPointF( width()/2, 0 );
    } else { 
        for (int i=0; i<position; ++i) {
            hOffset+=parentTable->columnWidth(i);
        }
        top += QPointF( hOffset, 0.0 );
	}
    QPointF bottom = top + QPointF( 0.0, height() );
    return QLineF(top, bottom);
}
Ejemplo n.º 6
0
void Configuration::readConfiguration(bool silent)
{
  std::ifstream s(configurationFile_.c_str(), std::ios::in | std::ios::binary);

  if (!s) {
    if (configurationFile_ != WT_CONFIG_XML)
      throw WServer::Exception
	("Error reading '" + configurationFile_ + "': could not open file.");
    else
      return;
  }

  s.seekg(0, std::ios::end);
  int length = s.tellg();
  s.seekg(0, std::ios::beg);

  boost::scoped_array<char> text(new char[length + 1]);
  s.read(text.get(), length);
  s.close();
  text[length] = 0;

  try {
    xml_document<> doc;
    doc.parse<parse_normalize_whitespace
      | parse_trim_whitespace
      | parse_validate_closing_tags>(text.get());

    xml_node<> *root = doc.first_node();

    if (!root)
      throw WServer::Exception("<server> expected.");

    std::vector<xml_node<> *> applications
      = childElements(root, "application-settings");

    /*
     * Scan the config file first to determine the logFile, in order
     * to setup logging before parsing the other settings.
     */
    std::string logFile;
    std::string logConfig;
    for (unsigned i = 0; i < applications.size(); ++i) {
      xml_node<> *app = applications[i];

      std::string appLocation;
      if (!attributeValue(app, "location", appLocation))
	throw WServer::Exception("<application-settings> requires attribute "
				 "'location'");

      if (appLocation == "*" || appLocation == applicationPath_) {
	logFile = singleChildElementValue(app, "log-file", logFile);
	logConfig = singleChildElementValue(app, "log-config", logConfig);
      }
    }

    if (server_)
      server_->initLogger(logFile, logConfig);

    if (!silent)
      LOG_INFO("reading Wt config file: " << configurationFile_
	       << " (location = '" << applicationPath_ << "')");

    /*
     * Now read application settings.
     */
    for (unsigned i = 0; i < applications.size(); ++i) {
      xml_node<> *app = applications[i];

      std::string appLocation;
      attributeValue(app, "location", appLocation);

      if (appLocation == "*" || appLocation == applicationPath_)
	readApplicationSettings(app);
    }
  } catch (std::exception& e) {
    throw WServer::Exception("Error reading: " + configurationFile_ + ": "
			     + e.what());
  } catch (...) {
    throw WServer::Exception("Exception of unknown type!\n");
  }
}
Ejemplo n.º 7
0
void Configuration::readApplicationSettings(xml_node<> *app)
{
  xml_node<> *sess = singleChildElement(app, "session-management");

  if (sess) {
    xml_node<> *dedicated = singleChildElement(sess, "dedicated-process");
    xml_node<> *shared = singleChildElement(sess, "shared-process");
    std::string tracking = singleChildElementValue(sess, "tracking", "");

    if (dedicated && shared)
      throw WServer::Exception("<application-settings> requires either "
			       "<dedicated-process> or <shared-process>, "
			       "not both");

    if (dedicated) {
      sessionPolicy_ = DedicatedProcess;
      setInt(dedicated, "max-num-sessions", maxNumSessions_);
    }

    if (shared) {
      sessionPolicy_ = SharedProcess;

      setInt(shared, "num-processes", numProcesses_);
    }

    if (!tracking.empty()) {
      if (tracking == "Auto")
	sessionTracking_ = CookiesURL;
      else if (tracking == "URL")
	sessionTracking_ = URL;
      else
	throw WServer::Exception("<session-tracking>: expecting 'Auto' "
				 "or 'URL'");
    }

    setInt(sess, "timeout", sessionTimeout_);
    setInt(sess, "bootstrap-timeout", bootstrapTimeout_);
    setInt(sess, "server-push-timeout", serverPushTimeout_);
    setBoolean(sess, "reload-is-new-session", reloadIsNewSession_);
  }

  std::string maxRequestStr
    = singleChildElementValue(app, "max-request-size", "");
  if (!maxRequestStr.empty())
    maxRequestSize_ = boost::lexical_cast< ::int64_t >(maxRequestStr) * 1024;

  std::string debugStr = singleChildElementValue(app, "debug", "");

  if (!debugStr.empty()) {
    if (debugStr == "stack")
      errorReporting_ = ErrorMessageWithStack;
    else if (debugStr == "true")
      errorReporting_ = NoErrors;
    else if (debugStr == "false")
      errorReporting_ = ErrorMessage;
    else
      throw WServer::Exception("<debug>: expecting 'true', 'false',"
			       "or 'stack'");
  }

  setInt(app, "num-threads", numThreads_);

  xml_node<> *fcgi = singleChildElement(app, "connector-fcgi");
  if (!fcgi)
    fcgi = app; // backward compatibility

  valgrindPath_ = singleChildElementValue(fcgi, "valgrind-path",
					  valgrindPath_);
  runDirectory_ = singleChildElementValue(fcgi, "run-directory",
					  runDirectory_);

  setInt(fcgi, "num-threads", numThreads_); // backward compatibility < 3.2.0

  xml_node<> *isapi = singleChildElement(app, "connector-isapi");
  if (!isapi)
    isapi = app; // backward compatibility

  setInt(isapi, "num-threads", numThreads_); // backward compatibility < 3.2.0

  std::string maxMemoryRequestSizeStr =
    singleChildElementValue(isapi, "max-memory-request-size", "");
  if (!maxMemoryRequestSizeStr.empty()) {
    isapiMaxMemoryRequestSize_ = boost::lexical_cast< ::int64_t >
      (maxMemoryRequestSizeStr) * 1024;
  }

  setInt(app, "session-id-length", sessionIdLength_);

  /*
   * If a session-id-prefix is defined in the configuration file, then
   * we loose the prefix defined by the connector (e.g. wthttpd), but who
   * would do such a thing ? */
  connectorSessionIdPrefix_
    = singleChildElementValue(app,"session-id-prefix",
			      connectorSessionIdPrefix_);

  setBoolean(app, "send-xhtml-mime-type", xhtmlMimeType_);
  if (xhtmlMimeType_)
    LOG_WARN("ignoring send-xhtml-mime-type setting: HTML5 is now always used");
  redirectMsg_ = singleChildElementValue(app, "redirect-message", redirectMsg_);

  setBoolean(app, "behind-reverse-proxy", behindReverseProxy_);
  setBoolean(app, "strict-event-serialization", serializedEvents_);
  setBoolean(app, "web-sockets", webSockets_);

  setBoolean(app, "inline-css", inlineCss_);
  setBoolean(app, "persistent-sessions", persistentSessions_);

  uaCompatible_ = singleChildElementValue(app, "UA-Compatible", "");

  setBoolean(app, "progressive-bootstrap", progressiveBoot_);
  if (progressiveBoot_)
    setBoolean(app, "split-script", splitScript_);
  setBoolean(app, "session-id-cookie", sessionIdCookie_);
  setBoolean(app, "cookie-checks", cookieChecks_);

  std::string plainAjaxSessionsRatioLimit
    = singleChildElementValue(app, "plain-ajax-sessions-ratio-limit", "");

  if (!plainAjaxSessionsRatioLimit.empty())
    maxPlainSessionsRatio_
      = boost::lexical_cast<float>(plainAjaxSessionsRatioLimit);

  setBoolean(app, "ajax-puzzle", ajaxPuzzle_);
  setInt(app, "indicator-timeout", indicatorTimeout_);
  setInt(app, "double-click-timeout", doubleClickTimeout_);

  std::vector<xml_node<> *> userAgents = childElements(app, "user-agents");

  for (unsigned i = 0; i < userAgents.size(); ++i) {
    xml_node<> *userAgentsList = userAgents[i];

    std::string type;
    if (!attributeValue(userAgentsList, "type", type))
      throw WServer::Exception("<user-agents> requires attribute 'type'");

    std::string mode;
    attributeValue(userAgentsList, "mode", mode);
    
    AgentList *list;
    if (type == "ajax") {
      list = &ajaxAgentList_;
      if (mode == "black-list")
	ajaxAgentWhiteList_ = false;
      else if (mode == "white-list")
	ajaxAgentWhiteList_ = true;
      else
	throw WServer::Exception
	  ("<user-agents type=\"ajax\" requires attribute 'mode' with value "
	   "\"white-list\" or \"black-list\"");
    } else if (type == "bot")
      list = &botList_;
    else
      throw WServer::Exception
	("<user-agents> requires attribute 'type' with value "
	 "\"ajax\" or \"bot\"");

    std::vector<xml_node<> *> agents
      = childElements(userAgentsList, "user-agent");

    for (unsigned j = 0; j < agents.size(); ++j)
      list->push_back(elementValue(agents[j], "user-agent"));
  }

  xml_node<> *properties = singleChildElement(app, "properties");

  if (properties) {
    std::vector<xml_node<> *> nodes = childElements(properties, "property");

    for (unsigned i = 0; i < nodes.size(); ++i) {
      xml_node<> *property = nodes[i];

      std::string name;
      if (!attributeValue(property, "name", name))
	throw WServer::Exception("<property> requires attribute 'name'");

      std::string value = elementValue(property, "property");

      if (name == "approot")
	name = "appRoot";

      if (name == "appRoot" && !appRoot_.empty())
	LOG_WARN("ignoring configuration property 'appRoot' ("
		 << value
		 << ") because was already set to " << appRoot_);
      else
        properties_[name] = value;
    }
  }
}
Ejemplo n.º 8
0
BasicElement* FixedElement::elementNext ( int position ) const
{
        return childElements()[position/2];
}