diff -r bf7eb7911fc5 -r 997a02608b3a emailuis/nmailuiwidgets/src/nmeditortextedit.cpp --- a/emailuis/nmailuiwidgets/src/nmeditortextedit.cpp Wed Jun 23 18:00:21 2010 +0300 +++ b/emailuis/nmailuiwidgets/src/nmeditortextedit.cpp Tue Jul 06 14:04:34 2010 +0300 @@ -17,23 +17,52 @@ #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(false, Qt::black); + + // Disable HbTextEdit scrolling. Background scroll area will handle scrolling. + setScrollable(false); + scrollArea()->setScrollDirections(0); + + // 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); + + // Create custom palette based on the current one + QPalette testPalette = QApplication::palette(); + + // Sets the selection background colour + testPalette.setColor(QPalette::Active, QPalette::Highlight, Qt::cyan); + testPalette.setColor(QPalette::Inactive, QPalette::Highlight, Qt::cyan); + + // Sets the link and visited link colours + testPalette.setColor(QPalette::Active, QPalette::Link, Qt::darkBlue); + testPalette.setColor(QPalette::Inactive, QPalette::Link, Qt::darkBlue); + testPalette.setColor(QPalette::Active, QPalette::LinkVisited, Qt::darkMagenta); + testPalette.setColor(QPalette::Inactive, QPalette::LinkVisited, Qt::darkMagenta); + + // Update custom palette for this widget + setPalette(testPalette); + + connect(this, SIGNAL(contentsChanged()), this, SLOT(updateCustomTextColor())); } /*! @@ -42,132 +71,9 @@ NmEditorTextEdit::~NmEditorTextEdit() { NM_FUNCTION; -} - -void NmEditorTextEdit::init(NmBaseViewScrollArea *bgScrollArea) -{ - NM_FUNCTION; - mPreviousContentsHeight = 0; - mFirstTime = true; - mCustomTextColor = QPair(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 +99,8 @@ tcursor.mergeCharFormat(fmt); } } - } else { + } + else { fmt = tcursor.charFormat(); fmt.setForeground(mCustomTextColor.second); tcursor.mergeCharFormat(fmt); @@ -203,18 +110,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 +149,14 @@ return mCustomTextColor; } + +/*! + * Returns the rectangle for the cursor. + */ +QRectF NmEditorTextEdit::rectForCursorPosition() const +{ + NM_FUNCTION; + + return HbTextEdit::rectForPosition(cursorPosition()); +} +