Commit 8cb25f9e authored by Eike Ziller's avatar Eike Ziller
Browse files

VariableChooser: Add support for (plain) text edits



Task-number: QTCREATORBUG-4309
Change-Id: I3d81244fe380bdf79e108f41c2c06df88b116137
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent b35ddc57
...@@ -173,6 +173,7 @@ void VariableChooser::updateCurrentEditor(QWidget *old, QWidget *widget) ...@@ -173,6 +173,7 @@ void VariableChooser::updateCurrentEditor(QWidget *old, QWidget *widget)
return; return;
widget->installEventFilter(this); // for intercepting escape key presses widget->installEventFilter(this); // for intercepting escape key presses
QLineEdit *previousLineEdit = m_lineEdit; QLineEdit *previousLineEdit = m_lineEdit;
QWidget *previousWidget = currentWidget();
m_lineEdit = 0; m_lineEdit = 0;
m_textEdit = 0; m_textEdit = 0;
m_plainTextEdit = 0; m_plainTextEdit = 0;
...@@ -187,23 +188,27 @@ void VariableChooser::updateCurrentEditor(QWidget *old, QWidget *widget) ...@@ -187,23 +188,27 @@ void VariableChooser::updateCurrentEditor(QWidget *old, QWidget *widget)
m_plainTextEdit = (supportsVariables ? plainTextEdit : 0); m_plainTextEdit = (supportsVariables ? plainTextEdit : 0);
if (!(m_lineEdit || m_textEdit || m_plainTextEdit)) if (!(m_lineEdit || m_textEdit || m_plainTextEdit))
hide(); hide();
if (m_lineEdit != previousLineEdit) {
QWidget *current = currentWidget();
if (current != previousWidget) {
if (previousLineEdit) if (previousLineEdit)
previousLineEdit->setTextMargins(0, 0, 0, 0); previousLineEdit->setTextMargins(0, 0, 0, 0);
if (m_iconButton) { if (m_iconButton) {
m_iconButton->hide(); m_iconButton->hide();
m_iconButton->setParent(0); m_iconButton->setParent(0);
} }
if (m_lineEdit) { if (current) {
if (!m_iconButton) if (!m_iconButton)
createIconButton(); createIconButton();
int margin = m_iconButton->pixmap().width() + 8; int margin = m_iconButton->pixmap().width() + 8;
if (style()->inherits("OxygenStyle")) if (style()->inherits("OxygenStyle"))
margin = qMax(24, margin); margin = qMax(24, margin);
if (m_lineEdit)
m_lineEdit->setTextMargins(0, 0, margin, 0); m_lineEdit->setTextMargins(0, 0, margin, 0);
m_iconButton->setParent(m_lineEdit); m_iconButton->setParent(current);
m_iconButton->setGeometry(m_lineEdit->rect().adjusted( m_iconButton->setGeometry(current->rect().adjusted(
m_lineEdit->width() - (margin + 4), 0, 0, 0)); current->width() - (margin + 4), 0,
0, -qMax(0, current->height() - (margin + 4))));
m_iconButton->show(); m_iconButton->show();
} }
} }
...@@ -235,6 +240,18 @@ void VariableChooser::updatePositionAndShow() ...@@ -235,6 +240,18 @@ void VariableChooser::updatePositionAndShow()
activateWindow(); activateWindow();
} }
/*!
* \internal
*/
QWidget *VariableChooser::currentWidget()
{
if (m_lineEdit)
return m_lineEdit;
if (m_textEdit)
return m_textEdit;
return m_plainTextEdit;
}
/*! /*!
* \internal * \internal
*/ */
......
...@@ -71,6 +71,7 @@ private slots: ...@@ -71,6 +71,7 @@ private slots:
void updatePositionAndShow(); void updatePositionAndShow();
private: private:
QWidget *currentWidget();
void createIconButton(); void createIconButton();
Internal::Ui::VariableChooser *ui; Internal::Ui::VariableChooser *ui;
......
Supports Markdown
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