2 Situare - A location system for Facebook
\r
3 Copyright (C) 2010 Ixonos Plc. Authors:
\r
5 Katri Kaikkonen - katri.kaikkonen@ixonos.com
\r
6 Henri Lampela - henri.lampela@ixonos.com
\r
8 Situare is free software; you can redistribute it and/or
\r
9 modify it under the terms of the GNU General Public License
\r
10 version 2 as published by the Free Software Foundation.
\r
12 Situare is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with Situare; if not, write to the Free Software
\r
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
\r
23 #include <QCheckBox>
\r
25 #include <QDialogButtonBox>
\r
26 #include <QGridLayout>
\r
28 #include <QPushButton>
\r
29 #include <QScrollArea>
\r
30 #include <QTextEdit>
\r
32 #include "updatelocationdialog.h"
\r
34 const int MESSAGE_MAX_LENGTH = 255;
\r
36 UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publishOnFacebook,
\r
40 qDebug() << __PRETTY_FUNCTION__;
\r
42 setWindowTitle(tr("Update Location"));
\r
44 QGridLayout *gridLayout = new QGridLayout();
\r
46 m_textEdit = new QTextEdit();
\r
47 m_charCountLabel = new QLabel();
\r
49 if (userMessage.isEmpty())
\r
51 m_textEdit->setText(tr("Message:"));
\r
52 m_textEdit->selectAll();
\r
53 m_charCountLabel->setNum(MESSAGE_MAX_LENGTH);
\r
55 connect(m_textEdit, SIGNAL(selectionChanged()),
\r
56 this, SLOT(textSelectionChanged()));
\r
60 m_textEdit->setText(userMessage);
\r
61 m_textEdit->document()->setModified(true);
\r
65 QScrollArea *scrollArea = new QScrollArea();
\r
67 QVBoxLayout* scrollAreaLayout = new QVBoxLayout;
\r
68 scrollAreaLayout->setSpacing(0);
\r
69 scrollAreaLayout->setMargin(0);
\r
70 scrollAreaLayout->addWidget(m_textEdit);
\r
72 QWidget* scrollAreaWidget = new QWidget;
\r
73 scrollAreaWidget->setLayout(scrollAreaLayout);
\r
75 scrollArea->setWidget(scrollAreaWidget);
\r
77 scrollArea->setWidgetResizable(true);
\r
78 scrollArea->setFrameShape(QScrollArea::NoFrame);
\r
80 m_locationLabel = new QLabel();
\r
81 m_locationLabel->setWordWrap(true);
\r
82 m_checkBox = new QCheckBox(tr("Publish on Facebook"));
\r
83 m_checkBox->setChecked(publishOnFacebook);
\r
85 QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
\r
86 QPushButton *sendButton = buttonBox->addButton(QDialogButtonBox::Ok);
\r
87 QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
\r
88 sendButton->setText(tr("Send"));
\r
90 gridLayout->addWidget(new QLabel(tr("Location:")), 0, 0, 1, 1, Qt::AlignTop | Qt::AlignLeft);
\r
91 gridLayout->addWidget(m_locationLabel, 0, 1, 1, 3);
\r
92 gridLayout->addWidget(scrollArea, 1, 0, 1, 4);
\r
93 gridLayout->addWidget(m_checkBox, 2, 0, 1, 2);
\r
94 gridLayout->addWidget(m_charCountLabel,2, 2, 1, 1, Qt::AlignCenter);
\r
95 gridLayout->addWidget(buttonBox, 2, 3, 2, 1, Qt::AlignTop);
\r
97 gridLayout->setColumnMinimumWidth(2, 2 * m_charCountLabel->fontMetrics().width(
\r
98 m_charCountLabel->text()));
\r
100 setLayout(gridLayout);
\r
102 const int LAYOUT_COLUMN_ONE_STRETCH = 10;
\r
103 const int LAYOUT_TOP_MARGIN = 15;
\r
104 gridLayout->setColumnStretch(1, LAYOUT_COLUMN_ONE_STRETCH);
\r
106 QMargins layoutMargins = gridLayout->contentsMargins();
\r
107 layoutMargins.setTop(LAYOUT_TOP_MARGIN);
\r
108 gridLayout->setContentsMargins(layoutMargins);
\r
110 connect(sendButton, SIGNAL(clicked()),
\r
111 this, SLOT(sendUpdate()));
\r
113 connect(cancelButton, SIGNAL(clicked()),
\r
114 this, SLOT(reject()));
\r
116 connect(m_textEdit, SIGNAL(textChanged()),
\r
117 this, SLOT(textChanged()));
\r
119 #ifdef Q_WS_MAEMO_5
\r
120 if (QAbstractKineticScroller *scroller = scrollArea->property("kineticScroller").value<
\r
121 QAbstractKineticScroller *>()) {
\r
122 scroller->setOvershootPolicy(QAbstractKineticScroller::OvershootAlwaysOff);
\r
125 new TextEditAutoResizer(m_textEdit);
\r
126 setAttribute(Qt::WA_Maemo5StackedWindow);
\r
127 setWindowFlags(Qt::Window);
\r
130 m_textEdit->setFocus(Qt::OtherFocusReason);
\r
133 UpdateLocationDialog::~UpdateLocationDialog()
\r
135 qDebug() << __PRETTY_FUNCTION__;
\r
138 void UpdateLocationDialog::setAddress(const QString &address)
\r
140 qDebug() << __PRETTY_FUNCTION__;
\r
142 m_locationLabel->setText(address);
\r
145 void UpdateLocationDialog::sendUpdate()
\r
147 qDebug() << __PRETTY_FUNCTION__;
\r
149 // coordinates for this call will be get from somewhere, map etc...
\r
150 emit statusUpdate(m_textEdit->document()->isModified() ? m_textEdit->toPlainText() : QString(),
\r
151 m_checkBox->isChecked());
\r
156 void UpdateLocationDialog::textChanged()
\r
158 qDebug() << __PRETTY_FUNCTION__;
\r
160 QString msgText = m_textEdit->toPlainText();
\r
162 if (msgText.length() > MESSAGE_MAX_LENGTH)
\r
164 int cursorPos = m_textEdit->textCursor().position();
\r
166 QTextCursor textCursor = m_textEdit->textCursor();
\r
167 int removedChars = msgText.length() - MESSAGE_MAX_LENGTH;
\r
168 m_textEdit->blockSignals(true);
\r
170 m_textEdit->setText( msgText.left(cursorPos - removedChars) + msgText.mid(cursorPos));
\r
171 m_textEdit->blockSignals(false);
\r
173 textCursor.setPosition(cursorPos - removedChars);
\r
174 m_textEdit->setTextCursor(textCursor);
\r
177 m_charCountLabel->setNum(MESSAGE_MAX_LENGTH - m_textEdit->toPlainText().length());
\r
180 void UpdateLocationDialog::textSelectionChanged()
\r
182 qDebug() << __PRETTY_FUNCTION__;
\r
184 if (!m_textEdit->document()->isModified())
\r
186 m_textEdit->clear();
\r
188 disconnect(m_textEdit, SIGNAL(selectionChanged()), this, SLOT(textSelectionChanged()));
\r