emailuis/nmailuiwidgets/src/nmeditortextedit.cpp
changeset 47 f83bd4ae1fe3
parent 43 99bcbff212ad
child 48 10eaf342f539
--- a/emailuis/nmailuiwidgets/src/nmeditortextedit.cpp	Fri Jun 11 16:42:02 2010 +0300
+++ b/emailuis/nmailuiwidgets/src/nmeditortextedit.cpp	Thu Jun 24 14:32:18 2010 +0300
@@ -17,23 +17,36 @@
 
 #include "nmailuiwidgetsheaders.h"
 
-// Following constants will be removed later when possible
-static const double Un = 6.66;
-static const double BodyMargin = Un;
-static const int ChromeHeight = 160;
-static const double FieldHeightWhenSecondaryFont = 7.46 * Un;
-static const int GroupBoxTitleHeight = 42;
-static const double HeightOfTheHeaderOnStartup =
-    2 * FieldHeightWhenSecondaryFont + GroupBoxTitleHeight;
+static const QString FILE_PATH_CSS = ":nmeditortextedit.css";
+static const QString FILE_PATH_WIDGETML = ":nmeditortextedit.widgetml";
 
 /*!
     Constructor
 */
 NmEditorTextEdit::NmEditorTextEdit(QGraphicsItem *parent) :
