#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(this);
- QGridLayout *gridLayout = new QGridLayout(this);
+ 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 *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
sendButton->setText(tr("Send"));
- QFormLayout *form = new QFormLayout();
- form->addRow(new QLabel(tr("Location:")), m_locationLabel);
- form->addRow(new QLabel(tr("Message:")), m_textEdit);
- form->addWidget(m_checkBox);
+ 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(form);
+ groupBox->setLayout(gridLayout2);
scrollArea->setWidget(groupBox);
scrollArea->setWidgetResizable(true);
gridLayout->addWidget(scrollArea, 0, 0, 2, 1);
- gridLayout->addWidget(buttonBox, 0, 1, 1, 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();
}
void UpdateLocationDialog::setAddress(const QString &address)
{
qDebug() << __PRETTY_FUNCTION__;
+
m_locationLabel->setText(address);
}
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
+ }
+}
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
-
public slots:
-
/**
* @brief Public slot, which is used to set the street address to location label
*
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
*
/*******************************************************************************
* 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
};