[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:       2010-05-23 22:25:12
Message-ID: 20100523222512.C24EBAC8BE () svn ! kde ! org
[Download RAW message or body]

SVN commit 1129840 by staniek:

Forms
*Image Box widget:
**added new property "Smoothing". When "Scaled Contents" is on, image is scaled \
                smoothly. On by default.
**cache scaled pixmap between paint events



 M  +1 -0      kexidbfactory.cpp  
 M  +33 -3     widgets/kexidbimagebox.cpp  
 M  +20 -9     widgets/kexidbimagebox.h  


--- trunk/koffice/kexi/plugins/forms/kexidbfactory.cpp #1129839:1129840
@@ -346,6 +346,7 @@
 // m_propDesc["pixmap"] = i18n("Image");
     m_propDesc["pixmapId"] = i18n("Image");
     m_propDesc["scaledContents"] = i18n("Scaled Contents");
+    m_propDesc["smoothTransformation"] = i18nc("Smoothing when contents are scaled", \
                "Smoothing");
     m_propDesc["keepAspectRatio"] = i18nc("Keep Aspect Ratio (short)", "Keep \
Ratio");  
     //hide classes that are replaced by db-aware versions
--- trunk/koffice/kexi/plugins/forms/widgets/kexidbimagebox.cpp #1129839:1129840
@@ -79,6 +79,7 @@
 //2.0 moved to FormWidgetInterface      , m_designMode(designMode)
         , m_readOnly(false)
         , m_scaledContents(false)
+        , m_smoothTransformation(true)
         , m_keepAspectRatio(true)
         , m_insideSetData(false)
         , m_setFocusOnButtonAfterClosingPopup(false)
@@ -179,6 +180,9 @@
         ///unused (m_valueMimeType is not available unless the px is inserted) \
QString type( KImageIO::typeForMime(m_valueMimeType) );  ///ok = KImageIO::canRead( \
                type );
         ok = loadPixmap ? m_pixmap.loadFromData(m_value) : true; //, \
type.toLatin1()); +        if (loadPixmap) {
+            m_currentScaledPixmap = QPixmap(); // clear cache
+        }
         if (!ok) {
             //! @todo inform about error?
         }
@@ -186,6 +190,7 @@
     if (!ok) {
         m_valueMimeType.clear();
         m_pixmap = QPixmap();
+        m_currentScaledPixmap = QPixmap(); // clear cache
     }
     repaint();
 }
@@ -287,15 +292,30 @@
 {
 //todo m_pixmapLabel->setScaledContents(set);
     m_scaledContents = set;
+    m_currentScaledPixmap = QPixmap();
     repaint();
 }
 
+bool KexiDBImageBox::smoothTransformation() const
+{
+    return m_smoothTransformation;
+}
+
+void KexiDBImageBox::setSmoothTransformation(bool set)
+{
+    m_smoothTransformation = set;
+    m_currentScaledPixmap = QPixmap();
+    repaint();
+}
+
 void KexiDBImageBox::setKeepAspectRatio(bool set)
 {
     m_keepAspectRatio = set;
-    if (m_scaledContents)
+    m_currentScaledPixmap = QPixmap();
+    if (m_scaledContents) {
         repaint();
 }
+}
 
 QWidget* KexiDBImageBox::widget()
 {
@@ -432,6 +452,7 @@
         buffer.open(IO_WriteOnly);
         if (m_pixmap.save(&buffer, "PNG")) {  // write pixmap into ba in PNG format
             setValueInternal(ba, true, false/* !loadPixmap */);
+            m_currentScaledPixmap = QPixmap(); // clear cache
         } else {
             setValueInternal(QByteArray(), true);
         }
@@ -710,9 +731,18 @@
         //clearing needed here because we may need to draw a pixmap with \
transparency  //       p.fillRect(0, 0, width(), height(), bgBrush);
 
-        KexiUtils::drawPixmap(p, margins, QRect(QPoint(0, 0), internalSize), \
                pixmap(), m_alignment,
-                              m_scaledContents, m_keepAspectRatio);
+        const QRect internalRect(QPoint(0, 0), internalSize);
+        if (m_currentScaledPixmap.isNull() || internalRect != m_currentRect) {
+            m_currentRect = internalRect;
+            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()) {
--- trunk/koffice/kexi/plugins/forms/widgets/kexidbimagebox.h #1129839:1129840
@@ -48,6 +48,7 @@
     Q_PROPERTY(uint pixmapId READ pixmapId WRITE setPixmapId STORED false)
     Q_PROPERTY(uint storedPixmapId READ storedPixmapId WRITE setStoredPixmapId \
                DESIGNABLE false STORED true)
     Q_PROPERTY(bool scaledContents READ hasScaledContents WRITE setScaledContents)
+    Q_PROPERTY(bool smoothTransformation READ smoothTransformation WRITE \
                setSmoothTransformation)
     Q_PROPERTY(bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio)
     Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
 // Q_PROPERTY( QString originalFileName READ originalFileName WRITE \
setOriginalFileName DESIGNABLE false ) @@ -98,6 +99,8 @@
 
     bool hasScaledContents() const;
 
+    bool smoothTransformation() const;
+
     Qt::Alignment alignment() const {
         return m_alignment;
     }
@@ -172,6 +175,8 @@
 
     void setScaledContents(bool set);
 
+    void setSmoothTransformation(bool set);
+
     void setAlignment(Qt::Alignment alignment);
 
     void setKeepAspectRatio(bool set);
@@ -275,16 +280,22 @@
     Qt::Alignment m_alignment;
     Qt::FocusPolicy m_focusPolicyInternal; //!< Used for focusPolicyInternal()
 //2.0 moved to FormWidgetInterface    bool m_designMode : 1;
-    bool m_readOnly : 1;
-    bool m_scaledContents : 1;
-    bool m_keepAspectRatio : 1;
-    bool m_insideSetData : 1;
-    bool m_setFocusOnButtonAfterClosingPopup : 1;
+
+    QPixmap m_currentScaledPixmap; //!< for caching
+    QRect m_currentRect;           //!< for caching
+    QPoint m_currentPixmapPos;     //!< for caching
+
+    bool m_readOnly;
+    bool m_scaledContents;
+    bool m_smoothTransformation;
+    bool m_keepAspectRatio;
+    bool m_insideSetData;
+    bool m_setFocusOnButtonAfterClosingPopup;
 //    bool m_lineWidthChanged : 1;
-    bool m_paletteBackgroundColorChanged : 1;
-    bool m_paintEventEnabled : 1; //!< used to disable paintEvent()
-    bool m_dropDownButtonVisible : 1;
-    bool m_insideSetPalette : 1;
+    bool m_paletteBackgroundColorChanged;
+    bool m_paintEventEnabled; //!< used to disable paintEvent()
+    bool m_dropDownButtonVisible;
+    bool m_insideSetPalette;
 };
 
 #endif


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

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