Integrated messageupdate dialog, code reviewed by wallika
authorJukka Saastamoinen <juksa@czc6303cj1.ixonos.local>
Mon, 19 Apr 2010 11:52:57 +0000 (14:52 +0300)
committerJukka Saastamoinen <juksa@czc6303cj1.ixonos.local>
Mon, 19 Apr 2010 11:52:57 +0000 (14:52 +0300)
src/src.pro
src/ui/listviewscreen.cpp
src/ui/listviewscreen.h
src/ui/updatelocation/texteditautoresizer.cpp [new file with mode: 0755]
src/ui/updatelocation/texteditautoresizer.h [new file with mode: 0755]
src/ui/updatelocation/updatelocationdialog.cpp [new file with mode: 0755]
src/ui/updatelocation/updatelocationdialog.h [new file with mode: 0755]

index 09d65ee..b3621b1 100644 (file)
@@ -14,7 +14,9 @@ SOURCES += main.cpp \
     map/maptile.cpp \
     map/mapfetcher.cpp \
     ui/pixmap.cpp \
-    ui/infotab.cpp
+    ui/infotab.cpp \
+    ui/updatelocation/updatelocationdialog.cpp \
+    ui/updatelocation/texteditautoresizer.cpp
 HEADERS += ui/mainwindow.h \
     ui/mapviewscreen.h \
     ui/listviewscreen.h \
@@ -25,7 +27,9 @@ HEADERS += ui/mainwindow.h \
     map/mapfetcher.h \
     common.h \
     ui/pixmap.h \
-    ui/infotab.h
+    ui/infotab.h \
+    ui/updatelocation/updatelocationdialog.h \
+    ui/updatelocation/texteditautoresizer.h
 QT += network \
     webkit
 
index 059c2fb..5b3583a 100644 (file)
@@ -27,8 +27,6 @@
 #include <QGraphicsProxyWidget>
 #include <QStateMachine>
 #include "listviewscreen.h"
-#include "pixmap.h"
-#include "infotab.h"
 #include <QDebug>
 
 ListViewScreen::ListViewScreen(QWidget *parent)
@@ -43,6 +41,7 @@ ListViewScreen::ListViewScreen(QWidget *parent)
     m_personalInfo->setTime("1 hour ago");
     m_personalInfo->setAddress("Kiviharjunlenkki 1E, 91910 Oulu");
 
+    m_locationDialog = new updatelocationdialog(this);
     m_widgetProxy = new QGraphicsProxyWidget();
     m_widgetProxy->setWidget(m_personalInfo);
 
@@ -94,6 +93,8 @@ ListViewScreen::ListViewScreen(QWidget *parent)
     m_vbox = new QVBoxLayout(this);
     m_vbox->addWidget(view);
     m_vbox->setMargin(0);
+
+    connect(m_personalInfo,SIGNAL(launchMessageUpdate()),this,SLOT(updateMessage()));
 }
 
 ListViewScreen::~ListViewScreen()
@@ -117,3 +118,9 @@ ListViewScreen::~ListViewScreen()
     if (m_vbox)
         delete m_vbox;
 }
+
+void ListViewScreen::updateMessage()
+{
+   qDebug() << __PRETTY_FUNCTION__;
+   m_locationDialog->exec();
+}
index 4dd6541..cb68640 100644 (file)
@@ -26,6 +26,7 @@
 #include <QtGui>
 #include "infotab.h"
 #include "pixmap.h"
+#include "updatelocation/updatelocationdialog.h"
 
 /**
 * @brief List View class. Used for displaying List of friends
@@ -34,6 +35,7 @@
 */
 class ListViewScreen : public QWidget
 {
+Q_OBJECT
 public:
     /**
     * @brief Constructor
@@ -46,6 +48,8 @@ public:
     *
     */
     ~ListViewScreen();
+public slots:
+    void updateMessage();
 private:
     QVBoxLayout *m_vbox;    ///< Holds the graphics view
     InfoTab *m_personalInfo;    ///< Personal info tab
@@ -57,6 +61,7 @@ private:
     QPropertyAnimation *m_anim2;    ///< Animation for arrowbutton from hidden to visible
     QPropertyAnimation *m_anim3;    ///< Animation for infotab from visible to hidden
     QPropertyAnimation *m_anim4;    ///< Animation for arrowbutton from visible to hidden
+    updatelocationdialog *m_locationDialog; ///< Message dialog
 };
 
 #endif // LISTVIEWTAB_H
