[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kexi/formeditor
From:       Jaroslaw Staniek <js () iidea ! pl>
Date:       2009-04-08 20:40:09
Message-ID: 1239223209.677636.17988.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 951275 by staniek:

Forms
- widget resizing now creates undoable command
- property values (x, y, w, h) are visually updated
  on widget resizing using handles
-- even if the properties are sorted alphabetically



 M  +21 -7     commands.cpp  
 M  +2 -2      container.cpp  
 M  +47 -14    form.cpp  
 M  +11 -0     form.h  
 M  +18 -5     resizehandle.cpp  
 M  +5 -1      resizehandle.h  
 M  +3 -7      widgetfactory.cpp  


--- trunk/koffice/kexi/formeditor/commands.cpp #951274:951275
@@ -74,10 +74,9 @@
     {
     }
 
-    //KoProperty::Set *propertySet;
     Form *form;
     QVariant value;
-    QHash<QByteArray, QVariant> oldValues;
+    QHash<QByteArray, QVariant> oldValues; //!< (widget_name -> value) hash
     QByteArray propertyName;
 };
 }
@@ -120,13 +119,28 @@
 
 void PropertyCommand::execute()
 {
-    d->form->selectFormWidget();
+    QWidget *selected = d->form->selectedWidget();
+    bool reSelectWidgets = true;
+    if (selected
+        && d->oldValues.count() == 1
+        && d->oldValues.contains(selected->objectName().toLatin1()) )
+    {
+        // do not reselect widget; this e.g. avoids removing resize handles
+        reSelectWidgets = false;
+    }
+
+    if (reSelectWidgets) {
+        d->form->selectFormWidget();
+    }
+
     d->form->setUndoing(true);
 
-    foreach (const QByteArray& name, d->oldValues.keys()) {
-        ObjectTreeItem* item = d->form->objectTree()->lookup(name);
-        if (item) { //we're checking for item!=0 because the name could be of a form \
                widget
-            d->form->selectWidget(item->widget(), Form::AddToPreviousSelection | \
Form::LastSelection); +    if (reSelectWidgets) {
+        foreach (const QByteArray& name, d->oldValues.keys()) {
+            ObjectTreeItem* item = d->form->objectTree()->lookup(name);
+            if (item) { //we're checking for item!=0 because the name could be of a \
form widget +                d->form->selectWidget(item->widget(), \
Form::AddToPreviousSelection | Form::LastSelection); +            }
         }
     }
 
--- trunk/koffice/kexi/formeditor/container.cpp #951274:951275
@@ -455,7 +455,7 @@
  //moved..           drawCopiedWidgetRect(mev);
             return true;
         }
-        else if ( (   mev->buttons() == Qt::LeftButton 
+        else if ( (   (mev->buttons() == Qt::LeftButton && mev->modifiers() == \
                Qt::NoModifier)
                    || (mev->buttons() == Qt::LeftButton && mev->modifiers() == \
(Qt::ControlModifier | Qt::AltModifier))  )
                   && d->form->state() != Form::WidgetInserting
@@ -465,7 +465,7 @@
             // we are dragging the widget(s) to move it
             if (!d->toplevel() && m_moving == widget()) // no effect for form
                 return false;
-            if ((!m_moving) || (!m_moving->parentWidget()))// || \
(m_moving->parentWidget()->inherits("QStackedWidget"))) +            if (!m_moving || \
!m_moving->parentWidget())// || \
(m_moving->parentWidget()->inherits("QStackedWidget")))  return true;
 
             moveSelectedWidgetsBy(mev->x() - m_grab.x(), mev->y() - m_grab.y());
--- trunk/koffice/kexi/formeditor/form.cpp #951274:951275
@@ -302,6 +302,7 @@
     GeometryPropertyCommand  *lastGeoCommand;
     bool slotPropertyChangedEnabled : 1;
     bool slotPropertyChanged_addCommandEnabled : 1;
+    bool insideAddPropertyCommand : 1;
 // end of moved from WidgetPropertySet
 
     // i18n stuff
@@ -348,6 +349,7 @@
     isUndoing = false;
     slotPropertyChangedEnabled = true;
     slotPropertyChanged_addCommandEnabled = true;
+    insideAddPropertyCommand = false;
     initPropertiesDescription();
     origActiveColors = 0;
 // end of moved from WidgetPropertySet
@@ -813,6 +815,12 @@
         selectWidget(widget());
         return;
     }
+    kDebug() << "selected count=" << d->selected.count();
+    if (!d->selected.isEmpty()) {
+        kDebug() << "first=" << d->selected.first();
+    }
+    kDebug() << w;
+
     if (d->selected.count() == 1 && d->selected.first() == w) {
         return;
     }
@@ -1609,6 +1617,27 @@
     return d->state;
 }
 
+void Form::addPropertyCommand(const QByteArray &wname, const QVariant &oldValue,
+                    const QVariant &value, const QByteArray &propertyName, bool \
execute) +{
+    kDebug() << d->propertySet[propertyName];
+    kDebug() << "oldValue:" << oldValue << "value:" << value;
+    d->insideAddPropertyCommand = true;
+    d->lastCommand = new PropertyCommand(*this, wname, oldValue, value, \
propertyName); +    addCommand(d->lastCommand, execute);
+    d->insideAddPropertyCommand = false;
+}
+
+void Form::addPropertyCommand(const QHash<QByteArray, QVariant> &oldValues,
+                    const QVariant &value, const QByteArray &propertyName, bool \
execute) +{
+    kDebug() << d->propertySet[propertyName];
+    d->insideAddPropertyCommand = true;
+    d->lastCommand = new PropertyCommand(*this, oldValues, value, propertyName);
+    addCommand(d->lastCommand, execute);
+    d->insideAddPropertyCommand = false;
+}
+
 // moved from FormManager
 void Form::slotPropertyChanged(KoProperty::Set& set, KoProperty::Property& p)
 {
@@ -1652,7 +1681,7 @@
     }
 
     // make sure we are not already undoing -> avoid recursion
-    if (d->isUndoing && !d->isRedoing)
+    if (d->isUndoing && !d->isRedoing) // && !d->insideAddPropertyCommand)
         return;
 
     const bool alterLastCommand = d->lastCommand && d->lastCommand->property() == \
property; @@ -1665,9 +1694,8 @@
         }
         else  {
             if (d->slotPropertyChanged_addCommandEnabled && !d->isRedoing) {
-                d->lastCommand = new PropertyCommand(*this, \
                d->selected.first()->objectName().toLatin1(),
-                                                     \
                d->selected.first()->property(property), value, property);
-                addCommand(d->lastCommand, false);
+                addPropertyCommand(d->selected.first()->objectName().toLatin1(),
+                    d->selected.first()->property(property), value, property, false \
/* !exec*/);  }
 
             // If the property is changed, we add it in ObjectTreeItem modifProp
@@ -1694,9 +1722,7 @@
                 foreach(QWidget* widget, d->selected) {
                     oldValues.insert(widget->objectName().toLatin1(), \
widget->property(property));  }
-
-                d->lastCommand = new PropertyCommand(*this, oldValues, value, \
                property);
-                addCommand(d->lastCommand, false);
+                addPropertyCommand(oldValues, value, property, false /* !exec*/);
             }
         }
 
