From 11eba85988f744c155f94015024243fd104e879a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20N=C3=A4tterlund?= Date: Tue, 19 Feb 2013 15:33:47 +0100 Subject: [PATCH] QNX: Added warning messages when icon/splashscreens are too big Change-Id: Idbad2d7c4760188c01c463a48317a407dc496914 Reviewed-by: Nicolas Arnaud-Cormos --- src/plugins/qnx/bardescriptoreditorwidget.cpp | 69 +++++++++++++++++++ src/plugins/qnx/bardescriptoreditorwidget.h | 9 +++ src/plugins/qnx/bardescriptoreditorwidget.ui | 44 ++++++++++-- 3 files changed, 118 insertions(+), 4 deletions(-) diff --git a/src/plugins/qnx/bardescriptoreditorwidget.cpp b/src/plugins/qnx/bardescriptoreditorwidget.cpp index 3d64cb3f17d..e17b9d05401 100644 --- a/src/plugins/qnx/bardescriptoreditorwidget.cpp +++ b/src/plugins/qnx/bardescriptoreditorwidget.cpp @@ -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("Could not open '%1' for reading.").arg(path)); + warningMessage->setVisible(true); + warningPixmap->setVisible(true); + break; + case IncorrectSize: { + warningMessage->setText(tr("The selected image is too big (%1x%2). The maximum size is %3x%4 pixels.") + .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(); diff --git a/src/plugins/qnx/bardescriptoreditorwidget.h b/src/plugins/qnx/bardescriptoreditorwidget.h index aaaae431b43..c650d908c44 100644 --- a/src/plugins/qnx/bardescriptoreditorwidget.h +++ b/src/plugins/qnx/bardescriptoreditorwidget.h @@ -146,13 +146,21 @@ private slots: void setApplicationIconDelayed(const QString &iconPath); void setApplicationIconPreview(const QString &path); + void validateIconSize(const QString &path); void appendSplashScreenDelayed(const QString &splashScreenPath); void browseForSplashScreen(); void removeSelectedSplashScreen(); void handleSplashScreenSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); + void validateSplashScreenSize(const QString &path); private: + enum ImageValidationResult { + Valid, + CouldNotLoad, + IncorrectSize + }; + BarDescriptorEditor *createEditor(); void initGeneralPage(); @@ -172,6 +180,7 @@ private: QString localAssetPathFromDestination(const QString &path); void setImagePreview(QLabel *previewLabel, const QString &path); + void validateImage(const QString &path, QLabel *warningMessage, QLabel *warningPixmap, const QSize &maximumSize); mutable Core::IEditor *m_editor; diff --git a/src/plugins/qnx/bardescriptoreditorwidget.ui b/src/plugins/qnx/bardescriptoreditorwidget.ui index 919603d211f..0872dc2a6eb 100644 --- a/src/plugins/qnx/bardescriptoreditorwidget.ui +++ b/src/plugins/qnx/bardescriptoreditorwidget.ui @@ -162,7 +162,7 @@ 0 0 1014 - 810 + 854 @@ -231,14 +231,14 @@ - + Splash screens: - + @@ -325,6 +325,40 @@ + + + + + + + + + + + + + + :/projectexplorer/images/compile_warning.png + + + + + + + + + + :/projectexplorer/images/compile_warning.png + + + + + + + + + + @@ -542,6 +576,8 @@ 1 - + + +