Modified update location dialog
authorKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Wed, 9 Jun 2010 12:45:36 +0000 (15:45 +0300)
committerKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Wed, 9 Jun 2010 12:45:36 +0000 (15:45 +0300)
src/ui/updatelocation/updatelocationdialog.cpp
src/ui/updatelocation/updatelocationdialog.h
src/ui/userinfo.cpp
src/ui/userinfo.h

index 5ff5042..935c738 100644 (file)
@@ -37,16 +37,18 @@ UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publ
 \r
     m_textEdit = new QTextEdit;\r
 \r
-    if ( userMessage.isEmpty() )\r
+    if (userMessage.isEmpty())\r
     {\r
-        m_textEdit->setText( tr("Message:") );\r
+        m_textEdit->setText(tr("Message:"));\r
         m_textEdit->selectAll();\r
-        connect(m_textEdit, SIGNAL(selectionChanged()), this, SLOT(textSelectionChanged()));\r
+\r
+        connect(m_textEdit, SIGNAL(selectionChanged()),\r
+                this, SLOT(textSelectionChanged()));\r
     }\r
     else\r
     {\r
-        m_textEdit->setText( userMessage );\r
-        m_textEdit->document()->setModified( true );\r
+        m_textEdit->setText(userMessage);\r
+        m_textEdit->document()->setModified(true);\r
     }\r
 \r
     QScrollArea *scrollArea = new QScrollArea();\r
@@ -54,10 +56,10 @@ UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publ
     QVBoxLayout* scrollAreaLayout = new QVBoxLayout;\r
     scrollAreaLayout->setSpacing(0);\r
     scrollAreaLayout->setMargin(0);\r
-    scrollAreaLayout->addWidget( m_textEdit );\r
+    scrollAreaLayout->addWidget(m_textEdit);\r
 \r
     QWidget* scrollAreaWidget = new QWidget;\r
-    scrollAreaWidget->setLayout( scrollAreaLayout );\r
+    scrollAreaWidget->setLayout(scrollAreaLayout);\r
 \r
     scrollArea->setWidget(scrollAreaWidget);\r
 \r
@@ -77,45 +79,50 @@ UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publ
     m_charCountLabel = new QLabel;\r
     m_charCountLabel->setNum(MESSAGE_MAX_LENGTH);\r
 \r
-    gridLayout->addWidget(new QLabel(tr("Location:")), 0, 0, 1, 1, Qt::AlignTop | Qt::AlignLeft );\r
+    gridLayout->addWidget(new QLabel(tr("Location:")), 0, 0, 1, 1, Qt::AlignTop | Qt::AlignLeft);\r
     gridLayout->addWidget(m_locationLabel, 0, 1, 1, 3);\r
     gridLayout->addWidget(scrollArea,      1, 0, 1, 4);\r
     gridLayout->addWidget(m_checkBox,      2, 0, 1, 2);\r
-    gridLayout->addWidget(m_charCountLabel,2, 2, 1, 1, Qt::AlignCenter );\r
+    gridLayout->addWidget(m_charCountLabel,2, 2, 1, 1, Qt::AlignCenter);\r
     gridLayout->addWidget(buttonBox,       2, 3, 2, 1, Qt::AlignTop);\r
 \r
-    gridLayout->setColumnMinimumWidth( 2, 2 * m_charCountLabel->fontMetrics().width(\r
-            m_charCountLabel->text() ));\r
+    gridLayout->setColumnMinimumWidth(2, 2 * m_charCountLabel->fontMetrics().width(\r
+            m_charCountLabel->text()));\r
 \r
     setLayout(gridLayout);\r
 \r
     const int LAYOUT_COLUMN_ONE_STRETCH = 10;\r
     const int LAYOUT_TOP_MARGIN = 15;\r
-    gridLayout->setColumnStretch( 1, LAYOUT_COLUMN_ONE_STRETCH );\r
+    gridLayout->setColumnStretch(1, LAYOUT_COLUMN_ONE_STRETCH);\r
 \r
     QMargins layoutMargins = gridLayout->contentsMargins();\r
