Exemplo n.º 1
0
void UIAnchorLayout::fill(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId)
{
    addAnchor(anchoredWidget, Fw::AnchorLeft, hookedWidgetId, Fw::AnchorLeft);
    addAnchor(anchoredWidget, Fw::AnchorRight, hookedWidgetId, Fw::AnchorRight);
    addAnchor(anchoredWidget, Fw::AnchorTop, hookedWidgetId, Fw::AnchorTop);
    addAnchor(anchoredWidget, Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom);
}
/*!
    Anchors two or four edges of \a firstItem with the corresponding
    edges of \a secondItem, so that \a firstItem has the same size as
    \a secondItem in the dimensions specified by \a orientations.

    For example, the following example anchors the left and right edges of two items
    to match their widths:

    \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes in two steps

    This can also be achieved using the following line of code:

    \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes

    \sa addAnchor(), addCornerAnchors()
*/
void QGraphicsAnchorLayout::addAnchors(QGraphicsLayoutItem *firstItem,
                                       QGraphicsLayoutItem *secondItem,
                                       Qt::Orientations orientations)
{
    if (orientations & Qt::Horizontal) {
        addAnchor(secondItem, Qt::AnchorLeft, firstItem, Qt::AnchorLeft);
        addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight);
    }
    if (orientations & Qt::Vertical) {
        addAnchor(secondItem, Qt::AnchorTop, firstItem, Qt::AnchorTop);
        addAnchor(firstItem, Qt::AnchorBottom, secondItem, Qt::AnchorBottom);
    }
}
Exemplo n.º 3
0
/*!
    Anchors two or four edges of \a firstItem with the corresponding
    edges of \a secondItem, so that \a firstItem has the same size as
    \a secondItem in the dimensions specified by \a orientations.

    For example, the following example anchors the left and right edges of two items
    to match their widths:

    \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes in two steps

    This can also be achieved using the following line of code:

    \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes

    \sa addAnchor(), addCornerAnchors()
*/
void QGraphicsAnchorLayout::addAnchors(QGraphicsLayoutItem *firstItem,
                                       QGraphicsLayoutItem *secondItem,
                                       Qt::Orientations orientations)
{
    bool ok = true;
    if (orientations & Qt::Horizontal) {
        // Currently, if the first is ok, then the rest of the calls should be ok
        ok = addAnchor(secondItem, Qt::AnchorLeft, firstItem, Qt::AnchorLeft) != 0;
        if (ok)
            addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight);
    }
    if (orientations & Qt::Vertical && ok) {
        addAnchor(secondItem, Qt::AnchorTop, firstItem, Qt::AnchorTop);
        addAnchor(firstItem, Qt::AnchorBottom, secondItem, Qt::AnchorBottom);
    }
}
Exemplo n.º 4
0
void UIWidget::removeAnchor(Fw::AnchorEdge anchoredEdge)
{
    addAnchor(anchoredEdge, "none", Fw::AnchorNone);
}
Exemplo n.º 5
0
void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
{
    // load styles used by all widgets
    for(const OTMLNodePtr& node : styleNode->children()) {
        if(node->tag() == "color")
            setColor(node->value<Color>());
        else if(node->tag() == "x")
            setX(node->value<int>());
        else if(node->tag() == "y")
            setY(node->value<int>());
        else if(node->tag() == "pos")
            setPosition(node->value<Point>());
        else if(node->tag() == "width")
            setWidth(node->value<int>());
        else if(node->tag() == "height")
            setHeight(node->value<int>());
        else if(node->tag() == "rect")
            setRect(node->value<Rect>());
        else if(node->tag() == "background")
            setBackgroundColor(node->value<Color>());
        else if(node->tag() == "background-color")
            setBackgroundColor(node->value<Color>());
        else if(node->tag() == "background-offset-x")
            setBackgroundOffsetX(node->value<int>());
        else if(node->tag() == "background-offset-y")
            setBackgroundOffsetY(node->value<int>());
        else if(node->tag() == "background-offset")
            setBackgroundOffset(node->value<Point>());
        else if(node->tag() == "background-width")
            setBackgroundWidth(node->value<int>());
        else if(node->tag() == "background-height")
            setBackgroundHeight(node->value<int>());
        else if(node->tag() == "background-size")
            setBackgroundSize(node->value<Size>());
        else if(node->tag() == "background-rect")
            setBackgroundRect(node->value<Rect>());
        else if(node->tag() == "icon")
            setIcon(stdext::resolve_path(node->value(), node->source()));
        else if(node->tag() == "icon-source")
            setIcon(stdext::resolve_path(node->value(), node->source()));
        else if(node->tag() == "icon-color")
            setIconColor(node->value<Color>());
        else if(node->tag() == "icon-offset-x")
            setIconOffsetX(node->value<int>());
        else if(node->tag() == "icon-offset-y")
            setIconOffsetY(node->value<int>());
        else if(node->tag() == "icon-offset")
            setIconOffset(node->value<Point>());
        else if(node->tag() == "icon-width")
            setIconWidth(node->value<int>());
        else if(node->tag() == "icon-height")
            setIconHeight(node->value<int>());
        else if(node->tag() == "icon-size")
            setIconSize(node->value<Size>());
        else if(node->tag() == "icon-rect")
            setIconRect(node->value<Rect>());
        else if(node->tag() == "opacity")
            setOpacity(node->value<float>());
        else if(node->tag() == "enabled")
            setEnabled(node->value<bool>());
        else if(node->tag() == "visible")
            setVisible(node->value<bool>());
        else if(node->tag() == "checked")
            setChecked(node->value<bool>());
        else if(node->tag() == "dragable")
            setChecked(node->value<bool>());
        else if(node->tag() == "on")
            setOn(node->value<bool>());
        else if(node->tag() == "focusable")
            setFocusable(node->value<bool>());
        else if(node->tag() == "phantom")
            setPhantom(node->value<bool>());
        else if(node->tag() == "size")
            setSize(node->value<Size>());
        else if(node->tag() == "fixed-size")
            setFixedSize(node->value<bool>());
        else if(node->tag() == "clipping")
            setClipping(node->value<bool>());
        else if(node->tag() == "border") {
            auto split = stdext::split(node->value(), " ");
            if(split.size() == 2) {
                setBorderWidth(stdext::safe_cast<int>(split[0]));
                setBorderColor(stdext::safe_cast<Color>(split[1]));
            } else
                throw OTMLException(node, "border param must have its width followed by its color");
        }
        else if(node->tag() == "border-width")
            setBorderWidth(node->value<int>());
        else if(node->tag() == "border-width-top")
            setBorderWidthTop(node->value<int>());
        else if(node->tag() == "border-width-right")
            setBorderWidthRight(node->value<int>());
        else if(node->tag() == "border-width-bottom")
            setBorderWidthBottom(node->value<int>());
        else if(node->tag() == "border-width-left")
            setBorderWidthLeft(node->value<int>());
        else if(node->tag() == "border-color")
            setBorderColor(node->value<Color>());
        else if(node->tag() == "border-color-top")
            setBorderColorTop(node->value<Color>());
        else if(node->tag() == "border-color-right")
            setBorderColorRight(node->value<Color>());
        else if(node->tag() == "border-color-bottom")
            setBorderColorBottom(node->value<Color>());
        else if(node->tag() == "border-color-left")
            setBorderColorLeft(node->value<Color>());
        else if(node->tag() == "margin-top")
            setMarginTop(node->value<int>());
        else if(node->tag() == "margin-right")
            setMarginRight(node->value<int>());
        else if(node->tag() == "margin-bottom")
            setMarginBottom(node->value<int>());
        else if(node->tag() == "margin-left")
            setMarginLeft(node->value<int>());
        else if(node->tag() == "margin") {
            std::string marginDesc = node->value();
            std::vector<std::string> split;
            boost::split(split, marginDesc, boost::is_any_of(std::string(" ")));
            if(split.size() == 4) {
                setMarginTop(stdext::safe_cast<int>(split[0]));
                setMarginRight(stdext::safe_cast<int>(split[1]));
                setMarginBottom(stdext::safe_cast<int>(split[2]));
                setMarginLeft(stdext::safe_cast<int>(split[3]));
            } else if(split.size() == 3) {
                int marginTop = stdext::safe_cast<int>(split[0]);
                int marginHorizontal = stdext::safe_cast<int>(split[1]);
                int marginBottom = stdext::safe_cast<int>(split[2]);
                setMarginTop(marginTop);
                setMarginRight(marginHorizontal);
                setMarginBottom(marginBottom);
                setMarginLeft(marginHorizontal);
            } else if(split.size() == 2) {
                int marginVertical = stdext::safe_cast<int>(split[0]);
                int marginHorizontal = stdext::safe_cast<int>(split[1]);
                setMarginTop(marginVertical);
                setMarginRight(marginHorizontal);
                setMarginBottom(marginVertical);
                setMarginLeft(marginHorizontal);
            } else if(split.size() == 1) {
                int margin = stdext::safe_cast<int>(split[0]);
                setMarginTop(margin);
                setMarginRight(margin);
                setMarginBottom(margin);
                setMarginLeft(margin);
            }
        }
        else if(node->tag() == "padding-top")
            setPaddingTop(node->value<int>());
        else if(node->tag() == "padding-right")
            setPaddingRight(node->value<int>());
        else if(node->tag() == "padding-bottom")
            setPaddingBottom(node->value<int>());
        else if(node->tag() == "padding-left")
            setPaddingLeft(node->value<int>());
        else if(node->tag() == "padding") {
            std::string paddingDesc = node->value();
            std::vector<std::string> split;
            boost::split(split, paddingDesc, boost::is_any_of(std::string(" ")));
            if(split.size() == 4) {
                setPaddingTop(stdext::safe_cast<int>(split[0]));
                setPaddingRight(stdext::safe_cast<int>(split[1]));
                setPaddingBottom(stdext::safe_cast<int>(split[2]));
                setPaddingLeft(stdext::safe_cast<int>(split[3]));
            } else if(split.size() == 3) {
                int paddingTop = stdext::safe_cast<int>(split[0]);
                int paddingHorizontal = stdext::safe_cast<int>(split[1]);
                int paddingBottom = stdext::safe_cast<int>(split[2]);
                setPaddingTop(paddingTop);
                setPaddingRight(paddingHorizontal);
                setPaddingBottom(paddingBottom);
                setPaddingLeft(paddingHorizontal);
            } else if(split.size() == 2) {
                int paddingVertical = stdext::safe_cast<int>(split[0]);
                int paddingHorizontal = stdext::safe_cast<int>(split[1]);
                setPaddingTop(paddingVertical);
                setPaddingRight(paddingHorizontal);
                setPaddingBottom(paddingVertical);
                setPaddingLeft(paddingHorizontal);
            } else if(split.size() == 1) {
                int padding = stdext::safe_cast<int>(split[0]);
                setPaddingTop(padding);
                setPaddingRight(padding);
                setPaddingBottom(padding);
                setPaddingLeft(padding);
            }
        }
        // layouts
        else if(node->tag() == "layout") {
            std::string layoutType;
            if(node->hasValue())
                layoutType = node->value();
            else
                layoutType = node->valueAt<std::string>("type", "");

            if(!layoutType.empty()) {
                UILayoutPtr layout;
                if(layoutType == "horizontalBox")
                    layout = UIHorizontalLayoutPtr(new UIHorizontalLayout(asUIWidget()));
                else if(layoutType == "verticalBox")
                    layout = UIVerticalLayoutPtr(new UIVerticalLayout(asUIWidget()));
                else if(layoutType == "grid")
                    layout = UIGridLayoutPtr(new UIGridLayout(asUIWidget()));
                else if(layoutType == "anchor")
                    layout = UIAnchorLayoutPtr(new UIAnchorLayout(asUIWidget()));
                else
                    throw OTMLException(node, "cannot determine layout type");
                setLayout(layout);
            }

            if(node->hasChildren())
                m_layout->applyStyle(node);
        }
        // anchors
        else if(boost::starts_with(node->tag(), "anchors.")) {
            UIWidgetPtr parent = getParent();
            if(!parent) {
                if(m_firstOnStyle)
                    throw OTMLException(node, "cannot create anchor, there is no parent widget!");
                else
                    continue;
            }

            UIAnchorLayoutPtr anchorLayout = parent->getLayout()->asUIAnchorLayout();
            if(!anchorLayout)
                throw OTMLException(node, "cannot create anchor, the parent widget doesn't use anchor layout!");

            std::string what = node->tag().substr(8);
            if(what == "fill") {
                fill(node->value());
            } else if(what == "centerIn") {
                centerIn(node->value());
            } else {
                Fw::AnchorEdge anchoredEdge = Fw::translateAnchorEdge(what);

                if(node->value() == "none") {
                    removeAnchor(anchoredEdge);
                } else {
                    std::vector<std::string> split = stdext::split(node->value(), ".");
                    if(split.size() != 2)
                        throw OTMLException(node, "invalid anchor description");

                    std::string hookedWidgetId = split[0];
                    Fw::AnchorEdge hookedEdge = Fw::translateAnchorEdge(split[1]);

                    if(anchoredEdge == Fw::AnchorNone)
                        throw OTMLException(node, "invalid anchor edge");

                    if(hookedEdge == Fw::AnchorNone)
                        throw OTMLException(node, "invalid anchor target edge");

                    addAnchor(anchoredEdge, hookedWidgetId, hookedEdge);
                }
            }
            // lua functions
        } else if(boost::starts_with(node->tag(), "@")) {
            // load once
            if(m_firstOnStyle) {
                std::string funcName = node->tag().substr(1);
                std::string funcOrigin = "@" + node->source() + "[" + node->tag() + "]";
                g_lua.loadFunction(node->value(), funcOrigin);
                luaSetField(funcName);
            }
            // lua fields value
        } else if(boost::starts_with(node->tag(), "&")) {
            std::string fieldName = node->tag().substr(1);
            std::string fieldOrigin = "@" + node->source() + "[" + node->tag() + "]";
            g_lua.evaluateExpression(node->value(), fieldOrigin);
            luaSetField(fieldName);
        }
    }
}
Exemplo n.º 6
0
int MyGlWindow::handle(int e)
{

	//int ret = Fl_Button::handle(e);
	//cout<<endl<<count++<<" ******** button "<<label()<<" receives ";
	switch(e)
	{
	case FL_FOCUS:
	case FL_UNFOCUS:
	case FL_KEYBOARD:
		return keyboard(e,Fl::event_key());
	case FL_WHEN_RELEASE:
		_pauseVideo = 1-pause_video->value();
		redraw();
		break;
	case FL_PUSH:
		
		_mousex = Fl::event_x();
		_mousey = Fl::event_y();
		
		if (_windowMode == MODE_3D_MAP) {
			_LUT.mouse_3d(Fl::event_button(),GLUT_DOWN,Fl::event_x(),Fl::event_y(),\
				fltk2gl_mousemodifier());
			if (fltk2gl_mousemodifier() == GLUT_ACTIVE_CTRL) {
				model_picking_3d(Fl::event_x(),Fl::event_y());
			} else if (fltk2gl_mousemodifier() == GLUT_ACTIVE_SHIFT) {
				_camera->came.getTranslation() = _LUT._viewer_3d.raycast(Fl::event_x(),WINDOW_HEIGHT-Fl::event_y());
				//_LUT._position = _camera->came.getTranslation();
				_sphere_viewer._target = _camera->came.getTranslation();
			}
		}
		else if (_windowMode == MODE_2D_MAP) {
			_LUT.mouse_3d_topview( Fl::event_button(),GLUT_DOWN,Fl::event_x(),Fl::event_y());
		} 
		else if (_windowMode == MODE_SPHERE) {
			_sphere_viewer.mouse(Fl::event_button(),GLUT_DOWN,Fl::event_x(),Fl::event_y(),fltk2gl_mousemodifier());
			if (fltk2gl_mousemodifier() == GLUT_ACTIVE_CTRL) {
				sphere_picking_3d(Fl::event_x(),Fl::event_y());
			}
		} 
		else if (_windowMode == MODE_VIDEO) {
			if (fltk2gl_mousemodifier() == GLUT_ACTIVE_CTRL) {
				video_picking_2d(Fl::event_x(),Fl::event_y());
			}
			if ( Fl::event_button() == FL_LEFT_MOUSE ) {
				if ( _adding_anchor ) {
					addAnchor( _mousex, _mousey, _calibrated_camera );
					_adding_anchor = false;
				}
				if ( _updating_anchor ) {
					updateAnchor(  _mousex, _mousey, _calibrated_camera );
					_updating_anchor = false;
				}
				
				if ( _removing_anchor ) {
					removeAnchor(  _mousex, _mousey, _calibrated_camera );
					_removing_anchor = false;
				}
			} else if (  Fl::event_button() == FL_RIGHT_MOUSE ) {
				LOG(LEVEL_INFO, "cancelled selection");
				_adding_anchor = false;
				_updating_anchor = false;
				_removing_anchor = false;
			}			
		}
		else if ( _windowMode == MODE_CALIBRATION ) { // let the user select points to create an anchor
			if ( Fl::event_button() == FL_LEFT_MOUSE ) {
				LOG(LEVEL_INFO, "selected (%d,%d)", _mousex, _mousey);
				if ( _adding_anchor ) {
					addAnchor( _mousex, _mousey, _calibrated_camera );
					_adding_anchor = false;
				}
				if ( _updating_anchor ) {
					updateAnchor(  _mousex, _mousey, _calibrated_camera );
					_updating_anchor = false;
				}

				if ( _removing_anchor ) {
					removeAnchor(  _mousex, _mousey, _calibrated_camera );
					_removing_anchor = false;
				}

			} else if (  Fl::event_button() == FL_RIGHT_MOUSE ) {
				LOG(LEVEL_INFO, "cancelled selection");
				_adding_anchor = false;
				_updating_anchor = false;
				_removing_anchor = false;
			}
		}
		else if ( _windowMode == MODE_ROTATIONS ) {
			_rotations_viewer.mouse(Fl::event_button(),GLUT_DOWN,Fl::event_x(),Fl::event_y(),fltk2gl_mousemodifier());
		}
		return 1;
	case FL_RELEASE:
	case FL_DRAG:
		if (_windowMode == MODE_3D_MAP) {
			_LUT.motion_3d(Fl::event_x(),Fl::event_y());
			if (fltk2gl_mousemodifier() == GLUT_ACTIVE_SHIFT) {
				
				if (e == FL_RELEASE) {
					// when released, compute the visible 3D features
					//_LUT.nframes = FRAMES_JUMP; // force the node jump
					_LUT.lookup( _camera->came.getTranslation(), MIN_SUBTENDED_ANGLE, 0.0, 0, 0);
				} else {
					// drag the camera position
					//double z = _camera->getTranslation()[2];
					_camera->came.setTranslation(_LUT._viewer_3d.raycast(Fl::event_x(),WINDOW_HEIGHT-Fl::event_y()));
					//_camera->setTranslation( Vec3d( _camera->getTranslation()[0], _camera->getTranslation()[1], z ) );
					//_LUT._position = _camera->came.getTranslation();
					_sphere_viewer._target = _camera->came.getTranslation();
				}
			} 
			redraw();
		} 
		else if (_windowMode == MODE_SPHERE) {
			_sphere_viewer.motion(Fl::event_x(),Fl::event_y(),4.0,400.0,4.0);
		}
		else if (_windowMode == MODE_2D_MAP) {
			_LUT.motion_3d_topview(Fl::event_x(),Fl::event_y());
		}
		else if ( _windowMode == MODE_ROTATIONS ) {
			_rotations_viewer.motion( Fl::event_x(),Fl::event_y(),4.0,400.0,4.0);
		}
		//redraw();
		return 1;
		//case FL_HIDE:
		//	 return 1;
	case FL_SHOW:
		show();
		return 1;
	default:
		return Fl_Widget::handle(e);
	}	
	return 1;
}
Exemplo n.º 7
0
void WMediaPlayer::createDefaultGui()
{
  gui_ = 0;

  static const char *media[] = { "audio", "video" };

  WTemplate *ui = new WTemplate
    (tr(std::string("Wt.WMediaPlayer.defaultgui-") + media[mediaType_]));

  addAnchor(ui, Play, "play-btn", "jp-play");
  addAnchor(ui, Pause, "pause-btn", "jp-pause");
  addAnchor(ui, Stop, "stop-btn", "jp-stop");
  addAnchor(ui, VolumeMute, "mute-btn", "jp-mute");
  addAnchor(ui, VolumeUnmute, "unmute-btn", "jp-unmute");
  addAnchor(ui, VolumeMax, "volume-max-btn", "jp-volume-max");
  addAnchor(ui, RepeatOn, "repeat-btn", "jp-repeat");
  addAnchor(ui, RepeatOff, "repeat-off-btn", "jp-repeat-off");

  if (mediaType_ == Video) {
    addAnchor(ui, VideoPlay, "video-play-btn", "jp-video-play-icon", "play");
    addAnchor(ui, FullScreen, "full-screen-btn", "jp-full-screen");
    addAnchor(ui, RestoreScreen, "restore-screen-btn", "jp-restore-screen");
  }

  addText(ui, CurrentTime, "current-time", "jp-current-time");
  addText(ui, Duration, "duration", "jp-duration");
  addText(ui, Title, "title", std::string());

  addProgressBar(ui, Time, "progress-bar", "jp-seek-bar",
		 "jp-play-bar");
  addProgressBar(ui, Volume, "volume-bar", "jp-volume-bar",
		 "jp-volume-bar-value");

  ui->bindString("title-display", title_.empty() ? "none" : "");

  addStyleClass(mediaType_ == Video ? "jp-video" : "jp-audio");

  setControlsWidget(ui);
}
Exemplo n.º 8
0
void UIAnchorLayout::centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId)
{
    addAnchor(anchoredWidget, Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter);
    addAnchor(anchoredWidget, Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter);
}