<commit_before>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "mcomboboxbutton.h"

#include "mimagewidget.h"
#include "mlabel.h"
#include "mprogressindicator.h"
#include "mlayout.h"
#include "mgridlayoutpolicy.h"

MComboBoxButton::MComboBoxButton(QGraphicsItem *parent)
    : MListItem(parent),
      icon(0),
      title(0),
      subtitle(0),
      indicator(0),
      progress(0),
      flags(TitleShown)
{
    memset(policy, 0, sizeof(policy));

    setLayout(new MLayout(this));
    layout()->setContentsMargins(0, 0, 0, 0);
    updateLayout();
}

void MComboBoxButton::updateLayout()
{
    static_cast<MLayout*>(layout())->setPolicy(layoutPolicy(flags));
}

MGridLayoutPolicy* MComboBoxButton::layoutPolicy(int f)
{
    if (!policy[f]) {
        MLayout* mlayout = static_cast<MLayout*>(layout());
        if ((f&IconShown) && (f&TitleShown) && !(f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(iconWidget(), 0, 0, 3, 1);
            policy[f]->addItem(titleWidget(), 0, 1);
            policy[f]->addItem(subtitleWidget(), 1, 1);
            policy[f]->addItem(indicatorWidget(), 0, 2, 3, 1, Qt::AlignVCenter);
            policy[f]->addItem(new QGraphicsWidget(this), 2, 1);

        } else if (!(f&IconShown) && (f&TitleShown) && !(f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(titleWidget(), 0, 0);
            policy[f]->addItem(subtitleWidget(), 1, 0);
            policy[f]->addItem(indicatorWidget(), 0, 1, 3, 1, Qt::AlignVCenter);
            policy[f]->addItem(new QGraphicsWidget(this), 2, 0);

        } else if ((f&IconShown) && (f&TitleShown) && (f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(iconWidget(), 0, 0, 3, 1);
            policy[f]->addItem(titleWidget(), 0, 1);
            policy[f]->addItem(progressWidget(), 1, 1);
            policy[f]->addItem(indicatorWidget(), 0, 2, 3, 1, Qt::AlignVCenter);
            policy[f]->addItem(new QGraphicsWidget(this), 2, 1);

        } else if (!(f&IconShown) && (f&TitleShown) && (f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(titleWidget(), 0, 0);
            policy[f]->addItem(progressWidget(), 1, 0);
            policy[f]->addItem(indicatorWidget(), 0, 1, 3, 1, Qt::AlignVCenter);
            policy[f]->addItem(new QGraphicsWidget(this), 2, 0);

        } else if (!(f&TitleShown) && !(f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(subtitleWidget(), 0, 0);
            policy[f]->addItem(indicatorWidget(), 0, 1, 2, 1, Qt::AlignVCenter);

        } else if (!(f&TitleShown) && (f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(progressWidget(), 0, 0);
            policy[f]->addItem(indicatorWidget(), 0, 1, 2, 1, Qt::AlignVCenter);
       }
    }
    return policy[f];
}

void MComboBoxButton::setProgressIndicatorVisible(bool visible)
{
    flags = visible ? flags | ProgressShown : flags & ~ProgressShown;
    updateLayout();
}

void MComboBoxButton::setIconVisible(bool visible)
{<commit_msg>Changes: Vertical centered combobox label.<commit_after>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "mcomboboxbutton.h"

#include "mimagewidget.h"
#include "mlabel.h"
#include "mprogressindicator.h"
#include "mlayout.h"
#include "mgridlayoutpolicy.h"

MComboBoxButton::MComboBoxButton(QGraphicsItem *parent)
    : MListItem(parent),
      icon(0),
      title(0),
      subtitle(0),
      indicator(0),
      progress(0),
      flags(TitleShown)
{
    memset(policy, 0, sizeof(policy));

    setLayout(new MLayout(this));
    layout()->setContentsMargins(0, 0, 0, 0);
    updateLayout();
}

void MComboBoxButton::updateLayout()
{
    static_cast<MLayout*>(layout())->setPolicy(layoutPolicy(flags));
}

MGridLayoutPolicy* MComboBoxButton::layoutPolicy(int f)
{
    if (!policy[f]) {
        MLayout* mlayout = static_cast<MLayout*>(layout());
        if ((f&IconShown) && (f&TitleShown) && !(f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(iconWidget(), 0, 0, 3, 1);
            policy[f]->addItem(titleWidget(), 0, 1);
            policy[f]->addItem(subtitleWidget(), 1, 1);
            policy[f]->addItem(indicatorWidget(), 0, 2, 3, 1, Qt::AlignVCenter);
            policy[f]->addItem(new QGraphicsWidget(this), 2, 1);

        } else if (!(f&IconShown) && (f&TitleShown) && !(f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(titleWidget(), 0, 0);
            policy[f]->addItem(subtitleWidget(), 1, 0);
            policy[f]->addItem(indicatorWidget(), 0, 1, 3, 1, Qt::AlignVCenter);
            policy[f]->addItem(new QGraphicsWidget(this), 2, 0);

        } else if ((f&IconShown) && (f&TitleShown) && (f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(iconWidget(), 0, 0, 3, 1);
            policy[f]->addItem(titleWidget(), 0, 1);
            policy[f]->addItem(progressWidget(), 1, 1);
            policy[f]->addItem(indicatorWidget(), 0, 2, 3, 1, Qt::AlignVCenter);
            policy[f]->addItem(new QGraphicsWidget(this), 2, 1);

        } else if (!(f&IconShown) && (f&TitleShown) && (f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(titleWidget(), 0, 0);
            policy[f]->addItem(progressWidget(), 1, 0);
            policy[f]->addItem(indicatorWidget(), 0, 1, 3, 1, Qt::AlignVCenter);
            policy[f]->addItem(new QGraphicsWidget(this), 2, 0);

        } else if (!(f&TitleShown) && !(f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(subtitleWidget(), 0, 0, Qt::AlignVCenter);
            policy[f]->addItem(indicatorWidget(), 0, 1, Qt::AlignVCenter);

        } else if (!(f&TitleShown) && (f&ProgressShown)) {
            policy[f] = new MGridLayoutPolicy(mlayout);
            policy[f]->addItem(progressWidget(), 0, 0);
            policy[f]->addItem(indicatorWidget(), 0, 1, 2, 1, Qt::AlignVCenter);
       }
    }
    return policy[f];
}

void MComboBoxButton::setProgressIndicatorVisible(bool visible)
{
    flags = visible ? flags | ProgressShown : flags & ~ProgressShown;
    updateLayout();
}

void MComboBoxButton::setIconVisible(bool visible)
{
{'fraction_non_alphanumeric': 0.1954227590591227, 'fraction_numerical': 0.019071837253655435, 'mean_word_length': 3.502575844304522, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6799686', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2394, 'n_words': 553}