Changeset View
Changeset View
Standalone View
Standalone View
src/formeditor/form.cpp
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at> | 2 | Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at> | ||
3 | Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> | 3 | Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> | ||
4 | Copyright (C) 2004-2014 Jarosław Staniek <staniek@kde.org> | 4 | Copyright (C) 2004-2017 Jarosław Staniek <staniek@kde.org> | ||
5 | 5 | | |||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. | ||
10 | 10 | | |||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 770 Lines • ▼ Show 20 Line(s) | |||||
783 | } | 783 | } | ||
784 | 784 | | |||
785 | bool Form::addCommand(Command *command, AddCommandOption option) | 785 | bool Form::addCommand(Command *command, AddCommandOption option) | ||
786 | { | 786 | { | ||
787 | setModified(true); | 787 | setModified(true); | ||
788 | if (option == DontExecuteCommand) { | 788 | if (option == DontExecuteCommand) { | ||
789 | command->blockRedoOnce(); | 789 | command->blockRedoOnce(); | ||
790 | } | 790 | } | ||
791 | d->undoStack.push(command); | 791 | return d->undoStack.push(command); | ||
792 | //qDebug() << "ADDED:" << *command; | | |||
793 | return true; | | |||
794 | } | 792 | } | ||
795 | 793 | | |||
796 | void Form::emitUndoEnabled() | 794 | void Form::emitUndoEnabled() | ||
797 | { | 795 | { | ||
798 | //! @todo pixmapcollection | 796 | //! @todo pixmapcollection | ||
799 | #ifdef KEXI_PIXMAP_COLLECTIONS_SUPPORT | 797 | #ifdef KEXI_PIXMAP_COLLECTIONS_SUPPORT | ||
800 | QAction *undoAction = d->collection->action(QLatin1String("edit_undo")); | 798 | QAction *undoAction = d->collection->action(QLatin1String("edit_undo")); | ||
801 | if (undoAction) | 799 | if (undoAction) | ||
▲ Show 20 Lines • Show All 1329 Lines • ▼ Show 20 Line(s) | |||||
2131 | 2129 | | |||
2132 | // Alignment-related functions ///////////////////////////// | 2130 | // Alignment-related functions ///////////////////////////// | ||
2133 | 2131 | | |||
2134 | void Form::createAlignProperty(const QMetaProperty& meta, QWidget *widget, QWidget *subwidget) | 2132 | void Form::createAlignProperty(const QMetaProperty& meta, QWidget *widget, QWidget *subwidget) | ||
2135 | { | 2133 | { | ||
2136 | if (!objectTree()) | 2134 | if (!objectTree()) | ||
2137 | return; | 2135 | return; | ||
2138 | 2136 | | |||
2139 | const int alignment = subwidget->property("alignment").toInt(); | 2137 | const Qt::Alignment alignment = Qt::Alignment(subwidget->property("alignment").toInt()); | ||
2140 | const QList<QByteArray> keys(meta.enumerator().valueToKeys(alignment).split('|')); | 2138 | WidgetInfo *winfo = library()->widgetInfoForClassName(subwidget->metaObject()->className()); | ||
2141 | //qDebug() << "keys:" << keys; | 2139 | const Qt::Alignment supportedAlignmentFlags = winfo | ||
2142 | 2140 | ? winfo->supportedAlignmentFlags() | |||
2143 | const QStringList possibleValues(KexiUtils::enumKeysForProperty(meta)); | 2141 | : Qt::Alignment(Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask); | ||
2144 | //qDebug() << "possibleValues:" << possibleValues; | | |||
2145 | ObjectTreeItem *tree = objectTree()->lookup(widget->objectName()); | 2142 | ObjectTreeItem *tree = objectTree()->lookup(widget->objectName()); | ||
2146 | const bool isTopLevel = isTopLevelWidget(widget); | 2143 | const bool isTopLevel = isTopLevelWidget(widget); | ||
2147 | 2144 | | |||
2148 | if (possibleValues.contains("AlignHCenter")) { | 2145 | const Qt::Alignment supportedHorizontalAlignmentFlags | ||
2146 | = supportedAlignmentFlags & Qt::AlignHorizontal_Mask; | ||||
2147 | if (supportedHorizontalAlignmentFlags) { | ||||
2149 | // Create the horizontal alignment property | 2148 | // Create the horizontal alignment property | ||
2150 | QString value; | 2149 | QStringList list(KexiUtils::enumKeysForProperty(meta, supportedHorizontalAlignmentFlags)); | ||
2151 | if (keys.contains("AlignHCenter") || keys.contains("AlignCenter")) | 2150 | if (list.removeOne(QStringLiteral("AlignHCenter"))) { // fix order | ||
2152 | value = "AlignHCenter"; | 2151 | list.prepend(QStringLiteral("AlignHCenter")); | ||
2153 | else if (keys.contains("AlignRight")) | 2152 | } | ||
2154 | value = "AlignRight"; | 2153 | if (list.removeOne(QStringLiteral("AlignLeft"))) { | ||
2155 | else if (keys.contains("AlignLeft")) | 2154 | list.prepend(QStringLiteral("AlignLeft")); | ||
2156 | value = "AlignLeft"; | 2155 | } | ||
2157 | else if (keys.contains("AlignJustify")) | 2156 | const Qt::Alignment selectedHorizontalAlignmentFlags | ||
2158 | value = "AlignJustify"; | 2157 | = alignment & supportedHorizontalAlignmentFlags; | ||
2159 | else | 2158 | const QStringList selectedKeys( | ||
2160 | value = "AlignAuto"; | 2159 | KexiUtils::enumKeysForProperty(meta, selectedHorizontalAlignmentFlags)); | ||
2161 | 2160 | QString selectedKey; | |||
2162 | QStringList list; | 2161 | if (selectedKeys.isEmpty()) { // for sanity | ||
2163 | list << "AlignAuto" << "AlignLeft" << "AlignRight" | 2162 | selectedKey = list.first(); | ||
2164 | << "AlignHCenter" << "AlignJustify"; | 2163 | } else { | ||
2164 | selectedKey = selectedKeys.first(); | ||||
2165 | } | ||||
2165 | KProperty *p = new KProperty( | 2166 | KProperty *p = new KProperty( | ||
2166 | "hAlign", d->createValueList(0, list), value, | 2167 | "hAlign", d->createValueList(0, list), selectedKey, | ||
2167 | xi18nc("Translators: please keep this string short (less than 20 chars)", "Hor. Alignment"), | 2168 | xi18nc("Translators: please keep this string short (less than 20 chars)", "Hor. Alignment"), | ||
2168 | xi18n("Horizontal Alignment")); | 2169 | xi18n("Horizontal Alignment")); | ||
2169 | d->propertySet.addProperty(p); | 2170 | d->propertySet.addProperty(p); | ||
2170 | if (!isPropertyVisible(p->name(), isTopLevel)) { | 2171 | if (!isPropertyVisible(p->name(), isTopLevel)) { | ||
2171 | p->setVisible(false); | 2172 | p->setVisible(false); | ||
2172 | } | 2173 | } | ||
2173 | updatePropertyValue(tree, "hAlign"); | 2174 | updatePropertyValue(tree, "hAlign"); | ||
2174 | } | 2175 | } | ||
2175 | 2176 | | |||
2176 | if (possibleValues.contains("AlignTop")) { | 2177 | const Qt::Alignment supportedVerticalAlignmentFlags | ||
2177 | // Create the ver alignment property | 2178 | = supportedAlignmentFlags & Qt::AlignVertical_Mask; | ||
2178 | QString value; | 2179 | if (supportedVerticalAlignmentFlags) { | ||
2179 | if (keys.contains("AlignTop")) | 2180 | QStringList list(KexiUtils::enumKeysForProperty(meta, supportedVerticalAlignmentFlags)); | ||
2180 | value = "AlignTop"; | 2181 | if (list.removeOne("AlignVCenter")) { // fix order | ||
2181 | else if (keys.contains("AlignBottom")) | 2182 | list.prepend("AlignVCenter"); | ||
2182 | value = "AlignBottom"; | 2183 | } | ||
2183 | else | 2184 | if (list.removeOne("AlignTop")) { | ||
2184 | value = "AlignVCenter"; | 2185 | list.prepend("AlignTop"); | ||
2185 | 2186 | } | |||
2186 | QStringList list; | 2187 | const Qt::Alignment selectedVerticalAlignmentFlags | ||
2187 | list << "AlignTop" << "AlignVCenter" << "AlignBottom"; | 2188 | = alignment & supportedVerticalAlignmentFlags; | ||
2189 | const QStringList selectedKeys( | ||||
2190 | KexiUtils::enumKeysForProperty(meta, selectedVerticalAlignmentFlags)); | ||||
2191 | QString selectedKey; | ||||
2192 | if (selectedKeys.isEmpty()) { // for sanity | ||||
2193 | selectedKey = list.first(); | ||||
2194 | } else { | ||||
2195 | selectedKey = selectedKeys.first(); | ||||
2196 | } | ||||
2188 | KProperty *p = new KProperty( | 2197 | KProperty *p = new KProperty( | ||
2189 | "vAlign", d->createValueList(0, list), value, | 2198 | "vAlign", d->createValueList(0, list), selectedKey, | ||
2190 | xi18nc("Translators: please keep this string short (less than 20 chars)", "Ver. Alignment"), | 2199 | xi18nc("Translators: please keep this string short (less than 20 chars)", "Ver. Alignment"), | ||
2191 | xi18n("Vertical Alignment")); | 2200 | xi18n("Vertical Alignment")); | ||
2192 | d->propertySet.addProperty(p); | 2201 | d->propertySet.addProperty(p); | ||
2193 | if (!isPropertyVisible(p->name(), isTopLevel)) { | 2202 | if (!isPropertyVisible(p->name(), isTopLevel)) { | ||
2194 | p->setVisible(false); | 2203 | p->setVisible(false); | ||
2195 | } | 2204 | } | ||
2196 | updatePropertyValue(tree, "vAlign"); | 2205 | updatePropertyValue(tree, "vAlign"); | ||
2197 | } | 2206 | } | ||
Show All 9 Lines | 2210 | { | |||
2207 | 2216 | | |||
2208 | WidgetWithSubpropertiesInterface* subpropIface | 2217 | WidgetWithSubpropertiesInterface* subpropIface | ||
2209 | = dynamic_cast<WidgetWithSubpropertiesInterface*>(d->selected.first()); | 2218 | = dynamic_cast<WidgetWithSubpropertiesInterface*>(d->selected.first()); | ||
2210 | QWidget *subwidget = (subpropIface && subpropIface->subwidget()) | 2219 | QWidget *subwidget = (subpropIface && subpropIface->subwidget()) | ||
2211 | ? subpropIface->subwidget() : (QWidget*)d->selected.first(); | 2220 | ? subpropIface->subwidget() : (QWidget*)d->selected.first(); | ||
2212 | int count = subwidget->metaObject()->indexOfProperty("alignment"); | 2221 | int count = subwidget->metaObject()->indexOfProperty("alignment"); | ||
2213 | const QMetaProperty meta( subwidget->metaObject()->property(count) ); | 2222 | const QMetaProperty meta( subwidget->metaObject()->property(count) ); | ||
2214 | const int valueForKeys = meta.enumerator().keysToValue(list.join("|").toLatin1()); | 2223 | const int valueForKeys = meta.enumerator().keysToValue(list.join("|").toLatin1()); | ||
2224 | const int oldValue = subwidget->property("alignment").toInt(); | ||||
2215 | subwidget->setProperty("alignment", valueForKeys); | 2225 | subwidget->setProperty("alignment", valueForKeys); | ||
2216 | 2226 | | |||
2217 | ObjectTreeItem *tree = objectTree()->lookup(d->selected.first()->objectName()); | 2227 | ObjectTreeItem *tree = objectTree()->lookup(d->selected.first()->objectName()); | ||
2218 | if (tree && d->propertySet[ property.toLatin1()].isModified()) { | 2228 | if (tree && d->propertySet[ property.toLatin1()].isModified()) { | ||
2219 | tree->addModifiedProperty( | 2229 | tree->addModifiedProperty( | ||
2220 | property.toLatin1(), d->propertySet[property.toLatin1()].oldValue()); | 2230 | property.toLatin1(), d->propertySet[property.toLatin1()].oldValue()); | ||
2221 | } | 2231 | } | ||
2222 | 2232 | | |||
2223 | if (d->isUndoing) { | 2233 | if (d->isUndoing) { | ||
2224 | return; | 2234 | return; | ||
2225 | } | 2235 | } | ||
2226 | 2236 | | |||
2227 | if (d->lastCommand && d->lastCommand->propertyName() == "alignment") { | | |||
2228 | d->lastCommand->setValue(valueForKeys); | | |||
2229 | } | | |||
2230 | else { | | |||
2231 | d->lastCommand = new PropertyCommand(*this, d->selected.first()->objectName().toLatin1(), | 2237 | d->lastCommand = new PropertyCommand(*this, d->selected.first()->objectName().toLatin1(), | ||
2232 | subwidget->property("alignment"), valueForKeys, "alignment"); | 2238 | oldValue, valueForKeys, "alignment"); | ||
2233 | if (!addCommand(d->lastCommand, DontExecuteCommand)) { | 2239 | if (!addCommand(d->lastCommand, DontExecuteCommand)) { | ||
2234 | d->lastCommand = 0; | 2240 | d->lastCommand = 0; | ||
2235 | } | 2241 | } | ||
2236 | } | 2242 | } | ||
2237 | } | | |||
2238 | 2243 | | |||
2239 | void Form::createPropertyCommandsInDesignMode(QWidget* widget, | 2244 | void Form::createPropertyCommandsInDesignMode(QWidget* widget, | ||
2240 | const QHash<QByteArray, QVariant> &propValues, Command *parentCommand, bool addToActiveForm) | 2245 | const QHash<QByteArray, QVariant> &propValues, Command *parentCommand, bool addToActiveForm) | ||
2241 | { | 2246 | { | ||
2242 | if (!widget || propValues.isEmpty()) | 2247 | if (!widget || propValues.isEmpty()) | ||
2243 | return; | 2248 | return; | ||
2244 | 2249 | | |||
2245 | //is this widget selected? (if so, use property system) | 2250 | //is this widget selected? (if so, use property system) | ||
▲ Show 20 Lines • Show All 425 Lines • Show Last 20 Lines |