diff --git a/src/ui/updatelocation/texteditautoresizer.cpp b/src/ui/updatelocation/texteditautoresizer.cpp
new file mode 100755 (executable)
index 0000000..dabf73a
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+      Katri Kaikkonen - katri.kaikkonen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QtGui>
+#include "texteditautoresizer.h"
+
+TextEditAutoResizer::TextEditAutoResizer(QWidget *parent)
+    : QObject(parent)
+    , m_edit(qobject_cast<QFrame *>(parent))
+    , m_plainTextEdit(qobject_cast<QPlainTextEdit *>(parent))
+    , m_textEdit(qobject_cast<QTextEdit *>(parent))
+    {
+     //parent must either inherit QPlainTextEdit or  QTextEdit!
+    Q_ASSERT(m_plainTextEdit || m_textEdit);
+
+    connect(parent, SIGNAL(textChanged()), this, SLOT(textEditChanged()));
+    connect(parent, SIGNAL(cursorPositionChanged()), this, SLOT(textEditChanged()));
+    }
+
+void TextEditAutoResizer::textEditChanged()
+{
+    QTextDocument *document = m_textEdit ? m_textEdit->document() : m_plainTextEdit->document();
+    QRect cursor = m_textEdit ? m_textEdit->cursorRect() : m_plainTextEdit->cursorRect();
+
+    QSize size = document->size().toSize();
+    if (m_plainTextEdit)
+        size.setHeight((size.height() + 1) * m_edit->fontMetrics().lineSpacing());
+
+    const QRect frameRect = m_edit->frameRect();
+    const QRect contentsRect = m_edit->contentsRect();
+
+    m_edit->setMinimumHeight(qMax(70, size.height() + (frameRect.height()
+                                                       - contentsRect.height() - 1)));
+
+    // make sure the cursor is visible in case we have a QAbstractScrollArea parent
+    QPoint position = m_edit->pos();
+    QWidget *parentWidget = m_edit->parentWidget();
+    while (parentWidget) {
+    #ifdef Q_WS_MAEMO_5
+        if (parentWidget->parentWidget()) {
+            if (QAbstractScrollArea *area = qobject_cast<QAbstractScrollArea *>(
+                    parentWidget->parentWidget()->parentWidget())) {
+                 if (QAbstractKineticScroller * scroller=
+                        area->property("kineticScroller").value<QAbstractKineticScroller *>()) {
+                            scroller->ensureVisible(position + cursor.center(), 10 + cursor.width(),
+                                 2 * cursor.height());
+                }
+                break;
+        }
+    }
+    #endif
+    position = parentWidget->mapToParent(position);
+    parentWidget = parentWidget->parentWidget();
+    }
+}
diff --git a/src/ui/updatelocation/texteditautoresizer.h b/src/ui/updatelocation/texteditautoresizer.h
new file mode 100755 (executable)
index 0000000..eccd964
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+      Katri Kaikkonen - katri.kaikkonen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#ifndef TEXTEDITAUTORESIZER_H
+#define TEXTEDITAUTORESIZER_H
+
+#include <QtGui>
+#ifdef Q_WS_MAEMO_5
+#include <QAbstractKineticScroller>
+#endif // Q_WS_MAEMO_5
+
+/**
+* @brief TextEditAutoResizer class
+*
+* @class TextEditAutoResizer class is used to automatically resize the QTextEdit once the contents
+*        become too large.
+*/
+class TextEditAutoResizer : public QObject
+{
+Q_OBJECT
+
+public:
+    /**
+    * @brief Default constructor
+    *
+    * @fn TextEditAutoResizer
+    * @param parent
+    */
+    TextEditAutoResizer(QWidget *parent = 0);
+
+private slots:
+    /**
+    * @brief Private slot which indicate when textEdit has been changed
+    *
+    * @fn textEditChanged
+    */
+    void textEditChanged();
+
+private:
+    QFrame *m_edit; ///< Pointer to Frame
+    QPlainTextEdit *m_plainTextEdit; ///< Pointer to PlainTextEdit
+    QTextEdit *m_textEdit; ///< Pointer to TextEdit
+};
+
+#endif // TEXTEDITAUTORESIZER_H
+
+
diff --git a/src/ui/updatelocation/updatelocationdialog.cpp b/src/ui/updatelocation/updatelocationdialog.cpp
new file mode 100755 (executable)
index 0000000..e745bd2
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+      Katri Kaikkonen - katri.kaikkonen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QtGui>
+#include <QDebug>
+#include "updatelocationdialog.h"
+
+updatelocationdialog::updatelocationdialog(QWidget *parent)
+    : QDialog(parent)
+{
+    setWindowTitle(tr("Update Location"));
+
+    QScrollArea *scrollArea = new QScrollArea(this);
+    QGridLayout *gridLayout = new QGridLayout(this);
+    QGroupBox *groupBox = new QGroupBox(scrollArea);
+
+    QTextEdit *m_textEdit = new QTextEdit;
+    QLineEdit *m_lineEdit = new QLineEdit;
+    QCheckBox *m_checkBox = new QCheckBox("Publish in Fabebook");
+
+    QPushButton *m_okButton = new QPushButton("Send");
+    QDialogButtonBox *m_buttonBox = new QDialogButtonBox(Qt::Vertical);
+    m_buttonBox->addButton(m_okButton, QDialogButtonBox::ActionRole);
+
+    QFormLayout *form = new QFormLayout();
+    form->addRow(new QLabel("Location:"), m_lineEdit);
+    form->addRow(new QLabel("Message:"), m_textEdit);
+    form->addWidget(m_checkBox);
+
+    new TextEditAutoResizer(m_textEdit);
+
+    groupBox->setLayout(form);
+    scrollArea->setWidget(groupBox);
+    scrollArea->setWidgetResizable(true);
+    gridLayout->addWidget(scrollArea, 0, 0, 2, 1);
+    gridLayout->addWidget(m_buttonBox, 0, 1, 1, 1);
+    setLayout(gridLayout);
+
+    scrollArea->show();
+}
diff --git a/src/ui/updatelocation/updatelocationdialog.h b/src/ui/updatelocation/updatelocationdialog.h
new file mode 100755 (executable)
index 0000000..538226a
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+      Katri Kaikkonen - katri.kaikkonen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#ifndef UPDATELOCATIONDIALOG_H
+#define UPDATELOCATIONDIALOG_H
+
+#include <QDialog>
+#include <QtGui>
+#ifdef Q_WS_MAEMO_5
+#include <QAbstractKineticScroller>
+#endif // Q_WS_MAEMO_5
+#include "texteditautoresizer.h"
+
+class QCheckBox;
+class QDialogButtonBox;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+class QPushButton;
+class QScrollArea;
+
+/**
+* @brief Update Location UI
+*
+* @class UI for update location functionality.
+*/
+class updatelocationdialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    /**
+    * @brief Default constructor
+    *
+    * @fn updatelocationdialog
+    * @param parent
+    */
+    updatelocationdialog(QWidget *parent = 0);
+
+private slots:
+
+private:
+    QDialogButtonBox *m_buttonBox; ///< Pointer to DialogButtonBox
+    QCheckBox *m_checkBox; ///< Pointer to CheckBox
+    QLineEdit *m_lineEdit; ///< Pointer to LineEdit
+    QPushButton *m_okButton; ///< Pointer to PushButton
+    QTextEdit *m_textEdit; ///< Pointer to TextEdit
+};
+
+#endif // UPDATELOCATIONDIALOG_H