QNX: Added warning messages when icon/splashscreens are too big

Change-Id: Idbad2d7c4760188c01c463a48317a407dc496914
Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
This commit is contained in:
Tobias Nätterlund
2013-02-19 15:33:47 +01:00
committed by Nicolas Arnaud-Cormos
parent e39ce66723
commit 11eba85988
3 changed files with 118 additions and 4 deletions

View File

@@ -83,6 +83,16 @@ void setCheckBoxBlocked(QCheckBox *checkBox, bool check)
checkBox->setChecked(check);
checkBox->blockSignals(blocked);
}
// Recommended maximum size for icons according to
// http://developer.blackberry.com/native/documentation/bb10/com.qnx.doc.native_sdk.devguide/com.qnx.doc.native_sdk.devguide/topic/r_barfile_dtd_ref_image.html
static int AppIconMaxWidth = 114;
static int AppIconMaxHeight = 114;
// Recommended maximum size for splashscreens according to
// http://developer.blackberry.com/native/documentation/bb10/com.qnx.doc.native_sdk.devguide/com.qnx.doc.native_sdk.devguide/topic/r_barfile_dtd_ref_splashscreens.html
static int SplashScreenMaxWidth = 1280;
static int SplashScreenMaxHeight = 1280;
}
BarDescriptorEditorWidget::BarDescriptorEditorWidget(QWidget *parent)
@@ -166,12 +176,19 @@ void BarDescriptorEditorWidget::initApplicationPage()
m_ui->iconFilePath->setExpectedKind(Utils::PathChooser::File);
m_ui->iconFilePath->setPromptDialogFilter(tr("Images (*.jpg *.png)"));
m_ui->iconWarningLabel->setVisible(false);
m_ui->iconWarningPixmap->setVisible(false);
m_ui->splashScreenWarningLabel->setVisible(false);
m_ui->splashScreenWarningPixmap->setVisible(false);
connect(m_ui->applicationName, SIGNAL(textChanged(QString)), this, SLOT(setDirty()));
connect(m_ui->applicationDescription, SIGNAL(textChanged()), this, SLOT(setDirty()));
connect(m_ui->iconFilePath, SIGNAL(changed(QString)), this, SLOT(setDirty()));
connect(m_ui->iconFilePath, SIGNAL(changed(QString)), this, SLOT(addImageAsAsset(QString)));
connect(m_ui->iconFilePath, SIGNAL(changed(QString)), this, SLOT(setApplicationIconPreview(QString)));
connect(m_ui->iconFilePath, SIGNAL(changed(QString)), this, SLOT(validateIconSize(QString)));
connect(m_ui->iconClearButton, SIGNAL(clicked()), m_ui->iconFilePath->lineEdit(), SLOT(clear()));
m_splashScreenModel = new QStringListModel(this);
@@ -452,6 +469,7 @@ void BarDescriptorEditorWidget::setApplicationIconDelayed(const QString &iconPat
const QString fullIconPath = localAssetPathFromDestination(iconPath);
setPathBlocked(m_ui->iconFilePath, fullIconPath);
setApplicationIconPreview(fullIconPath);
validateIconSize(fullIconPath);
}
void BarDescriptorEditorWidget::setImagePreview(QLabel *previewLabel, const QString &path)
@@ -477,11 +495,54 @@ void BarDescriptorEditorWidget::setImagePreview(QLabel *previewLabel, const QStr
previewLabel->setPixmap(scaledPixmap);
}
void BarDescriptorEditorWidget::validateImage(const QString &path, QLabel *warningMessage, QLabel *warningPixmap, const QSize &maximumSize)
{
ImageValidationResult result = Valid;
QSize actualSize;
if (!path.isEmpty()) {
QImage img(path);
if (img.isNull()) {
result = CouldNotLoad;
} else {
actualSize = img.size();
if (actualSize.width() > maximumSize.width() || actualSize.height() > maximumSize.height())
result = IncorrectSize;
}
}
switch (result) {
case CouldNotLoad:
warningMessage->setText(tr("<font color=\"red\">Could not open '%1' for reading.</font>").arg(path));
warningMessage->setVisible(true);
warningPixmap->setVisible(true);
break;
case IncorrectSize: {
warningMessage->setText(tr("<font color=\"red\">The selected image is too big (%1x%2). The maximum size is %3x%4 pixels.</font>")
.arg(actualSize.width()).arg(actualSize.height())
.arg(maximumSize.width()).arg(maximumSize.height()));
warningMessage->setVisible(true);
warningPixmap->setVisible(true);
break;
}
case Valid:
default:
warningMessage->setVisible(false);
warningPixmap->setVisible(false);
break;
}
}
void BarDescriptorEditorWidget::setApplicationIconPreview(const QString &path)
{
setImagePreview(m_ui->iconPreviewLabel, path);
}
void BarDescriptorEditorWidget::validateIconSize(const QString &path)
{
validateImage(path, m_ui->iconWarningLabel, m_ui->iconWarningPixmap, QSize(AppIconMaxWidth, AppIconMaxHeight));
}
void BarDescriptorEditorWidget::appendSplashScreenDelayed(const QString &splashScreenPath)
{
const QString fullSplashScreenPath = localAssetPathFromDestination(splashScreenPath);
@@ -538,11 +599,19 @@ void BarDescriptorEditorWidget::handleSplashScreenSelectionChanged(const QItemSe
if (!emptySelection) {
QString path = m_splashScreenModel->data(selected.indexes().at(0), Qt::DisplayRole).toString();
setImagePreview(m_ui->splashScreenPreviewLabel, path);
validateSplashScreenSize(path);
} else {
setImagePreview(m_ui->splashScreenPreviewLabel, QString());
m_ui->splashScreenWarningLabel->setVisible(false);
m_ui->splashScreenWarningPixmap->setVisible(false);
}
}
void BarDescriptorEditorWidget::validateSplashScreenSize(const QString &path)
{
validateImage(path, m_ui->splashScreenWarningLabel, m_ui->splashScreenWarningPixmap, QSize(SplashScreenMaxWidth, SplashScreenMaxHeight));
}
void BarDescriptorEditorWidget::addAsset(const BarDescriptorAsset &asset)
{
disconnectAssetsModel();