示例#1
0
void SubtitleScreen::OptimiseDisplayedArea(void)
{
    if (!m_refreshArea)
        return;

    QRegion visible;
    QListIterator<MythUIType *> i(m_ChildrenList);
    while (i.hasNext())
    {
        MythUIType *img = i.next();
        visible = visible.united(img->GetArea());
    }

    if (visible.isEmpty())
        return;

    QRect bounding  = visible.boundingRect();
    bounding = bounding.translated(m_safeArea.topLeft());
    bounding = m_safeArea.intersected(bounding);
    int left = m_safeArea.left() - bounding.left();
    int top  = m_safeArea.top()  - bounding.top();
    SetArea(MythRect(bounding));

    i.toFront();;
    while (i.hasNext())
    {
        MythUIType *img = i.next();
        img->SetArea(img->GetArea().translated(left, top));
    }
}
示例#2
0
bool MythUIStateType::DisplayState(const QString &name)
{
    if (name.isEmpty())
        return false;

    MythUIType *old = m_CurrentState;

    QMap<QString, MythUIType *>::Iterator i = m_ObjectsByName.find(name.toLower());

    if (i != m_ObjectsByName.end())
        m_CurrentState = i.value();
    else
        m_CurrentState = NULL;

    if (m_CurrentState != old)
    {
        if (m_ShowEmpty || m_CurrentState)
        {
            if (m_deferload && m_CurrentState)
                m_CurrentState->LoadNow();

            if (old)
                old->SetVisible(false);

            if (m_CurrentState)
                m_CurrentState->SetVisible(true);
        }
    }
    AdjustDependence();

    return (m_CurrentState != NULL);
}
示例#3
0
bool MythUIStateType::DisplayState(StateType type)
{
    MythUIType *old = m_CurrentState;

    QMap<int, MythUIType *>::Iterator i = m_ObjectsByState.find((int)type);

    if (i != m_ObjectsByState.end())
        m_CurrentState = i.value();
    else
        m_CurrentState = NULL;

    if (m_CurrentState != old)
    {
        if (m_ShowEmpty || m_CurrentState)
        {
            if (m_deferload && m_CurrentState)
                m_CurrentState->LoadNow();

            if (old)
                old->SetVisible(false);

            if (m_CurrentState)
                m_CurrentState->SetVisible(true);
        }
    }
    AdjustDependence();

    return (m_CurrentState != NULL);
}
示例#4
0
/**
 *  \copydoc MythUIType::Finalize()
 */
void MythUIEditBar::Finalize(void)
{
    MythUIType *position = GetChild("position");

    if (position)
        position->MoveToTop();
}
示例#5
0
/**
 *  \brief Copy this widgets state from another.
 */
void MythUIType::CopyFrom(MythUIType *base)
{
    m_Visible = base->m_Visible;
    m_Enabled = base->m_Enabled;
    m_CanHaveFocus = base->m_CanHaveFocus;
    m_focusOrder = base->m_focusOrder;

    SetArea(base->m_Area);
    m_MinArea = base->m_MinArea;
    m_MinSize = base->m_MinSize;
    m_Alpha = base->m_Alpha;
    m_AlphaChangeMode = base->m_AlphaChangeMode;
    m_AlphaChange = base->m_AlphaChange;
    m_AlphaMin = base->m_AlphaMin;
    m_AlphaMax = base->m_AlphaMax;

    m_Moving = base->m_Moving;
    m_XYDestination = base->m_XYDestination;
    m_XYSpeed = base->m_XYSpeed;
    m_deferload = base->m_deferload;

    QList<MythUIType *>::Iterator it;
    for (it = base->m_ChildrenList.begin(); it != base->m_ChildrenList.end();
         ++it)
    {
        MythUIType *child = GetChild((*it)->objectName());
        if (child)
            child->CopyFrom(*it);
        else
            (*it)->CreateCopy(this);
    }
}
示例#6
0
bool MythScreenType::gestureEvent(MythGestureEvent *event)
{
    bool handled = false;
    if (event->gesture() == MythGestureEvent::Click)
    {
        switch (event->GetButton())
        {
            case MythGestureEvent::RightButton :
                ShowMenu();
                handled = true;
                break;
            default :
                break;
        }

    }

    if (!handled)
    {
        MythUIType *clicked = GetChildAt(event->GetPosition());
        if (clicked && clicked->IsEnabled())
        {
            SetFocusWidget(clicked);
            if (clicked->gestureEvent(event))
                handled = true;
        }
    }

    return handled;
}
示例#7
0
void MythUIScrollBar::Finalize()
{
    MythUIType *slider = GetChild("slider");
    if (slider)
        m_sliderArea = slider->GetArea();

    CalculatePosition();
}
示例#8
0
void MythUIEditBar::AddMark(MythUIShape *shape, MythUIImage *image,
                            int start, bool left)
{
    MythUIType *add = GetNew(shape, image);
    if (add)
    {
        if (left)
            start -= add->GetArea().width();
        add->SetPosition(start, add->GetArea().top());
    }
}
示例#9
0
/**
 *  \brief Reset the widget to it's original state, should not reset changes
 *         made by the theme
 */
