Commit c6260d84 authored by Karel Slaný's avatar Karel Slaný
Browse files

Connecting directly to text area paste slot.

parent ca3f3b06
......@@ -33,13 +33,21 @@
PasteInputDialogue::PasteInputDialogue(QWidget *parent, Qt::WindowFlags flags)
: QInputDialog(parent, flags),
m_timer(this),
m_pasteButton(Q_NULLPTR)
m_pasteButton(Q_NULLPTR),
m_textField(Q_NULLPTR)
{
}
PasteInputDialogue::~PasteInputDialogue(void)
{
m_timer.stop();
if ((m_pasteButton != NULL) && (m_textField != NULL)) {
m_pasteButton->disconnect(SIGNAL(clicked()), m_textField,
SLOT(paste()));
m_timer.disconnect(SIGNAL(timeout()), this,
SLOT(activatePasteButton()));
}
}
QString PasteInputDialogue::getText(QWidget *parent, const QString &title,
......@@ -57,6 +65,7 @@ QString PasteInputDialogue::getText(QWidget *parent, const QString &title,
#if defined Q_OS_ANDROID
//#if 1
dialogue.setVisible(true); /* Constructs the dialogue. */
dialogue.setVisible(false);
dialogue.extendDialoguePaste();
#endif /* defined Q_OS_ANDROID */
......@@ -83,44 +92,31 @@ void PasteInputDialogue::activatePasteButton(void)
}
/* Activate button only when clipboard contains text. */
//m_pasteButton->setVisible(!clipboard->text().isEmpty());
m_pasteButton->setEnabled(!clipboard->text().isEmpty());
}
void PasteInputDialogue::paste(void)
{
QLineEdit *lineEdit = Q_NULLPTR;
QPlainTextEdit *plainTextEdit = Q_NULLPTR;
{
QList<QLineEdit *> lineEdits(findChildren<QLineEdit *>());
if (lineEdits.size() == 1) {
lineEdit = lineEdits.at(0);
}
QList<QPlainTextEdit *> plainTextEdits(findChildren<QPlainTextEdit *>());
if (plainTextEdits.size() == 1) {
plainTextEdit = plainTextEdits.at(0);
}
}
if ((lineEdit != Q_NULLPTR) && (plainTextEdit == Q_NULLPTR)) {
lineEdit->paste();
} else if ((lineEdit == Q_NULLPTR) && (plainTextEdit != Q_NULLPTR)) {
plainTextEdit->paste();
}
}
void PasteInputDialogue::extendDialoguePaste(void)
{
QList<QDialogButtonBox *> buttonBoxes(
findChildren<QDialogButtonBox *>());
QDialogButtonBox *buttonBox = Q_NULLPTR;
/* There should be only one button box. */
if (buttonBoxes.size() != 1) {
m_textField = findEditArea();
if (m_textField == Q_NULLPTR) {
/* No suitable text field found. */
qWarning("Could not find editable area.\n");
return;
}
QDialogButtonBox *buttonBox = buttonBoxes.at(0);
/* There should be only one button box. */
if (buttonBoxes.size() == 1) {
buttonBox = buttonBoxes.at(0);
}
if (buttonBox == Q_NULLPTR) {
qWarning("Could not locate button box.\n");
m_textField = Q_NULLPTR;
return;
}
......@@ -128,13 +124,44 @@ void PasteInputDialogue::extendDialoguePaste(void)
tr("Paste"), QDialogButtonBox::ActionRole);
if (m_pasteButton == Q_NULLPTR) {
qWarning("Could not create paste button.\n");
m_textField = Q_NULLPTR;
return;
}
m_pasteButton->setEnabled(false);
//m_pasteButton->setVisible(false);
connect(m_pasteButton, SIGNAL(clicked()), this, SLOT(paste()));
connect(m_pasteButton, SIGNAL(clicked()), m_textField, SLOT(paste()));
connect(&m_timer, SIGNAL(timeout()), this, SLOT(activatePasteButton()));
m_timer.setInterval(500);
m_timer.start();
qInfo("Created and connected paste button.\n");
}
QObject *PasteInputDialogue::findEditArea(void) const
{
QLineEdit *lineEdit = Q_NULLPTR;
QPlainTextEdit *plainTextEdit = Q_NULLPTR;
{
QList<QLineEdit *> lineEdits(findChildren<QLineEdit *>());
if (lineEdits.size() == 1) {
lineEdit = lineEdits.at(0);
}
QList<QPlainTextEdit *> plainTextEdits(
findChildren<QPlainTextEdit *>());
if (plainTextEdits.size() == 1) {
plainTextEdit = plainTextEdits.at(0);
}
}
if ((lineEdit != Q_NULLPTR) && (plainTextEdit == Q_NULLPTR)) {
return lineEdit;
} else if ((lineEdit == Q_NULLPTR) && (plainTextEdit != Q_NULLPTR)) {
return plainTextEdit;
}
return Q_NULLPTR;
}
......@@ -70,11 +70,6 @@ private slots:
*/
void activatePasteButton(void);
/*!
* @brief Pastes clipboard content into text field.
*/
void paste(void);
private:
/*!
* @brief This method adds the paste button.
......@@ -83,8 +78,16 @@ private:
*/
void extendDialoguePaste(void);
/*!
* @brief Find text field in the dialogue.
*
* @return Pointer to text field object if found.
*/
QObject *findEditArea(void) const;
QTimer m_timer; /*!< Timer used to check clipboard and activate button. */
QPushButton *m_pasteButton; /*!< Convenience pointer to paste button. */
QObject *m_textField; /*!< Text field receiving the paste command. */
};
#endif /* _PASTE_INPUT_DIALOGUE_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment