messagingapp/msgui/conversationview/src/msgeditorwidget.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 41 25fe1fe642e3
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    22 #include <HbPushButton>
    22 #include <HbPushButton>
    23 #include <HbTextItem>
    23 #include <HbTextItem>
    24 #include <qgraphicsscene.h>
    24 #include <qgraphicsscene.h>
    25 #include <HbFrameDrawer>
    25 #include <HbFrameDrawer>
    26 #include <HbFrameItem>
    26 #include <HbFrameItem>
       
    27 #include <HbAction>
    27 #include <csmsaccount.h>
    28 #include <csmsaccount.h>
    28 #include <smutset.h>
    29 #include <smutset.h>
    29 #include <hbmessagebox.h>
    30 #include <hbmessagebox.h>
    30 #include <QTimer>
    31 #include <QTimer>
    31 #include "unieditorpluginloader.h"
    32 #include "unieditorpluginloader.h"
    32 #include "unieditorplugininterface.h"
    33 #include "unieditorplugininterface.h"
    33 #include "unisendingsettings.h"
    34 #include "UniSendingSettings.h"
    34 #include "unieditorgenutils.h"
    35 #include "UniEditorGenUtils.h"
    35 #include "debugtraces.h"
    36 #include "debugtraces.h"
    36 
    37 
    37 // LOCAL CONSTANTS
    38 // LOCAL CONSTANTS
    38 const QString PLUGINPATH("conversationviewplugin.dll");
       
    39 
    39 
    40 const QString SEND_ICON("qtg_mono_send");
    40 const QString SEND_ICON("qtg_mono_send");
    41 const QString BACKGROUND("qtg_fr_input_bg");
    41 const QString BACKGROUND("qtg_fr_input_v_bg");
    42 const QString BACKGROUND_FRAME("qtg_fr_btn_normal");
    42 const QString BACKGROUND_FRAME("qtg_fr_btn_normal");
    43 
    43 
    44 const QString SEND_BUTTON_NORMAL("qtg_fr_input_btn_function_normal");
    44 const QString SEND_BUTTON_NORMAL("qtg_fr_input_btn_function_normal");
    45 const QString SEND_BUTTON_PRESSED("qtg_fr_input_btn_function_pressed");
    45 const QString SEND_BUTTON_PRESSED("qtg_fr_input_btn_function_pressed");
    46 const QString SEND_BUTTON_DISABLED("qtg_fr_input_btn_function_disabled");
    46 const QString SEND_BUTTON_DISABLED("qtg_fr_input_btn_function_disabled");
    47 
    47 
    48 #define LOC_SMS_CHAR_LIMIT_REACHED hbTrId("txt_messaging_dialog_sms_character_count_exceeded")
    48 #define LOC_SMS_CHAR_LIMIT_REACHED hbTrId("txt_messaging_dialog_sms_character_count_exceeded")
    49 #define LOC_DIALOG_OK hbTrId("txt_common_button_ok")
    49 #define LOC_HINT_TEXT hbTrId("txt_messaging_formlabel_enter_message_here")
    50 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
    50 
    51   
    51   
    52 const TInt KShowCounterLimit = 10;
    52 const TInt KShowCounterLimit = 10;
    53 
    53 
    54 QGraphicsItem* FOCUSITEM = 0;
    54 QGraphicsItem* FOCUSITEM = 0;
    55 
    55 
    59 //---------------------------------------------------------------
    59 //---------------------------------------------------------------
    60 MsgEditorWidget::MsgEditorWidget(QGraphicsItem *parent) :
    60 MsgEditorWidget::MsgEditorWidget(QGraphicsItem *parent) :
    61     HbWidget(parent), mMsgEditor(NULL),
    61     HbWidget(parent), mMsgEditor(NULL),
    62     mSendButton(NULL),mPluginLoader(NULL)
    62     mSendButton(NULL),mPluginLoader(NULL)
    63 {
    63 {
    64     int baseId = style()->registerPlugin(PLUGINPATH);
       
    65     
       
    66     #ifdef _DEBUG_TRACES_
       
    67     qDebug() << "MsgEditorWidget BASE ID --->" << baseId;
       
    68     #endif
       
    69     
       
    70     setPluginBaseId(baseId);
       
    71     
       
    72     //setting background.
    64     //setting background.
    73     HbFrameItem* backGround = new HbFrameItem(this);
    65     HbFrameItem* backGround = new HbFrameItem(this);
    74     backGround->frameDrawer().setFrameGraphicsName(BACKGROUND);
    66     backGround->frameDrawer().setFrameGraphicsName(BACKGROUND);
    75     backGround->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesVertical);
    67     backGround->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesVertical);
    76     backGround->frameDrawer().setFillWholeRect(true);
    68     backGround->frameDrawer().setFillWholeRect(true);
    89     // Create mandatory element of mesh layout.
    81     // Create mandatory element of mesh layout.
    90     mMsgEditor = new MsgEditor(this);
    82     mMsgEditor = new MsgEditor(this);
    91     mMsgEditor->setMaxRows(3); // NOTE: Don't remove this line.
    83     mMsgEditor->setMaxRows(3); // NOTE: Don't remove this line.
    92     HbStyle::setItemName(mMsgEditor, "msgEditor");
    84     HbStyle::setItemName(mMsgEditor, "msgEditor");
    93 
    85 
    94     mSendButton = new HbPushButton(this);
    86 	mSendButton = new HbPushButton(this); 
    95     HbStyle::setItemName(mSendButton, "sendButton");
    87     HbStyle::setItemName(mSendButton, "sendButton"); 
       
    88     mSendButton->setEnabled(false); 
       
    89     
       
    90     HbFrameItem* backGround = new HbFrameItem(this); 
       
    91     backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); 
       
    92     mSendButton->setBackgroundItem(backGround); 
       
    93     updateButtonBackground(SEND_BUTTON_DISABLED); 
    96     mSendButton->setIcon(HbIcon(SEND_ICON));
    94     mSendButton->setIcon(HbIcon(SEND_ICON));
    97     mSendButton->setEnabled(false);
       
    98     HbFrameDrawer* drawer = new HbFrameDrawer(this);
       
    99     drawer->setFrameType(HbFrameDrawer::NinePieces);
       
   100     mSendButton->setFrameBackground(drawer);
       
   101     updateButtonBackground(SEND_BUTTON_DISABLED);
       
   102     
    95     
   103     mCharCounter = new HbTextItem(this);
    96     mCharCounter = new HbTextItem(this);
   104     HbStyle::setItemName(mCharCounter, "charCounter");
    97     HbStyle::setItemName(mCharCounter, "charCounter");
   105     mCharCounter->setZValue(1.5);
    98     mCharCounter->setZValue(1.5);
   106     
    99     
   131 // MsgEditorWidget::~MsgEditorWidget
   124 // MsgEditorWidget::~MsgEditorWidget
   132 // @see header
   125 // @see header
   133 //---------------------------------------------------------------
   126 //---------------------------------------------------------------
   134 MsgEditorWidget::~MsgEditorWidget()
   127 MsgEditorWidget::~MsgEditorWidget()
   135 {
   128 {
   136     style()->unregisterPlugin(PLUGINPATH);
       
   137     delete mEditorUtils;
   129     delete mEditorUtils;
   138 }
   130 }
   139 
   131 
   140 //---------------------------------------------------------------
   132 //---------------------------------------------------------------
   141 // MsgEditorWidget::content
   133 // MsgEditorWidget::content
   227     }
   219     }
   228     
   220     
   229     //Check if sms segment limit has been reached
   221     //Check if sms segment limit has been reached
   230     bool unicode = (unicodeMode) ? true : false;
   222     bool unicode = (unicodeMode) ? true : false;
   231     int contentSize = mEditorUtils->UTF8Size(string);
   223     int contentSize = mEditorUtils->UTF8Size(string);
   232     int maxSmsSize =  mEditorUtils->MaxSmsMsgSizeL(unicode);
   224     int maxSmsSize =  0;
       
   225     TRAP_IGNORE(maxSmsSize = mEditorUtils->MaxSmsMsgSizeL(unicode));
   233     
   226     
   234     if(contentSize > maxSmsSize)
   227     if(contentSize > maxSmsSize)
   235     {        
   228     {        
   236         //Give breathing time for ITUT to complete its processing
   229         //Give breathing time for ITUT to complete its processing
   237         //without this there is a crash as ITUT cant complete its processing
   230         //without this there is a crash as ITUT cant complete its processing
   257 //---------------------------------------------------------------
   250 //---------------------------------------------------------------
   258 void MsgEditorWidget::handleSmsCharLimitReached()
   251 void MsgEditorWidget::handleSmsCharLimitReached()
   259 {
   252 {
   260     mSmsCharLimitReached = false;
   253     mSmsCharLimitReached = false;
   261     
   254     
   262     if(HbMessageBox::question(LOC_SMS_CHAR_LIMIT_REACHED,
   255     HbMessageBox::question(LOC_SMS_CHAR_LIMIT_REACHED,
   263         LOC_DIALOG_OK,
   256                            this,SLOT(onSmsCharLimitReached(HbAction*)),
   264         LOC_BUTTON_CANCEL))
   257                            HbMessageBox::Ok | HbMessageBox::Cancel);
   265     {
   258 
   266         //Launch UniEditor 
       
   267         emit smsCharLimitReached();
       
   268         return;
       
   269     }
       
   270     else
       
   271     {
       
   272         //Set the previous content
       
   273         setContent(QString(mPrevBuffer));
       
   274         return;
       
   275     }
       
   276 
   259 
   277 }
   260 }
   278 
   261 
   279 //---------------------------------------------------------------
   262 //---------------------------------------------------------------
   280 // MsgEditor::onClicked
   263 // MsgEditor::onClicked
   297 
   280 
   298 //---------------------------------------------------------------
   281 //---------------------------------------------------------------
   299 // MsgEditor::updateButtonBackground
   282 // MsgEditor::updateButtonBackground
   300 // @see header
   283 // @see header
   301 //---------------------------------------------------------------
   284 //---------------------------------------------------------------
   302 void MsgEditorWidget::updateButtonBackground(const QString& bg)
   285 void MsgEditorWidget::updateButtonBackground(const QString& bg) 
   303     {
   286     { 
   304     HbFrameDrawer* drawer = mSendButton->frameBackground();
   287     HbFrameItem* drawer = static_cast<HbFrameItem*>(mSendButton->backgroundItem()); 
   305     if(drawer)
   288     if(drawer) 
   306         {
   289         { 
   307         drawer->setFrameGraphicsName(bg);        
   290         drawer->frameDrawer().setFrameGraphicsName(bg);   
   308         }
   291         } 
   309     }
   292     } 
       
   293     
   310 
   294 
   311 //---------------------------------------------------------------
   295 //---------------------------------------------------------------
   312 // MsgEditor::onPressed
   296 // MsgEditor::onPressed
   313 // @see header
   297 // @see header
   314 //---------------------------------------------------------------
   298 //---------------------------------------------------------------
   325     {
   309     {
   326     updateButtonBackground(SEND_BUTTON_NORMAL);
   310     updateButtonBackground(SEND_BUTTON_NORMAL);
   327     }
   311     }
   328 	
   312 	
   329 //---------------------------------------------------------------
   313 //---------------------------------------------------------------
   330 // MsgEditor::setEncodingSettings
   314 // MsgEditor::setEncodingSettingsL
   331 // @see header
   315 // @see header
   332 //---------------------------------------------------------------
   316 //---------------------------------------------------------------
   333 void MsgEditorWidget::setEncodingSettings()
   317 void MsgEditorWidget::setEncodingSettingsL()
   334 { 
   318 { 
   335     if( mPluginLoader )
   319     if( mPluginLoader )
   336     {
   320     {
   337         delete mPluginLoader;
   321         delete mPluginLoader;
   338     }
   322     }
   371 // @see header
   355 // @see header
   372 //---------------------------------------------------------------
   356 //---------------------------------------------------------------
   373 MsgEditor::MsgEditor(QGraphicsItem *parent)
   357 MsgEditor::MsgEditor(QGraphicsItem *parent)
   374 :HbLineEdit(parent)
   358 :HbLineEdit(parent)
   375     {
   359     {
   376     
   360      this->setPlaceholderText(LOC_HINT_TEXT);
   377     }
   361     }
   378 
   362 
   379 //---------------------------------------------------------------
   363 //---------------------------------------------------------------
   380 // MsgEditor::focusInEvent
   364 // MsgEditor::focusInEvent
   381 // @see header
   365 // @see header
   404     FOCUSITEM->setFocusProxy(0);
   388     FOCUSITEM->setFocusProxy(0);
   405     setCursorVisibility(Hb::TextCursorHidden);
   389     setCursorVisibility(Hb::TextCursorHidden);
   406     HbLineEdit::focusOutEvent(event);  
   390     HbLineEdit::focusOutEvent(event);  
   407     }
   391     }
   408 
   392 
       
   393 //---------------------------------------------------------------
       
   394 // MsgEditor::onSmsCharLimitReached
       
   395 // @see header
       
   396 //---------------------------------------------------------------
       
   397 void MsgEditorWidget::onSmsCharLimitReached(HbAction* action)
       
   398 {
       
   399     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   400     if (action == dlg->actions().at(0)) {
       
   401 
       
   402         //Launch UniEditor 
       
   403         emit smsCharLimitReached();
       
   404     }
       
   405     else {
       
   406         //Set the previous content
       
   407         setContent( QString(mPrevBuffer));
       
   408     }
       
   409 }
   409 
   410 
   410 // EOF
   411 // EOF