-/*
- 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 <QDebug>
-#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
- }
-}
+/*\r
+ Situare - A location system for Facebook\r
+ Copyright (C) 2010 Ixonos Plc. Authors:\r
+\r
+ Katri Kaikkonen - katri.kaikkonen@ixonos.com\r
+ Henri Lampela - henri.lampela@ixonos.com\r
+\r
+ Situare is free software; you can redistribute it and/or\r
+ modify it under the terms of the GNU General Public License\r
+ version 2 as published by the Free Software Foundation.\r
+\r
+ Situare is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ GNU General Public License for more details.\r
+\r
+ You should have received a copy of the GNU General Public License\r
+ along with Situare; if not, write to the Free Software\r
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,\r
+ USA.\r
+*/\r
+\r
+#include <QDebug>\r
+#include "updatelocationdialog.h"\r
+\r
+const int MESSAGE_MAX_LENGTH = 255;\r
+\r
+UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publishOnFacebook,\r
+ QWidget *parent)\r
+ : QDialog(parent)\r
+{\r
+ qDebug() << __PRETTY_FUNCTION__;\r
+\r
+ setWindowTitle(tr("Update Location"));\r
+\r
+ QGridLayout *gridLayout = new QGridLayout();\r
+\r
+ m_textEdit = new QTextEdit;\r
+\r
+ if ( userMessage.isEmpty() )\r
+ {\r
+ m_textEdit->setText( tr("Message:") );\r
+ m_textEdit->selectAll();\r
+ connect(m_textEdit, SIGNAL(selectionChanged()), this, SLOT(textSelectionChanged()));\r
+ }\r
+ else\r
+ {\r
+ m_textEdit->setText( userMessage );\r
+ m_textEdit->document()->setModified( true );\r
+ }\r
+\r
+ QScrollArea *scrollArea = new QScrollArea();\r
+\r
+ QVBoxLayout* scrollAreaLayout = new QVBoxLayout;\r
+ scrollAreaLayout->setSpacing(0);\r
+ scrollAreaLayout->setMargin(0);\r
+ scrollAreaLayout->addWidget( m_textEdit );\r
+\r
+ QWidget* scrollAreaWidget = new QWidget;\r
+ scrollAreaWidget->setLayout( scrollAreaLayout );\r
+\r
+ scrollArea->setWidget(scrollAreaWidget);\r
+\r
+ scrollArea->setWidgetResizable(true);\r
+ scrollArea->setFrameShape(QScrollArea::NoFrame);\r
+\r
+ m_locationLabel = new QLabel;\r
+ m_locationLabel->setWordWrap(true);\r
+ m_checkBox = new QCheckBox(tr("Publish on Facebook"));\r
+ m_checkBox->setChecked(publishOnFacebook);\r
+\r
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);\r
+ QPushButton *sendButton = buttonBox->addButton(QDialogButtonBox::Ok);\r
+ QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);\r
+ sendButton->setText(tr("Send"));\r
+\r
+ 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(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(buttonBox, 2, 3, 2, 1, Qt::AlignTop);\r
+\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
+\r
+ QMargins layoutMargins = gridLayout->contentsMargins();\r
+ layoutMargins.setTop( LAYOUT_TOP_MARGIN );\r
+ gridLayout->setContentsMargins( layoutMargins );\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
+\r
+#ifdef Q_WS_MAEMO_5\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
+#endif\r
+}\r
+\r
+UpdateLocationDialog::~UpdateLocationDialog()\r
+{\r
+ qWarning() << __PRETTY_FUNCTION__;\r
+}\r
+\r
+void UpdateLocationDialog::setAddress(const QString &address)\r
+{\r
+ qDebug() << __PRETTY_FUNCTION__;\r
+\r
+ m_locationLabel->setText(address);\r
+}\r
+\r
+void UpdateLocationDialog::sendUpdate()\r
+{\r
+ qDebug() << __PRETTY_FUNCTION__;\r
+\r
+ // coordinates for this call will be get from somewhere, map etc...\r
+ emit statusUpdate(m_textEdit->document()->isModified() ? m_textEdit->toPlainText() : QString(),\r
+ m_checkBox->isChecked());\r
+\r
+ close();\r
+}\r
+\r
+void UpdateLocationDialog::textChanged()\r
+{\r
+ qDebug() << __PRETTY_FUNCTION__;\r
+\r
+ QString msgText( m_textEdit->toPlainText() );\r
+\r
+ if ( msgText.length() > MESSAGE_MAX_LENGTH )\r
+ {\r
+ int cursorPos ( m_textEdit->textCursor().position() );\r
+\r
+ QTextCursor textCursor = m_textEdit->textCursor();\r
+ int removedChars( msgText.length() - MESSAGE_MAX_LENGTH );\r
+\r
+ m_textEdit->setText( msgText.left(cursorPos - removedChars) + msgText.mid( cursorPos ) );\r
+\r
+ textCursor.setPosition( cursorPos - removedChars );\r
+ m_textEdit->setTextCursor( textCursor );\r
+ }\r
+\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
+ {\r
+ m_textEdit->clear();\r
+ }\r
+ disconnect(m_textEdit, SIGNAL(selectionChanged()), this, SLOT(textSelectionChanged()));\r
+}\r
+\r
-/*
- 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 <QDialog>
-#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 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
+/*\r
+ Situare - A location system for Facebook\r
+ Copyright (C) 2010 Ixonos Plc. Authors:\r
+\r
+ Katri Kaikkonen - katri.kaikkonen@ixonos.com\r
+ Henri Lampela - henri.lampela@ixonos.com\r
+\r
+ Situare is free software; you can redistribute it and/or\r
+ modify it under the terms of the GNU General Public License\r
+ version 2 as published by the Free Software Foundation.\r
+\r
+ Situare is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ GNU General Public License for more details.\r
+\r
+ You should have received a copy of the GNU General Public License\r
+ along with Situare; if not, write to the Free Software\r
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,\r
+ USA.\r
+*/\r
+\r
+#ifndef UPDATELOCATIONDIALOG_H\r
+#define UPDATELOCATIONDIALOG_H\r
+\r
+#include <QDialog>\r
+#ifdef Q_WS_MAEMO_5\r
+#include <QAbstractKineticScroller>\r
+#endif // Q_WS_MAEMO_5\r
+#include "texteditautoresizer.h"\r
+\r
+class QCheckBox;\r
+class QDialogButtonBox;\r
+class QGroupBox;\r
+class QLabel;\r
+class QLineEdit;\r
+class QPushButton;\r
+class QScrollArea;\r
+class QTextEdit;\r
+\r
+/**\r
+* @brief Update Location UI\r
+*\r
+* UI for update location functionality.\r
+*\r
+* @class UpdateLocationDialog\r
+*/\r
+class UpdateLocationDialog : public QDialog\r
+{\r
+ Q_OBJECT\r
+\r
+public:\r
+ /**\r
+ * @brief Default constructor\r
+ *\r
+ * @param userMessage update location dialog message\r
+ * @param publishOnFacebook update location dialog Facebook publish policity\r
+ * @param parent\r
+ */\r
+ UpdateLocationDialog(const QString &userMessage = "", bool publishOnFacebook = false,\r
+ QWidget *parent = 0);\r
+\r
+ ~UpdateLocationDialog();\r
+\r
+/*******************************************************************************\r
+ * MEMBER FUNCTIONS AND SLOTS\r
+ ******************************************************************************/\r
+\r
+public slots:\r
+\r
+ /**\r
+ * @brief Public slot, which is used to set the street address to location label\r
+ *\r
+ * @param address Street address, result from SituareService's reverseGeo\r
+ */\r
+ void setAddress(const QString &address);\r
+\r
+private slots:\r
+\r
+ /**\r
+ * @brief Private slot, which is used to connect send button\r
+ *\r
+ */\r
+ void sendUpdate();\r
+ void textChanged();\r
+ void textSelectionChanged();\r
+\r
+/*******************************************************************************\r
+ * SIGNALS\r
+ ******************************************************************************/\r
+\r
+signals:\r
+\r
+ /**\r
+ * @brief Signal Signal for requestLocationUpdate from SituareEngine via MainWindow class\r
+ *\r
+ * @param status Status message\r
+ * @param publish Publish on Facebook\r
+ */\r
+ void statusUpdate(const QString &status, const bool &publish);\r
+\r
+/*******************************************************************************\r
+ * DATA MEMBERS\r
+ ******************************************************************************/\r
+\r
+private:\r
+\r
+ QCheckBox *m_checkBox; ///< Pointer to CheckBox\r
+ QLabel *m_locationLabel; ///< Pointer to locationLabel\r
+ QLabel *m_charCountLabel; ///< Pointer to locationLabel\r
+ QTextEdit *m_textEdit; ///< Pointer to TextEdit\r
+};\r
+\r
+#endif // UPDATELOCATIONDIALOG_H\r