示例#1
0
Q_GUI_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint,
                                 const QSize &minSize, const QSize &maxSize,
                                 const QSizePolicy &sizePolicy)
{
    QSize s(0, 0);

    if (sizePolicy.horizontalPolicy() != QSizePolicy::Ignored) {
        if (sizePolicy.horizontalPolicy() & QSizePolicy::ShrinkFlag)
            s.setWidth(minSizeHint.width());
        else
            s.setWidth(qMax(sizeHint.width(), minSizeHint.width()));
    }

    if (sizePolicy.verticalPolicy() != QSizePolicy::Ignored) {
        if (sizePolicy.verticalPolicy() & QSizePolicy::ShrinkFlag) {
            s.setHeight(minSizeHint.height());
        } else {
            s.setHeight(qMax(sizeHint.height(), minSizeHint.height()));
        }
    }

    s = s.boundedTo(maxSize);
    if (minSize.width() > 0)
        s.setWidth(minSize.width());
    if (minSize.height() > 0)
        s.setHeight(minSize.height());

    return s.expandedTo(QSize(0,0));
}
示例#2
0
QString KPropertySizePolicyDelegate::valueToString(const QVariant& value, const QLocale &locale) const
{
    const QSizePolicy sp(value.value<QSizePolicy>());
    if (locale.language() == QLocale::C) {
        return QString::fromLatin1("%1, %2, %3, %4")
                .arg(KPropertyUtils::keyForEnumValue("SizePolicy", sp.horizontalPolicy()))
                .arg(KPropertyUtils::keyForEnumValue("SizePolicy", sp.verticalPolicy()))
                .arg(sp.horizontalStretch())
                .arg(sp.verticalStretch());
    }
    return QObject::tr("%1, %2, %3, %4", "Size Policy")
        .arg(s_sizePolicyListData->nameForPolicy(sp.horizontalPolicy()))
        .arg(s_sizePolicyListData->nameForPolicy(sp.verticalPolicy()))
        .arg(locale.toString(sp.horizontalStretch()))
        .arg(locale.toString(sp.verticalStretch()));
}
示例#3
0
 E2MemoryBar(QWidget* par) : QWidget(par), m_percent(0) {
     QSizePolicy sp = sizePolicy();
     setSizePolicy(QSizePolicy(QSizePolicy::Expanding, sp.verticalPolicy()));
     QFontMetrics fm(font());
     int h = fm.height() + 2*2+2;
     setFixedHeight(h);
 }