@@ -1840,7 +1866,7 @@
     for (KoProperty::Set::Iterator it(d->propertySet); it.current(); ++it) {
         kDebug() << it.current();
         if (!isPropertyVisible(it.current()->name(), isTopLevel, classname)) {
-            d->propertySet[it.current()->name()].setVisible(false);
+            it.current()->setVisible(false);
         }
     }
 
@@ -2025,13 +2051,15 @@
 // moved from WidgetPropertySet
 void Form::updatePropertyValue(ObjectTreeItem *tree, const char *property, const \
QMetaProperty &meta)  {
+    return; //????
+//! @todo ????
     const char *propertyName = meta.isValid() ? meta.name() : property;
     if (!d->propertySet.contains(propertyName))
         return;
-    KoProperty::Property p(d->propertySet[propertyName]);
+    KoProperty::Property &p = d->propertySet[propertyName];
 
 //! \todo what about set properties, and lists properties
-    QHash<QString, QVariant>::ConstIterator \
it(tree->modifiedProperties()->find(propertyName)); +    const QHash<QString, \
QVariant>::ConstIterator it(tree->modifiedProperties()->find(propertyName));  if (it \
!= tree->modifiedProperties()->constEnd()) {  blockSignals(true);
         if (meta.isValid() && meta.isEnumType()) {
@@ -2990,17 +3018,22 @@
             continue;
 
         QPalette p(widget->palette());
-        if (!d->origActiveColors)
+        p.setCurrentColorGroup(value ? QPalette::Normal : QPalette::Disabled);
+#if 0
+        QPalette p(widget->palette());
+        if (!d->origActiveColors) {
             d->origActiveColors = new QColorGroup(p.active());
+        }
         if (value) {
-            if (d->origActiveColors)
-                p.setActive(*d->origActiveColors);   //revert
-        } else {
+            p.setActive(*d->origActiveColors);   //revert
+        }
+        else {
             QColorGroup cg = p.disabled();
             //also make base color a bit disabled-like
             cg.setColor(QColorGroup::Base, cg.color(QColorGroup::Background));
             p.setActive(cg);
         }
+#endif
         widget->setPalette(p);
 
         tree->setEnabled(value);
--- trunk/koffice/kexi/formeditor/form.h #951274:951275
@@ -242,10 +242,21 @@
 
     PixmapCollection* pixmapCollection() const;
 
+/*    enum AddCommandOption {
+        NoAddCommandOptions = 0,
+        ExecuteCommand = 1,
+    }*/
+
     /*! Adds a widget in the form's command history. Please use it instead
     of calling directly actionCollection()->addCommand(). */
     void addCommand(K3Command *command, bool execute);
 
+    void addPropertyCommand(const QByteArray &wname, const QVariant &oldValue,
+                            const QVariant &value, const QByteArray &propertyName, \
bool execute); +
+    void addPropertyCommand(const QHash<QByteArray, QVariant> &oldValues,
+                            const QVariant &value, const QByteArray &propertyName, \
bool execute); +
     /*! Clears form's command history. */
     void clearCommandHistory();
 
--- trunk/koffice/kexi/formeditor/resizehandle.cpp #951274:951275
@@ -21,15 +21,12 @@
 #include <kdebug.h>
 #include <klocale.h>
 
-#include <qpainter.h>
-#include <qcursor.h>
-//Added by qt3to4:
+#include <QPainter>
+#include <QCursor>
 #include <QMouseEvent>
-#include <QEvent>
 #include <QPaintEvent>
 
 #include "form.h"
-//#include "formmanager.h"
 #include "resizehandle.h"
 #include "container.h"
 #include "widgetfactory.h"
@@ -143,6 +140,7 @@
     m_y = ev->y();
     if (startDragging) {
 // m_form->resizeHandleDraggingStarted(m_set->widget());
+        m_set->resizeStarted();
         WidgetFactory *wfactory = \
m_set->m_form->library()->factoryForClassName(m_set->widget()->metaObject()->className());
  if (wfactory)
             wfactory->resetEditor();
@@ -261,6 +259,7 @@
 void ResizeHandle::mouseReleaseEvent(QMouseEvent *)
 {
     m_dragging = false;
+    m_set->resizeFinished();
 }
 
 void ResizeHandle::paintEvent(QPaintEvent *)
@@ -334,4 +333,18 @@
         m_handles[i]->setEditingMode(editing);
 }
 
+void ResizeHandleSet::resizeStarted()
+{
+    m_origWidgetRect = m_widget->geometry();
+}
+
+void ResizeHandleSet::resizeFinished()
+{
+    if (m_widget) {
+        kDebug() << "old:" << m_origWidgetRect << "new:" << m_widget->geometry();
+        m_form->addPropertyCommand(m_widget->objectName().toLatin1(), \
m_origWidgetRect, +                                   m_widget->geometry(), \
"geometry", true /*execute*/); +    }
+}
+
 #include "resizehandle.moc"
--- trunk/koffice/kexi/formeditor/resizehandle.h #951274:951275
@@ -43,7 +43,7 @@
 
 public:
     enum HandlePos {
-        TopLeftCorner = 0,
+        TopLeftCorner = 1,
         TopCenter = 2,
         TopRightCorner = 4,
         LeftCenter = 8,
@@ -97,7 +97,11 @@
     void raise();
     void setEditingMode(bool editing);
 
+protected:
+    void resizeStarted();
+    void resizeFinished();
 private:
+    QRect m_origWidgetRect;
     QPointer<ResizeHandle> m_handles[8];
     QPointer<QWidget> m_widget;
     QPointer<Form>   m_form;
--- trunk/koffice/kexi/formeditor/widgetfactory.cpp #951274:951275
@@ -463,7 +463,7 @@
 
     if (m_widget) {
         disconnect(m_widget, 0, this, 0);
-        m_widget->repaint();
+        m_widget->update();
     }
 
 //js delete m_handles;
@@ -510,12 +510,8 @@
 // m_container = 0;
 }
 
-void
-WidgetFactory::changeProperty(const char *name, const QVariant &value, Form *form)
-//WidgetFactory::changeProperty(const char *name, const QVariant &value, Container \
*container) +void WidgetFactory::changeProperty(const char *name, const QVariant \
&value, Form *form)  {
-// if (!form->manager())
-//  return;
     if (!form->selectedWidgets()->isEmpty()) { // If eg multiple labels are \
                selected, 
                                                // we only want to change the text of \
one of them (the one the user cliked on)  if (m_widget) {
@@ -525,7 +521,7 @@
             form->selectedWidgets()->first()->setProperty(name, value);
         }
     }
-    else {
+    else { // single selection
         form->propertySet().changePropertyIfExists(name, value);
     }
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic