From bcb1c1bd2d18300f6c7a48b42b9c65f52c71eb6e Mon Sep 17 00:00:00 2001 From: Katri Kaikkonen Date: Wed, 9 Jun 2010 12:33:09 +0300 Subject: [PATCH] Changed from dialog to stacked widget --- src/ui/mainwindow.cpp | 3 + src/ui/updatelocation/updatelocationdialog.cpp | 290 ++++++++++++++---------- src/ui/updatelocation/updatelocationdialog.h | 222 +++++++++--------- src/ui/userinfo.cpp | 2 +- 4 files changed, 289 insertions(+), 228 deletions(-) mode change 100755 => 100644 src/ui/updatelocation/updatelocationdialog.cpp mode change 100755 => 100644 src/ui/updatelocation/updatelocationdialog.h diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index c412071..26f2b86 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -93,6 +93,9 @@ MainWindow::MainWindow(QWidget *parent) // set screen size in desktop matching N900 screen size resize(N900_APP_WIDTH, N900_APP_HEIGHT); +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5StackedWindow); +#endif } MainWindow::~MainWindow() diff --git a/src/ui/updatelocation/updatelocationdialog.cpp b/src/ui/updatelocation/updatelocationdialog.cpp old mode 100755 new mode 100644 index 7483668..5ff5042 --- a/src/ui/updatelocation/updatelocationdialog.cpp +++ b/src/ui/updatelocation/updatelocationdialog.cpp @@ -1,119 +1,171 @@ -/* - Situare - A location system for Facebook - Copyright (C) 2010 Ixonos Plc. Authors: - - Katri Kaikkonen - katri.kaikkonen@ixonos.com - Henri Lampela - henri.lampela@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 -#include "updatelocationdialog.h" - -const int MAX_CHAR = 255; ///< Maximum input length for QTextEdit -const QFont NOKIA_FONT_VERY_SMALL = QFont("Nokia Sans", 10, QFont::Normal); ///< Very small font - -UpdateLocationDialog::UpdateLocationDialog(QWidget *parent) - : QDialog(parent) -{ - qDebug() << __PRETTY_FUNCTION__; - - setWindowTitle(tr("Update Location")); - - QScrollArea *scrollArea = new QScrollArea(); - QGridLayout *gridLayout = new QGridLayout(); - QGroupBox *groupBox = new QGroupBox(scrollArea); - - m_textEdit = new QTextEdit; - m_locationLabel = new QLabel; - m_locationLabel->setWordWrap(true); - m_characterLabel = new QLabel; - m_characterLabel->setNum(MAX_CHAR); - m_characterLabel->setFont(NOKIA_FONT_VERY_SMALL); - m_characterNumberLabel = new QLabel(tr("Characters left:")); - m_characterNumberLabel->setFont(NOKIA_FONT_VERY_SMALL); - m_checkBox = new QCheckBox(tr("Publish on Facebook")); - - QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical); - QPushButton *sendButton = buttonBox->addButton(QDialogButtonBox::Ok); - QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); - sendButton->setText(tr("Send")); - - QGridLayout *gridLayout2 = new QGridLayout(); - gridLayout2->setMargin(0); - gridLayout2->setSpacing(0); - gridLayout2->addWidget(new QLabel(tr("Location:")),0, 0, 1, 1, Qt::AlignTop); - gridLayout2->addWidget(m_locationLabel, 0, 1, 1, 3); - gridLayout2->addWidget(new QLabel(tr("Message:")),1, 0, 1, 1, Qt::AlignTop); - gridLayout2->addWidget(m_textEdit, 1, 1, 1, 3); - gridLayout2->addWidget(m_characterNumberLabel, 4, 1, 1, 1, Qt::AlignLeft); - gridLayout2->addWidget(m_characterLabel, 4, 1, 1, 1, Qt::AlignRight); - gridLayout2->addWidget(m_checkBox, 5, 1, 1, 3); - - new TextEditAutoResizer(m_textEdit); - - groupBox->setLayout(gridLayout2); - scrollArea->setWidget(groupBox); - scrollArea->setWidgetResizable(true); - gridLayout->addWidget(scrollArea, 0, 0, 2, 1); - gridLayout->addWidget(buttonBox, 1, 1, 1, 1); - setLayout(gridLayout); - - connect(sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); - connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(characterCounter())); - - scrollArea->show(); -} - -UpdateLocationDialog::~UpdateLocationDialog() -{ - qDebug() << __PRETTY_FUNCTION__; -} - -void UpdateLocationDialog::setAddress(const QString &address) -{ - qDebug() << __PRETTY_FUNCTION__; - - m_locationLabel->setText(address); -} - -void UpdateLocationDialog::sendUpdate() -{ - qDebug() << __PRETTY_FUNCTION__; - - // coordinates for this call will be get from somewhere, map etc... - emit statusUpdate(m_textEdit->toPlainText(), m_checkBox->isChecked()); - - this->close(); -} - -void UpdateLocationDialog::characterCounter() -{ - qDebug() << __PRETTY_FUNCTION__; - - QString message; - int charLeft = 0; - - charLeft = MAX_CHAR - m_textEdit->toPlainText().toUtf8().size(); - m_characterLabel->setNum(charLeft); - - if(charLeft < 0){ - message = (m_textEdit -> toPlainText()).left(MAX_CHAR); //more than maxChar so keep only the first maxChar characters - m_textEdit -> setText(message); //set these characters as the visble - m_textEdit -> moveCursor(QTextCursor::End,QTextCursor::MoveAnchor); //set cursor to the end - } -} +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Katri Kaikkonen - katri.kaikkonen@ixonos.com + Henri Lampela - henri.lampela@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 +#include "updatelocationdialog.h" + +const int MESSAGE_MAX_LENGTH = 255; + +UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publishOnFacebook, + QWidget *parent) + : QDialog(parent) +{ + qDebug() << __PRETTY_FUNCTION__; + + setWindowTitle(tr("Update Location")); + + QGridLayout *gridLayout = new QGridLayout(); + + m_textEdit = new QTextEdit; + + if ( userMessage.isEmpty() ) + { + m_textEdit->setText( tr("Message:") ); + m_textEdit->selectAll(); + connect(m_textEdit, SIGNAL(selectionChanged()), this, SLOT(textSelectionChanged())); + } + else + { + m_textEdit->setText( userMessage ); + m_textEdit->document()->setModified( true ); + } + + QScrollArea *scrollArea = new QScrollArea(); + + QVBoxLayout* scrollAreaLayout = new QVBoxLayout; + scrollAreaLayout->setSpacing(0); + scrollAreaLayout->setMargin(0); + scrollAreaLayout->addWidget( m_textEdit ); + + QWidget* scrollAreaWidget = new QWidget; + scrollAreaWidget->setLayout( scrollAreaLayout ); + + scrollArea->setWidget(scrollAreaWidget); + + scrollArea->setWidgetResizable(true); + scrollArea->setFrameShape(QScrollArea::NoFrame); + + m_locationLabel = new QLabel; + m_locationLabel->setWordWrap(true); + m_checkBox = new QCheckBox(tr("Publish on Facebook")); + m_checkBox->setChecked(publishOnFacebook); + + QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical); + QPushButton *sendButton = buttonBox->addButton(QDialogButtonBox::Ok); + QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); + sendButton->setText(tr("Send")); + + m_charCountLabel = new QLabel; + m_charCountLabel->setNum(MESSAGE_MAX_LENGTH); + + gridLayout->addWidget(new QLabel(tr("Location:")), 0, 0, 1, 1, Qt::AlignTop | Qt::AlignLeft ); + gridLayout->addWidget(m_locationLabel, 0, 1, 1, 3); + gridLayout->addWidget(scrollArea, 1, 0, 1, 4); + gridLayout->addWidget(m_checkBox, 2, 0, 1, 2); + gridLayout->addWidget(m_charCountLabel,2, 2, 1, 1, Qt::AlignCenter ); + gridLayout->addWidget(buttonBox, 2, 3, 2, 1, Qt::AlignTop); + + gridLayout->setColumnMinimumWidth( 2, 2 * m_charCountLabel->fontMetrics().width( + m_charCountLabel->text() )); + + setLayout(gridLayout); + + const int LAYOUT_COLUMN_ONE_STRETCH = 10; + const int LAYOUT_TOP_MARGIN = 15; + gridLayout->setColumnStretch( 1, LAYOUT_COLUMN_ONE_STRETCH ); + + QMargins layoutMargins = gridLayout->contentsMargins(); + layoutMargins.setTop( LAYOUT_TOP_MARGIN ); + gridLayout->setContentsMargins( layoutMargins ); + + connect(sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate())); + connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); + connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(textChanged())); + +#ifdef Q_WS_MAEMO_5 + if (QAbstractKineticScroller * scroller = scrollArea->property("kineticScroller").value< + QAbstractKineticScroller *>()) { + scroller->setOvershootPolicy(QAbstractKineticScroller::OvershootAlwaysOff); + } + + new TextEditAutoResizer(m_textEdit); + setAttribute(Qt::WA_Maemo5StackedWindow); + setWindowFlags( Qt::Window ); +#endif +} + +UpdateLocationDialog::~UpdateLocationDialog() +{ + qWarning() << __PRETTY_FUNCTION__; +} + +void UpdateLocationDialog::setAddress(const QString &address) +{ + qDebug() << __PRETTY_FUNCTION__; + + m_locationLabel->setText(address); +} + +void UpdateLocationDialog::sendUpdate() +{ + qDebug() << __PRETTY_FUNCTION__; + + // coordinates for this call will be get from somewhere, map etc... + emit statusUpdate(m_textEdit->document()->isModified() ? m_textEdit->toPlainText() : QString(), + m_checkBox->isChecked()); + + close(); +} + +void UpdateLocationDialog::textChanged() +{ + qDebug() << __PRETTY_FUNCTION__; + + QString msgText( m_textEdit->toPlainText() ); + + if ( msgText.length() > MESSAGE_MAX_LENGTH ) + { + int cursorPos ( m_textEdit->textCursor().position() ); + + QTextCursor textCursor = m_textEdit->textCursor(); + int removedChars( msgText.length() - MESSAGE_MAX_LENGTH ); + + m_textEdit->setText( msgText.left(cursorPos - removedChars) + msgText.mid( cursorPos ) ); + + textCursor.setPosition( cursorPos - removedChars ); + m_textEdit->setTextCursor( textCursor ); + } + + m_charCountLabel->setNum(MESSAGE_MAX_LENGTH - m_textEdit->toPlainText().length() ); +} + +void UpdateLocationDialog::textSelectionChanged() +{ + qDebug() << __PRETTY_FUNCTION__; + + if ( !m_textEdit->document()->isModified() ) + { + m_textEdit->clear(); + } + disconnect(m_textEdit, SIGNAL(selectionChanged()), this, SLOT(textSelectionChanged())); +} + diff --git a/src/ui/updatelocation/updatelocationdialog.h b/src/ui/updatelocation/updatelocationdialog.h old mode 100755 new mode 100644 index 56639fa..a19a237 --- a/src/ui/updatelocation/updatelocationdialog.h +++ b/src/ui/updatelocation/updatelocationdialog.h @@ -1,108 +1,114 @@ -/* - Situare - A location system for Facebook - Copyright (C) 2010 Ixonos Plc. Authors: - - Katri Kaikkonen - katri.kaikkonen@ixonos.com - Henri Lampela - henri.lampela@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 -#ifdef Q_WS_MAEMO_5 -#include -#endif // Q_WS_MAEMO_5 -#include "texteditautoresizer.h" - -class QCheckBox; -class QDialogButtonBox; -class QGroupBox; -class QLabel; -class QLineEdit; -class QPushButton; -class QScrollArea; -class QTextEdit; - -/** -* @brief Update Location UI -* -* UI for update location functionality. -* -* @class UpdateLocationDialog -*/ -class UpdateLocationDialog : public QDialog -{ - Q_OBJECT - -public: - /** - * @brief Default constructor - * - * @param parent - */ - UpdateLocationDialog(QWidget *parent = 0); - ~UpdateLocationDialog(); - -/******************************************************************************* - * MEMBER FUNCTIONS AND SLOTS - ******************************************************************************/ -public slots: - /** - * @brief Public slot, which is used to set the street address to location label - * - * @param address Street address, result from SituareService's reverseGeo - */ - void setAddress(const QString &address); - -private slots: - /** - * @brief Private slot, which is used to connect send button - * - */ - void sendUpdate(); - - /** - * @brief Private slot, which counts message text length - * - */ - void characterCounter(); - -/******************************************************************************* - * SIGNALS - ******************************************************************************/ -signals: - /** - * @brief Signal Signal for requestLocationUpdate from SituareEngine via MainWindow class - * - * @param status Status message - * @param publish Publish on Facebook - */ - void statusUpdate(const QString &status, const bool &publish); - -/******************************************************************************* - * DATA MEMBERS - ******************************************************************************/ -private: - QCheckBox *m_checkBox; ///< Pointer to CheckBox - QLabel *m_characterLabel; ///< Pointer to characterLabel - QLabel *m_characterNumberLabel; - QLabel *m_locationLabel; ///< Pointer to locationLabel - QTextEdit *m_textEdit; ///< Pointer to TextEdit -}; - -#endif // UPDATELOCATIONDIALOG_H +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Katri Kaikkonen - katri.kaikkonen@ixonos.com + Henri Lampela - henri.lampela@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 +#ifdef Q_WS_MAEMO_5 +#include +#endif // Q_WS_MAEMO_5 +#include "texteditautoresizer.h" + +class QCheckBox; +class QDialogButtonBox; +class QGroupBox; +class QLabel; +class QLineEdit; +class QPushButton; +class QScrollArea; +class QTextEdit; + +/** +* @brief Update Location UI +* +* UI for update location functionality. +* +* @class UpdateLocationDialog +*/ +class UpdateLocationDialog : public QDialog +{ + Q_OBJECT + +public: + /** + * @brief Default constructor + * + * @param userMessage update location dialog message + * @param publishOnFacebook update location dialog Facebook publish policity + * @param parent + */ + UpdateLocationDialog(const QString &userMessage = "", bool publishOnFacebook = false, + QWidget *parent = 0); + + ~UpdateLocationDialog(); + +/******************************************************************************* + * MEMBER FUNCTIONS AND SLOTS + ******************************************************************************/ + +public slots: + + /** + * @brief Public slot, which is used to set the street address to location label + * + * @param address Street address, result from SituareService's reverseGeo + */ + void setAddress(const QString &address); + +private slots: + + /** + * @brief Private slot, which is used to connect send button + * + */ + void sendUpdate(); + void textChanged(); + void textSelectionChanged(); + +/******************************************************************************* + * SIGNALS + ******************************************************************************/ + +signals: + + /** + * @brief Signal Signal for requestLocationUpdate from SituareEngine via MainWindow class + * + * @param status Status message + * @param publish Publish on Facebook + */ + void statusUpdate(const QString &status, const bool &publish); + +/******************************************************************************* + * DATA MEMBERS + ******************************************************************************/ + +private: + + QCheckBox *m_checkBox; ///< Pointer to CheckBox + QLabel *m_locationLabel; ///< Pointer to locationLabel + QLabel *m_charCountLabel; ///< Pointer to locationLabel + QTextEdit *m_textEdit; ///< Pointer to TextEdit +}; + +#endif // UPDATELOCATIONDIALOG_H diff --git a/src/ui/userinfo.cpp b/src/ui/userinfo.cpp index f0bec2f..e18f6f5 100644 --- a/src/ui/userinfo.cpp +++ b/src/ui/userinfo.cpp @@ -259,7 +259,7 @@ void UserInfo::messageUpdate() { qDebug() << __PRETTY_FUNCTION__; - UpdateLocationDialog updateLocationDialog(this); + UpdateLocationDialog updateLocationDialog("", false, this); emit requestReverseGeo(); -- 1.7.9.5