示例#4
0
void SizePolicyComposedProperty::setValue(Property *property,
    const QVariant &value, bool rememberOldValue)
{
    const QSizePolicy sp( value.value<QSizePolicy>() );
    property->child("hor_policy")->setValue(sp.horizontalPolicy(), rememberOldValue, false);
    property->child("vert_policy")->setValue(sp.verticalPolicy(), rememberOldValue, false);
    property->child("hor_stretch")->setValue(sp.horizontalStretch(), rememberOldValue, false);
    property->child("vert_stretch")->setValue(sp.verticalStretch(), rememberOldValue, false);
}
示例#5
0
/*!
    \reimp
*/
void QWidgetItem::setGeometry(const QRect &rect)
{
    if (isEmpty())
        return;

    QRect r = !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect)
            ? fromLayoutItemRect(wid->d_func(), rect)
            : rect;
    const QSize widgetRectSurplus = r.size() - rect.size(); 

    /* 
       For historical reasons, this code is done using widget rect 
       coordinates, not layout item rect coordinates. However, 
       QWidgetItem's sizeHint(), maximumSize(), and heightForWidth() 
       all work in terms of layout item rect coordinates, so we have to 
       add or subtract widgetRectSurplus here and there. The code could 
       be much simpler if we did everything using layout item rect 
       coordinates and did the conversion right before the call to 
       QWidget::setGeometry(). 
     */ 

    QSize s = r.size().boundedTo(maximumSize() + widgetRectSurplus);  
    int x = r.x();
    int y = r.y();
    if (align & (Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask)) {
        QSize pref(sizeHint());
        QSizePolicy sp = wid->sizePolicy();
        if (sp.horizontalPolicy() == QSizePolicy::Ignored)
            pref.setWidth(wid->sizeHint().expandedTo(wid->minimumSize()).width());
        if (sp.verticalPolicy() == QSizePolicy::Ignored)
            pref.setHeight(wid->sizeHint().expandedTo(wid->minimumSize()).height());
        pref += widgetRectSurplus;
        if (align & Qt::AlignHorizontal_Mask)
            s.setWidth(qMin(s.width(), pref.width()));
        if (align & Qt::AlignVertical_Mask) {
            if (hasHeightForWidth())
                s.setHeight(qMin(s.height(), 
                                 heightForWidth(s.width() - widgetRectSurplus.width()) 
                                 + widgetRectSurplus.height()));
            else
                s.setHeight(qMin(s.height(), pref.height()));
        }
    }
    Qt::Alignment alignHoriz = QStyle::visualAlignment(wid->layoutDirection(), align);
    if (alignHoriz & Qt::AlignRight)
        x = x + (r.width() - s.width());
    else if (!(alignHoriz & Qt::AlignLeft))
        x = x + (r.width() - s.width()) / 2;

    if (align & Qt::AlignBottom)
        y = y + (r.height() - s.height());
    else if (!(align & Qt::AlignTop))
        y = y + (r.height() - s.height()) / 2;

    wid->setGeometry(x, y, s.width(), s.height());
}
示例#6
0
QString SizePolicyDelegate::displayText( const QVariant& value ) const
{
    const QSizePolicy sp(value.value<QSizePolicy>());

    return QString::fromLatin1(SIZEPOLICY_MASK)
        .arg(s_sizePolicyListData->nameForPolicy(sp.horizontalPolicy()))
        .arg(s_sizePolicyListData->nameForPolicy(sp.verticalPolicy()))
        .arg(sp.horizontalStretch())
        .arg(sp.verticalStretch());
}
示例#7
0
WBWebView *WBTabWidget::newTab(bool makeCurrent)
{
    // line edit
    WBUrlLineEdit *urlLineEdit = new WBUrlLineEdit;

    QSizePolicy urlPolicy = urlLineEdit->sizePolicy();
    urlLineEdit->setSizePolicy(QSizePolicy::MinimumExpanding, urlPolicy.verticalPolicy());

    QLineEdit *lineEdit = urlLineEdit->lineEdit();
    QSizePolicy policy = lineEdit->sizePolicy();
    lineEdit->setSizePolicy(QSizePolicy::MinimumExpanding, policy.verticalPolicy());

    if (!mLineEditCompleter && count() > 0)
    {
        WBHistoryCompletionModel *completionModel = new WBHistoryCompletionModel(this);
        completionModel->setSourceModel(WBBrowserWindow::historyManager()->historyFilterModel());
        mLineEditCompleter = new QCompleter(completionModel, this);
        // Should this be in Qt by default?
        QAbstractItemView *popup = mLineEditCompleter->popup();
        QListView *listView = qobject_cast<QListView*>(popup);
        if (listView)
            listView->setUniformItemSizes(true);
    }

    lineEdit->setCompleter(mLineEditCompleter);
    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(lineEditReturnPressed()));
    mLineEdits->addWidget(urlLineEdit);
    mLineEdits->setSizePolicy(lineEdit->sizePolicy());

    // optimization to delay creating the more expensive WebView, history, etc
    if (count() == 0)
    {
        QWidget *emptyWidget = new QWidget;
        QPalette p = emptyWidget->palette();
        p.setColor(QPalette::Window, palette().color(QPalette::Base));
        emptyWidget->setPalette(p);
        emptyWidget->setAutoFillBackground(true);
        disconnect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
        addTab(emptyWidget, tr("(Untitled)"));
        connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
        return 0;
    }
/*
    SearchLineEdit is an enhanced QLineEdit
    - A Search icon on the left with optional menu
    - When there is no text and doesn't have focus an "inactive text" is displayed
    - When there is text a clear button is displayed on the right hand side
 */
SearchLineEdit::SearchLineEdit(QWidget *parent) : ExLineEdit(parent),
    m_searchButton(new SearchButton(this))
{
    connect(lineEdit(), SIGNAL(textChanged(QString)),
            this, SIGNAL(textChanged(QString)));
    setLeftWidget(m_searchButton);
    m_inactiveText = tr("Search");

    QSizePolicy policy = sizePolicy();
    setSizePolicy(QSizePolicy::Preferred, policy.verticalPolicy());
}
示例#9
0
QString LayoutDumper::toString(const QSizePolicy& policy)
{
    QString result = QString("(%1, %2)")
            .arg(toString(policy.horizontalPolicy()))
            .arg(toString(policy.verticalPolicy()));
    if (policy.hasHeightForWidth()) {
        result += " [hasHeightForWidth]";
    }
    if (policy.hasWidthForHeight()) {
        result += " [hasWidthForHeight]";
    }
    return result;
}
示例#10
0
static QString sizePolicyToString(const QSizePolicy &p)
{
    QString rc; {
        QTextStream str(&rc);
        str << "Control=" << p.controlType() << " expdirs=" << p.expandingDirections()
            << " hasHeightForWidth=" << p.hasHeightForWidth()
            << " H: Policy=" << p.horizontalPolicy()
            << " stretch=" << p.horizontalStretch()
            << " V: Policy=" << p.verticalPolicy()
            << " stretch=" << p.verticalStretch();
    }
    return rc;
}
示例#11
0
/*
    SearchLineEdit is an enhanced QLineEdit
    - A Search icon on the left with optional menu
    - When there is no text and doesn't have focus an "inactive text" is displayed
    - When there is text a clear button is displayed on the right hand side
 */
WBSearchLineEdit::WBSearchLineEdit(QWidget *parent)
    : WBExLineEdit(parent),
    mSearchButton(new WBSearchButton(this))
{
    connect(lineEdit(), SIGNAL(textChanged(const QString &)),
            this, SIGNAL(textChanged(const QString &)));
    setLeftWidget(mSearchButton);
    mInactiveText = tr("Search");

    setMinimumWidth(150);

    QSizePolicy policy = sizePolicy();
    setSizePolicy(QSizePolicy::Maximum, policy.verticalPolicy());
}
示例#12
0
SearchLineEdit::SearchLineEdit(QWidget *parent)
    : ExLineEdit(parent), searchButton(new SearchButton(this)) {
    connect(m_lineEdit, SIGNAL(textChanged(const QString &)), SIGNAL(textChanged(const QString &)));
    connect(m_lineEdit, SIGNAL(textEdited(const QString &)), SIGNAL(textEdited(const QString &)));
    connect(m_lineEdit, SIGNAL(returnPressed()), SLOT(returnPressed()));

    setLeftWidget(searchButton);
    inactiveText = tr("Search");

    QSizePolicy policy = sizePolicy();
    setSizePolicy(QSizePolicy::Preferred, policy.verticalPolicy());

    // completion
    autoComplete = new AutoComplete(this, m_lineEdit);
    connect(autoComplete, SIGNAL(suggestionAccepted(Suggestion *)),
            SIGNAL(suggestionAccepted(Suggestion *)));
}
示例#13
0
/*
    SearchLineEdit is an enhanced QLineEdit
    - A Search icon on the left with optional menu
    - When there is no text and doesn't have focus an "inactive text" is displayed
    - When there is text a clear button is displayed on the right hand side
 */
SearchLineEdit::SearchLineEdit(QWidget *parent)
    : LineEdit(parent)
    , m_searchButton(new SearchButton(this))
{
    addWidget(m_searchButton, LeftSide);
    m_inactiveText = tr("Search");

    QSizePolicy policy = sizePolicy();
    setSizePolicy(QSizePolicy::Preferred, policy.verticalPolicy());

    // clear button on the right
    ClearButton *m_clearButton = new ClearButton(this);
    connect(m_clearButton, SIGNAL(clicked()),
            this, SLOT(clear()));
    connect(this, SIGNAL(textChanged(const QString&)),
            m_clearButton, SLOT(textChanged(const QString&)));
    addWidget(m_clearButton, RightSide);
    m_clearButton->hide();
}
示例#14
0
void AnimatedFrame::updateSizeHints()
{
	if(widget_) {
		QSize hint = widget_->minimumSizeHint();
		if(!hint.isValid())
			hint = widget_->sizeHint();

		QSizePolicy policy = widget_->sizePolicy();

		if(edge_ == kNorth || edge_ == kSouth) {
			int minimum = widget_->minimumHeight();
			int maximum = widget_->maximumHeight();

			minimumSizeHint_.setWidth(0);
			minimumSizeHint_.setHeight(qBound(minimum, hint.height(), maximum));

			setSizePolicy(policy.horizontalPolicy(), QSizePolicy::Maximum);
		}
		else {
			int minimum = widget_->minimumWidth();
			int maximum = widget_->maximumWidth();

			minimumSizeHint_.setWidth(qBound(minimum, hint.width(), maximum));
			minimumSizeHint_.setHeight(0);

			setSizePolicy(QSizePolicy::Maximum, policy.verticalPolicy());
		}

		setMinimumSize(widget_->minimumSize());
		setMaximumSize(widget_->maximumSize());
	}
	else {
		minimumSizeHint_ = QSize();
		setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
	}

	sizeHint_ = minimumSizeHint_;

	if(isUnfolded())
		updateGeometry();
}
示例#15
0
Q_GUI_EXPORT QSize qSmartMaxSize(const QSize &sizeHint,
                                 const QSize &minSize, const QSize &maxSize,
                                 const QSizePolicy &sizePolicy, Qt::Alignment align)
{
    if (align & Qt::AlignHorizontal_Mask && align & Qt::AlignVertical_Mask)
        return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
    QSize s = maxSize;
    QSize hint = sizeHint.expandedTo(minSize);
    if (s.width() == QWIDGETSIZE_MAX && !(align & Qt::AlignHorizontal_Mask))
        if (!(sizePolicy.horizontalPolicy() & QSizePolicy::GrowFlag))
            s.setWidth(hint.width());

    if (s.height() == QWIDGETSIZE_MAX && !(align & Qt::AlignVertical_Mask))
        if (!(sizePolicy.verticalPolicy() & QSizePolicy::GrowFlag))
            s.setHeight(hint.height());

    if (align & Qt::AlignHorizontal_Mask)
        s.setWidth(QLAYOUTSIZE_MAX);
    if (align & Qt::AlignVertical_Mask)
        s.setHeight(QLAYOUTSIZE_MAX);
    return s;
}
示例#16
0
osg::GraphicsContext::Traits* GraphicsWindowQt::createTraits( const QGLWidget* widget )
{
    osg::GraphicsContext::Traits *traits = new osg::GraphicsContext::Traits;

    qglFormat2traits( widget->format(), traits );

    QRect r = widget->geometry();
    traits->x = r.x();
    traits->y = r.y();
    traits->width = r.width();
    traits->height = r.height();

    traits->windowName = widget->windowTitle().toLocal8Bit().data();
    Qt::WindowFlags f = widget->windowFlags();
    traits->windowDecoration = ( f & Qt::WindowTitleHint ) &&
                            ( f & Qt::WindowMinMaxButtonsHint ) &&
                            ( f & Qt::WindowSystemMenuHint );
    QSizePolicy sp = widget->sizePolicy();
    traits->supportsResize = sp.horizontalPolicy() != QSizePolicy::Fixed ||
                            sp.verticalPolicy() != QSizePolicy::Fixed;

    return traits;
}
示例#17
0
WBTabWidget::WBTabWidget(QWidget *parent)
    : QTabWidget(parent)
    , mRecentlyClosedTabsMenu(0)
    , mLineEditCompleter(0)
    , mLineEdits(0)
    , mTabBar(new WBTabBar(this))
{
    setObjectName("ubWebBrowserTabWidget");
    mAddTabIcon = QPixmap(":/images/toolbar/plusBlack.png");

    setElideMode(Qt::ElideRight);

    connect(mTabBar, SIGNAL(newTab()), this, SLOT(newTab()));
    connect(mTabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
    connect(mTabBar, SIGNAL(cloneTab(int)), this, SLOT(cloneTab(int)));
    connect(mTabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(closeOtherTabs(int)));
    connect(mTabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
    connect(mTabBar, SIGNAL(reloadAllTabs()), this, SLOT(reloadAllTabs()));
    connect(mTabBar, SIGNAL(tabMoved(int, int)), this, SLOT(moveTab(int, int)));
    setTabBar(mTabBar);
    setDocumentMode(false);

    mRecentlyClosedTabsMenu = new QMenu(this);
    connect(mRecentlyClosedTabsMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowRecentTabsMenu()));
    connect(mRecentlyClosedTabsMenu, SIGNAL(triggered(QAction *)), this, SLOT(aboutToShowRecentTriggeredAction(QAction *)));
    mRecentlyClosedTabsAction = new QAction(tr("Recently Closed Tabs"), this);
    mRecentlyClosedTabsAction->setMenu(mRecentlyClosedTabsMenu);
    mRecentlyClosedTabsAction->setEnabled(false);

    connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));

    mLineEdits = new QStackedWidget(this);
    mLineEdits->setMinimumWidth(200);
    QSizePolicy spolicy = mLineEdits->sizePolicy();
    mLineEdits->setSizePolicy(QSizePolicy::Maximum, spolicy.verticalPolicy());
}
示例#18
0
/*
    SearchLineEdit is an enhanced QLineEdit
    - A Search icon on the left with optional menu
    - When there is no text and doesn't have focus an "inactive text" is displayed
    - When there is text a clear button is displayed on the right hand side
 */
