void MythRect::CalculateArea(const MythRect & parentArea) { QRect area = parentArea.toQRect(); if ((m_parentArea == area && !m_needsUpdate) || !parentArea.isValid()) return; m_parentArea = area; int w = width(); int h = height(); int X = x(); int Y = y(); if (m_percentX > 0.0) X = (int) (m_percentX * (float)m_parentArea.width()) + m_offsetX; if (m_percentY > 0.0) Y = (int) (m_percentY * (float)m_parentArea.height()) + m_offsetY; if (m_percentWidth > 0.0) w = (int) (m_percentWidth * (float)(m_parentArea.width() - X)) + m_offsetWidth; else if (m_offsetWidth != 0) w = m_parentArea.width() - X + m_offsetWidth; if (m_percentHeight > 0.0) h = (int) (m_percentHeight * (float)(m_parentArea.height() - Y)) + m_offsetHeight; else if (m_offsetHeight != 0) h = m_parentArea.height() - Y + m_offsetHeight; QRect::setRect(X,Y,w,h); m_needsUpdate = false; }
void OSD::PositionWindow(MythScreenType *window) { if (!window) return; MythRect rect = window->GetArea(); rect.translate(m_Rect.left(), m_Rect.top()); window->SetArea(rect); }
void MythUITextEdit::SetInitialStates() { if (m_initialized) return; m_initialized = true; m_Text = dynamic_cast<MythUIText*>(GetChild("text")); m_cursorImage = dynamic_cast<MythUIImage*>(GetChild("cursor")); m_backgroundState = dynamic_cast<MythUIStateType*>(GetChild("background")); if (!m_Text) VERBOSE(VB_IMPORTANT, LOC_ERR + "Missing text element."); if (!m_cursorImage) VERBOSE(VB_IMPORTANT, LOC_ERR + "Missing cursor element."); if (!m_backgroundState) VERBOSE(VB_IMPORTANT, LOC_WARN + "Missing background element."); if (!m_Text || !m_cursorImage) { m_Text = NULL; m_cursorImage = NULL; m_backgroundState = NULL; return; } if (m_backgroundState && !m_backgroundState->DisplayState("active")) VERBOSE(VB_IMPORTANT, "MythUITextEdit: active state doesn't exist"); QFontMetrics fm(m_Text->GetFontProperties()->face()); int height = fm.height(); if (height > 0) { MythRect imageArea = m_cursorImage->GetArea(); int width = int(((float)height / (float)imageArea.height()) * (float)imageArea.width()); if (width <= 0) width = 1; m_cursorImage->ForceSize(QSize(width,height)); } MythRect textrect = m_Text->GetArea(); if (textrect.isNull()) textrect = MythRect(5,5,m_Area.width()-10,m_Area.height()-10); textrect.setWidth(textrect.width() - m_cursorImage->GetArea().width()); if (textrect.isValid()) m_Text->SetArea(textrect); m_Text->SetCutDown(false); m_cursorImage->SetPosition(textrect.x(),textrect.y()); }
MythRect XMLParseBase::parseRect(const QString &text, bool normalize) { MythRect retval; QStringList values = text.split(',', QString::SkipEmptyParts); if (values.size() == 4) retval = MythRect(values[0], values[1], values[2], values[3]); if (normalize) retval.NormRect(); return retval; }
void MythUIScrollBar::CalculatePosition(void) { if (m_maximum > 0) Show(); else { Hide(); return; } MythUIType *slider = GetChild("slider"); if (!slider) { LOG(VB_GENERAL, LOG_ERR, "Slider element doesn't exist"); return; } float percentage = (float)m_sliderPosition / m_maximum; float relativeSize = (float)m_pageStep / (m_maximum + m_pageStep); MythRect newSliderArea = slider->GetArea(); MythRect fillArea = GetArea(); QPoint endPos(newSliderArea.left(), newSliderArea.top()); if (m_layout == LayoutHorizontal) { int width = qMax((int)(fillArea.width() * relativeSize + 0.5), m_sliderArea.width()); newSliderArea.setWidth(width); endPos.setX((int)((fillArea.width() - width) * percentage + 0.5)); } else { int height = qMax((int)(fillArea.height() * relativeSize + 0.5), m_sliderArea.height()); newSliderArea.setHeight(height); endPos.setY((int)((fillArea.height() - height) * percentage + 0.5)); } slider->SetArea(newSliderArea); slider->SetPosition(endPos); if (m_hideDelay > 0) { if (m_timerId) killTimer(m_timerId); m_timerId = startTimer(m_hideDelay); AdjustAlpha(1, 10, 0, 255); } }
/** * \copydoc MythUIType::ParseElement() */ bool MythScreenType::ParseElement( const QString &filename, QDomElement &element, bool showWarnings) { if (element.tagName() == "area") { MythRect rect = parseRect(element, false); MythRect rectN = parseRect(element); QRect screenArea = GetMythMainWindow()->GetUIScreenRect(); if (rect.x() == -1) rectN.moveLeft((screenArea.width() - rectN.width()) / 2); if (rect.y() == -1) rectN.moveTop((screenArea.height() - rectN.height()) / 2); SetArea(rectN); if (m_Area.width() < screenArea.width() || m_Area.height() < screenArea.height()) { m_FullScreen = false; } else { m_FullScreen = true; } } else { return MythUIType::ParseElement(filename, element, showWarnings); } return true; }
bool MythUIStateType::AddObject(StateType type, MythUIType *object) { if (m_ObjectsByState.contains((int)type) || !object) return false; object->SetVisible(false); m_ObjectsByState[(int)type] = object; MythRect objectArea = object->GetArea(); objectArea.CalculateArea(m_ParentArea); ExpandArea(objectArea); return true; }
void MythUITextEdit::SetInitialStates() { if (m_initialized) return; m_initialized = true; m_Text = dynamic_cast<MythUIText *>(GetChild("text")); m_cursorImage = dynamic_cast<MythUIImage *>(GetChild("cursor")); m_backgroundState = dynamic_cast<MythUIStateType *>(GetChild("background")); if (!m_Text) LOG(VB_GENERAL, LOG_ERR, LOC + "Missing text element."); if (!m_cursorImage) LOG(VB_GENERAL, LOG_ERR, LOC + "Missing cursor element."); if (!m_backgroundState) LOG(VB_GENERAL, LOG_WARNING, LOC + "Missing background element."); if (!m_Text || !m_cursorImage) { m_Text = NULL; m_cursorImage = NULL; m_backgroundState = NULL; return; } if (m_backgroundState && !m_backgroundState->DisplayState("active")) LOG(VB_GENERAL, LOG_ERR, LOC + "active state doesn't exist"); m_Text->SetCutDown(Qt::ElideNone); QFontMetrics fm(m_Text->GetFontProperties()->face()); int height = fm.height(); if (height > 0) { MythRect imageArea = m_cursorImage->GetFullArea(); int width = int(((float)height / (float)imageArea.height()) * (float)imageArea.width()); if (width <= 0) width = 1; m_cursorImage->ForceSize(QSize(width, height)); } }
bool MythUIStateType::AddObject(const QString &name, MythUIType *object) { QString key = name.toLower(); if (m_ObjectsByName.contains(key) || !object) return false; object->SetVisible(false); m_ObjectsByName[key] = object; MythRect objectArea = object->GetArea(); objectArea.CalculateArea(m_ParentArea); ExpandArea(objectArea); return true; }
void MythUIType::ExpandArea(const MythRect &rect) { QSize childSize = rect.size(); QSize size = m_Area.size(); if (childSize == size) return; SetSize(size.expandedTo(childSize)); SetRedraw(); }
void MythPoint::CalculatePoint(const MythRect & parentArea) { QRect area = parentArea.toQRect(); if ((m_parentArea == area && !m_needsUpdate) || !parentArea.isValid()) return; m_parentArea = area; int X = x(); int Y = y(); if (m_percentX > 0.0) X = (int) (m_percentX * (float)m_parentArea.width()) + m_offsetX; if (m_percentY > 0.0) Y = (int) (m_percentY * (float)m_parentArea.height()) + m_offsetY; QPoint::setX(X); QPoint::setY(Y); m_needsUpdate = false; valid = true; }
/** * Set the minimum area based on the given size */ void MythUIType::SetMinArea(const MythRect &rect) { // If a minsize is not set, don't use MinArea if (!m_Initiator || !m_MinSize.isValid()) return; QRect bounded(rect); bool vanish = (m_Vanish && rect.isNull()); if (vanish) { bounded.moveLeft(0); bounded.moveTop(0); } else { QPoint center = bounded.center(); if (bounded.isNull()) bounded.setSize(GetMinSize()); else bounded.setSize(bounded.size().expandedTo(GetMinSize())); bounded.moveCenter(center); if (bounded.x() + bounded.width() > m_Area.x() + m_Area.width()) bounded.moveRight(m_Area.x() + m_Area.width()); if (bounded.y() + bounded.height() > m_Area.y() + m_Area.height()) bounded.moveBottom(m_Area.x() + m_Area.height()); if (bounded.x() < m_Area.x()) { bounded.moveLeft(m_Area.x()); if (bounded.width() > m_Area.width()) bounded.setWidth(m_Area.width()); } if (bounded.y() < m_Area.y()) { bounded.moveTop(m_Area.y()); if (bounded.height() > m_Area.height()) bounded.setHeight(m_Area.height()); } } m_MinArea = bounded; m_Vanished = vanish; if (m_Parent) m_Parent->SetMinAreaParent(m_MinArea, m_Area, this); }
bool MythUIVirtualKeyboard::Create() { if (!LoadWindowFromXML("keyboard/keyboard.xml", "keyboard", this)) return false; BuildFocusList(); loadKeyDefinitions(gCoreContext->GetLanguageAndVariant()); updateKeys(true); int screenWidth, screenHeight; float xmult, ymult; GetMythUI()->GetScreenSettings(screenWidth, xmult, screenHeight, ymult); MythRect editArea = m_parentEdit->GetArea(); MythRect area = GetArea(); MythPoint newPos; //FIXME this assumes the edit is a direct child of the parent screen MythUIType *parentScreen = NULL; parentScreen = dynamic_cast<MythUIType *>(m_parentEdit->parent()); if (parentScreen) { editArea.moveTopLeft(QPoint(editArea.x() + parentScreen->GetArea().x(), editArea.y() + parentScreen->GetArea().y())); } switch (m_preferredPos) { case VK_POSABOVEEDIT: if (editArea.y() - area.height() - 5 > 0) { newPos = QPoint(editArea.x() + editArea.width() / 2 - area.width() / 2, editArea.y() - area.height() - 5); } else { newPos = QPoint(editArea.x() + editArea.width() / 2 - area.width() / 2, editArea.y() + editArea.height() + 5); } break; case VK_POSTOPDIALOG: newPos = QPoint(screenWidth / 2 - area.width() / 2, 5); break; case VK_POSBOTTOMDIALOG: newPos = QPoint(screenWidth / 2 - area.width() / 2, screenHeight - 5 - area.height()); break; case VK_POSCENTERDIALOG: newPos = QPoint(screenWidth / 2 - area.width() / 2, screenHeight / 2 - area.height() / 2); break; default: // VK_POSBELOWEDIT if (editArea.y() + editArea.height() + area.height() + 5 < screenHeight) { newPos = QPoint(editArea.x() + editArea.width() / 2 - area.width() / 2, editArea.y() + editArea.height() + 5); } else { newPos = QPoint(editArea.x() + editArea.width() / 2 - area.width() / 2, editArea.y() - area.height() - 5); } break; } // make sure the popup doesn't go off screen if (newPos.x() < 5) newPos.setX(5); if (newPos.x() + area.width() + 5 > screenWidth) newPos.setX(screenWidth - area.width() - 5); if (newPos.y() < 5) newPos.setY(5); if (newPos.y() + area.height() + 5 > screenHeight) newPos.setY(screenHeight - area.height() - 5); SetPosition(newPos); return true; }
bool MythUITextEdit::MoveCursor(MoveDirection moveDir) { if (!m_Text || !m_Text->GetFontProperties() || !m_cursorImage) return false; QFontMetrics fm(m_Text->GetFontProperties()->face()); int cursorPos = m_cursorImage->GetArea().x(); int cursorWidth = m_cursorImage->GetArea().width(); MythRect textRect = m_Text->GetArea(); MythRect drawRect = m_Text->GetDrawRect(); int newcursorPos = 0; QString string; if (m_isPassword) { while (string.size() < m_Message.size()) string.append("*"); } else string = m_Message; QSize stringSize = fm.size(Qt::TextSingleLine, string); m_Text->SetDrawRectSize(stringSize.width()+1, textRect.height()); QSize charSize; switch (moveDir) { case MoveLeft: if (m_Position < 0) return false; charSize = fm.size(Qt::TextSingleLine, string.mid(m_Position,1)); newcursorPos = cursorPos - charSize.width(); if (newcursorPos < (textRect.x() + (textRect.width()/2))) { if (m_Position == 0 || (drawRect.x() + charSize.width() > textRect.x())) m_Text->SetDrawRectPosition(0,0); else m_Text->MoveDrawRect(charSize.width(), 0); if (drawRect.x() < textRect.x()) newcursorPos = cursorPos; } m_Position--; break; case MoveRight: if (m_Position == (string.size() - 1)) return false; charSize = fm.size(Qt::TextSingleLine, string.mid(m_Position+1,1)); newcursorPos = cursorPos + charSize.width(); if (newcursorPos > textRect.width()) { m_Text->MoveDrawRect(-(charSize.width()), 0); newcursorPos = cursorPos; } m_Position++; break; case MoveEnd: int messageWidth = stringSize.width(); if ((messageWidth + cursorWidth) >= textRect.width()) { int newx = drawRect.width() - (messageWidth + cursorWidth); m_Text->MoveDrawRect(newx, 0); newcursorPos = messageWidth + newx + textRect.x(); } else { m_Text->SetDrawRectPosition(0, 0); if (messageWidth <= 0) newcursorPos = textRect.x(); else newcursorPos = messageWidth + textRect.x(); } m_Position = string.size() - 1; break; } m_cursorImage->SetPosition(newcursorPos, textRect.y()); SetRedraw(); return true; }
/** * Adjust the size of sibling objects within the button. */ void MythUIType::SetMinAreaParent(MythRect actual_area, MythRect allowed_area, const MythUIType *calling_child) { int delta_x = 0, delta_y = 0; MythRect area; // If a minsize is not set, don't use MinArea if (!m_MinSize.isValid()) return; m_MinArea.setWidth(0); if (m_Area.width() < m_NormalSize.width()) m_Area.setWidth(m_NormalSize.width()); if (m_Area.height() < m_NormalSize.height()) m_Area.setHeight(m_NormalSize.height()); if (calling_child->m_Vanished) { actual_area.moveLeft(0); actual_area.moveTop(0); allowed_area.moveLeft(0); allowed_area.moveTop(0); } actual_area.translate(m_Area.topLeft()); allowed_area.translate(m_Area.topLeft()); QList<MythUIType *>::iterator it; for (it = m_ChildrenList.begin(); it != m_ChildrenList.end(); ++it) { if (*it == calling_child || !(*it)->m_Initiator) continue; // Find union of area(s) area = (*it)->GetArea(); area.translate(m_Area.topLeft()); actual_area = actual_area.united(area); area = (*it)->m_Area; area.translate(m_Area.topLeft()); allowed_area = allowed_area.united(area); } // Make sure it is not larger than the area allowed actual_area = actual_area.intersected(m_Area); allowed_area = allowed_area.intersected(m_Area); if (m_Vanish && actual_area.size().isNull()) { m_Vanished = true; } else { if (calling_child->m_Vanished) { delta_x = (actual_area.x() + actual_area.width()) - (m_Area.x() + m_Area.width()); delta_y = (actual_area.y() + actual_area.height()) - (m_Area.y() + m_Area.height()); } else { delta_x = (actual_area.x() + actual_area.width()) - (allowed_area.x() + allowed_area.width()); delta_y = (actual_area.y() + actual_area.height()) - (allowed_area.y() + allowed_area.height()); } m_Vanished = false; } for (it = m_ChildrenList.begin(); it != m_ChildrenList.end(); ++it) { if (*it == calling_child) continue; if (!(*it)->m_Initiator) { if (m_Vanished) (*it)->VanishSibling(); else (*it)->AdjustMinArea(delta_x, delta_y); } area = (*it)->GetArea(); area.translate(m_Area.topLeft()); actual_area = actual_area.united(area); } QSize bound(actual_area.width(), actual_area.height()); if (m_Vanished) { m_MinArea.moveLeft(0); m_MinArea.moveTop(0); } else bound = bound.expandedTo(GetMinSize()); m_MinArea.setWidth(bound.width()); m_MinArea.setHeight(bound.height()); if (m_Parent) m_Parent->SetMinAreaParent(actual_area, m_Area, this); }