void ActionGraphicsItem::calculateLayout() { if(elementLayout() == 0) return; const ElementLayout & el = *elementLayout(); // calculate the size of the label QSizeF labelSize = calculateLabelSize(); QSize connectorSize = inputLayout()->connector().size(); // find the new width & height float height = labelSize.height() + 2*el.yMargin(); float width = labelSize.width() + 2*el.xMargin() + connectorSize.width(); if(width < el.minSize().width()) width = el.minSize().width(); if(height < el.minSize().height()) height = el.minSize().height(); // the height should be bigger or the same as the attached elements if(inputItem() && height < inputItem()->boundingRect().height()) height = inputItem()->boundingRect().height(); // update the bounding rect & position where text should start setInnerRect(QRectF(0, -height/2.0f, width, height)); setLabelStart(QPointF(connectorSize.width() + el.xMargin(), -labelSize.height()/2.0f)); setBoundingRect(innerRect().adjusted(-inputItem()->innerRect().width(), 0, 0, 0)); }
void Window::setRect(const IRect &rect) { DASSERT(!m_dragging_mode); DASSERT(!rect.empty()); m_rect = rect; setInnerRect(IRect({0, 0}, m_rect.size())); updateRects(); }
void GroupEditor::updateSelector() { PTileListModel model = m_mode == mAddRemove? allTilesModel() : m_tile_group? make_shared<TileGroupModel>(*m_tile_group) : nullptr; m_current_entry = nullptr; m_tile_list.setModel(filteredTilesModel(model, m_tile_filter)); int2 pos(0, -m_offset[m_mode].y); int2 size(rect().width(), m_tile_list.m_height + (m_mode == mAddRemove? 0 : rect().height() / 2)); setInnerRect(IRect(pos, pos + size)); }
void Window::process(const InputState &state) { Window *popup = nullptr; m_is_focused = true; for(int n = 0; n < (int)m_children.size(); n++) { m_children[n]->m_is_focused = false; m_children[n]->m_is_mouse_over = false; if(m_children[n]->m_is_closing) { PWindow window = m_children[n]; m_children.erase(m_children.begin() + n); sendEvent(window.get(), Event::window_closed, m_children[n]->m_closing_value); n--; } else if(m_children[n]->m_is_popup) popup = m_children[n].get(); } if(popup) { popup->process(state); return; } int2 mouse_pos = state.mousePos(); int2 local_mouse_pos = mouse_pos - m_clipped_rect.min; int finished_dragging = 0; bool escape = state.isKeyDown(InputKey::esc); InputButton button_map[3] = { InputButton::left, InputButton::right, InputButton::middle }; if(m_dragging_mode) { if(!state.isMouseButtonPressed(button_map[m_dragging_mode - 1]) || escape) finished_dragging = escape? -1 : 1; } else { for(int k = 0; k < 3; k++) { if(state.isMouseButtonDown(button_map[k])) { m_dragging_mode = k + 1; m_drag_start = local_mouse_pos; break; } } } int2 focus_point = m_dragging_mode? m_drag_start : local_mouse_pos; bool is_handled = false; for(int n = (int)m_children.size() - 1; n >= 0; n--) { Window *child = m_children[n].get(); if(child->isVisible() && m_has_hard_focus == child->m_has_hard_focus) { if(m_has_hard_focus || child->rect().isInside(focus_point)) { child->m_is_mouse_over = child->clippedRect().isInside(mouse_pos); child->process(state); is_handled = true; break; } } } if(!is_handled) { if(m_dragging_mode && !is_handled) { if(m_has_inner_rect && m_dragging_mode - 1 == 2) { setInnerRect(m_inner_rect + state.mouseMove()); is_handled = true; } if(!is_handled) is_handled = onMouseDrag(state, m_drag_start, local_mouse_pos, m_dragging_mode - 1, finished_dragging); if(!is_handled) is_handled = onMouseClick(state, local_mouse_pos, m_dragging_mode - 1, finished_dragging); } if(!is_handled) { if(m_has_inner_rect) { int wheel = state.mouseWheelMove(); int2 vector(0, 0); if(wheel) vector.y += wheel * rect().height() / 8; if(state.isKeyDownAuto(InputKey::pageup, 2)) vector.y += rect().height(); if(state.isKeyDownAuto(InputKey::pagedown, 2)) vector.y -= rect().height(); setInnerRect(m_inner_rect + vector); } onInput(state); } } if(escape && (!m_parent || m_is_popup) && !m_dragging_mode) // sending Event::escape only from main window sendEvent(this, Event::escape); //TODO: send only to focused windows if(finished_dragging) m_dragging_mode = 0; }
void Window::setInnerOffset(const int2 &offset) { setInnerRect(IRect(-offset, -offset + m_inner_rect.size())); }
void TileSelector::update() { m_tile_list.update(); setInnerRect(IRect(0, 0, rect().width(), m_tile_list.m_height)); }
void TileSelector::setModel(PTileListModel model) { m_tile_list.setModel(model); setInnerRect(IRect(0, 0, rect().width(), m_tile_list.m_height)); m_selection = nullptr; }