forked from qt-creator/qt-creator
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: BogDan Vatra <bogdan@kde.org>
This commit is contained in:
@@ -180,6 +180,11 @@ bool ToolTip::isVisible()
|
|||||||
return t->m_tip && t->m_tip->isVisible();
|
return t->m_tip && t->m_tip->isVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPoint ToolTip::offsetFromPosition()
|
||||||
|
{
|
||||||
|
return QPoint(2, HostOsInfo::isWindowsHost() ? 21 : 16);
|
||||||
|
}
|
||||||
|
|
||||||
void ToolTip::showTip()
|
void ToolTip::showTip()
|
||||||
{
|
{
|
||||||
#if !defined(QT_NO_EFFECTS) && !defined(Q_OS_MAC)
|
#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);
|
QRect screen = Internal::screenGeometry(pos, w);
|
||||||
QPoint p = pos;
|
QPoint p = pos;
|
||||||
p += QPoint(2, HostOsInfo::isWindowsHost() ? 21 : 16);
|
p += offsetFromPosition();
|
||||||
if (p.x() + m_tip->width() > screen.x() + screen.width())
|
if (p.x() + m_tip->width() > screen.x() + screen.width())
|
||||||
p.rx() -= 4 + m_tip->width();
|
p.rx() -= 4 + m_tip->width();
|
||||||
if (p.y() + m_tip->height() > screen.y() + screen.height())
|
if (p.y() + m_tip->height() > screen.y() + screen.height())
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ public:
|
|||||||
static void hide();
|
static void hide();
|
||||||
static bool isVisible();
|
static bool isVisible();
|
||||||
|
|
||||||
|
static QPoint offsetFromPosition();
|
||||||
|
|
||||||
// Helper to 'pin' (show as real window) a tooltip shown
|
// Helper to 'pin' (show as real window) a tooltip shown
|
||||||
// using WidgetContent
|
// using WidgetContent
|
||||||
static bool pinToolTip(QWidget *w, QWidget *parent);
|
static bool pinToolTip(QWidget *w, QWidget *parent);
|
||||||
|
|||||||
@@ -30,17 +30,24 @@
|
|||||||
|
|
||||||
#include "avddialog.h"
|
#include "avddialog.h"
|
||||||
#include "androidconfigurations.h"
|
#include "androidconfigurations.h"
|
||||||
#include <coreplugin/coreconstants.h>
|
|
||||||
|
|
||||||
|
#include <coreplugin/coreconstants.h>
|
||||||
|
#include <utils/tooltip/tooltip.h>
|
||||||
|
|
||||||
|
#include <QKeyEvent>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QToolTip>
|
||||||
|
|
||||||
using namespace Android;
|
using namespace Android;
|
||||||
using namespace Android::Internal;
|
using namespace Android::Internal;
|
||||||
|
|
||||||
AvdDialog::AvdDialog(int minApiLevel, const QString &targetArch, const AndroidConfig *config, QWidget *parent) :
|
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_avdDialog.setupUi(this);
|
||||||
|
m_hideTipTimer.setInterval(2000);
|
||||||
|
m_hideTipTimer.setSingleShot(true);
|
||||||
|
|
||||||
if (targetArch.isEmpty())
|
if (targetArch.isEmpty())
|
||||||
m_avdDialog.abiComboBox->addItems(QStringList()
|
m_avdDialog.abiComboBox->addItems(QStringList()
|
||||||
@@ -51,15 +58,19 @@ AvdDialog::AvdDialog(int minApiLevel, const QString &targetArch, const AndroidCo
|
|||||||
else
|
else
|
||||||
m_avdDialog.abiComboBox->addItems(QStringList(targetArch));
|
m_avdDialog.abiComboBox->addItems(QStringList(targetArch));
|
||||||
|
|
||||||
QRegExp rx(QLatin1String("\\S+"));
|
QRegExpValidator *v = new QRegExpValidator(m_allowedNameChars, this);
|
||||||
QRegExpValidator v(rx, 0);
|
m_avdDialog.nameLineEdit->setValidator(v);
|
||||||
m_avdDialog.nameLineEdit->setValidator(&v);
|
m_avdDialog.nameLineEdit->installEventFilter(this);
|
||||||
|
|
||||||
m_avdDialog.warningIcon->setPixmap(QPixmap(QLatin1String(Core::Constants::ICON_WARNING)));
|
m_avdDialog.warningIcon->setPixmap(QPixmap(QLatin1String(Core::Constants::ICON_WARNING)));
|
||||||
|
|
||||||
updateApiLevelComboBox();
|
updateApiLevelComboBox();
|
||||||
|
|
||||||
connect(m_avdDialog.abiComboBox, SIGNAL(currentIndexChanged(int)),
|
connect(m_avdDialog.abiComboBox, SIGNAL(currentIndexChanged(int)),
|
||||||
this, SLOT(updateApiLevelComboBox()));
|
this, SLOT(updateApiLevelComboBox()));
|
||||||
|
|
||||||
|
connect(&m_hideTipTimer, &QTimer::timeout,
|
||||||
|
this, [](){Utils::ToolTip::hide();});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AvdDialog::isValid() const
|
bool AvdDialog::isValid() const
|
||||||
@@ -115,3 +126,21 @@ void AvdDialog::updateApiLevelComboBox()
|
|||||||
m_avdDialog.warningText->setVisible(false);
|
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
|
#define AVDDIALOG_H
|
||||||
|
|
||||||
#include "ui_addnewavddialog.h"
|
#include "ui_addnewavddialog.h"
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
namespace Android {
|
namespace Android {
|
||||||
class AndroidConfig;
|
class AndroidConfig;
|
||||||
@@ -51,12 +53,17 @@ public:
|
|||||||
QString abi() const;
|
QString abi() const;
|
||||||
int sdcardSize() const;
|
int sdcardSize() const;
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateApiLevelComboBox();
|
void updateApiLevelComboBox();
|
||||||
private:
|
private:
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
Ui::AddNewAVDDialog m_avdDialog;
|
Ui::AddNewAVDDialog m_avdDialog;
|
||||||
const AndroidConfig *m_config;
|
const AndroidConfig *m_config;
|
||||||
int m_minApiLevel;
|
int m_minApiLevel;
|
||||||
|
QTimer m_hideTipTimer;
|
||||||
|
QRegExp m_allowedNameChars;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user