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

List:       kde-commits
Subject:    koffice/kexi/plugins/forms
From:       Jarosław Staniek <staniek () kde ! org>
Date:       2009-11-04 13:16:56
Message-ID: 1257340616.599662.32454.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1044677 by staniek:

Forms
*line edit widget:
**"data source tag" icon is displayed to indicate there is data source assigned
**disabled inline editing when data source is assigned
**disabled inline editing for newly inserted widget



 M  +21 -11    kexidbfactory.cpp  
 M  +110 -12   widgets/kexidblineedit.cpp  
 M  +7 -7      widgets/kexidblineedit.h  


--- trunk/koffice/kexi/plugins/forms/kexidbfactory.cpp #1044676:1044677
@@ -35,13 +35,16 @@
 #include <formeditor/formIO.h>
 #include <formeditor/objecttree.h>
 #include <formeditor/utils.h>
+#include <formeditor/widgetlibrary.h>
+#include <core/kexi.h>
+#include <core/kexipart.h>
+#include <core/KexiMainWindowIface.h>
 #include <kexidb/utils.h>
 #include <kexidb/connection.h>
-#include <kexipart.h>
-#include <formeditor/widgetlibrary.h>
 #include <kexiutils/utils.h>
 #include <widget/kexicustompropertyfactory.h>
 #include <widget/utils/kexicontextmenuutils.h>
+#include <kexi_global.h>
 
 #include "kexiformview.h"
 #include "widgets/kexidbautofield.h"
@@ -60,9 +63,7 @@
 #include "kexidataawarewidgetinfo.h"
 
 #include "kexidbfactory.h"
-#include <core/kexi.h>
-#include <kexi_global.h>
-#include <KexiMainWindowIface.h>
+#include "kexiformdataiteminterface.h"
 
 
 //////////////////////////////////////////
@@ -109,6 +110,7 @@
         i18nc("Widget name. This string will be used to name widgets of this class. \
                "
               "It must _not_ contain white spaces and non latin1 characters.", \
                "textBox"));
     wi->setDescription(i18n("A widget for entering and displaying text"));
+    wi->setInternalProperty("dontStartEditingOnInserting", true); // because we are \
most probably assign data source to this widget  addClass(wi);
 
     // inherited
@@ -170,10 +172,9 @@
     wi->setDescription(i18n("A widget for displaying images"));
 // wi->setCustomTypeForProperty("pixmapData", \
                KexiCustomPropertyFactory::PixmapData);
     wi->setCustomTypeForProperty("pixmapId", KexiCustomPropertyFactory::PixmapId);
+    wi->setInternalProperty("dontStartEditingOnInserting", true);
     addClass(wi);
 
-    setInternalProperty("KexiDBImageBox", "dontStartEditingOnInserting", "1");
-// setInternalProperty("KexiDBImageBox", "forceShowAdvancedProperty:pixmap", "1");
 #endif
 
 #ifdef KEXI_DB_COMBOBOX_WIDGET
