Commit 0bd04682 authored by Daniel Teske's avatar Daniel Teske
Browse files

Android Avd Dialog: Fix what the Name validator accepts



While at it, make non acceptable chars give better feedback.

Change-Id: I080f01592b2c8cbd6580734ca3e6fd46b9491106
Task-number: QTCREATORBUG-13589
Reviewed-by: default avatarBogDan Vatra <bogdan@kde.org>
parent 37217333
......@@ -180,6 +180,11 @@ bool ToolTip::isVisible()
return t->m_tip && t->m_tip->isVisible();
}
QPoint ToolTip::offsetFromPosition()
{
return QPoint(2, HostOsInfo::isWindowsHost() ? 21 : 16);
}
void ToolTip::showTip()
{
#if !defined(QT_NO_EFFECTS) && !defined(Q_OS_MAC)
......@@ -249,7 +254,7 @@ void ToolTip::placeTip(const QPoint &pos, QWidget *w)
{
QRect screen = Internal::screenGeometry(pos, w);
QPoint p = pos;
p += QPoint(2, HostOsInfo::isWindowsHost() ? 21 : 16);
p += offsetFromPosition();
if (p.x() + m_tip->width() > screen.x() + screen.width())
p.rx() -= 4 + m_tip->width();
if (p.y() + m_tip->height() > screen.y() + screen.height())
......
......@@ -82,6 +82,8 @@ public:
static void hide();
static bool isVisible();
static QPoint offsetFromPosition();
// Helper to 'pin' (show as real window) a tooltip shown
// using WidgetContent
static bool pinToolTip(QWidget *w, QWidget *parent);
......
......@@ -30,17 +30,24 @@
#include "avddialog.h"
#include "androidconfigurations.h"
#include <coreplugin/coreconstants.h>
#include <utils/tooltip/tooltip.h>
#include <QKeyEvent>
#include <QMessageBox>
#include <QToolTip>
using namespace Android;
using namespace Android::Internal;
AvdDialog::AvdDialog(int minApiLevel, const QString &targetArch, const AndroidConfig *config, QWidget *parent) :
QDialog(parent), m_config(config), m_minApiLevel(minApiLevel)
QDialog(parent), m_config(config), m_minApiLevel(minApiLevel),
m_allowedNameChars(QLatin1String("[a-z|A-Z|0-9|._-]*"))
{
m_avdDialog.setupUi(this);
m_hideTipTimer.setInterval(2000);
m_hideTipTimer.setSingleShot(true);
if (targetArch.isEmpty())
m_avdDialog.abiComboBox->addItems(QStringList()
......@@ -51,15 +58,19 @@ AvdDialog::AvdDialog(int minApiLevel, const QString &targetArch, const AndroidCo
else
m_avdDialog.abiComboBox->addItems(QStringList(targetArch));
QRegExp rx(QLatin1String("\\S+"));
QRegExpValidator v(rx, 0);
m_avdDialog.nameLineEdit->setValidator(&v);
QRegExpValidator *v = new QRegExpValidator(m_allowedNameChars, this);
m_avdDialog.nameLineEdit->setValidator(v);
m_avdDialog.nameLineEdit->installEventFilter(this);
m_avdDialog.warningIcon->setPixmap(QPixmap(QLatin1String(Core::Constants::ICON_WARNING)));
updateApiLevelComboBox();
connect(m_avdDialog.abiComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(updateApiLevelComboBox()));
connect(&m_hideTipTimer, &QTimer::timeout,
this, [](){Utils::ToolTip::hide();});
}
bool AvdDialog::isValid() const
......@@ -115,3 +126,21 @@ void AvdDialog::updateApiLevelComboBox()
m_avdDialog.warningText->setVisible(false);
}
}
bool AvdDialog::eventFilter(QObject *obj, QEvent *event)
{
if (obj == m_avdDialog.nameLineEdit && event->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
const QString key = ke->text();
if (!key.isEmpty() && !m_allowedNameChars.exactMatch(key)) {
QPoint position = m_avdDialog.nameLineEdit->parentWidget()->mapToGlobal(m_avdDialog.nameLineEdit->geometry().bottomLeft());
position -= Utils::ToolTip::offsetFromPosition();
Utils::ToolTip::show(position, tr("Allowed characters are: a-z A-Z 0-9 and . _ -"), m_avdDialog.nameLineEdit);
m_hideTipTimer.start();
} else {
m_hideTipTimer.stop();
Utils::ToolTip::hide();
}
}
return QDialog::eventFilter(obj, event);
}
......@@ -32,7 +32,9 @@
#define AVDDIALOG_H
#include "ui_addnewavddialog.h"
#include <QDialog>
#include <QTimer>
namespace Android {
class AndroidConfig;
......@@ -51,12 +53,17 @@ public:
QString abi() const;
int sdcardSize() const;
bool isValid() const;
private slots:
void updateApiLevelComboBox();
private:
bool eventFilter(QObject *obj, QEvent *event);
Ui::AddNewAVDDialog m_avdDialog;
const AndroidConfig *m_config;
int m_minApiLevel;
QTimer m_hideTipTimer;
QRegExp m_allowedNameChars;
};
}
}
......
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