-    HbTextEdit(parent),
-    mFirstTimeToScrollPosUpdate(true)
+    HbTextEdit(parent)
 {
     NM_FUNCTION;
+    
+    HbStyleLoader::registerFilePath(FILE_PATH_WIDGETML);
+    HbStyleLoader::registerFilePath(FILE_PATH_CSS);
+
+    mCustomTextColor = QPair<bool, QColor>(false, Qt::black);
+    
+    // Enable scrolling using cursor
+    setScrollable(true);
+    scrollArea()->setScrollDirections(Qt::Horizontal);
+
+    // set background colour to plain white
+    QPixmap whitePixmap(10,10);
+    whitePixmap.fill(Qt::white);
+    QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem (whitePixmap);
+    setBackgroundItem(pixmapItem); 
+    
+    // disables highlight frame for now - new api to set the frame item should be release somewhere wk26
+    setFocusHighlight(HbStyle::P_TextEdit_frame_highlight, HbWidget::FocusHighlightNone);
+    
+    connect(this, SIGNAL(contentsChanged()), this, SLOT(updateCustomTextColor()));
 }
 
 /*!
@@ -42,132 +55,9 @@
 NmEditorTextEdit::~NmEditorTextEdit()
 {
     NM_FUNCTION;
-}
-
-void NmEditorTextEdit::init(NmBaseViewScrollArea *bgScrollArea)
-{
-    NM_FUNCTION;
     
-    mPreviousContentsHeight = 0;
-    mFirstTime = true;
-    mCustomTextColor = QPair<bool, QColor>(false,Qt::black);
-    mBackgroundScrollArea = bgScrollArea;
-    mHeaderHeight = (int)HeightOfTheHeaderOnStartup;
-    mBgScrollPosition.setX(0);
-    mBgScrollPosition.setY(0);
-    document()->setDocumentMargin(BodyMargin);
-
-    mScrollArea = this->scrollArea();
-
-    // Enable scrolling using cursor
-    setScrollable(true);
-    mScrollArea->setScrollDirections(Qt::Horizontal);
-
-    connect(this, SIGNAL(contentsChanged()), this, SLOT(updateEditorHeight()));
-    connect(this, SIGNAL(cursorPositionChanged(int, int)),
-            this, SLOT(setScrollPosition(int, int)));
-    connect(this, SIGNAL(contentsChanged()), this, SLOT(updateCustomTextColor()));
-}
-
-/*!
-    This function returns the height (pixels) of the body fields document content.
- */
-qreal NmEditorTextEdit::contentHeight() const
-{
-    NM_FUNCTION;
-    
-    QSizeF s = document()->size();
-    return s.height();
-}
-
-/*!
-   This slot updates the editor height. It is called every time when text edit
-   widget content has been changed.
- */
-void NmEditorTextEdit::updateEditorHeight()
-{
-    NM_FUNCTION;
-    
-    // Get current body content height
-    qreal heightOfTheTextEdit = contentHeight();
-
-    // Check if height is changed
-    if (mPreviousContentsHeight != heightOfTheTextEdit) {
-        mPreviousContentsHeight = heightOfTheTextEdit;
-        setPreferredHeight(heightOfTheTextEdit);
-        setMaximumHeight(heightOfTheTextEdit);
-    }
-    // Inform parent that content height has been changed
-    emit editorContentHeightChanged();
-}
-
-/*!
-    This slot is called when cursor position is changed in body area using
-    'pointing stick' or keyboard. Function will update the scroll position
-    of the content so that cursor does not go outside of the screen or
-    behind the virtual keyboard.
- */
-void NmEditorTextEdit::setScrollPosition(int oldPos, int newPos)
-{
-    NM_FUNCTION;
-    
-    Q_UNUSED(oldPos);
-
-    if (mFirstTime) {
-        // For some reason content height of the HbTextEdit is wrong
-        // right after construction. That is the reason why this mFirstTime
-        // member is used to set content height bit later.
-        mFirstTime = false;
-        updateEditorHeight();
-    }
-    const QSizeF screenReso = HbDeviceProfile::current().logicalSize();
-    qreal maxHeight = screenReso.height() - ChromeHeight;
-
-    // Get cursor position coordinates
-    QRectF cursorPosPix = rectForPosition(newPos);
-
-    // Calculate the screen top and bottom boundaries, this means the part of the
-    // background scroll area which is currently visible.
-    qreal visibleRectTopBoundary;
-    qreal visibleRectBottomBoundary;
-
-    if (mBgScrollPosition.y() < mHeaderHeight) {
-        // Header is completely or partially visible
-        visibleRectTopBoundary = mHeaderHeight - mBgScrollPosition.y();
-        visibleRectBottomBoundary = maxHeight - visibleRectTopBoundary;
-    }
-    else {
-        // Header is not visible
-        visibleRectTopBoundary = mBgScrollPosition.y() - mHeaderHeight;
-        visibleRectBottomBoundary = visibleRectTopBoundary + maxHeight;
-    }
-
-    // Do scrolling if cursor is out of the screen boundaries
-    if (cursorPosPix.y() > visibleRectBottomBoundary) {
-        // Do scroll forward
-        mBackgroundScrollArea->scrollContentsTo(
-            QPointF(0,cursorPosPix.y() - maxHeight + mHeaderHeight));
-    }
-    else if (cursorPosPix.y() + mHeaderHeight < mBgScrollPosition.y()) {
-        // Do scroll backward
-        mBackgroundScrollArea->scrollContentsTo(QPointF(0,cursorPosPix.y() + mHeaderHeight));
-    }
-}
-
-/*!
-    This slot is called when background scroll areas scroll position has been shanged.
-*/
-void NmEditorTextEdit::updateScrollPosition(const QPointF &newPosition)
-{
-    NM_FUNCTION;
-    
-    // Temporary fix: When this is called for the first time, the editor is scrolled down for 
-    // some reason so this will restore the scroll position.
-    if(mFirstTimeToScrollPosUpdate) {
-        mFirstTimeToScrollPosUpdate = false;
-        mBackgroundScrollArea->scrollContentsTo(QPointF(0,0));        
-    }
-    mBgScrollPosition = newPosition;
+    HbStyleLoader::unregisterFilePath(FILE_PATH_WIDGETML);
+    HbStyleLoader::unregisterFilePath(FILE_PATH_CSS);    
 }
 
 /*!
@@ -193,7 +83,8 @@
                     tcursor.mergeCharFormat(fmt);
                 }
             }
-        } else {
+        }
+        else {
             fmt = tcursor.charFormat();
             fmt.setForeground(mCustomTextColor.second);
             tcursor.mergeCharFormat(fmt);
@@ -203,18 +94,6 @@
 }
 
 /*!
-    This slot is called when header widget height has been changed. Function performs
-    the repositioning of the body field and resizing of the editor and content area.
- */
-void NmEditorTextEdit::setHeaderHeight(int newHeight)
-{
-    NM_FUNCTION;
-    
-    mHeaderHeight = newHeight;
-    updateEditorHeight();
-}
-
-/*!
    Sets flag is custom text color should be used and sets the custom color.
    
    Function does not affect the color of existing content, only text that will be entered later.
@@ -254,3 +133,12 @@
     
     return mCustomTextColor;
 }
+
+/*!
+ *  Returns the calculated rect in item coordinates of the editor for the the given \a position inside a document.
+ */
+QRectF NmEditorTextEdit::rectForPosition(int position)
+{
+    return HbTextEdit::rectForPosition(position);
+}
+