@@ -455,11 +456,20 @@
     if (args.classname == "KexiDBLineEdit") {
 //! @todo this code should not be copied here but
 //! just inherited StdWidgetFactory::startInlineEditing() should be called
+
         KLineEdit *lineedit = static_cast<KLineEdit*>(args.widget);
-        args.text = lineedit->text();
-        args.alignment = lineedit->alignment();
-        args.useFrame = true;
-        return true;
+        KexiFormDataItemInterface* iface = \
dynamic_cast<KexiFormDataItemInterface*>(lineedit); +        if (iface && \
!iface->dataSource().isEmpty()) { +//! @todo reimplement inline editing for \
KexiDBLineEdit using combobox with data sources +            return false;
+        }
+        else {
+            KLineEdit *lineedit = static_cast<KLineEdit*>(args.widget);
+            args.text = lineedit->text();
+            args.alignment = lineedit->alignment();
+            args.useFrame = true;
+            return true;
+        }
     }
     else if (args.classname == "KexiDBTextEdit") {
 //! @todo this code should not be copied here but
--- trunk/koffice/kexi/plugins/forms/widgets/kexidblineedit.cpp #1044676:1044677
@@ -1,6 +1,6 @@
 /* This file is part of the KDE project
    Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
-   Copyright (C) 2004-2007 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2004-2009 Jarosław Staniek <staniek@kde.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -21,20 +21,23 @@
 #include "kexidblineedit.h"
 #include "kexidbautofield.h"
 
-#include <kdebug.h>
-#include <knumvalidator.h>
-#include <kdatetable.h>
+#include <KDebug>
+#include <KNumInput>
+#include <KDateTable>
+#include <KIconEffect>
 
-#include <qmenu.h>
-#include <qpainter.h>
+#include <QMenu>
+#include <QPainter>
+#include <QEvent>
+#include <QPaintEvent>
+#include <QStyle>
+#include <QStyleOption>
 
 #include <kexiutils/utils.h>
+#include <kexiutils/styleproxy.h>
 #include <kexidb/queryschema.h>
 #include <kexidb/fieldvalidator.h>
 #include <kexiutils/utils.h>
-//Added by qt3to4:
-#include <QEvent>
-#include <QPaintEvent>
 
 //! @todo reenable as an app aption
 //#define USE_KLineEdit_setReadOnly
@@ -54,6 +57,56 @@
 
 //-----
 
+//! A style proxy overriding KexiDBLineEdit style
+class KexiDBLineEditStyle : public KexiUtils::StyleProxy
+{
+public:
+    KexiDBLineEditStyle(QStyle* parentStyle) : KexiUtils::StyleProxy(parentStyle), \
indent(0) +    {
+    }
+
+    void setIndent(int indent) {
+        this->indent = indent;
+    }
+
+    QRect subElementRect(SubElement element, const QStyleOption *option, const \
QWidget *widget) const +    {
+        const KFormDesigner::FormWidgetInterface *formWidget = dynamic_cast<const \
KFormDesigner::FormWidgetInterface*>(widget); +        if (formWidget->designMode()) \
{ +            const KexiFormDataItemInterface *dataItemIface = dynamic_cast<const \
KexiFormDataItemInterface*>(widget); +            if (dataItemIface && \
!dataItemIface->dataSource().isEmpty() && !formWidget->editingMode()) { +             \
if (element == SE_LineEditContents) { +                    QRect rect = \
KexiUtils::StyleProxy::subElementRect(SE_LineEditContents, option, widget); +         \
if (option->direction == Qt::LeftToRight) +                        return \
rect.adjusted(indent, 0, 0, 0); +                    else
+                        return rect.adjusted(0, 0, -indent, 0);
+                }
+            }
+        }
+        return KexiUtils::StyleProxy::subElementRect(element, option, widget);
+    }
+    int indent;
+};
+
+//-----
+
+//! For KexiDBLineEdit's singleton
+struct KexiDBLineEditData
+{
+    void init(QWidget *w) {
+        QFontMetrics fm(w->font());
+        int size = KIconLoader::global()->currentSize(KIconLoader::Small);
+        if (size < KIconLoader::SizeSmallMedium && fm.height() >= \
KIconLoader::SizeSmallMedium) +            size = KIconLoader::SizeSmallMedium;
+        dataSourceTagIcon = \
KIconLoader::global()->loadIcon(QLatin1String("data-source-tag"), KIconLoader::Small, \
size); +        KIconEffect::semiTransparent(dataSourceTagIcon);
+    }
+    QPixmap dataSourceTagIcon;
+};
+
+K_GLOBAL_STATIC(KexiDBLineEditData, g_lineEditData)
+
 KexiDBLineEdit::KexiDBLineEdit(QWidget *parent)
         : KLineEdit(parent)
         , KexiDBTextWidgetInterface()
@@ -73,6 +126,12 @@
     tmpFont.setPointSize(KGlobalSettings::smallestReadableFont().pointSize());
     setMinimumHeight(QFontMetrics(tmpFont).height() + 6);
     connect(this, SIGNAL(textChanged(const QString&)), this, \
SLOT(slotTextChanged(const QString&))); +
+    g_lineEditData->init(this);
+    KexiDBLineEditStyle *ks = new KexiDBLineEditStyle(style());
+    ks->setParent(this);
+    ks->setIndent(g_lineEditData->dataSourceTagIcon.width());
+    setStyle( ks );
 }
 
 KexiDBLineEdit::~KexiDBLineEdit()
@@ -195,7 +254,6 @@
         KLineEdit::clear();
 }
 
-
 void KexiDBLineEdit::setColumnInfo(KexiDB::QueryColumnInfo* cinfo)
 {
     KexiFormDataItemInterface::setColumnInfo(cinfo);
@@ -223,8 +281,29 @@
 void KexiDBLineEdit::paintEvent(QPaintEvent *pe)
 {
     KLineEdit::paintEvent(pe);
-    QPainter p(this);
-    KexiDBTextWidgetInterface::paint(this, &p, text().isEmpty(), alignment(), \
hasFocus()); +    KFormDesigner::FormWidgetInterface *formWidget = \
dynamic_cast<KFormDesigner::FormWidgetInterface*>(this); +    if \
(formWidget->designMode()) { +        KexiFormDataItemInterface *dataItemIface = \
dynamic_cast<KexiFormDataItemInterface*>(this); +        if (dataItemIface && \
!dataItemIface->dataSource().isEmpty() && !formWidget->editingMode()) { +            \
// draw "data source tag" icon +            QPainter p(this);
+//! @todo RTL...
+            QStyleOptionFrameV2 option;
+            initStyleOption(&option);
+            
+            int leftMargin, topMargin, rightMargin, bottomMargin;
+            getContentsMargins(&leftMargin, &topMargin, &rightMargin, \
&bottomMargin); +            QRect r( \
style()->subElementRect(QStyle::SE_LineEditContents, &option, this) ); +            \
r.setX(r.x() + leftMargin); +            r.setY(r.y() + topMargin);
+            r.setRight(r.right() - rightMargin);
+            r.setBottom(r.bottom() - bottomMargin);
+            p.drawPixmap( r.left() - g_lineEditData->dataSourceTagIcon.width() + 2,
+                r.top() + (r.height() - g_lineEditData->dataSourceTagIcon.height()) \
/ 2, +                g_lineEditData->dataSourceTagIcon
+            );
+        }
+    }
 }
 
 bool KexiDBLineEdit::event(QEvent * e)
@@ -297,4 +376,23 @@
     return false;
 }
 
+void KexiDBLineEdit::updateTextForDataSource()
+{
+    if (!designMode())
+        return;
+    setText(dataSource());
+}
+
+void KexiDBLineEdit::setDataSource(const QString &ds)
+{
+    KexiFormDataItemInterface::setDataSource(ds);
+    updateTextForDataSource();
+}
+
+void KexiDBLineEdit::setDataSourcePartClass(const QString &partClass)
+{
+    KexiFormDataItemInterface::setDataSourcePartClass(partClass);
+    updateTextForDataSource();
+}
+
 #include "kexidblineedit.moc"
--- trunk/koffice/kexi/plugins/forms/widgets/kexidblineedit.h #1044676:1044677
@@ -1,6 +1,6 @@
 /* This file is part of the KDE project
    Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
-   Copyright (C) 2004-2007 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2004-2009 Jarosław Staniek <staniek@kde.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -111,12 +111,10 @@
     virtual bool keyPressed(QKeyEvent *ke);
 
 public slots:
-    inline void setDataSource(const QString &ds) {
-        KexiFormDataItemInterface::setDataSource(ds);
-    }
-    inline void setDataSourcePartClass(const QString &partClass) {
-        KexiFormDataItemInterface::setDataSourcePartClass(partClass);
-    }
+    void setDataSource(const QString &ds);
+
+    void setDataSourcePartClass(const QString &partClass);
+
     virtual void setReadOnly(bool readOnly);
 
     //! Reimplemented, so "undo" means the same as "cancelEditor" action
@@ -147,6 +145,8 @@
     //! Implemented for KexiSubwidgetInterface
     virtual bool appendStretchRequired(KexiDBAutoField* autoField) const;
 
+    void updateTextForDataSource();
+
     //! Used to format text
     KexiTextFormatter m_textFormatter;
 


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

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