void MythUIType::Reset()
{
    // Reset all children
    QMutableListIterator<MythUIType *> it(m_ChildrenList);
    while (it.hasNext())
    {
        it.next();
        MythUIType *type = it.value();
        type->Reset();
    }
}
示例#10
0
void TeletextScreen::OptimiseDisplayedArea(void)
{
    VideoOutput *vo = m_player->GetVideoOutput();
    if (!vo)
        return;
    MythPainter *osd_painter = vo->GetOSDPainter();
    if (!osd_painter)
        return;

    QHashIterator<int, QImage*> it(m_rowImages);
    while (it.hasNext())
    {
        it.next();
        MythImage* image = osd_painter->GetFormatImage();
        if (!image || !it.value())
            continue;

        int row = it.key();
        image->Assign(*(it.value()));
        MythUIImage *uiimage = new MythUIImage(this, QString("ttrow%1")
                                                        .arg(row));
        if (uiimage)
        {
            uiimage->SetImage(image);
            uiimage->SetArea(MythRect(0, row * m_rowHeight,
                                      m_safeArea.width(), m_rowHeight * 2));
        }
    }

    QRegion visible;
    QListIterator<MythUIType *> i(m_ChildrenList);
    while (i.hasNext())
    {
        MythUIType *img = i.next();
        visible = visible.united(img->GetArea());
    }

    if (visible.isEmpty())
        return;

    QRect bounding  = visible.boundingRect();
    bounding = bounding.translated(m_safeArea.topLeft());
    bounding = m_safeArea.intersected(bounding);
    int left = m_safeArea.left() - bounding.left();
    int top  = m_safeArea.top()  - bounding.top();
    SetArea(MythRect(bounding));

    i.toFront();;
    while (i.hasNext())
    {
        MythUIType *img = i.next();
        img->SetArea(img->GetArea().translated(left, top));
    }
}
示例#11
0
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);
    }
}
示例#12
0
void ZMEvents::setGridLayout(int layout)
{
    if (layout < 1 || layout > 3)
        layout = 1;

    if (layout == m_layout)
        return;

    if (m_eventGrid)
        m_eventGrid->Reset();

    m_layout = layout;

    // iterate though the children showing/hiding them as appropriate
    QString name;
    QString layoutName = QString("layout%1").arg(layout);
    QList<MythUIType *> *children = GetAllChildren();

    for (int x = 0; x < children->size(); x++)
    {
        MythUIType *type = children->at(x);
        name = type->objectName();
        if (name.startsWith("layout"))
        {
            if (name.startsWith(layoutName))
                type->SetVisible(true);
            else
                type->SetVisible(false);
        }
    }

    // get the correct grid
    m_eventGrid = dynamic_cast<MythUIButtonList *> (GetChild(layoutName + "_eventlist"));

    if (m_eventGrid)
    {
        connect(m_eventGrid, SIGNAL(itemSelected( MythUIButtonListItem*)),
                this, SLOT(eventChanged(MythUIButtonListItem*)));
        connect(m_eventGrid, SIGNAL(itemClicked( MythUIButtonListItem*)),
                this, SLOT(playPressed()));
        connect(m_eventGrid, SIGNAL(itemVisible(MythUIButtonListItem*)),
             this, SLOT(eventVisible(MythUIButtonListItem*)));

        updateUIList();

        BuildFocusList();

        SetFocusWidget(m_eventGrid);
    }
    else
    {
示例#13
0
void MythUIStateType::CopyFrom(MythUIType *base)
{
    MythUIStateType *st = dynamic_cast<MythUIStateType *>(base);

    if (!st)
        return;

    m_ShowEmpty = st->m_ShowEmpty;

    MythUIType::CopyFrom(base);

    QMap<QString, MythUIType *>::iterator i;

    for (i = st->m_ObjectsByName.begin(); i != st->m_ObjectsByName.end(); ++i)
    {
        MythUIType *other = i.value();
        QString key = i.key();

        MythUIType *newtype = GetChild(other->objectName());
        AddObject(key, newtype);
        newtype->SetVisible(false);
    }

    QMap<int, MythUIType *>::iterator j;

    for (j = st->m_ObjectsByState.begin(); j != st->m_ObjectsByState.end(); ++j)
    {
        MythUIType *other = j.value();
        int key = j.key();

        MythUIType *newtype = GetChild(other->objectName());
        AddObject((StateType)key, newtype);
        newtype->SetVisible(false);
    }
}
示例#14
0
/**
 *  \brief Delete a named child of this UIType
 *
 *  \param Name of child
 */
void MythUIType::DeleteChild(const QString &name)
{
    QMutableListIterator<MythUIType *> it(m_ChildrenList);
    while (it.hasNext())
    {
        it.next();
        MythUIType *type = it.value();
        if (type->objectName() == name)
        {
            delete type;
            it.remove();
            return;
        }
    }
}
示例#15
0
void MythUIEditBar::AddBar(MythUIShape *shape, MythUIImage *image,
                           const QRect &area)
{
    MythUIType *add = GetNew(shape, image);
    if (add)
    {
        MythUIShape *shape = dynamic_cast<MythUIShape*>(add);
        MythUIImage *image = dynamic_cast<MythUIImage*>(add);
        if (shape)
            shape->SetCropRect(area.left(), area.top(), area.width(), area.height());
        if (image)
            image->SetCropRect(area.left(), area.top(), area.width(), area.height());
        add->SetPosition(area.left(), area.top());
    }
}
示例#16
0
/** \brief Return the first MythUIType which accepts focus found at the given
 *         coordinates
 *
 *  \param p QPoint coordinates
 *  \param recursive Whether to perform a recursive search
 *
 *  \return The widget at these coordinates
 */
MythUIType *MythUIType::GetChildAt(const QPoint &p, bool recursive,
                                   bool focusable) const
{
    if (GetArea().contains(p))
    {
        if (!IsVisible() || !IsEnabled())
            return NULL;

        if (m_ChildrenList.isEmpty())
            return NULL;

        /* check all children */
        QList<MythUIType *>::const_iterator it;

        for (it = m_ChildrenList.end() - 1; it != m_ChildrenList.begin() - 1; --it)
        {
            if (!(*it))
                continue;

            // If this point doesn't fall within the child's area then move on
            // This requires that the area is actually accurate and in some
            // cases this still isn't true
            if (!(*it)->GetArea().contains(p - GetArea().topLeft()))
                continue;


            MythUIType *child = *it;

            if (recursive && (focusable && !child->CanTakeFocus()))
                child = child->GetChildAt(p - GetArea().topLeft(), recursive,
                                          focusable);

            if (child)
            {
                // NOTE: Assumes no selectible ui type will contain another
                // selectible ui type.
                if (focusable && !child->CanTakeFocus())
                    continue;

                return child;
            }
        }
    }

    return NULL;
}
示例#17
0
/** \brief Return the first MythUIType which accepts focus found at the given
 *         coordinates
 *
 *  \param p QPoint coordinates
 *  \param recursive Whether to perform a recursive search
 *
 *  \return The widget at these coordinates
 */
MythUIType *MythUIType::GetChildAt(const QPoint &p, bool recursive,
                                   bool focusable) const
{
    if (GetArea().contains(p))
    {
        if (!IsVisible() || !IsEnabled())
            return NULL;

        if (m_ChildrenList.isEmpty())
            return NULL;

        /* check all children */
        QList<MythUIType *>::const_iterator it;

        for (it = m_ChildrenList.end() - 1; it != m_ChildrenList.begin() - 1; --it)
        {
            if (!(*it))
                continue;

            MythUIType *child = NULL;


            if ((*it)->GetArea().contains(p - GetArea().topLeft()))
                child = *it;

            if (!child && recursive)
                child = (*it)->GetChildAt(p - GetArea().topLeft(), recursive,
                                          focusable);

            if (child)
            {
                // NOTE: Assumes no selectible ui type will contain another
                // selectible ui type.
                if (focusable && !child->CanTakeFocus())
                    continue;

                return child;
            }
        }
    }

    return NULL;
}
示例#18
0
bool MythScreenType::SetFocusWidget(MythUIType *widget)
{ 
    if (!widget || !widget->IsVisible())
    {
        QMap<int, MythUIType *>::iterator it = m_FocusWidgetList.begin();
        MythUIType *current;

        while (it != m_FocusWidgetList.end())
        {
            current = *it;

            if (current->CanTakeFocus() && current->IsVisible())
            {
                widget = current;
                break;
            }
            ++it;
        }
    }

    if (!widget)
        return false;

    if (m_CurrentFocusWidget == widget)
        return true;
    
    MythUIText *helpText = dynamic_cast<MythUIText *>(GetChild("helptext"));
    if (helpText)
        helpText->Reset();

    if (m_CurrentFocusWidget)
        m_CurrentFocusWidget->LoseFocus();
    m_CurrentFocusWidget = widget;
    m_CurrentFocusWidget->TakeFocus();

    if (helpText && !widget->GetHelpText().isEmpty())
        helpText->SetText(widget->GetHelpText());

    return true;
}
示例#19
0
void IdleScreen::UpdateStatus(void)
{
    QString state = "idle";

    if (CheckConnectionToServer())
    {
        if (m_secondsToShutdown >= 0)
            state = "shuttingdown";
        else if (RemoteGetRecordingStatus())
            state = "recording";
    }
    else
    {
        state = "offline";
    }

    m_statusState->DisplayState(state);

    MythUIType* shuttingdown = m_statusState->GetState("shuttingdown");

    if (shuttingdown)
    {
        MythUIText *statusText = dynamic_cast<MythUIText *>(shuttingdown->GetChild("status"));

        if (statusText)
        {
            if (m_secondsToShutdown >= 0)
            {
                QString status = tr("Backend will shutdown in %n "
                                    "second(s).", "", m_secondsToShutdown);

                statusText->SetText(status);
            }
            else
                statusText->Reset();
        }
    }
}
示例#20
0
static void DoSetTextFromMap(MythUIType *UItype, QHash<QString, QString> &infoMap)
{
    QList<MythUIType *> *children = UItype->GetAllChildren();

    MythUIText *textType;

    QMutableListIterator<MythUIType *> i(*children);
    while (i.hasNext())
    {
        MythUIType *type = i.next();
        if (!type->IsVisible())
            continue;

        textType = dynamic_cast<MythUIText *> (type);
        if (textType && infoMap.contains(textType->objectName()))
            textType->SetTextFromMap(infoMap);


        MythUIGroup *group = dynamic_cast<MythUIGroup *> (type);
        if (group)
            DoSetTextFromMap(type, infoMap);
    }
}
示例#21
0
bool MythUIStateType::DisplayState(StateType type)
{
    MythUIType *old = m_CurrentState;

    QMap<int, MythUIType *>::Iterator i = m_ObjectsByState.find((int)type);
    if (i != m_ObjectsByState.end())
        m_CurrentState = i.data();
    else
        m_CurrentState = NULL;

    if (m_CurrentState != old)
    {
        if (m_ShowEmpty || m_CurrentState != NULL)
        {
            if (m_CurrentState)
                m_CurrentState->SetVisible(true);
            if (old)
                old->SetVisible(false);
        }
    }

    return (m_CurrentState != NULL);
}
示例#22
0
bool MythUIStateType::DisplayState(const QString &name)
{
    MythUIType *old = m_CurrentState;

    QMap<QString, MythUIType *>::Iterator i = m_ObjectsByName.find(name.lower());
    if (i != m_ObjectsByName.end())
        m_CurrentState = i.data();
    else
        m_CurrentState = NULL;

    if (m_CurrentState != old)
    {
        if (m_ShowEmpty || m_CurrentState != NULL)
        {
            if (m_CurrentState)
                m_CurrentState->SetVisible(true);
            if (old)
                old->SetVisible(false);
        }
    }

    return (m_CurrentState != NULL);
}
示例#23
0
void MythUIStateType::CopyFrom(MythUIType *base)
{
    MythUIStateType *st = dynamic_cast<MythUIStateType *>(base);
    if (!st)
    {
        VERBOSE(VB_IMPORTANT, "ERROR, bad parsing");
        return;
    }

    ClearMaps();

    m_ShowEmpty = st->m_ShowEmpty;

    MythUIType::CopyFrom(base);

    QMap<QString, MythUIType *>::iterator i;
    for (i = st->m_ObjectsByName.begin(); i != st->m_ObjectsByName.end(); ++i)
    {
        MythUIType *other = i.data();
        QString key = i.key();

        MythUIType *newtype = GetChild(other->name());
        AddObject(key, newtype);
        newtype->SetVisible(other->IsVisible());
    }

    QMap<int, MythUIType *>::iterator j;
    for (j = st->m_ObjectsByState.begin(); j != st->m_ObjectsByState.end(); ++j)
    {
        MythUIType *other = j.data();
        int key = j.key();

        MythUIType *newtype = GetChild(other->name());
        AddObject((StateType)key, newtype);
        newtype->SetVisible(other->IsVisible());
    }
}
示例#24
0
void MythUIEditBar::Display(void)
{
    QRect keeparea = QRect();
    QRect cutarea  = QRect();
    MythUIType *position    = GetChild("position");
    MythUIType *keep        = GetChild("keep");
    MythUIType *cut         = GetChild("cut");
    MythUIType *cuttoleft   = GetChild("cuttoleft");
    MythUIType *cuttoright  = GetChild("cuttoright");
    MythUIType *keeptoleft  = GetChild("keeptoleft");
    MythUIType *keeptoright = GetChild("keeptoright");

    if (position)
        position->SetVisible(false);

    if (keep)
    {
        keep->SetVisible(false);
        keeparea = keep->GetArea();
    }

    if (cut)
    {
        cut->SetVisible(false);
        cutarea = cut->GetArea();
    }

    if (cuttoleft)
        cuttoleft->SetVisible(false);

    if (cuttoright)
        cuttoright->SetVisible(false);

    if (keeptoleft)
        keeptoleft->SetVisible(false);

    if (keeptoright)
        keeptoright->SetVisible(false);

    if (position && keeparea.isValid())
    {
        int offset = position->GetArea().width() / 2;
        int newx   = (int)(((float)keeparea.width() * m_editPosition) + 0.5f);
        int newy   = position->GetArea().top();
        position->SetPosition(newx - offset, newy);
        position->SetVisible(true);
    }

    ClearImages();

    if (!m_regions.size())
    {
        if (keep)
            keep->SetVisible(true);

        return;
    }

    MythUIShape *barshape   = dynamic_cast<MythUIShape *>(cut);
    MythUIImage *barimage   = dynamic_cast<MythUIImage *>(cut);
    MythUIShape *leftshape  = dynamic_cast<MythUIShape *>(cuttoleft);
    MythUIImage *leftimage  = dynamic_cast<MythUIImage *>(cuttoleft);
    MythUIShape *rightshape = dynamic_cast<MythUIShape *>(cuttoright);
    MythUIImage *rightimage = dynamic_cast<MythUIImage *>(cuttoright);

    QListIterator<QPair<float, float> > regions(m_regions);

    while (regions.hasNext() && cutarea.isValid())
    {
        QPair<float, float> region = regions.next();
        int left  = (int)((region.first * cutarea.width()) + 0.5f);
        int right = (int)((region.second * cutarea.width()) + 0.5f);

        if (left >= right)
            right = left + 1;

        if (cut)
        {
            AddBar(barshape, barimage, QRect(left, cutarea.top(), right - left,
                                             cutarea.height()));
        }

        if (cuttoleft && (region.second < 1.0f))
            AddMark(leftshape, leftimage, right, true);

        if (cuttoright && (region.first > 0.0f))
            AddMark(rightshape, rightimage, left, false);
    }

    CalcInverseRegions();

    barshape   = dynamic_cast<MythUIShape *>(keep);
    barimage   = dynamic_cast<MythUIImage *>(keep);
    leftshape  = dynamic_cast<MythUIShape *>(keeptoleft);
    leftimage  = dynamic_cast<MythUIImage *>(keeptoleft);
    rightshape = dynamic_cast<MythUIShape *>(keeptoright);
    rightimage = dynamic_cast<MythUIImage *>(keeptoright);

    QListIterator<QPair<float, float> > regions2(m_invregions);

    while (regions2.hasNext() && keeparea.isValid())
    {
        QPair<float, float> region = regions2.next();
        int left  = (int)((region.first * keeparea.width()) + 0.5f);
        int right = (int)((region.second * keeparea.width()) + 0.5f);

        if (left >= right)
            right = left + 1;

        if (keep)
        {
            AddBar(barshape, barimage, QRect(left, keeparea.top(), right - left,
                                             keeparea.height()));
        }

        if (keeptoleft && (region.second < 1.0f))
            AddMark(leftshape, leftimage, right, true);

        if (keeptoright && (region.first > 0.0f))
            AddMark(rightshape, rightimage, left, false);
    }

    if (position)
        position->MoveToTop();
}
示例#25
0
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;
}
示例#26
0
MythUIType *XMLParseBase::ParseUIType(
    const QString &filename,
    QDomElement &element, const QString &type,
    MythUIType *parent,
    MythScreenType *screen,
    bool showWarnings)
{
    QString name = element.attribute("name", "");
    if (name.isEmpty())
    {
        VERBOSE_XML(VB_IMPORTANT, filename, element,
                    LOC_ERR + "This element requires a name");
        return NULL;
    }

    MythUIType *olduitype = NULL;

    // check for name in immediate parent as siblings cannot share names
    if (parent && parent->GetChild(name))
    {
        // if we're the global object store, assume it's just a theme overriding
        // the defaults..
        if (parent == GetGlobalObjectStore())
            return NULL;

        // Reuse the existing child and reparse
        olduitype = parent->GetChild(name);
    }

    MythUIType *uitype = NULL;
    MythUIType *base = NULL;

    QString inherits = element.attribute("from", "");
    if (!inherits.isEmpty())
    {
        if (parent)
            base = parent->GetChild(inherits);

        // might remove this
        if (screen && !base)
            base = screen->GetChild(inherits);

        if (!base)
            base = GetGlobalObjectStore()->GetChild(inherits);

        if (!base)
        {
            VERBOSE_XML(VB_IMPORTANT, filename, element,
                        LOC_ERR + QString(
                            "Couldn't find object '%1' to inherit '%2' from")
                        .arg(inherits).arg(name));
            return NULL;
        }
    }

    if (type == "imagetype")
        uitype = new MythUIImage(parent, name);
    else if (type == "textarea")
        uitype = new MythUIText(parent, name);
    else if (type == "group")
        uitype = new MythUIGroup(parent, name);
    else if (type == "textedit")
        uitype = new MythUITextEdit(parent, name);
    else if (type == "button")
        uitype = new MythUIButton(parent, name);
    else if (type == "buttonlist2" || type == "buttonlist")
        uitype = new MythUIButtonList(parent, name);
    else if (type == "buttontree")
        uitype = new MythUIButtonTree(parent, name);
    else if (type == "spinbox")
        uitype = new MythUISpinBox(parent, name);
    else if (type == "checkbox")
        uitype = new MythUICheckBox(parent, name);
    else if (type == "statetype")
        uitype = new MythUIStateType(parent, name);
    else if (type == "clock")
        uitype = new MythUIClock(parent, name);
    else if (type == "progressbar")
        uitype = new MythUIProgressBar(parent, name);
    else if (type == "webbrowser")
        uitype = new MythUIWebBrowser(parent, name);
    else if (type == "guidegrid")
        uitype = new MythUIGuideGrid(parent, name);
    else if (type == "shape")
        uitype = new MythUIShape(parent, name);
    else if (type == "editbar")
        uitype = new MythUIEditBar(parent, name);
    else if (type == "video")
        uitype = new MythUIVideo(parent, name);
    else if (type == "window" && parent == GetGlobalObjectStore())
        uitype = new MythScreenType(parent, name);
    else
    {
        VERBOSE_XML(VB_IMPORTANT, filename, element,
                    LOC_ERR + "Unknown widget type.");
        return NULL;
    }

    if (!uitype)
    {
        VERBOSE_XML(VB_IMPORTANT, filename, element,
                    LOC_ERR + "Failed to instantiate widget type.");
        return NULL;
    }

    if (olduitype)
    {
        if (typeid(*olduitype) != typeid(*uitype))
        {
            VERBOSE_XML(VB_IMPORTANT, filename, element, LOC_ERR +
                        QString("Duplicate name: '%1' in parent '%2'")
                        .arg(name).arg(parent->objectName()));
            parent->DeleteChild(olduitype);
        }
        else
        {
            parent->DeleteChild(uitype);
            uitype = olduitype;
        }
    }

    if (base)
    {
        if (typeid(*base) != typeid(*uitype))
        {
            VERBOSE_XML(VB_IMPORTANT, filename, element, LOC_ERR +
                        QString("Type of new widget '%1' doesn't "
                                "match old '%2'")
                        .arg(name).arg(inherits));
            parent->DeleteChild(uitype);
            return NULL;
        }
        else
            uitype->CopyFrom(base);
    }

    for (QDomNode child = element.firstChild(); !child.isNull();
         child = child.nextSibling())
    {
        QDomElement info = child.toElement();
        if (!info.isNull())
        {
            if (uitype->ParseElement(filename, info, showWarnings))
            {
            }
            else if (info.tagName() == "font" || info.tagName() == "fontdef")
            {
                bool global = (GetGlobalObjectStore() == parent);
                MythFontProperties *font = MythFontProperties::ParseFromXml(
                    filename, info, parent, global, showWarnings);

                if (!global && font)
                {
                    QString name = info.attribute("name");
                    uitype->AddFont(name, font);
                }

                delete font;
            }
            else if (info.tagName() == "imagetype" ||
                     info.tagName() == "textarea" ||
                     info.tagName() == "group" ||
                     info.tagName() == "textedit" ||
                     info.tagName() == "button" ||
                     info.tagName() == "buttonlist" ||
                     info.tagName() == "buttonlist2" ||
                     info.tagName() == "buttontree" ||
                     info.tagName() == "spinbox" ||
                     info.tagName() == "checkbox" ||
                     info.tagName() == "statetype" ||
                     info.tagName() == "clock" ||
                     info.tagName() == "progressbar" ||
                     info.tagName() == "webbrowser" ||
                     info.tagName() == "guidegrid" ||
                     info.tagName() == "shape" ||
                     info.tagName() == "editbar" ||
                     info.tagName() == "video")
            {
                ParseUIType(filename, info, info.tagName(),
                            uitype, screen, showWarnings);
            }
            else
            {
                VERBOSE_XML(VB_IMPORTANT, filename, info,
                            LOC_ERR + "Unknown widget type.");
            }
        }
    }

    uitype->Finalize();
    return uitype;
}
示例#27
0
bool MythScreenType::NextPrevWidgetFocus(bool up)
{
    if (!m_CurrentFocusWidget || m_FocusWidgetList.isEmpty())
        return SetFocusWidget(NULL);

    bool reachedCurrent = false;
    bool looped = false;

    QMap<int, MythUIType *>::iterator it = m_FocusWidgetList.begin();
    MythUIType *current;

    // There is probably a more efficient way to do this, but the list
    // is never going to be that big so it will do for now
    if (up)
    {
        while (it != m_FocusWidgetList.end())
        {
            current = *it;

            if ((looped || reachedCurrent) &&
                current->IsVisible() && current->IsEnabled())
                return SetFocusWidget(current);

            if (current == m_CurrentFocusWidget)
                reachedCurrent = true;

            ++it;

            if (it == m_FocusWidgetList.end())
            {
                if (looped)
                    return false;
                else
                {
                    looped = true;
                    it = m_FocusWidgetList.begin();
                }
            }
        }
    }
    else
    {
        it = m_FocusWidgetList.end() - 1;
        while (it != m_FocusWidgetList.begin() - 1)
        {
            current = *it;

            if ((looped || reachedCurrent) &&
                current->IsVisible() && current->IsEnabled())
                return SetFocusWidget(current);

            if (current == m_CurrentFocusWidget)
                reachedCurrent = true;

            --it;

            if (it == m_FocusWidgetList.begin() - 1)
            {
                if (looped)
                    return false;
                else
                {
                    looped = true;
                    it = m_FocusWidgetList.end() - 1;
                }
            }
        }
    }

    return false;
}
示例#28
0
/** \brief keyboard/LIRC event handler.
 *
 *  This translates key presses through the "Main Menu" context into MythTV
 *  actions and then handles them as appropriate.
 */
bool MythThemedMenu::keyPressEvent(QKeyEvent *event)
{
    if (m_ignorekeys)
        return false;

    m_ignorekeys = true;

    MythUIType *type = GetFocusWidget();
    if (type && type->keyPressEvent(event))
    {
        m_ignorekeys = false;
        return true;
    }

    QStringList actions;
    bool handled = false;

    handled = GetMythMainWindow()->TranslateKeyPress("Main Menu", event,
                                                     actions);

    for (int i = 0; i < actions.size() && !handled; i++)
    {
        QString action = actions[i];
        handled = true;

        if (action == "ESCAPE" || action == "EXIT" || action == "EXITPROMPT")
        {
            bool    callbacks  = m_state->m_callback;
            bool    lastScreen = (GetMythMainWindow()->GetMainStack()
                                                     ->TotalScreens() == 1);
            QString menuaction = "UPMENU";
            QString selExit    = "EXITING_APP_PROMPT";
            if (action == "EXIT")
                selExit = "EXITING_APP";

            if (!m_allocedstate)
                handleAction(menuaction);
            else if (m_state->m_killable)
            {
                m_wantpop = true;
                if (callbacks)
                {
                    QString sel = "EXITING_MENU";
                    m_state->m_callback(m_state->m_callbackdata, sel);
                }

                if (lastScreen)
                {
                    if (callbacks)
                        m_state->m_callback(m_state->m_callbackdata, selExit);
                    QCoreApplication::exit();
                }
            }
            else if ((action == "EXIT" || action == "EXITPROMPT" ||
                      (action == "ESCAPE" &&
                       (QCoreApplication::applicationName() ==
                        MYTH_APPNAME_MYTHTV_SETUP))) && lastScreen)
            {
                if (callbacks)
                    m_state->m_callback(m_state->m_callbackdata, selExit);
                else
                {
                    QCoreApplication::exit();
                    m_wantpop = true;
                }
            }
        }
        else if (action == "HELP")
        {
            aboutScreen();
        }
        else if (action == "EJECT")
        {
            handleAction(action);
        }
        else
            handled = false;
    }

    if (!handled && MythScreenType::keyPressEvent(event))
        handled = true;

    m_ignorekeys = false;

    if (m_wantpop)
        m_ScreenStack->PopScreen();

    return handled;
}
示例#29
0
bool XMLParseBase::doLoad(const QString &windowname,
                          MythUIType *parent,
                          const QString &filename,
                          bool onlywindows,
                          bool showWarnings)
{
    QDomDocument doc;
    QFile f(filename);

    if (!f.open(QIODevice::ReadOnly))
        return false;

    QString errorMsg;
    int errorLine = 0;
    int errorColumn = 0;

    if (!doc.setContent(&f, false, &errorMsg, &errorLine, &errorColumn))
    {
        LOG(VB_GENERAL, LOG_ERR, LOC +
            QString("Location: '%1' @ %2 column: %3"
                    "\n\t\t\tError: %4")
                .arg(qPrintable(filename)).arg(errorLine).arg(errorColumn)
                .arg(qPrintable(errorMsg)));
        f.close();
        return false;
    }

    f.close();

    QDomElement docElem = doc.documentElement();
    QDomNode n = docElem.firstChild();
    while (!n.isNull())
    {
        QDomElement e = n.toElement();
        if (!e.isNull())
        {
            if (e.tagName() == "include")
            {
                QString include = getFirstText(e);

                if (!include.isEmpty())
                     LoadBaseTheme(include);
            }

            if (onlywindows && e.tagName() == "window")
            {
                QString name = e.attribute("name", "");
                QString include = e.attribute("include", "");
                if (name.isEmpty())
                {
                    VERBOSE_XML(VB_GENERAL, LOG_ERR, filename, e,
                                "Window needs a name");
                    return false;
                }

                if (!include.isEmpty())
                    LoadBaseTheme(include);

                if (name == windowname)
                {
                    ParseChildren(filename, e, parent, showWarnings);
                    return true;
                }
            }

            if (!onlywindows)
            {
                QString type = e.tagName();
                if (type == "font" || type == "fontdef")
                {
                    bool global = (GetGlobalObjectStore() == parent);
                    MythFontProperties *font = MythFontProperties::ParseFromXml(
                        filename, e, parent, global, showWarnings);

                    if (!global && font)
                    {
                        QString name = e.attribute("name");
                        parent->AddFont(name, font);
                    }
                    delete font;
                }
                else if (type == "imagetype" ||
                         type == "textarea" ||
                         type == "group" ||
                         type == "textedit" ||
                         type == "button" ||
                         type == "buttonlist" ||
                         type == "buttonlist2" ||
                         type == "buttontree" ||
                         type == "spinbox" ||
                         type == "checkbox" ||
                         type == "statetype" ||
                         type == "window" ||
                         type == "clock" ||
                         type == "progressbar" ||
                         type == "scrollbar" ||
                         type == "webbrowser" ||
                         type == "guidegrid" ||
                         type == "shape" ||
                         type == "editbar" ||
                         type == "video")
                {

                    // We don't want widgets in base.xml
                    // depending on each other so ignore dependsMap
                    QMap<QString, QString> dependsMap;
                    MythUIType *uitype = NULL;
                    uitype = ParseUIType(filename, e, type, parent,
                                         NULL, showWarnings, dependsMap);
                    if (uitype)
                        uitype->ConnectDependants(true);
                }
                else
                {
                    VERBOSE_XML(VB_GENERAL, LOG_ERR, filename, e,
                                "Unknown widget type");
                }
            }
        }
        n = n.nextSibling();
    }
    if (onlywindows)
        return false;
    return true;
}
示例#30
0
void MythUIProgressBar::CalculatePosition(void)
{
    MythUIType *progressType = GetChild("progressimage");

    if (!progressType)
    {
        LOG(VB_GENERAL, LOG_ERR, "Progress image doesn't exist");
        return;
    }

    progressType->SetVisible(false);

    int total = m_total - m_start;
    int current = m_current - m_start;
    float percentage = 0.0;

    if (total <= 0 || current <= 0 || current > total)
        return;

    percentage = (float)current / (float)total;
    progressType->SetVisible(true);

    QRect fillArea = progressType->GetArea();

    int height = fillArea.height();
    int width = fillArea.width();
    int x = fillArea.x();
    int y = fillArea.y();

    switch (m_effect)
    {
        case EffectReveal :

            if (m_layout == LayoutHorizontal)
            {
                width = (int)((float)fillArea.width() * percentage);
            }
            else
            {
                height = (int)((float)fillArea.height() * percentage);
            }

            break;
        case EffectSlide :

            if (m_layout == LayoutHorizontal)
            {
                int newwidth = (int)((float)fillArea.width() * percentage);
                x = width - newwidth;
                width = newwidth;
            }
            else
            {
                int newheight = (int)((float)fillArea.height() * percentage);
                y = height - newheight;
                height = newheight;
            }

            break;
        case EffectAnimate :
            // Not implemented yet
            break;
    }

    MythUIImage *progressImage = dynamic_cast<MythUIImage *>(progressType);
    MythUIShape *progressShape = dynamic_cast<MythUIShape *>(progressType);

    if (width <= 0)
        width = 1;

    if (height <= 0)
        height = 1;

    if (progressImage)
        progressImage->SetCropRect(x, y, width, height);
    else if (progressShape)
        progressShape->SetCropRect(x, y, width, height);

    SetRedraw();
}