SearchLineEdit::SearchLineEdit(QWidget *parent)
    : LineEdit(parent)
    , m_searchButton(0)
{
    setUpdatesEnabled(false);
    m_searchButton = new SearchButton(this);
    updateGeometries();
    addWidget(m_searchButton, LeftSide);
    setInactiveText(tr("Search"));

    QSizePolicy policy = sizePolicy();
    setSizePolicy(QSizePolicy::Preferred, policy.verticalPolicy());

    // clear button on the right
    ClearButton *m_clearButton = new ClearButton(this);
    connect(m_clearButton, SIGNAL(clicked()),
            this, SLOT(clear()));
    connect(this, SIGNAL(textChanged(const QString&)),
            m_clearButton, SLOT(textChanged(const QString&)));
    addWidget(m_clearButton, RightSide);
    m_clearButton->hide();
    updateTextMargins();
    setUpdatesEnabled(true);
}
示例#19
0
QDebug operator<<(QDebug dbg, const QSizePolicy &p)
{
    dbg.nospace() << "QSizePolicy(horizontalPolicy = " << p.horizontalPolicy()
                  << ", verticalPolicy = " << p.verticalPolicy() << ')';
    return dbg.space();
}
示例#20
0
// Apply a simple variant type to a DOM property
static bool applySimpleProperty(const QVariant &v, bool translateString, DomProperty *dom_prop)
{
    switch (v.type()) {
    case QVariant::String: {
        DomString *str = new DomString();
        str->setText(v.toString());
        if (!translateString)
            str->setAttributeNotr(QStringLiteral("true"));
        dom_prop->setElementString(str);
    }
        return true;

    case QVariant::ByteArray:
        dom_prop->setElementCstring(QString::fromUtf8(v.toByteArray()));
        return true;

    case QVariant::Int:
        dom_prop->setElementNumber(v.toInt());
        return true;

    case QVariant::UInt:
        dom_prop->setElementUInt(v.toUInt());
        return true;

    case QVariant::LongLong:
        dom_prop->setElementLongLong(v.toLongLong());
        return true;

    case QVariant::ULongLong:
        dom_prop->setElementULongLong(v.toULongLong());
        return true;

    case QVariant::Double:
        dom_prop->setElementDouble(v.toDouble());
        return true;

    case QVariant::Bool:
        dom_prop->setElementBool(v.toBool() ? QFormBuilderStrings::instance().trueValue : QFormBuilderStrings::instance().falseValue);
        return true;

    case QVariant::Char: {
        DomChar *ch = new DomChar();
        const QChar character = v.toChar();
        ch->setElementUnicode(character.unicode());
        dom_prop->setElementChar(ch);
    }
        return true;

    case QVariant::Point: {
        DomPoint *pt = new DomPoint();
        const QPoint point = v.toPoint();
        pt->setElementX(point.x());
        pt->setElementY(point.y());
        dom_prop->setElementPoint(pt);
    }
        return true;

    case QVariant::PointF: {
        DomPointF *ptf = new DomPointF();
        const QPointF pointf = v.toPointF();
        ptf->setElementX(pointf.x());
        ptf->setElementY(pointf.y());
        dom_prop->setElementPointF(ptf);
    }
        return true;

    case QVariant::Color: {
        DomColor *clr = new DomColor();
        const QColor color = qvariant_cast<QColor>(v);
        clr->setElementRed(color.red());
        clr->setElementGreen(color.green());
        clr->setElementBlue(color.blue());
        const int alphaChannel = color.alpha();
        if (alphaChannel != 255)
            clr->setAttributeAlpha(alphaChannel);
        dom_prop->setElementColor(clr);
    }
        return true;

    case QVariant::Size: {
        DomSize *sz = new DomSize();
        const QSize size = v.toSize();
        sz->setElementWidth(size.width());
        sz->setElementHeight(size.height());
        dom_prop->setElementSize(sz);
    }
        return true;

    case QVariant::SizeF: {
        DomSizeF *szf = new DomSizeF();
        const QSizeF sizef = v.toSizeF();
        szf->setElementWidth(sizef.width());
        szf->setElementHeight(sizef.height());
        dom_prop->setElementSizeF(szf);
    }
        return true;

    case QVariant::Rect: {
        DomRect *rc = new DomRect();
        const QRect rect = v.toRect();
        rc->setElementX(rect.x());
        rc->setElementY(rect.y());
        rc->setElementWidth(rect.width());
        rc->setElementHeight(rect.height());
        dom_prop->setElementRect(rc);
    }
        return true;

    case QVariant::RectF: {
        DomRectF *rcf = new DomRectF();
        const QRectF rectf = v.toRectF();
        rcf->setElementX(rectf.x());
        rcf->setElementY(rectf.y());
        rcf->setElementWidth(rectf.width());
        rcf->setElementHeight(rectf.height());
        dom_prop->setElementRectF(rcf);
    }
        return true;

    case QVariant::Font: {
        DomFont *fnt = new DomFont();
        const QFont font = qvariant_cast<QFont>(v);
        const uint mask = font.resolve();
        if (mask & QFont::WeightResolved) {
            fnt->setElementBold(font.bold());
            fnt->setElementWeight(font.weight());
        }
        if (mask & QFont::FamilyResolved)
            fnt->setElementFamily(font.family());
        if (mask & QFont::StyleResolved)
            fnt->setElementItalic(font.italic());
        if (mask & QFont::SizeResolved)
            fnt->setElementPointSize(font.pointSize());
        if (mask & QFont::StrikeOutResolved)
            fnt->setElementStrikeOut(font.strikeOut());
        if (mask & QFont::UnderlineResolved)
            fnt->setElementUnderline(font.underline());
        if (mask & QFont::KerningResolved)
            fnt->setElementKerning(font.kerning());
        if (mask & QFont::StyleStrategyResolved) {
            const QMetaEnum styleStrategy_enum = metaEnum<QAbstractFormBuilderGadget>("styleStrategy");
            fnt->setElementStyleStrategy(QLatin1String(styleStrategy_enum.valueToKey(font.styleStrategy())));
        }
        dom_prop->setElementFont(fnt);
    }
        return true;

#ifndef QT_NO_CURSOR
    case QVariant::Cursor: {
        const QMetaEnum cursorShape_enum = metaEnum<QAbstractFormBuilderGadget>("cursorShape");
        dom_prop->setElementCursorShape(QLatin1String(cursorShape_enum.valueToKey(qvariant_cast<QCursor>(v).shape())));
        }
        return true;
#endif

    case QVariant::KeySequence: {
        DomString *s = new DomString();
        s->setText(qvariant_cast<QKeySequence>(v).toString(QKeySequence::PortableText));
        dom_prop->setElementString(s);
        }
        return true;

    case QVariant::Locale: {
        DomLocale *dom = new DomLocale();
        const QLocale locale = qvariant_cast<QLocale>(v);

        const QMetaEnum language_enum = metaEnum<QAbstractFormBuilderGadget>("language");
        const QMetaEnum country_enum = metaEnum<QAbstractFormBuilderGadget>("country");

        dom->setAttributeLanguage(QLatin1String(language_enum.valueToKey(locale.language())));
        dom->setAttributeCountry(QLatin1String(country_enum.valueToKey(locale.country())));

        dom_prop->setElementLocale(dom);
        }
        return true;

    case QVariant::SizePolicy: {
        DomSizePolicy *dom = new DomSizePolicy();
        const QSizePolicy sizePolicy = qvariant_cast<QSizePolicy>(v);

        dom->setElementHorStretch(sizePolicy.horizontalStretch());
        dom->setElementVerStretch(sizePolicy.verticalStretch());

        const QMetaEnum sizeType_enum = metaEnum<QAbstractFormBuilderGadget>("sizeType");

        dom->setAttributeHSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.horizontalPolicy())));
        dom->setAttributeVSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.verticalPolicy())));

        dom_prop->setElementSizePolicy(dom);
    }
        return true;

    case QVariant::Date: {
        DomDate *dom = new DomDate();
        const QDate date = qvariant_cast<QDate>(v);

        dom->setElementYear(date.year());
        dom->setElementMonth(date.month());
        dom->setElementDay(date.day());

        dom_prop->setElementDate(dom);
        }
        return true;

    case QVariant::Time: {
        DomTime *dom = new DomTime();
        const QTime time = qvariant_cast<QTime>(v);

        dom->setElementHour(time.hour());
        dom->setElementMinute(time.minute());
        dom->setElementSecond(time.second());

        dom_prop->setElementTime(dom);
        }
        return true;

    case QVariant::DateTime: {
        DomDateTime *dom = new DomDateTime();
        const QDateTime dateTime = qvariant_cast<QDateTime>(v);

        dom->setElementHour(dateTime.time().hour());
        dom->setElementMinute(dateTime.time().minute());
        dom->setElementSecond(dateTime.time().second());
        dom->setElementYear(dateTime.date().year());
        dom->setElementMonth(dateTime.date().month());
        dom->setElementDay(dateTime.date().day());

        dom_prop->setElementDateTime(dom);
    }
        return true;

    case QVariant::Url: {
        DomUrl *dom = new DomUrl();
        const QUrl url = v.toUrl();

        DomString *str = new DomString();
        str->setText(url.toString());
        dom->setElementString(str);

        dom_prop->setElementUrl(dom);
    }
        return true;

    case QVariant::StringList: {
        DomStringList *sl = new DomStringList;
        sl->setElementString(qvariant_cast<QStringList>(v));
        dom_prop->setElementStringList(sl);
    }
        return true;

    default:
        break;
    }

    return false;
}
示例#21
0
bool DockableWidgetLayout::insertLocation(
	QRect& rect, int& index, DockSide& side, const QSizePolicy& sizePol)
{
	// best insertion data
	// Distance is a number that represents the how far
	// the insertion rectangle is from the final location.
	unsigned bestDistance = 0xFFFFFFFF;
	int bestIndex = 0;
	DockSide bestSide;
	QRect bestRect;

	// loop over all widgets and find appropriate matching sides
	for (int i = 0; i < dockedWidgets.size(); ++i) {
		DockInfo* d = dockedWidgets[i];
		/*****************************************************
		 * Check for placement against the top of the widget *
		 *****************************************************/
		if (i == 0 || d->dockSide != BOTTOM) {
			if (!(rect.left()  > d->right() - SNAP_DISTANCE ||
			      rect.right() < d->left    + SNAP_DISTANCE) &&
			    isClose(rect.bottom(), d->top)) {
				// rectangle is close to the edge
				unsigned dist = 8 * abs(rect.bottom() - d->top);
				// now find all points on this side
				// (use set as a sorted unique list)
				QSet<int> sidePoints;
				for (int j = 0; j <= i; ++j) {
					DockInfo* d2 = dockedWidgets[j];
					if (d->top == d2->top) {
						sidePoints.insert(d2->left);
						sidePoints.insert(d2->right());
						// check if any other widget rest against this side
						for (int k = i + 1; k < dockedWidgets.size(); ++k) {
							DockInfo* d3 = dockedWidgets[k];
							if (d3->bottom() == d2->top) {
								sidePoints.insert(d3->left);
								sidePoints.insert(d3->right());
							}
						}
					}
				}
				// widget placement can occur at all points, find the closest
				QSet<int>::iterator it = sidePoints.begin();
				for (int j = 0; j < sidePoints.size() - 1; ++j) {
					// check after point
					unsigned newDist1 = dist + abs(*it - rect.left());
					if (newDist1 < bestDistance && isClose(*it, rect.left())) {
						QRect r(QPoint(*it, d->top - rect.height()), rect.size());
						if (!overlaysWithFirstNWidgets(r, i)) {
							bestDistance = newDist1;
							bestIndex = i + 1;
							bestSide = TOP;
							bestRect = r;
						}
					}
					++it;
					// check before point
					unsigned newDist2 = dist + abs(*it - rect.right());
					if (newDist2 < bestDistance && isClose(*it, rect.right())) {
						QRect r(QPoint(*it - rect.width(), d->top - rect.height()),
						        rect.size());
						if (!overlaysWithFirstNWidgets(r, i)) {
							bestDistance = newDist2;
							bestIndex = i + 1;
							bestSide = TOP;
							bestRect = r;
						}
					}
				}
				// check for resized placement options
				if (sizePol.horizontalPolicy() != QSizePolicy::Fixed) {
					int mid = rect.left() + rect.width() / 2;
					for (QSet<int>::iterator ita = sidePoints.begin() + 1;
					     ita != sidePoints.end(); ++ita) {
						for (QSet<int>::iterator itb = sidePoints.begin();
						     ita != itb; ++itb) {
							int sp_mid = (*ita + *itb) / 2;
							int sp_diff = *ita - *itb;
							if (isClose(sp_mid, mid)) {
								QRect r(*itb, d->top - rect.height(),
								        sp_diff, rect.height());
								if (!overlaysWithFirstNWidgets(r, i)) {
									bestDistance = dist + abs(sp_mid - mid);
									bestIndex = i + 1;
									bestSide = TOP;
									bestRect = r;
								}
							}
						}
					}
				}
			}
		}

		/********************************************************
		 * Check for placement against the bottom of the widget *
		 ********************************************************/
		if (i == 0 || d->dockSide != TOP) {
			if (!(rect.left()  > d->right() - SNAP_DISTANCE ||
			      rect.right() < d->left    + SNAP_DISTANCE) &&
			    isClose(rect.top(), d->bottom())) {
				// rectangle is close to the edge
				unsigned dist = 8 * abs(rect.top() - d->bottom());
				// now find all points on this side
				// (use set as a sorted unique list)
				QSet<int> sidePoints;
				for (int j = 0; j <= i; ++j) {
					DockInfo* d2 = dockedWidgets[j];
					if (d->bottom() == d2->bottom()) {
						sidePoints.insert(d2->left);
						sidePoints.insert(d2->right());
						// check if any other widget rest against this side
						for (int k = i + 1; k < dockedWidgets.size(); ++k) {
							DockInfo* d3 = dockedWidgets[k];
							if (d3->top == d2->bottom()) {
								sidePoints.insert(d3->left);
								sidePoints.insert(d3->right());
							}
						}
					}
				}
				// widget placement can occur at all points, find the closest
				QSet<int>::iterator it = sidePoints.begin();
				for (int j = 0; j < sidePoints.size() - 1; ++j) {
					// check after point
					unsigned newDist1 = dist + abs(*it - rect.left());
					if (newDist1 < bestDistance && isClose(*it, rect.left())) {
						QRect r(QPoint(*it, d->bottom()), rect.size());
						if (!overlaysWithFirstNWidgets(r, i)) {
							bestDistance = newDist1;
							bestIndex = i + 1;
							bestSide = BOTTOM;
							bestRect = r;
						}
					}
					++it;
					// check before point
					unsigned newDist2 = dist + abs(*it - rect.right());
					if (newDist2 < bestDistance && isClose(*it, rect.right())) {
						QRect r(QPoint(*it - rect.width(), d->bottom()), rect.size());
						if (!overlaysWithFirstNWidgets(r, i)) {
							bestDistance = newDist2;
							bestIndex = i + 1;
							bestSide = BOTTOM;
							bestRect = r;
						}
					}
				}
				// check for resized placement options
				if (sizePol.horizontalPolicy() != QSizePolicy::Fixed) {
					int mid = rect.left() + rect.width() / 2;
					for (QSet<int>::iterator ita = sidePoints.begin() + 1;
					     ita != sidePoints.end(); ++ita) {
						for (QSet<int>::iterator itb = sidePoints.begin();
						     ita != itb; ++itb) {
							int sp_mid = (*ita + *itb) / 2;
							int sp_diff = *ita - *itb;
							if (isClose(sp_mid, mid)) {
								QRect r(*itb, d->bottom(),
								        sp_diff, rect.height());
								if (!overlaysWithFirstNWidgets(r, i)) {
									bestDistance = dist + abs(sp_mid - mid);
									bestIndex = i + 1;
									bestSide = BOTTOM;
									bestRect = r;
								}
							}
						}
					}
				}
			}
		}

		/******************************************************
		 * Check for placement against the left of the widget *
		 ******************************************************/
		if (i == 0 || d->dockSide != RIGHT) {
			if (!(rect.top()    > d->bottom() - SNAP_DISTANCE ||
			      rect.bottom() < d->top      + SNAP_DISTANCE) &&
			    isClose(rect.right(), d->left)) {
				// rectangle is close to the edge
				unsigned dist = 8 * abs(rect.right() - d->left);
				// now find all points on this side
				// (use set as a sorted unique list)
				QSet<int> sidePoints;
				for (int j = 0; j <= i; ++j) {
					DockInfo* d2 = dockedWidgets[j];
					if (d->left == d2->left) {
						sidePoints.insert(d2->top);
						sidePoints.insert(d2->bottom());
						// check if any other widget rest against this side
						for (int k = i + 1; k < dockedWidgets.size(); ++k) {
							DockInfo* d3 = dockedWidgets[k];
							if (d3->right() == d2->left) {
								sidePoints.insert(d3->top);
								sidePoints.insert(d3->bottom());
							}
						}
					}
				}
				// widget placement can occur at all points, find the closest
				QSet<int>::iterator it = sidePoints.begin();
				for (int j = 0; j < sidePoints.size() - 1; ++j) {
					// check after point
					unsigned newDist1 = dist + abs(*it - rect.top());
					if (newDist1 < bestDistance && isClose(*it, rect.top())) {
						QRect r(QPoint(d->left - rect.width(), *it), rect.size());
						if (!overlaysWithFirstNWidgets(r, i)) {
							bestDistance = newDist1;
							bestIndex = i + 1;
							bestSide = LEFT;
							bestRect = r;
						}
					}
					++it;
					// check before point
					unsigned newDist2 = dist + abs(*it - rect.bottom());
					if (newDist2 < bestDistance && isClose(*it, rect.bottom())) {
						QRect r(QPoint(d->left - rect.width(), *it - rect.height()),
						        rect.size());
						if (!overlaysWithFirstNWidgets(r, i)) {
							bestDistance = newDist2;
							bestIndex = i + 1;
							bestSide = LEFT;
							bestRect = r;
						}
					}
				}
				// check for resized placement options
				if (sizePol.verticalPolicy() != QSizePolicy::Fixed) {
					int mid = rect.top() + rect.height() / 2;
					for (QSet<int>::iterator ita = sidePoints.begin() + 1;
					     ita != sidePoints.end(); ++ita) {
						for (QSet<int>::iterator itb = sidePoints.begin();
						     ita != itb; ++itb) {
							int sp_mid = (*ita + *itb) / 2;
							int sp_diff = *ita - *itb;
							if (isClose(sp_mid, mid)) {
								QRect r(d->left - rect.width(), *itb,
								        rect.width(), sp_diff);
								if (!overlaysWithFirstNWidgets(r, i)) {
									bestDistance = dist + abs(sp_mid - mid);
									bestIndex = i + 1;
									bestSide = LEFT;
									bestRect = r;
								}
							}
						}
					}
				}
			}
		}
		/*******************************************************
		 * Check for placement against the right of the widget *
		 *******************************************************/
		if (i == 0 || d->dockSide != LEFT) {
			if (!(rect.top()    > d->bottom() - SNAP_DISTANCE ||
			      rect.bottom() < d->top      + SNAP_DISTANCE) &&
			    isClose(rect.left(), d->right())) {
				// rectangle is close to the edge
				unsigned dist = 8 * abs(rect.left() - d->right());
				// now find all points on this side
				// (use set as a sorted unique list)
				QSet<int> sidePoints;
				for (int j = 0; j <= i; ++j) {
					DockInfo* d2 = dockedWidgets[j];
					if (d->right() == d2->right()) {
						sidePoints.insert(d2->top);
						sidePoints.insert(d2->bottom());
						// check if any other widget rest against this side
						for (int k = i + 1; k < dockedWidgets.size(); ++k) {
							DockInfo* d3 = dockedWidgets[k];
							if (d3->left == d2->right()) {
								sidePoints.insert(d3->top);
								sidePoints.insert(d3->bottom());
							}
						}
					}
				}
				// widget placement can occur at all points, find the closest
				QSet<int>::iterator it = sidePoints.begin();
				for (int j = 0; j < sidePoints.size() - 1; ++j) {
					// check after point
					unsigned newDist1 = dist + abs(*it - rect.top());
					if (newDist1 < bestDistance && isClose(*it, rect.top())) {
						QRect r(QPoint(d->left + d->width, *it), rect.size());
						if (!overlaysWithFirstNWidgets(r, i)) {
							bestDistance = newDist1;
							bestIndex = i + 1;
							bestSide = RIGHT;
							bestRect = r;
						}
					}
					++it;
					// check before point
					unsigned newDist2 = dist + abs(*it - rect.bottom());
					if (newDist2 < bestDistance && isClose(*it, rect.bottom())) {
						QRect r(QPoint(d->right(), *it - rect.height()), rect.size());
						if (!overlaysWithFirstNWidgets(r, i)) {
							bestDistance = newDist2;
							bestIndex = i + 1;
							bestSide = RIGHT;
							bestRect = r;
						}
					}
				}
				// check for resized placement options
				if (sizePol.verticalPolicy() != QSizePolicy::Fixed) {
					int mid = rect.top() + rect.height() / 2;
					for (QSet<int>::iterator ita = sidePoints.begin() + 1;
					     ita != sidePoints.end(); ++ita) {
						for (QSet<int>::iterator itb = sidePoints.begin();
						     ita != itb; ++itb) {
							int sp_mid = (*ita + *itb) / 2;
							int sp_diff = *ita - *itb;
							if (isClose(sp_mid, mid)) {
								QRect r(d->right(), *itb, rect.width(), sp_diff);
								if (!overlaysWithFirstNWidgets(r, i)) {
									bestDistance = dist + abs(sp_mid - mid);
									bestIndex = i + 1;
									bestSide = RIGHT;
									bestRect = r;
								}
							}
						}
					}
				}
			}
		}
	}

	if (bestIndex) {
		rect = bestRect;
		index = bestIndex;
		side = bestSide;
		return true;
	} else {
		return false;
	}
}