diff --git a/src/formeditor/WidgetInfo.h b/src/formeditor/WidgetInfo.h --- a/src/formeditor/WidgetInfo.h +++ b/src/formeditor/WidgetInfo.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004-2009 Jarosław Staniek + Copyright (C) 2004-2017 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -162,6 +162,23 @@ to describe class' details. */ void setInternalProperty(const QByteArray& property, const QVariant& value); + /** + * @brief Returns @c alignment flags supports by the widget + * + * By default returns all possible flags minus Qt::AlignAbsolute. + * @see setSupportedAlignmentFlags + */ + Qt::Alignment supportedAlignmentFlags() const; + + /** + * @brief Sets alignment flags supported by the widget + * + * Used for example by an image box that does not support justified, absolute and baseline + * alignment. + * @see supportedAlignmentFlags + */ + void setSupportedAlignmentFlags(Qt::Alignment flags); + protected: void setInheritedClass(WidgetInfo *inheritedClass); diff --git a/src/formeditor/WidgetInfo.cpp b/src/formeditor/WidgetInfo.cpp --- a/src/formeditor/WidgetInfo.cpp +++ b/src/formeditor/WidgetInfo.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004-2009 Jarosław Staniek + Copyright (C) 2004-2017 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -59,7 +59,7 @@ QByteArray parentFactoryName; QByteArray inheritedClassName; //!< Used for inheriting widgets between factories WidgetInfo* inheritedClass; - + Qt::Alignment supportedAlignmentFlags = Qt::Alignment(Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask) ^ Qt::AlignAbsolute; }; } @@ -271,3 +271,13 @@ InternalPropertyHandlerInterface *iface = static_cast(d->factory); iface->setInternalProperty(d->className, property, value); } + +Qt::Alignment WidgetInfo::supportedAlignmentFlags() const +{ + return d->supportedAlignmentFlags; +} + +void WidgetInfo::setSupportedAlignmentFlags(Qt::Alignment flags) +{ + d->supportedAlignmentFlags = flags; +} diff --git a/src/formeditor/form.h b/src/formeditor/form.h --- a/src/formeditor/form.h +++ b/src/formeditor/form.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004-2014 Jarosław Staniek + Copyright (C) 2004-2017 Jarosław Staniek Copyright (C) 2014 Michał Poteralski This library is free software; you can redistribute it and/or diff --git a/src/formeditor/form.cpp b/src/formeditor/form.cpp --- a/src/formeditor/form.cpp +++ b/src/formeditor/form.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004-2014 Jarosław Staniek + Copyright (C) 2004-2017 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -788,9 +788,7 @@ if (option == DontExecuteCommand) { command->blockRedoOnce(); } - d->undoStack.push(command); - //qDebug() << "ADDED:" << *command; - return true; + return d->undoStack.push(command); } void Form::emitUndoEnabled() @@ -2136,34 +2134,37 @@ if (!objectTree()) return; - const int alignment = subwidget->property("alignment").toInt(); - const QList keys(meta.enumerator().valueToKeys(alignment).split('|')); - //qDebug() << "keys:" << keys; - - const QStringList possibleValues(KexiUtils::enumKeysForProperty(meta)); - //qDebug() << "possibleValues:" << possibleValues; + const Qt::Alignment alignment = Qt::Alignment(subwidget->property("alignment").toInt()); + WidgetInfo *winfo = library()->widgetInfoForClassName(subwidget->metaObject()->className()); + const Qt::Alignment supportedAlignmentFlags = winfo + ? winfo->supportedAlignmentFlags() + : Qt::Alignment(Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask); ObjectTreeItem *tree = objectTree()->lookup(widget->objectName()); const bool isTopLevel = isTopLevelWidget(widget); - if (possibleValues.contains("AlignHCenter")) { + const Qt::Alignment supportedHorizontalAlignmentFlags + = supportedAlignmentFlags & Qt::AlignHorizontal_Mask; + if (supportedHorizontalAlignmentFlags) { // Create the horizontal alignment property - QString value; - if (keys.contains("AlignHCenter") || keys.contains("AlignCenter")) - value = "AlignHCenter"; - else if (keys.contains("AlignRight")) - value = "AlignRight"; - else if (keys.contains("AlignLeft")) - value = "AlignLeft"; - else if (keys.contains("AlignJustify")) - value = "AlignJustify"; - else - value = "AlignAuto"; - - QStringList list; - list << "AlignAuto" << "AlignLeft" << "AlignRight" - << "AlignHCenter" << "AlignJustify"; + QStringList list(KexiUtils::enumKeysForProperty(meta, supportedHorizontalAlignmentFlags)); + if (list.removeOne(QStringLiteral("AlignHCenter"))) { // fix order + list.prepend(QStringLiteral("AlignHCenter")); + } + if (list.removeOne(QStringLiteral("AlignLeft"))) { + list.prepend(QStringLiteral("AlignLeft")); + } + const Qt::Alignment selectedHorizontalAlignmentFlags + = alignment & supportedHorizontalAlignmentFlags; + const QStringList selectedKeys( + KexiUtils::enumKeysForProperty(meta, selectedHorizontalAlignmentFlags)); + QString selectedKey; + if (selectedKeys.isEmpty()) { // for sanity + selectedKey = list.first(); + } else { + selectedKey = selectedKeys.first(); + } KProperty *p = new KProperty( - "hAlign", d->createValueList(0, list), value, + "hAlign", d->createValueList(0, list), selectedKey, xi18nc("Translators: please keep this string short (less than 20 chars)", "Hor. Alignment"), xi18n("Horizontal Alignment")); d->propertySet.addProperty(p); @@ -2173,20 +2174,28 @@ updatePropertyValue(tree, "hAlign"); } - if (possibleValues.contains("AlignTop")) { - // Create the ver alignment property - QString value; - if (keys.contains("AlignTop")) - value = "AlignTop"; - else if (keys.contains("AlignBottom")) - value = "AlignBottom"; - else - value = "AlignVCenter"; - - QStringList list; - list << "AlignTop" << "AlignVCenter" << "AlignBottom"; + const Qt::Alignment supportedVerticalAlignmentFlags + = supportedAlignmentFlags & Qt::AlignVertical_Mask; + if (supportedVerticalAlignmentFlags) { + QStringList list(KexiUtils::enumKeysForProperty(meta, supportedVerticalAlignmentFlags)); + if (list.removeOne("AlignVCenter")) { // fix order + list.prepend("AlignVCenter"); + } + if (list.removeOne("AlignTop")) { + list.prepend("AlignTop"); + } + const Qt::Alignment selectedVerticalAlignmentFlags + = alignment & supportedVerticalAlignmentFlags; + const QStringList selectedKeys( + KexiUtils::enumKeysForProperty(meta, selectedVerticalAlignmentFlags)); + QString selectedKey; + if (selectedKeys.isEmpty()) { // for sanity + selectedKey = list.first(); + } else { + selectedKey = selectedKeys.first(); + } KProperty *p = new KProperty( - "vAlign", d->createValueList(0, list), value, + "vAlign", d->createValueList(0, list), selectedKey, xi18nc("Translators: please keep this string short (less than 20 chars)", "Ver. Alignment"), xi18n("Vertical Alignment")); d->propertySet.addProperty(p); @@ -2212,6 +2221,7 @@ int count = subwidget->metaObject()->indexOfProperty("alignment"); const QMetaProperty meta( subwidget->metaObject()->property(count) ); const int valueForKeys = meta.enumerator().keysToValue(list.join("|").toLatin1()); + const int oldValue = subwidget->property("alignment").toInt(); subwidget->setProperty("alignment", valueForKeys); ObjectTreeItem *tree = objectTree()->lookup(d->selected.first()->objectName()); @@ -2224,15 +2234,10 @@ return; } - if (d->lastCommand && d->lastCommand->propertyName() == "alignment") { - d->lastCommand->setValue(valueForKeys); - } - else { - d->lastCommand = new PropertyCommand(*this, d->selected.first()->objectName().toLatin1(), - subwidget->property("alignment"), valueForKeys, "alignment"); - if (!addCommand(d->lastCommand, DontExecuteCommand)) { - d->lastCommand = 0; - } + d->lastCommand = new PropertyCommand(*this, d->selected.first()->objectName().toLatin1(), + oldValue, valueForKeys, "alignment"); + if (!addCommand(d->lastCommand, DontExecuteCommand)) { + d->lastCommand = 0; } } diff --git a/src/formeditor/form_p.cpp b/src/formeditor/form_p.cpp --- a/src/formeditor/form_p.cpp +++ b/src/formeditor/form_p.cpp @@ -288,8 +288,11 @@ propValCaption["AutoText"] = xi18nc("Auto (HINT: for AutoText)", "Auto"); propValCaption["AlignAuto"] = xi18nc("Auto (HINT: for Align)", "Auto"); + propValCaption["AlignBaseline"] = "Baseline"; propValCaption["AlignLeft"] = xi18nc("Left (HINT: for Align)", "Left"); + propValCaption["AlignLeading"] = xi18nc("Left (HINT: for Align)", "Left"); propValCaption["AlignRight"] = xi18nc("Right (HINT: for Align)", "Right"); + propValCaption["AlignTrailing"] = xi18nc("Right (HINT: for Align)", "Right"); propValCaption["AlignHCenter"] = xi18nc("Center (HINT: for Align)", "Center"); propValCaption["AlignJustify"] = xi18nc("Justify (HINT: for Align)", "Justify"); propValCaption["AlignVCenter"] = xi18nc("Center (HINT: for Align)", "Center"); diff --git a/src/kexiutils/utils.h b/src/kexiutils/utils.h --- a/src/kexiutils/utils.h +++ b/src/kexiutils/utils.h @@ -135,7 +135,10 @@ const QMetaObject *metaObject); //! \return a list of enum keys for meta property \a metaProperty. -KEXIUTILS_EXPORT QStringList enumKeysForProperty(const QMetaProperty& metaProperty); +//! If @a filter is not INT_MIN, the method only returns enum keys that overlap with filter +//! and are not combination of other keys. +KEXIUTILS_EXPORT QStringList enumKeysForProperty(const QMetaProperty &metaProperty, + int filter = INT_MIN); //! Convert a list @a list of @a SourceType type to another list of @a DestinationType //! type using @a convertMethod function diff --git a/src/kexiutils/utils.cpp b/src/kexiutils/utils.cpp --- a/src/kexiutils/utils.cpp +++ b/src/kexiutils/utils.cpp @@ -238,13 +238,23 @@ return result; } -QStringList KexiUtils::enumKeysForProperty(const QMetaProperty& metaProperty) +QStringList KexiUtils::enumKeysForProperty(const QMetaProperty& metaProperty, int filter) { QStringList result; - QMetaEnum enumerator(metaProperty.enumerator()); + const QMetaEnum enumerator(metaProperty.enumerator()); const int count = enumerator.keyCount(); - for (int i = 0; i < count; i++) - result.append(QString::fromLatin1(enumerator.key(i))); + int total = 0; + for (int i = 0; i < count; i++) { + if (filter == INT_MIN) { + result.append(QString::fromLatin1(enumerator.key(i))); + } else { + const int v = enumerator.value(i); + if ((v & filter) && !(total & v)) { // !(total & v) is a protection adding against masks + result.append(QString::fromLatin1(enumerator.key(i))); + total |= v; + } + } + } return result; } diff --git a/src/plugins/forms/kexidbfactory.cpp b/src/plugins/forms/kexidbfactory.cpp --- a/src/plugins/forms/kexidbfactory.cpp +++ b/src/plugins/forms/kexidbfactory.cpp @@ -201,6 +201,8 @@ // wi->setCustomTypeForProperty("pixmapData", KexiCustomPropertyFactory::PixmapData); wi->setCustomTypeForProperty("pixmapId", KexiCustomPropertyFactory::PixmapId); wi->setInternalProperty("dontStartEditingOnInserting", true); + wi->setSupportedAlignmentFlags(Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter + | Qt::AlignTop | Qt::AlignBottom | Qt::AlignVCenter); addClass(wi); }