-    layoutMargins.setTop( LAYOUT_TOP_MARGIN );\r
-    gridLayout->setContentsMargins( layoutMargins );\r
+    layoutMargins.setTop(LAYOUT_TOP_MARGIN);\r
+    gridLayout->setContentsMargins(layoutMargins);\r
+\r
+    connect(sendButton, SIGNAL(clicked()),\r
+            this, SLOT(sendUpdate()));\r
 \r
-    connect(sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate()));\r
-    connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));\r
-    connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(textChanged()));\r
+    connect(cancelButton, SIGNAL(clicked()),\r
+            this, SLOT(reject()));\r
+\r
+    connect(m_textEdit, SIGNAL(textChanged()),\r
+            this, SLOT(textChanged()));\r
 \r
 #ifdef Q_WS_MAEMO_5\r
-    if (QAbstractKineticScroller * scroller = scrollArea->property("kineticScroller").value<\r
+    if (QAbstractKineticScroller *scroller = scrollArea->property("kineticScroller").value<\r
                                               QAbstractKineticScroller *>()) {\r
         scroller->setOvershootPolicy(QAbstractKineticScroller::OvershootAlwaysOff);\r
     }\r
 \r
     new TextEditAutoResizer(m_textEdit);\r
     setAttribute(Qt::WA_Maemo5StackedWindow);\r
-    setWindowFlags( Qt::Window );\r
+    setWindowFlags(Qt::Window);\r
 #endif\r
 }\r
 \r
 UpdateLocationDialog::~UpdateLocationDialog()\r
 {\r
-    qWarning() << __PRETTY_FUNCTION__;\r
+    qDebug() << __PRETTY_FUNCTION__;\r
 }\r
 \r
 void UpdateLocationDialog::setAddress(const QString &address)\r
