forked from qt-creator/qt-creator
Android: Merge splashscreenwidget related file pairs
Change-Id: I8b21fff7954aa279cbf852ab07f837187ac9ce77 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -45,7 +45,6 @@ add_qtc_plugin(Android
|
|||||||
javalanguageserver.cpp javalanguageserver.h
|
javalanguageserver.cpp javalanguageserver.h
|
||||||
javaparser.cpp javaparser.h
|
javaparser.cpp javaparser.h
|
||||||
splashscreencontainerwidget.cpp splashscreencontainerwidget.h
|
splashscreencontainerwidget.cpp splashscreencontainerwidget.h
|
||||||
splashscreenwidget.cpp splashscreenwidget.h
|
|
||||||
sdkmanageroutputparser.cpp sdkmanageroutputparser.h
|
sdkmanageroutputparser.cpp sdkmanageroutputparser.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -95,8 +95,6 @@ QtcPlugin {
|
|||||||
"javaparser.h",
|
"javaparser.h",
|
||||||
"splashscreencontainerwidget.cpp",
|
"splashscreencontainerwidget.cpp",
|
||||||
"splashscreencontainerwidget.h",
|
"splashscreencontainerwidget.h",
|
||||||
"splashscreenwidget.cpp",
|
|
||||||
"splashscreenwidget.h",
|
|
||||||
"sdkmanageroutputparser.cpp",
|
"sdkmanageroutputparser.cpp",
|
||||||
"sdkmanageroutputparser.h"
|
"sdkmanageroutputparser.h"
|
||||||
]
|
]
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
// Copyright (C) 2020 The Qt Company Ltd.
|
// Copyright (C) 2020 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "androidtr.h"
|
|
||||||
#include "splashscreencontainerwidget.h"
|
#include "splashscreencontainerwidget.h"
|
||||||
#include "splashscreenwidget.h"
|
|
||||||
|
#include "androidtr.h"
|
||||||
|
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
@@ -14,11 +14,13 @@
|
|||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLoggingCategory>
|
||||||
|
#include <QPainter>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@@ -27,8 +29,7 @@
|
|||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Android {
|
namespace Android::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
const char extraExtraExtraHighDpiImagePath[] = "/res/drawable-xxxhdpi/";
|
const char extraExtraExtraHighDpiImagePath[] = "/res/drawable-xxxhdpi/";
|
||||||
const char extraExtraHighDpiImagePath[] = "/res/drawable-xxhdpi/";
|
const char extraExtraHighDpiImagePath[] = "/res/drawable-xxhdpi/";
|
||||||
@@ -66,6 +67,271 @@ static FilePath manifestDir(TextEditor::TextEditorWidget *textEditorWidget)
|
|||||||
return textEditorWidget->textDocument()->filePath().absolutePath();
|
return textEditorWidget->textDocument()->filePath().absolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Q_LOGGING_CATEGORY(androidManifestEditorLog, "qtc.android.splashScreenWidget", QtWarningMsg);
|
||||||
|
|
||||||
|
class SplashScreenWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
class SplashScreenButton : public QToolButton
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit SplashScreenButton(SplashScreenWidget *parent)
|
||||||
|
: QToolButton(parent),
|
||||||
|
m_parentWidget(parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void paintEvent(QPaintEvent *event) override
|
||||||
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
|
QPainter painter(this);
|
||||||
|
painter.setPen(QPen(Qt::gray, 1));
|
||||||
|
painter.setBrush(QBrush(m_parentWidget->m_backgroundColor));
|
||||||
|
painter.drawRect(0, 0, width()-1, height()-1);
|
||||||
|
if (!m_parentWidget->m_image.isNull())
|
||||||
|
painter.drawImage(m_parentWidget->m_imagePosition, m_parentWidget->m_image);
|
||||||
|
}
|
||||||
|
|
||||||
|
SplashScreenWidget *m_parentWidget;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit SplashScreenWidget(QWidget *parent) : QWidget(parent) {}
|
||||||
|
SplashScreenWidget(QWidget *parent,
|
||||||
|
const QSize &size,
|
||||||
|
const QSize &screenSize,
|
||||||
|
const QString &title,
|
||||||
|
const QString &tooltip,
|
||||||
|
const QString &imagePath,
|
||||||
|
int scalingRatio, int maxScalingRatio,
|
||||||
|
TextEditor::TextEditorWidget *textEditorWidget = nullptr);
|
||||||
|
|
||||||
|
bool hasImage() const;
|
||||||
|
void clearImage();
|
||||||
|
void setBackgroundColor(const QColor &backgroundColor);
|
||||||
|
void showImageFullScreen(bool fullScreen);
|
||||||
|
void setImageFromPath(const FilePath &imagePath, bool resize = true);
|
||||||
|
void setImageFileName(const QString &imageFileName);
|
||||||
|
void loadImage();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void imageChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void selectImage();
|
||||||
|
void removeImage();
|
||||||
|
void setScaleWarningLabelVisible(bool visible);
|
||||||
|
|
||||||
|
private:
|
||||||
|
TextEditor::TextEditorWidget *m_textEditorWidget = nullptr;
|
||||||
|
QLabel *m_scaleWarningLabel = nullptr;
|
||||||
|
SplashScreenButton *m_splashScreenButton = nullptr;
|
||||||
|
int m_scalingRatio, m_maxScalingRatio;
|
||||||
|
QColor m_backgroundColor = Qt::white;
|
||||||
|
QImage m_image;
|
||||||
|
QPoint m_imagePosition;
|
||||||
|
QString m_imagePath;
|
||||||
|
QString m_imageFileName;
|
||||||
|
QString m_imageSelectionText;
|
||||||
|
QSize m_screenSize;
|
||||||
|
bool m_showImageFullScreen = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
SplashScreenWidget::SplashScreenWidget(
|
||||||
|
QWidget *parent,
|
||||||
|
const QSize &size, const QSize &screenSize,
|
||||||
|
const QString &title, const QString &tooltip,
|
||||||
|
const QString &imagePath,
|
||||||
|
int scalingRatio, int maxScalingRatio,
|
||||||
|
TextEditor::TextEditorWidget *textEditorWidget)
|
||||||
|
: QWidget(parent),
|
||||||
|
m_textEditorWidget(textEditorWidget),
|
||||||
|
m_scalingRatio(scalingRatio),
|
||||||
|
m_maxScalingRatio(maxScalingRatio),
|
||||||
|
m_imagePath(imagePath),
|
||||||
|
m_screenSize(screenSize)
|
||||||
|
{
|
||||||
|
auto splashLayout = new QVBoxLayout(this);
|
||||||
|
auto splashTitle = new QLabel(title, this);
|
||||||
|
auto splashButtonLayout = new QGridLayout();
|
||||||
|
m_splashScreenButton = new SplashScreenButton(this);
|
||||||
|
m_splashScreenButton->setMinimumSize(size);
|
||||||
|
m_splashScreenButton->setMaximumSize(size);
|
||||||
|
m_splashScreenButton->setToolTip(tooltip);
|
||||||
|
QSize clearAndWarningSize(16, 16);
|
||||||
|
QToolButton *clearButton = nullptr;
|
||||||
|
if (textEditorWidget) {
|
||||||
|
clearButton = new QToolButton(this);
|
||||||
|
clearButton->setMinimumSize(clearAndWarningSize);
|
||||||
|
clearButton->setMaximumSize(clearAndWarningSize);
|
||||||
|
clearButton->setIcon(Utils::Icons::CLOSE_FOREGROUND.icon());
|
||||||
|
}
|
||||||
|
if (textEditorWidget) {
|
||||||
|
m_scaleWarningLabel = new QLabel(this);
|
||||||
|
m_scaleWarningLabel->setMinimumSize(clearAndWarningSize);
|
||||||
|
m_scaleWarningLabel->setMaximumSize(clearAndWarningSize);
|
||||||
|
m_scaleWarningLabel->setPixmap(Utils::Icons::WARNING.icon().pixmap(clearAndWarningSize));
|
||||||
|
m_scaleWarningLabel->setToolTip(Tr::tr("Icon scaled up."));
|
||||||
|
m_scaleWarningLabel->setVisible(false);
|
||||||
|
}
|
||||||
|
auto label = new QLabel(Tr::tr("Click to select..."), parent);
|
||||||
|
splashLayout->addWidget(splashTitle);
|
||||||
|
splashLayout->setAlignment(splashTitle, Qt::AlignHCenter);
|
||||||
|
splashButtonLayout->setColumnMinimumWidth(0, 16);
|
||||||
|
splashButtonLayout->addWidget(m_splashScreenButton, 0, 1, 1, 3);
|
||||||
|
splashButtonLayout->setAlignment(m_splashScreenButton, Qt::AlignVCenter);
|
||||||
|
if (textEditorWidget) {
|
||||||
|
splashButtonLayout->addWidget(clearButton, 0, 4, 1, 1);
|
||||||
|
splashButtonLayout->setAlignment(clearButton, Qt::AlignTop);
|
||||||
|
}
|
||||||
|
if (textEditorWidget) {
|
||||||
|
splashButtonLayout->addWidget(m_scaleWarningLabel, 0, 0, 1, 1);
|
||||||
|
splashButtonLayout->setAlignment(m_scaleWarningLabel, Qt::AlignTop);
|
||||||
|
}
|
||||||
|
splashLayout->addLayout(splashButtonLayout);
|
||||||
|
splashLayout->setAlignment(splashButtonLayout, Qt::AlignHCenter);
|
||||||
|
splashLayout->addWidget(label);
|
||||||
|
splashLayout->setAlignment(label, Qt::AlignHCenter);
|
||||||
|
this->setLayout(splashLayout);
|
||||||
|
connect(m_splashScreenButton, &QAbstractButton::clicked,
|
||||||
|
this, &SplashScreenWidget::selectImage);
|
||||||
|
if (clearButton)
|
||||||
|
connect(clearButton, &QAbstractButton::clicked,
|
||||||
|
this, &SplashScreenWidget::removeImage);
|
||||||
|
m_imageSelectionText = tooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreenWidget::setBackgroundColor(const QColor &backgroundColor)
|
||||||
|
{
|
||||||
|
m_backgroundColor = backgroundColor;
|
||||||
|
m_splashScreenButton->update();
|
||||||
|
emit imageChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreenWidget::showImageFullScreen(bool fullScreen)
|
||||||
|
{
|
||||||
|
m_showImageFullScreen = fullScreen;
|
||||||
|
loadImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreenWidget::setImageFromPath(const FilePath &imagePath, bool resize)
|
||||||
|
{
|
||||||
|
if (!m_textEditorWidget)
|
||||||
|
return;
|
||||||
|
const FilePath baseDir = manifestDir(m_textEditorWidget);
|
||||||
|
const FilePath targetPath = baseDir / m_imagePath / m_imageFileName;
|
||||||
|
if (targetPath.isEmpty()) {
|
||||||
|
qCDebug(androidManifestEditorLog) << "Image target path is empty, cannot set image.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QImage image = QImage(imagePath.toString());
|
||||||
|
if (image.isNull()) {
|
||||||
|
qCDebug(androidManifestEditorLog) << "Image '" << imagePath << "' not found or invalid format.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!targetPath.absolutePath().ensureWritableDir()) {
|
||||||
|
qCDebug(androidManifestEditorLog) << "Cannot create image target path.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (resize == true && m_scalingRatio < m_maxScalingRatio) {
|
||||||
|
const QSize size = QSize((float(image.width()) / float(m_maxScalingRatio)) * float(m_scalingRatio),
|
||||||
|
(float(image.height()) / float(m_maxScalingRatio)) * float(m_scalingRatio));
|
||||||
|
image = image.scaled(size);
|
||||||
|
}
|
||||||
|
QFile file(targetPath.toString());
|
||||||
|
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||||
|
image.save(&file, "PNG");
|
||||||
|
file.close();
|
||||||
|
loadImage();
|
||||||
|
emit imageChanged();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qCDebug(androidManifestEditorLog).noquote()
|
||||||
|
<< "Cannot save image." << targetPath.toUserOutput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreenWidget::selectImage()
|
||||||
|
{
|
||||||
|
const FilePath file = FileUtils::getOpenFilePath(this, m_imageSelectionText,
|
||||||
|
FileUtils::homePath(),
|
||||||
|
QStringLiteral("%1 (*.png *.jpg *.jpeg)")
|
||||||
|
.arg(Tr::tr("Images")));
|
||||||
|
if (file.isEmpty())
|
||||||
|
return;
|
||||||
|
setImageFromPath(file, false);
|
||||||
|
emit imageChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreenWidget::removeImage()
|
||||||
|
{
|
||||||
|
const FilePath baseDir = manifestDir(m_textEditorWidget);
|
||||||
|
const FilePath targetPath = baseDir / m_imagePath / m_imageFileName;
|
||||||
|
if (targetPath.isEmpty()) {
|
||||||
|
qCDebug(androidManifestEditorLog) << "Image target path empty, cannot remove image.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
targetPath.removeFile();
|
||||||
|
m_image = QImage();
|
||||||
|
m_splashScreenButton->update();
|
||||||
|
setScaleWarningLabelVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreenWidget::clearImage()
|
||||||
|
{
|
||||||
|
removeImage();
|
||||||
|
emit imageChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreenWidget::loadImage()
|
||||||
|
{
|
||||||
|
if (m_imageFileName.isEmpty()) {
|
||||||
|
qCDebug(androidManifestEditorLog) << "Image name not set, cannot load image.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const FilePath baseDir = manifestDir(m_textEditorWidget);
|
||||||
|
const FilePath targetPath = baseDir / m_imagePath / m_imageFileName;
|
||||||
|
if (targetPath.isEmpty()) {
|
||||||
|
qCDebug(androidManifestEditorLog) << "Image target path empty, cannot load image.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QImage image = QImage(targetPath.toString());
|
||||||
|
if (image.isNull()) {
|
||||||
|
qCDebug(androidManifestEditorLog).noquote()
|
||||||
|
<< "Cannot load image." << targetPath.toUserOutput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_showImageFullScreen) {
|
||||||
|
m_image = image.scaled(m_splashScreenButton->size());
|
||||||
|
m_imagePosition = QPoint(0,0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QSize scaledSize = QSize((m_splashScreenButton->width() * image.width()) / m_screenSize.width(),
|
||||||
|
(m_splashScreenButton->height() * image.height()) / m_screenSize.height());
|
||||||
|
m_image = image.scaled(scaledSize, Qt::KeepAspectRatio);
|
||||||
|
m_imagePosition = QPoint((m_splashScreenButton->width() - m_image.width()) / 2,
|
||||||
|
(m_splashScreenButton->height() - m_image.height()) / 2);
|
||||||
|
}
|
||||||
|
m_splashScreenButton->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SplashScreenWidget::hasImage() const
|
||||||
|
{
|
||||||
|
return !m_image.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreenWidget::setScaleWarningLabelVisible(bool visible)
|
||||||
|
{
|
||||||
|
if (m_scaleWarningLabel)
|
||||||
|
m_scaleWarningLabel->setVisible(visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreenWidget::setImageFileName(const QString &imageFileName)
|
||||||
|
{
|
||||||
|
m_imageFileName = imageFileName;
|
||||||
|
}
|
||||||
|
|
||||||
static SplashScreenWidget *addWidgetToPage(QWidget *page,
|
static SplashScreenWidget *addWidgetToPage(QWidget *page,
|
||||||
const QSize &size, const QSize &screenSize,
|
const QSize &size, const QSize &screenSize,
|
||||||
const QString &title, const QString &tooltip,
|
const QString &title, const QString &tooltip,
|
||||||
@@ -618,5 +884,6 @@ QString SplashScreenContainerWidget::landscapeImageName() const
|
|||||||
return splashscreenLandscapeName;
|
return splashscreenLandscapeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Android::Internal
|
||||||
} // namespace Android
|
|
||||||
|
#include "splashscreencontainerwidget.moc"
|
||||||
|
@@ -15,8 +15,7 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace TextEditor { class TextEditorWidget; }
|
namespace TextEditor { class TextEditorWidget; }
|
||||||
|
|
||||||
namespace Android {
|
namespace Android::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class SplashScreenWidget;
|
class SplashScreenWidget;
|
||||||
|
|
||||||
@@ -62,5 +61,4 @@ private:
|
|||||||
QToolButton *m_convertSplashscreen = nullptr;
|
QToolButton *m_convertSplashscreen = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Android::Internal
|
||||||
} // namespace Android
|
|
||||||
|
@@ -1,247 +0,0 @@
|
|||||||
// Copyright (C) 2020 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#include "androidtr.h"
|
|
||||||
#include "splashscreenwidget.h"
|
|
||||||
|
|
||||||
#include <texteditor/textdocument.h>
|
|
||||||
#include <texteditor/texteditor.h>
|
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
|
||||||
#include <utils/utilsicons.h>
|
|
||||||
|
|
||||||
#include <QGridLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QLoggingCategory>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QToolButton>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
using namespace Utils;
|
|
||||||
|
|
||||||
namespace Android::Internal {
|
|
||||||
|
|
||||||
static Q_LOGGING_CATEGORY(androidManifestEditorLog, "qtc.android.splashScreenWidget", QtWarningMsg)
|
|
||||||
|
|
||||||
FilePath manifestDir(TextEditor::TextEditorWidget *textEditorWidget)
|
|
||||||
{
|
|
||||||
// Get the manifest file's directory from its filepath.
|
|
||||||
return textEditorWidget->textDocument()->filePath().absolutePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
SplashScreenWidget::SplashScreenWidget(QWidget *parent) : QWidget(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SplashScreenWidget::SplashScreenWidget(
|
|
||||||
QWidget *parent,
|
|
||||||
const QSize &size, const QSize &screenSize,
|
|
||||||
const QString &title, const QString &tooltip,
|
|
||||||
const QString &imagePath,
|
|
||||||
int scalingRatio, int maxScalingRatio,
|
|
||||||
TextEditor::TextEditorWidget *textEditorWidget)
|
|
||||||
: QWidget(parent),
|
|
||||||
m_textEditorWidget(textEditorWidget),
|
|
||||||
m_scalingRatio(scalingRatio),
|
|
||||||
m_maxScalingRatio(maxScalingRatio),
|
|
||||||
m_imagePath(imagePath),
|
|
||||||
m_screenSize(screenSize)
|
|
||||||
{
|
|
||||||
auto splashLayout = new QVBoxLayout(this);
|
|
||||||
auto splashTitle = new QLabel(title, this);
|
|
||||||
auto splashButtonLayout = new QGridLayout();
|
|
||||||
m_splashScreenButton = new SplashScreenButton(this);
|
|
||||||
m_splashScreenButton->setMinimumSize(size);
|
|
||||||
m_splashScreenButton->setMaximumSize(size);
|
|
||||||
m_splashScreenButton->setToolTip(tooltip);
|
|
||||||
QSize clearAndWarningSize(16, 16);
|
|
||||||
QToolButton *clearButton = nullptr;
|
|
||||||
if (textEditorWidget) {
|
|
||||||
clearButton = new QToolButton(this);
|
|
||||||
clearButton->setMinimumSize(clearAndWarningSize);
|
|
||||||
clearButton->setMaximumSize(clearAndWarningSize);
|
|
||||||
clearButton->setIcon(Utils::Icons::CLOSE_FOREGROUND.icon());
|
|
||||||
}
|
|
||||||
if (textEditorWidget) {
|
|
||||||
m_scaleWarningLabel = new QLabel(this);
|
|
||||||
m_scaleWarningLabel->setMinimumSize(clearAndWarningSize);
|
|
||||||
m_scaleWarningLabel->setMaximumSize(clearAndWarningSize);
|
|
||||||
m_scaleWarningLabel->setPixmap(Utils::Icons::WARNING.icon().pixmap(clearAndWarningSize));
|
|
||||||
m_scaleWarningLabel->setToolTip(Tr::tr("Icon scaled up."));
|
|
||||||
m_scaleWarningLabel->setVisible(false);
|
|
||||||
}
|
|
||||||
auto label = new QLabel(Tr::tr("Click to select..."), parent);
|
|
||||||
splashLayout->addWidget(splashTitle);
|
|
||||||
splashLayout->setAlignment(splashTitle, Qt::AlignHCenter);
|
|
||||||
splashButtonLayout->setColumnMinimumWidth(0, 16);
|
|
||||||
splashButtonLayout->addWidget(m_splashScreenButton, 0, 1, 1, 3);
|
|
||||||
splashButtonLayout->setAlignment(m_splashScreenButton, Qt::AlignVCenter);
|
|
||||||
if (textEditorWidget) {
|
|
||||||
splashButtonLayout->addWidget(clearButton, 0, 4, 1, 1);
|
|
||||||
splashButtonLayout->setAlignment(clearButton, Qt::AlignTop);
|
|
||||||
}
|
|
||||||
if (textEditorWidget) {
|
|
||||||
splashButtonLayout->addWidget(m_scaleWarningLabel, 0, 0, 1, 1);
|
|
||||||
splashButtonLayout->setAlignment(m_scaleWarningLabel, Qt::AlignTop);
|
|
||||||
}
|
|
||||||
splashLayout->addLayout(splashButtonLayout);
|
|
||||||
splashLayout->setAlignment(splashButtonLayout, Qt::AlignHCenter);
|
|
||||||
splashLayout->addWidget(label);
|
|
||||||
splashLayout->setAlignment(label, Qt::AlignHCenter);
|
|
||||||
this->setLayout(splashLayout);
|
|
||||||
connect(m_splashScreenButton, &QAbstractButton::clicked,
|
|
||||||
this, &SplashScreenWidget::selectImage);
|
|
||||||
if (clearButton)
|
|
||||||
connect(clearButton, &QAbstractButton::clicked,
|
|
||||||
this, &SplashScreenWidget::removeImage);
|
|
||||||
m_imageSelectionText = tooltip;
|
|
||||||
}
|
|
||||||
|
|
||||||
SplashScreenWidget::SplashScreenButton::SplashScreenButton(SplashScreenWidget *parent)
|
|
||||||
: QToolButton(parent),
|
|
||||||
m_parentWidget(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplashScreenWidget::SplashScreenButton::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
QPainter painter(this);
|
|
||||||
painter.setPen(QPen(Qt::gray, 1));
|
|
||||||
painter.setBrush(QBrush(m_parentWidget->m_backgroundColor));
|
|
||||||
painter.drawRect(0, 0, width()-1, height()-1);
|
|
||||||
if (!m_parentWidget->m_image.isNull())
|
|
||||||
painter.drawImage(m_parentWidget->m_imagePosition, m_parentWidget->m_image);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplashScreenWidget::setBackgroundColor(const QColor &backgroundColor)
|
|
||||||
{
|
|
||||||
m_backgroundColor = backgroundColor;
|
|
||||||
m_splashScreenButton->update();
|
|
||||||
emit imageChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplashScreenWidget::showImageFullScreen(bool fullScreen)
|
|
||||||
{
|
|
||||||
m_showImageFullScreen = fullScreen;
|
|
||||||
loadImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplashScreenWidget::setImageFromPath(const FilePath &imagePath, bool resize)
|
|
||||||
{
|
|
||||||
if (!m_textEditorWidget)
|
|
||||||
return;
|
|
||||||
const FilePath baseDir = manifestDir(m_textEditorWidget);
|
|
||||||
const FilePath targetPath = baseDir / m_imagePath / m_imageFileName;
|
|
||||||
if (targetPath.isEmpty()) {
|
|
||||||
qCDebug(androidManifestEditorLog) << "Image target path is empty, cannot set image.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QImage image = QImage(imagePath.toString());
|
|
||||||
if (image.isNull()) {
|
|
||||||
qCDebug(androidManifestEditorLog) << "Image '" << imagePath << "' not found or invalid format.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!targetPath.absolutePath().ensureWritableDir()) {
|
|
||||||
qCDebug(androidManifestEditorLog) << "Cannot create image target path.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (resize == true && m_scalingRatio < m_maxScalingRatio) {
|
|
||||||
const QSize size = QSize((float(image.width()) / float(m_maxScalingRatio)) * float(m_scalingRatio),
|
|
||||||
(float(image.height()) / float(m_maxScalingRatio)) * float(m_scalingRatio));
|
|
||||||
image = image.scaled(size);
|
|
||||||
}
|
|
||||||
QFile file(targetPath.toString());
|
|
||||||
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
|
||||||
image.save(&file, "PNG");
|
|
||||||
file.close();
|
|
||||||
loadImage();
|
|
||||||
emit imageChanged();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qCDebug(androidManifestEditorLog).noquote()
|
|
||||||
<< "Cannot save image." << targetPath.toUserOutput();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplashScreenWidget::selectImage()
|
|
||||||
{
|
|
||||||
const FilePath file = FileUtils::getOpenFilePath(this, m_imageSelectionText,
|
|
||||||
FileUtils::homePath(),
|
|
||||||
QStringLiteral("%1 (*.png *.jpg *.jpeg)")
|
|
||||||
.arg(Tr::tr("Images")));
|
|
||||||
if (file.isEmpty())
|
|
||||||
return;
|
|
||||||
setImageFromPath(file, false);
|
|
||||||
emit imageChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplashScreenWidget::removeImage()
|
|
||||||
{
|
|
||||||
const FilePath baseDir = manifestDir(m_textEditorWidget);
|
|
||||||
const FilePath targetPath = baseDir / m_imagePath / m_imageFileName;
|
|
||||||
if (targetPath.isEmpty()) {
|
|
||||||
qCDebug(androidManifestEditorLog) << "Image target path empty, cannot remove image.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
targetPath.removeFile();
|
|
||||||
m_image = QImage();
|
|
||||||
m_splashScreenButton->update();
|
|
||||||
setScaleWarningLabelVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplashScreenWidget::clearImage()
|
|
||||||
{
|
|
||||||
removeImage();
|
|
||||||
emit imageChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplashScreenWidget::loadImage()
|
|
||||||
{
|
|
||||||
if (m_imageFileName.isEmpty()) {
|
|
||||||
qCDebug(androidManifestEditorLog) << "Image name not set, cannot load image.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const FilePath baseDir = manifestDir(m_textEditorWidget);
|
|
||||||
const FilePath targetPath = baseDir / m_imagePath / m_imageFileName;
|
|
||||||
if (targetPath.isEmpty()) {
|
|
||||||
qCDebug(androidManifestEditorLog) << "Image target path empty, cannot load image.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QImage image = QImage(targetPath.toString());
|
|
||||||
if (image.isNull()) {
|
|
||||||
qCDebug(androidManifestEditorLog).noquote()
|
|
||||||
<< "Cannot load image." << targetPath.toUserOutput();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m_showImageFullScreen) {
|
|
||||||
m_image = image.scaled(m_splashScreenButton->size());
|
|
||||||
m_imagePosition = QPoint(0,0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QSize scaledSize = QSize((m_splashScreenButton->width() * image.width()) / m_screenSize.width(),
|
|
||||||
(m_splashScreenButton->height() * image.height()) / m_screenSize.height());
|
|
||||||
m_image = image.scaled(scaledSize, Qt::KeepAspectRatio);
|
|
||||||
m_imagePosition = QPoint((m_splashScreenButton->width() - m_image.width()) / 2,
|
|
||||||
(m_splashScreenButton->height() - m_image.height()) / 2);
|
|
||||||
}
|
|
||||||
m_splashScreenButton->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SplashScreenWidget::hasImage() const
|
|
||||||
{
|
|
||||||
return !m_image.isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplashScreenWidget::setScaleWarningLabelVisible(bool visible)
|
|
||||||
{
|
|
||||||
if (m_scaleWarningLabel)
|
|
||||||
m_scaleWarningLabel->setVisible(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplashScreenWidget::setImageFileName(const QString &imageFileName)
|
|
||||||
{
|
|
||||||
m_imageFileName = imageFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Android::Internal
|
|
@@ -1,75 +0,0 @@
|
|||||||
// Copyright (C) 2020 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <utils/filepath.h>
|
|
||||||
|
|
||||||
#include <QToolButton>
|
|
||||||
|
|
||||||
namespace TextEditor { class TextEditorWidget; }
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QLabel;
|
|
||||||
class QColor;
|
|
||||||
class QImage;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Android::Internal {
|
|
||||||
|
|
||||||
class SplashScreenWidget : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
class SplashScreenButton : public QToolButton
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit SplashScreenButton(SplashScreenWidget *parent);
|
|
||||||
private:
|
|
||||||
void paintEvent(QPaintEvent *event) override;
|
|
||||||
SplashScreenWidget *m_parentWidget;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit SplashScreenWidget(QWidget *parent);
|
|
||||||
SplashScreenWidget(QWidget *parent,
|
|
||||||
const QSize &size,
|
|
||||||
const QSize &screenSize,
|
|
||||||
const QString &title,
|
|
||||||
const QString &tooltip,
|
|
||||||
const QString &imagePath,
|
|
||||||
int scalingRatio, int maxScalingRatio,
|
|
||||||
TextEditor::TextEditorWidget *textEditorWidget = nullptr);
|
|
||||||
|
|
||||||
bool hasImage() const;
|
|
||||||
void clearImage();
|
|
||||||
void setBackgroundColor(const QColor &backgroundColor);
|
|
||||||
void showImageFullScreen(bool fullScreen);
|
|
||||||
void setImageFromPath(const Utils::FilePath &imagePath, bool resize = true);
|
|
||||||
void setImageFileName(const QString &imageFileName);
|
|
||||||
void loadImage();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void imageChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void selectImage();
|
|
||||||
void removeImage();
|
|
||||||
void setScaleWarningLabelVisible(bool visible);
|
|
||||||
|
|
||||||
private:
|
|
||||||
TextEditor::TextEditorWidget *m_textEditorWidget = nullptr;
|
|
||||||
QLabel *m_scaleWarningLabel = nullptr;
|
|
||||||
SplashScreenButton *m_splashScreenButton = nullptr;
|
|
||||||
int m_scalingRatio, m_maxScalingRatio;
|
|
||||||
QColor m_backgroundColor = Qt::white;
|
|
||||||
QImage m_image;
|
|
||||||
QPoint m_imagePosition;
|
|
||||||
QString m_imagePath;
|
|
||||||
QString m_imageFileName;
|
|
||||||
QString m_imageSelectionText;
|
|
||||||
QSize m_screenSize;
|
|
||||||
bool m_showImageFullScreen = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // Android::Internal
|
|
Reference in New Issue
Block a user