Example #1
1
// private methods of FFileDialog
//----------------------------------------------------------------------
void FFileDialog::init()
{
  static constexpr std::size_t w = 42;
  static constexpr std::size_t h = 15;
  int x, y;

  setGeometry(FPoint(1, 1), FSize(w, h), false);
  auto parent_widget = getParentWidget();

  if ( parent_widget )
  {
    x = 1 + int((parent_widget->getWidth() - w) / 2);
    y = 1 + int((parent_widget->getHeight() - h) / 3);
  }
  else
    x = y = 1;

  if ( dlg_type == FFileDialog::Save )
    FDialog::setText("Save file");
  else
    FDialog::setText("Open file");

  widgetSettings (FPoint(x, y));  // Create widgets
  initCallbacks();
  setModal();
  readDir();
}
Example #2
0
/*
 * Init a QLabel
 */
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtLabelPeer_init
(JNIEnv *env, jobject obj)
{
  QWidget *parentWidget = (QWidget *) getParentWidget( env, obj );  
  QLabel *label = new MyLabel( env, obj, parentWidget );
  assert( label );
  setNativeObject( env, obj, label );
}
Example #3
0
/*
 * Constructs a QDialog native object.
 */
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFileDialogPeer_init
(JNIEnv *env, jobject obj)
{
  QWidget *parentWidget = (QWidget *) getParentWidget( env, obj );
  QFileDialog *dialog = new QFileDialog(parentWidget);
  assert( dialog );
  setNativeObject( env, obj, dialog );
}
Example #4
0
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_init
(JNIEnv *env, jobject obj)
{
  QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
  assert( parentWidget );
  QLineEdit *line = new QLineEdit( parentWidget );
  assert( line );
  
  setNativeObject( env, obj, line );
  connectLineEdit(line, env, obj);
}
Example #5
0
/*
 * Construct a QScrollbar object
 */
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_init
(JNIEnv *env, jobject obj)
{
  QWidget *parentWidget = (QWidget *)getParentWidget( env, obj );
  assert( parentWidget );
  //  QScrollBar *scrollbar = new QScrollBar( parentWidget );
  MyScrollBar *scrollbar = new MyScrollBar( env, obj, parentWidget );
  assert( scrollbar );
      
  setNativeObject( env, obj, scrollbar );
  connectScrollBar(scrollbar, env, obj);
}
Example #6
0
/*
 * Constructs tha QComboBox object
 */
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtChoicePeer_init
(JNIEnv *env, jobject obj)
{
  QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
      
  QComboBox *box = new QComboBox( parentWidget );
  assert( box );

  setNativeObject( env, obj, box );

  connectChoice(box, env, obj); // connect the fireChoice method.
}
Example #7
0
void
InvAnnotationEditor::show()
{
    // init local vars
    setClassName("InvAnnotationEditor");

    // Build the widget tree, and let SoXtComponent know about our base widget.
    if (buildNow_)
    {
        Widget w = buildWidget(getParentWidget());
        setBaseWidget(w);
    }
    switchTag = VIS;
    SoXtComponent::show();
}
Example #8
0
void UIAnchorLayout::addAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge,
                               const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge)
{
    if(!anchoredWidget)
        return;

    assert(anchoredWidget != getParentWidget());

    UIAnchor anchor(anchoredEdge, hookedWidgetId, hookedEdge);
    UIAnchorGroup& anchorGroup = m_anchorsGroups[anchoredWidget];
    anchorGroup.addAnchor(anchor);

    // layout must be updated because a new anchor got in
    update();
}
Example #9
0
void UIMapAnchorLayout::addPositionAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge, const Position& hookedPosition, Fw::AnchorEdge hookedEdge)
{
    if(!anchoredWidget)
        return;

    assert(anchoredWidget != getParentWidget());

    UIPositionAnchorPtr anchor(new UIPositionAnchor(anchoredEdge, hookedPosition, hookedEdge));
    UIAnchorGroupPtr& anchorGroup = m_anchorsGroups[anchoredWidget];
    if(!anchorGroup)
        anchorGroup = UIAnchorGroupPtr(new UIAnchorGroup);

    anchorGroup->addAnchor(anchor);

    // layout must be updated because a new anchor got in
    update();
}
Example #10
0
//=========================================================================
//
// Called by the constructors
//
// Use: protected
//
//=========================================================================
void InvPartEditor::show()
{

    // init local vars
    setClassName("InvPartEditor");

    // Build the widget tree, and let SoXtComponent know about our base widget.
    if (buildNow_)
    {
        Widget w = buildWidget(getParentWidget());
        setBaseWidget(w);
    }
    switchTag = VIS;
    referenceTag = false;
    transTag = UNDIS;
    SoXtComponent::show();
}
	ScriptOSDropTarget::ScriptOSDropTarget(MonoObject* instance, ScriptEditorWindow* parent)
		:ScriptObject(instance), mParent(parent), mDropTarget(nullptr), mIsDestroyed(false)
	{
		EditorWidgetBase* parentWidget = getParentWidget();

		if (parentWidget != nullptr)
		{
			mWidgetParentChangedConn = parentWidget->onParentChanged.connect(std::bind(&ScriptOSDropTarget::widgetParentChanged, this, _1));
			mWidgetResizedConn = parentWidget->onResized.connect(std::bind(&ScriptOSDropTarget::widgetResized, this, _1, _2));
			mWidgetMovedConn = parentWidget->onMoved.connect(std::bind(&ScriptOSDropTarget::widgetMoved, this, _1, _2));

			EditorWindowBase* parentWindow = parentWidget->getParentWindow();

			if (parentWindow != nullptr)
				setDropTarget(parentWindow->getRenderWindow(), 0, 0, 0, 0);

			mParentArea = parentWidget->getBounds();
		}
	}