@@ -140,29 +147,31 @@ void UpdateLocationDialog::textChanged()
 {\r
     qDebug() << __PRETTY_FUNCTION__;\r
 \r
-    QString msgText( m_textEdit->toPlainText() );\r
+    QString msgText = m_textEdit->toPlainText();\r
 \r
-    if ( msgText.length() > MESSAGE_MAX_LENGTH )\r
+    if (msgText.length() > MESSAGE_MAX_LENGTH)\r
     {\r
-        int cursorPos ( m_textEdit->textCursor().position() );\r
+        int cursorPos = m_textEdit->textCursor().position();\r
 \r
         QTextCursor textCursor = m_textEdit->textCursor();\r
-        int removedChars( msgText.length() - MESSAGE_MAX_LENGTH );\r
+        int removedChars = msgText.length() - MESSAGE_MAX_LENGTH;\r
+        m_textEdit->blockSignals(true);\r
 \r
-        m_textEdit->setText( msgText.left(cursorPos - removedChars) + msgText.mid( cursorPos ) );\r
+        m_textEdit->setText( msgText.left(cursorPos - removedChars) + msgText.mid(cursorPos));\r
+        m_textEdit->blockSignals(false);\r
 \r
-        textCursor.setPosition( cursorPos - removedChars );\r
-        m_textEdit->setTextCursor( textCursor );\r
+        textCursor.setPosition(cursorPos - removedChars);\r
+        m_textEdit->setTextCursor(textCursor);\r
     }\r
 \r
-    m_charCountLabel->setNum(MESSAGE_MAX_LENGTH - m_textEdit->toPlainText().length() );\r
+    m_charCountLabel->setNum(MESSAGE_MAX_LENGTH - m_textEdit->toPlainText().length());\r
 }\r
 \r
 void UpdateLocationDialog::textSelectionChanged()\r
 {\r
     qDebug() << __PRETTY_FUNCTION__;\r
 \r
-    if ( !m_textEdit->document()->isModified() )\r
+    if (!m_textEdit->document()->isModified())\r
     {\r
         m_textEdit->clear();\r
     }\r
index a19a237..e6d932b 100644 (file)
@@ -82,7 +82,17 @@ private slots:
     *\r
     */\r
     void sendUpdate();\r
+\r
+    /**\r
+    * @brief Private slot, which is used to get changes in messagetext\r
+    *\r
+    */\r
     void textChanged();\r
+\r
+    /**\r
+    * @brief Private slot, which is used to clear default messagetext\r
+    *\r
+    */\r
     void textSelectionChanged();\r
 \r
 /*******************************************************************************\r
index a97f499..794df19 100644 (file)
@@ -48,7 +48,8 @@ const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3 * MARGIN - ICON_WIDTH + 130;
 
 UserInfo::UserInfo(QWidget *parent)
     : QWidget(parent),
-      m_expanded(false)
+      m_expanded(false),
+      m_updateLocation(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -114,7 +115,7 @@ UserInfo::UserInfo(QWidget *parent)
             this, SIGNAL(refreshUserData()));
 
     connect(m_findButton, SIGNAL(clicked()),
-        this, SLOT(findButtonClicked()));    
+            this, SLOT(findButtonClicked()));
 
     setFixedWidth(BACKGROUND_WIDTH);
 
@@ -263,27 +264,23 @@ void UserInfo::messageUpdate()
 
     emit requestReverseGeo();
 
-    UpdateLocationDialog updateLocation(m_backupMessage, m_backupFacebookPublishPolicity, this);
+    delete m_updateLocation;
+    m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
+                                                this);
 
     connect(this, SIGNAL(reverseGeoReady(QString)),
-            &updateLocation, SLOT(setAddress(QString)));
+            m_updateLocation, SLOT(setAddress(QString)));
 
-    connect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
+    connect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
             this, SIGNAL(statusUpdate(QString,bool)));
 
-    connect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
+    connect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
             this, SLOT(backupUpdateLocationDialogData(QString,bool)));
 
-    updateLocation.exec();
+    connect(m_updateLocation, SIGNAL(finished(int)),
+            this, SLOT(updateLocationDialogFinished(int)));
 
-    disconnect(this, SIGNAL(reverseGeoReady(QString)),
-            &updateLocation, SLOT(setAddress(QString)));
-
-    disconnect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
-            this, SIGNAL(statusUpdate(QString,bool)));
-
-    disconnect(&updateLocation, SIGNAL(statusUpdate(QString,bool)),
-            this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+    m_updateLocation->show();
 }
 
 void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
@@ -345,3 +342,28 @@ void UserInfo::verifyMessageUpdateFailure(const QString &errorMessage)
 
     m_messageUpdateVerified = true;
 }
+
+void UserInfo::updateLocationDialogFinished(int reason)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    Q_UNUSED(reason);
+
+    if (m_updateLocation) {
+        disconnect(this, SIGNAL(reverseGeoReady(QString)),
+                m_updateLocation, SLOT(setAddress(QString)));
+
+        disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
+                this, SIGNAL(statusUpdate(QString,bool)));
+
+        disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
+                this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+
+        disconnect(m_updateLocation, SIGNAL(finished(int)),
+                this, SLOT(updateLocationDialogFinished(int)));
+
+        m_updateLocation->deleteLater();
+        m_updateLocation = 0;
+    }
+
+}
index c404217..17f1181 100644 (file)
@@ -185,6 +185,12 @@ private slots:
     */
     void messageUpdate();    
 
+    /**
+    * @brief Slot function to get indication when dialog is finished
+    *
+    */
+    void updateLocationDialogFinished(int reason);
+
 /******************************************************************************
 * SIGNALS
 ******************************************************************************/
@@ -258,6 +264,7 @@ private:
     QString m_time;                     ///< Time when the new message was sent
     QString m_userName;                 ///< User's name
     ImageButton *m_findButton;          ///< User find button   
+    UpdateLocationDialog *m_updateLocation; ///< Update location dialog
 };
 
 #endif // USERINFO_H