void
VBox::paintEvent(QPaintEvent *)
{
    if (!designMode())
        return;
    QPainter p(this);
    p.setPen(QPen(Qt::blue, 2, Qt::DashLine));
    p.drawRect(1, 1, width() - 1, height() - 1);
}
Пример #2
0
void KexiFrame::paintEvent(QPaintEvent *pe)
{
    QFrame::paintEvent(pe);
    if (designMode()) {
        const bool hasFrame = frameWidth() >= 1 && frameShape() != QFrame::NoFrame;
        if (!hasFrame) {
            QPainter p(this);
            KFormDesigner::paintWidgetFrame(p, rect());
        }
    }
}
Пример #3
0
void
Spring::paintEvent(QPaintEvent *ev)
{
    if (!designMode())
        return;

    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing, true);
//! @todo p.setPen(QPen(Qt::white, 1));
//! @todo p.setCompositionMode(QPainter::CompositionMode_Xor);
    if (m_orient == Qt::Vertical) {
        uint part = (height() + 16) / 16;
        if (part < 3)
            part = 3;
        uint w = width() - 1;
        uint offset = 0;
        for (uint i = 0; i < 4; i++, offset += (part * 4)) {
            QPolygon poly1(4);
            poly1.putPoints(0, 4,
                         w / 2, offset, w, offset + part, w, offset + part, w / 2, offset + part*2);
            QPainterPath ppath1;
            ppath1.addPolygon(poly1);
            p.strokePath(ppath1, p.pen());
            QPolygon poly2(4);
            poly2.putPoints(0, 4,
                         w / 2, offset + part*2, 0, offset + part*3, 0, offset + part*3, w / 2, offset + part*4);
            QPainterPath ppath2;
            ppath2.addPolygon(poly2);
            p.strokePath(ppath2, p.pen());
        }
    } else {
        uint part = (width() + 16) / 16;
        if (part < 3)
            part = 3;
        uint h = height() - 1;
        uint offset = 0;
        for (uint i = 0; i < 4; i++, offset += (part * 4)) {
            QPolygon poly1(4);
            poly1.putPoints(0, 4,
                         offset, h / 2, offset + part, 0, offset + part, 0, offset + part*2, h / 2);
            QPainterPath ppath1;
            ppath1.addPolygon(poly1);
            p.strokePath(ppath1, p.pen());
            QPolygon poly2(4);
            poly2.putPoints(0, 4,
                         offset + part*2, h / 2, offset + part*3, h, offset + part*3, h, offset + part*4, h / 2);
            QPainterPath ppath2;
            ppath2.addPolygon(poly2);
            p.strokePath(ppath2, p.pen());
        }
    }
}
Пример #4
0
void
KexiDBAutoField::changeText(const QString &text, bool beautify)
{
    QString realText;
    bool unbound = false;
    if (d->autoCaption && (d->widgetType == Auto || dataSource().isEmpty())) {
        if (designMode())
            realText = i18nc("Unbound Auto Field", "%1 (unbound)", objectName());
        else
            realText.clear();
        unbound = true;
    } else {
        if (beautify) {
            /*! @todo look at appendColonToAutoLabels setting [bool]
              @todo look at makeFirstCharacterUpperCaseInCaptions setting [bool]
              (see doc/dev/settings.txt) */
            if (!text.isEmpty()) {
                realText = text[0].toUpper() + text.mid(1);
                if (d->widgetType != Boolean) {
//! @todo ":" suffix looks weird for checkbox; remove this condition when [x] is displayed _after_ label
//! @todo support right-to-left layout where position of ":" is inverted
                    realText += ": ";
                }
            }
        } else
            realText = text;
    }

    if (unbound) {
        d->label->setAlignment(Qt::AlignCenter);
        d->label->setWordWrap(true);
    } else {
        d->label->setAlignment(Qt::AlignCenter);
    }
// QWidget* widgetToAlterForegroundColor;
    if (d->widgetType == Boolean) {
        static_cast<QCheckBox*>((QWidget*)subwidget())->setText(realText);
//  widgetToAlterForegroundColor = m_subwidget;
    } else {
        d->label->setText(realText);
//  widgetToAlterForegroundColor = d->label;
    }
    /*
      if (unbound)
        widgetToAlterForegroundColor->setPaletteForegroundColor(
          KexiUtils::blendedColors(
            widgetToAlterForegroundColor->paletteForegroundColor(),
            widgetToAlterForegroundColor->paletteBackgroundColor(), 2, 1));
      else
        widgetToAlterForegroundColor->setPaletteForegroundColor( paletteForegroundColor() );*/
}
Пример #5
0
void
KexiDBAutoField::setInvalidState(const QString &text)
{
    // Widget with an invalid dataSource is just a QLabel
    if (designMode())
        return;
    d->widgetType = Auto;
    createEditor();
    setFocusPolicy(Qt::NoFocus);
    if (subwidget())
        subwidget()->setFocusPolicy(Qt::NoFocus);
//! @todo or set this to editor's text?
    d->label->setText(text);
}
Пример #6
0
void KexiDBImageBox::updatePixmap()
{
    if (!(designMode() && pixmap().isNull()))
        return;

    if (!KexiDBImageBox_static->pixmap) {
        const QString fname(KStandardDirs::locate("data", QLatin1String("kexi/pics/imagebox.png")));
        QPixmap pm( KIconLoader::global()->loadMimeTypeIcon(
            koIconNameCStr("image-x-generic"), KIconLoader::NoGroup, KIconLoader::SizeLarge, KIconLoader::DisabledState) );
        if (!pm.isNull()) {
            KIconEffect::semiTransparent(pm);
            KIconEffect::semiTransparent(pm);
        }
        KexiDBImageBox_static->pixmap = new QPixmap(pm);
        KexiDBImageBox_static->small = new QPixmap( 
            KexiDBImageBox_static->pixmap->scaled(
                KexiDBImageBox_static->pixmap->width() / 2, KexiDBImageBox_static->pixmap->height() / 2, 
                Qt::KeepAspectRatio, Qt::SmoothTransformation) );
    }
}
Пример #7
0
void
KexiDBAutoField::setLabelPosition(LabelPosition position)
{
    d->lblPosition = position;
    if (d->layout) {
        QBoxLayout *lyr = d->layout;
        d->layout = 0;
        delete lyr;
    }

    if (subwidget())
        subwidget()->show();
    //! \todo support right-to-left layout where positions are inverted
    if (position == Top || position == Left) {
        Qt::Alignment align = d->label->alignment();
        if (position == Top) {
            d->layout = (QBoxLayout*) new QVBoxLayout(this);
            align |= Qt::AlignVertical_Mask;
            align ^= Qt::AlignVertical_Mask;
            align |= Qt::AlignTop;
        } else {
            d->layout = (QBoxLayout*) new QHBoxLayout(this);
            align |= Qt::AlignVertical_Mask;
            align ^= Qt::AlignVertical_Mask;
            align |= Qt::AlignVCenter;
        }
        d->label->setAlignment(align);
        if (d->widgetType == Boolean
                || (d->widgetType == Auto && fieldTypeInternal() == KexiDB::Field::InvalidType && !designMode())) {
            d->label->hide();
        } else {
            d->label->show();
        }
        d->layout->addWidget(d->label, 0, position == Top ? Qt::AlignLeft : QFlags<Qt::AlignmentFlag>(0));
        if (position == Left && d->widgetType != Boolean)
            d->layout->addSpacing(KexiDBAutoField_SPACING);
        d->layout->addWidget(subwidget(), 1);
        KexiSubwidgetInterface *subwidgetInterface = dynamic_cast<KexiSubwidgetInterface*>((QWidget*)subwidget());
        if (subwidgetInterface) {
            if (subwidgetInterface->appendStretchRequired(this))
                d->layout->addStretch(0);
            if (subwidgetInterface->subwidgetStretchRequired(this)) {
                QSizePolicy sizePolicy(subwidget()->sizePolicy());
                if (position == Left) {
                    sizePolicy.setHorizontalPolicy(QSizePolicy::Minimum);
                    d->label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
                } else {
                    sizePolicy.setVerticalPolicy(QSizePolicy::Minimum);
                    d->label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
                }
                subwidget()->setSizePolicy(sizePolicy);
            }
        }
    } else {
        d->layout = (QBoxLayout*) new QHBoxLayout(this);
        d->label->hide();
        d->layout->addWidget(subwidget());
    }
    //a hack to force layout to be refreshed (any better idea for this?)
    resize(size() + QSize(1, 0));
    resize(size() - QSize(1, 0));
    if (dynamic_cast<KexiDBAutoField*>((QWidget*)subwidget())) {
        //needed for KexiDBComboBox
        dynamic_cast<KexiDBAutoField*>((QWidget*)subwidget())->setLabelPosition(position);
    }
}
Пример #8
0
void
KexiDBAutoField::createEditor()
{
    if (subwidget()) {
        delete(QWidget *)subwidget();
    }

    QWidget *newSubwidget;
    //kDebug() << "widgetType:" << d->widgetType;
    switch (d->widgetType) {
    case Text:
    case Double: //! @todo setup validator
    case Integer: //! @todo setup validator
    case Date:
    case Time:
    case DateTime: {
        KexiDBLineEdit *le = new KexiDBLineEdit(this);
        newSubwidget = le;
        le->setFrame(false);
        break;
    }
    case MultiLineText:
        newSubwidget = new KexiDBTextEdit(this);
        break;
    case Boolean:
        newSubwidget = new KexiDBCheckBox(dataSource(), this);
        break;
    case Image:
        newSubwidget = new KexiDBImageBox(designMode(), this);
        break;
    case ComboBox: {
        KexiDBComboBox *cbox = new KexiDBComboBox(this);
        newSubwidget = cbox;
        cbox->setDesignMode(designMode());
        break;
    }
    default:
        newSubwidget = 0;
        changeText(d->caption);
        break;
    }

    //kDebug() << newSubwidget;
    setSubwidget(newSubwidget);   //this will also allow to declare subproperties, see KFormDesigner::WidgetWithSubpropertiesInterface
    if (newSubwidget) {
        newSubwidget->setObjectName(
            QString::fromLatin1("KexiDBAutoField_") + newSubwidget->metaObject()->className());
        dynamic_cast<KexiDataItemInterface*>(newSubwidget)->setParentDataItemInterface(this);
        dynamic_cast<KexiFormDataItemInterface*>(newSubwidget)
        ->setColumnInfo(columnInfo()); //needed at least by KexiDBImageBox
        dynamic_cast<KexiFormDataItemInterface*>(newSubwidget)
        ->setVisibleColumnInfo(visibleColumnInfo()); //needed at least by KexiDBComboBox
        newSubwidget->setProperty("dataSource", dataSource()); //needed at least by KexiDBImageBox
        KFormDesigner::DesignTimeDynamicChildWidgetHandler::childWidgetAdded(this);
        newSubwidget->show();
        d->label->setBuddy(newSubwidget);
        if (d->focusPolicyChanged) {//if focusPolicy is changed at top level, editor inherits it
            newSubwidget->setFocusPolicy(focusPolicy());
        } else {//if focusPolicy is not changed at top level, inherit it from editor
            QWidget::setFocusPolicy(newSubwidget->focusPolicy());
        }
        setFocusProxy(newSubwidget); //ok?
        if (parentWidget())
            newSubwidget->setPalette(qApp->palette());
        copyPropertiesToEditor();
    }

    setLabelPosition(labelPosition());
}
Пример #9
0
void KexiDBImageBox::paintEvent(QPaintEvent *pe)
{
    if (!m_paintEventEnabled)
        return;
    QPainter p(this);
    p.setClipRect(pe->rect());
    const int _realLineWidth = realLineWidth();
    KexiUtils::WidgetMargins margins(this);
    margins += KexiUtils::WidgetMargins(_realLineWidth);
//Qt3 replaced with 'margins': const int m = realLineWidth() + margin();
    const QBrush bgBrush(palette().brush(backgroundRole()));
    if (designMode() && pixmap().isNull()) {
        QRect r(
            QPoint(margins.left, margins.top),
            size() - QSize(margins.left + margins.right, margins.top + margins.bottom));
//        p.fillRect(0, 0, width(), height(), bgBrush);

        updatePixmap();
        QPixmap *imagBoxPm = scaledImageBoxIcon(margins, size());
        if (imagBoxPm) {
//        QImage img(imagBoxPm->toImage());
//          QPixmap converted(QPixmap::fromImage(img));
            p.drawPixmap(2, height() - margins.top - margins.bottom - imagBoxPm->height() - 2, *imagBoxPm);
        }
        QFont f(qApp->font());
        p.setFont(f);
//        p.setPen(KexiUtils::contrastColor(bg));
        QString text;
        if (dataSource().isEmpty()) {
            text = objectName() + "\n" + i18nc("Unbound Image Box", "(unbound)");
        }
        else {
            text = dataSource();
            const QFontMetrics fm(fontMetrics());
            const QPixmap dataSourceTagIcon(KexiFormUtils::dataSourceTagIcon());
            if (width() >= (dataSourceTagIcon.width() + 2 + fm.boundingRect(r, Qt::AlignCenter, text).width())) {
                r.setLeft( r.left() + dataSourceTagIcon.width() + 2 ); // make some room for the [>] icon
                QRect bounding = fm.boundingRect(r, Qt::AlignCenter, text);
                p.drawPixmap(
                    bounding.left() - dataSourceTagIcon.width() - 2,
                    bounding.top() + bounding.height() / 2 - dataSourceTagIcon.height() / 2,
                    dataSourceTagIcon);
            }
        }
        p.drawText(r, Qt::AlignCenter, text);
    }
    else {
        QSize internalSize(size());
        if (m_chooser && m_dropDownButtonVisible && !dataSource().isEmpty())
            internalSize.setWidth(internalSize.width() - m_chooser->width());

        //clearing needed here because we may need to draw a pixmap with transparency
 //       p.fillRect(0, 0, width(), height(), bgBrush);

        const QRect internalRect(QPoint(0, 0), internalSize);
        if (m_currentScaledPixmap.isNull() || internalRect != m_currentRect) {
            m_currentRect = internalRect;
            m_currentPixmapPos = QPoint(0, 0);
            m_currentScaledPixmap = KexiUtils::scaledPixmap(
                margins, m_currentRect, pixmap(), m_currentPixmapPos, m_alignment,
                m_scaledContents, m_keepAspectRatio,
                m_smoothTransformation ? Qt::SmoothTransformation : Qt::FastTransformation);
        }
        p.drawPixmap(m_currentPixmapPos, m_currentScaledPixmap);
//        KexiUtils::drawPixmap(p, margins, QRect(QPoint(0, 0), internalSize), pixmap(), m_alignment,
//                              m_scaledContents, m_keepAspectRatio);
    }
    KexiFrame::drawFrame(&p);

    if (designMode()) {
        const bool hasFrame = frameWidth() >= 1 && frameShape() != QFrame::NoFrame;
        if (!hasFrame) {
            KFormDesigner::paintWidgetFrame(p, rect());
        }
    }
    else { // data mode
        // if the widget is focused, draw focus indicator rect _if_ there is no chooser button
        if (   !dataSource().isEmpty()
            && hasFocus()
            && (!m_chooser || !m_chooser->isVisible()))
        {
            QStyleOptionFocusRect option;
            option.initFrom(this);
            //option.rect = style().subRect(QStyle::SR_PushButtonContents);
            style()->drawPrimitive(
                QStyle::PE_FrameFocusRect, &option, &p, this
                /*Qt4 , palette().active()*/);
        }
    }
}