Example #12
0
void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup)
{
    UIWidgetPtr parentWidget = getParentWidget();
    Rect newRect = widget->getRect();
    bool verticalMoved = false;
    bool horizontalMoved = false;

    // calculates new rect based on anchors
    for(const UIAnchor& anchor : anchorGroup.getAnchors()) {
        // skip invalid anchors
        if(anchor.getHookedEdge() == Fw::AnchorNone)
            continue;

        // determine hooked widget
        UIWidgetPtr hookedWidget;
        if(parentWidget) {
            if(anchor.getHookedWidgetId() == "parent")
                hookedWidget = parentWidget;
            else if(anchor.getHookedWidgetId() == "next")
                hookedWidget = parentWidget->getChildAfter(widget);
            else if(anchor.getHookedWidgetId() == "prev")
                hookedWidget = parentWidget->getChildBefore(widget);
            else
                hookedWidget = parentWidget->getChildById(anchor.getHookedWidgetId());
        }

        // skip invalid anchors
        if(!hookedWidget)
            continue;

        if(hookedWidget != getParentWidget()) {
            // update this hooked widget anchors
            auto it = m_anchorsGroups.find(hookedWidget);
            if(it != m_anchorsGroups.end()) {
                UIAnchorGroup& hookedAnchorGroup = it->second;
                if(!hookedAnchorGroup.isUpdated())
                    updateWidget(hookedWidget, hookedAnchorGroup);
            }
        }

        // determine hooked widget edge point
        int point = 0;
        switch(anchor.getHookedEdge()) {
            case Fw::AnchorLeft:
                point = hookedWidget->getRect().left();
                break;
            case Fw::AnchorRight:
                point = hookedWidget->getRect().right();
                break;
            case Fw::AnchorTop:
                point = hookedWidget->getRect().top();
                break;
            case Fw::AnchorBottom:
                point = hookedWidget->getRect().bottom();
                break;
            case Fw::AnchorHorizontalCenter:
                point = hookedWidget->getRect().horizontalCenter();
                break;
            case Fw::AnchorVerticalCenter:
                point = hookedWidget->getRect().verticalCenter();
                break;
            default:
                // must never happens
                assert(false);
                break;
        }

        switch(anchor.getAnchoredEdge()) {
            case Fw::AnchorHorizontalCenter:
                newRect.moveHorizontalCenter(point + widget->getMarginLeft() - widget->getMarginRight());
                horizontalMoved = true;
                break;
            case Fw::AnchorLeft:
                if(!horizontalMoved) {
                    newRect.moveLeft(point + widget->getMarginLeft());
                    horizontalMoved = true;
                } else
                    newRect.setLeft(point + widget->getMarginLeft());
                break;
            case Fw::AnchorRight:
                if(!horizontalMoved) {
                    newRect.moveRight(point - widget->getMarginRight());
                    horizontalMoved = true;
                } else
                    newRect.setRight(point - widget->getMarginRight());
                break;
            case Fw::AnchorVerticalCenter:
                newRect.moveVerticalCenter(point + widget->getMarginTop() - widget->getMarginBottom());
                verticalMoved = true;
                break;
            case Fw::AnchorTop:
                if(!verticalMoved) {
                    newRect.moveTop(point + widget->getMarginTop());
                    verticalMoved = true;
                } else
                    newRect.setTop(point + widget->getMarginTop());
                break;
            case Fw::AnchorBottom:
                if(!verticalMoved) {
                    newRect.moveBottom(point - widget->getMarginBottom());
                    verticalMoved = true;
                } else
                    newRect.setBottom(point - widget->getMarginBottom());
                break;
            default:
                break;
        }
    }

    widget->setRect(newRect);
    anchorGroup.setUpdated(true);
}
bool UIHorizontalLayout::internalUpdate()
{
    UIWidgetPtr parentWidget = getParentWidget();
    if(!parentWidget)
        return false;
    UIWidgetList widgets = parentWidget->getChildren();

    if(m_alignRight)
        std::reverse(widgets.begin(), widgets.end());

    bool changed = false;
    Rect paddingRect = parentWidget->getPaddingRect();
    Point pos = (m_alignRight) ? paddingRect.topRight() : paddingRect.topLeft();
    int preferredWidth = 0;
    int gap;

    for(const UIWidgetPtr& widget : widgets) {
        if(!widget->isExplicitlyVisible())
            continue;

        Size size = widget->getSize();

        gap = (m_alignRight) ? -(widget->getMarginRight()+widget->getWidth()) : widget->getMarginLeft();
        pos.x += gap;
        preferredWidth += gap;

        if(widget->isFixedSize()) {
            if(widget->getTextAlign() & Fw::AlignTop) {
                pos.y = paddingRect.top() + widget->getMarginTop();
            } else if(widget->getTextAlign() & Fw::AlignBottom) {
                pos.y = paddingRect.bottom() - widget->getHeight() - widget->getMarginBottom();
                pos.y = std::max<int>(pos.y, paddingRect.top());
            } else { // center it
                pos.y = paddingRect.top() + (paddingRect.height() - (widget->getMarginTop() + widget->getHeight() + widget->getMarginBottom()))/2;
                pos.y = std::max<int>(pos.y, paddingRect.top());
            }
        } else {
            // expand height
            size.setHeight(paddingRect.height() - (widget->getMarginTop() + widget->getMarginBottom()));
            pos.y = paddingRect.top() + (paddingRect.height() - size.height())/2;
        }

        if(widget->setRect(Rect(pos - parentWidget->getVirtualOffset(), size)))
            changed = true;

        gap = (m_alignRight) ? -widget->getMarginLeft() : (widget->getWidth() + widget->getMarginRight());
        gap += m_spacing;
        pos.x += gap;
        preferredWidth += gap;
    }

    preferredWidth -= m_spacing;
    preferredWidth += parentWidget->getPaddingLeft() + parentWidget->getPaddingRight();

    if(m_fitChildren && preferredWidth != parentWidget->getWidth()) {
        // must set the preferred width later
        g_dispatcher.addEvent([=] {
            parentWidget->setWidth(preferredWidth);
        });
    }

    return changed;
}
Example #14
0
bool UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup, UIWidgetPtr first)
{
    UIWidgetPtr parentWidget = getParentWidget();
    if(!parentWidget)
        return false;

    if(first == widget) {
        g_logger.error(stdext::format("child '%s' of parent widget '%s' is recursively anchored to itself, please fix this", widget->getId(), parentWidget->getId()));
        return false;
    }

    if(!first)
        first = widget;

    Rect newRect = widget->getRect();
    bool verticalMoved = false;
    bool horizontalMoved = false;

    // calculates new rect based on anchors
    for(const UIAnchor& anchor : anchorGroup.getAnchors()) {
        // skip invalid anchors
        if(anchor.getHookedEdge() == Fw::AnchorNone)
            continue;

        // determine hooked widget
        UIWidgetPtr hookedWidget;
        if(parentWidget) {
            if(anchor.getHookedWidgetId() == "parent")
                hookedWidget = parentWidget;
            else if(anchor.getHookedWidgetId() == "next")
                hookedWidget = parentWidget->getChildAfter(widget);
            else if(anchor.getHookedWidgetId() == "prev")
                hookedWidget = parentWidget->getChildBefore(widget);
            else
                hookedWidget = parentWidget->getChildById(anchor.getHookedWidgetId());
        }

        // skip invalid anchors
        if(!hookedWidget)
            continue;

        if(hookedWidget != getParentWidget()) {
            // update this hooked widget anchors
            auto it = m_anchorsGroups.find(hookedWidget);
            if(it != m_anchorsGroups.end()) {
                UIAnchorGroup& hookedAnchorGroup = it->second;
                if(!hookedAnchorGroup.isUpdated())
                    updateWidget(hookedWidget, hookedAnchorGroup, first);
            }
        }

        // determine hooked widget edge point
        Rect hookedWidgetRect = hookedWidget->getRect();
        if(hookedWidget == parentWidget)
            hookedWidgetRect = parentWidget->getPaddingRect();

        int point = 0;
        switch(anchor.getHookedEdge()) {
            case Fw::AnchorLeft:
                point = hookedWidgetRect.left();
                break;
            case Fw::AnchorRight:
                point = hookedWidgetRect.right();
                break;
            case Fw::AnchorTop:
                point = hookedWidgetRect.top();
                break;
            case Fw::AnchorBottom:
                point = hookedWidgetRect.bottom();
                break;
            case Fw::AnchorHorizontalCenter:
                point = hookedWidgetRect.horizontalCenter();
                break;
            case Fw::AnchorVerticalCenter:
                point = hookedWidgetRect.verticalCenter();
                break;
            default:
                // must never happens
                assert(false);
                break;
        }

        if(hookedWidget == parentWidget) {
            switch(anchor.getHookedEdge()) {
                case Fw::AnchorLeft:
                case Fw::AnchorRight:
                case Fw::AnchorHorizontalCenter:
                    point -= parentWidget->getVirtualOffset().x;
                    break;
                case Fw::AnchorBottom:
                case Fw::AnchorTop:
                case Fw::AnchorVerticalCenter:
                    point -= parentWidget->getVirtualOffset().y;
                    break;
                default:
                    break;
            }
        }

        switch(anchor.getAnchoredEdge()) {
            case Fw::AnchorHorizontalCenter:
                newRect.moveHorizontalCenter(point + widget->getMarginLeft() - widget->getMarginRight());
                horizontalMoved = true;
                break;
            case Fw::AnchorLeft:
                if(!horizontalMoved) {
                    newRect.moveLeft(point + widget->getMarginLeft());
                    horizontalMoved = true;
                } else
                    newRect.setLeft(point + widget->getMarginLeft());
                break;
            case Fw::AnchorRight:
                if(!horizontalMoved) {
                    newRect.moveRight(point - widget->getMarginRight());
                    horizontalMoved = true;
                } else
                    newRect.setRight(point - widget->getMarginRight());
                break;
            case Fw::AnchorVerticalCenter:
                newRect.moveVerticalCenter(point + widget->getMarginTop() - widget->getMarginBottom());
                verticalMoved = true;
                break;
            case Fw::AnchorTop:
                if(!verticalMoved) {
                    newRect.moveTop(point + widget->getMarginTop());
                    verticalMoved = true;
                } else
                    newRect.setTop(point + widget->getMarginTop());
                break;
            case Fw::AnchorBottom:
                if(!verticalMoved) {
                    newRect.moveBottom(point - widget->getMarginBottom());
                    verticalMoved = true;
                } else
                    newRect.setBottom(point - widget->getMarginBottom());
                break;
            default:
                break;
        }
    }

    bool changed = false;
    if(widget->setRect(newRect))
        changed = true;
    anchorGroup.setUpdated(true);
    return changed;
}
Example #15
0
bool UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, const UIAnchorGroupPtr& anchorGroup, UIWidgetPtr first)
{
    UIWidgetPtr parentWidget = getParentWidget();
    if(!parentWidget)
        return false;

    if(first == widget) {
        g_logger.error(stdext::format("child '%s' of parent widget '%s' is recursively anchored to itself, please fix this", widget->getId(), parentWidget->getId()));
        return false;
    }

    if(!first)
        first = widget;

    Rect newRect = widget->getRect();
    bool verticalMoved = false;
    bool horizontalMoved = false;

    // calculates new rect based on anchors
    for(const UIAnchorPtr& anchor : anchorGroup->getAnchors()) {
        // skip invalid anchors
        if(anchor->getHookedEdge() == Fw::AnchorNone)
            continue;

        // determine hooked widget
        UIWidgetPtr hookedWidget = anchor->getHookedWidget(widget, parentWidget);

        // skip invalid anchors
        if(!hookedWidget)
            continue;

        if(hookedWidget != getParentWidget()) {
            // update this hooked widget anchors
            auto it = m_anchorsGroups.find(hookedWidget);
            if(it != m_anchorsGroups.end()) {
                const UIAnchorGroupPtr& hookedAnchorGroup = it->second;
                if(!hookedAnchorGroup->isUpdated())
                    updateWidget(hookedWidget, hookedAnchorGroup, first);
            }
        }

        int point = anchor->getHookedPoint(hookedWidget, parentWidget);

        switch(anchor->getAnchoredEdge()) {
            case Fw::AnchorHorizontalCenter:
                newRect.moveHorizontalCenter(point + widget->getMarginLeft() - widget->getMarginRight());
                horizontalMoved = true;
                break;
            case Fw::AnchorLeft:
                if(!horizontalMoved) {
                    newRect.moveLeft(point + widget->getMarginLeft());
                    horizontalMoved = true;
                } else
                    newRect.setLeft(point + widget->getMarginLeft());
                break;
            case Fw::AnchorRight:
                if(!horizontalMoved) {
                    newRect.moveRight(point - widget->getMarginRight());
                    horizontalMoved = true;
                } else
                    newRect.setRight(point - widget->getMarginRight());
                break;
            case Fw::AnchorVerticalCenter:
                newRect.moveVerticalCenter(point + widget->getMarginTop() - widget->getMarginBottom());
                verticalMoved = true;
                break;
            case Fw::AnchorTop:
                if(!verticalMoved) {
                    newRect.moveTop(point + widget->getMarginTop());
                    verticalMoved = true;
                } else
                    newRect.setTop(point + widget->getMarginTop());
                break;
            case Fw::AnchorBottom:
                if(!verticalMoved) {
                    newRect.moveBottom(point - widget->getMarginBottom());
                    verticalMoved = true;
                } else
                    newRect.setBottom(point - widget->getMarginBottom());
                break;
            default:
                break;
        }
    }

    bool changed = false;
    if(widget->setRect(newRect))
        changed = true;
    anchorGroup->setUpdated(true);
    return changed;
}