summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/aspectratiolabel.h
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2020-09-10 17:20:21 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2020-09-16 09:45:13 +0300
commit913c7ea16f961a8f5688734cd12d00fbeaa5d48c (patch)
tree8cd9c58233ea51ffddbcfc2f879f78a6da17cb15 /src/libs/installer/aspectratiolabel.h
parent244b3c4e92f0909085d5068d5a8c04137068c06b (diff)
Fix image aspect ratio not preserved when resizing window
As this is not currently possible using only QLabel, subclass it with a new AspectRatioLabel class to provide the functionality. This should be usable also on other places where we need scaling with aspect ratio maintaining. Task-number: QTIFW-1944 Change-Id: I32147b2b487573bb054fcf66b09eb3f8a0350ccd Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src/libs/installer/aspectratiolabel.h')
-rw-r--r--src/libs/installer/aspectratiolabel.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/libs/installer/aspectratiolabel.h b/src/libs/installer/aspectratiolabel.h
new file mode 100644
index 000000000..28fc5aea4
--- /dev/null
+++ b/src/libs/installer/aspectratiolabel.h
@@ -0,0 +1,63 @@
+/**************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+**************************************************************************/
+
+#ifndef ASPECTRATIOLABEL_H
+#define ASPECTRATIOLABEL_H
+
+#include "installer_global.h"
+
+#include <QLabel>
+#include <QPixmap>
+#include <QResizeEvent>
+
+namespace QInstaller {
+
+class INSTALLER_EXPORT AspectRatioLabel : public QLabel
+{
+ Q_OBJECT
+
+public:
+ explicit AspectRatioLabel(QWidget *parent = nullptr);
+
+ int heightForWidth(int w) const;
+ QSize sizeHint() const;
+
+public slots:
+ void setPixmap (const QPixmap &pixmap);
+ void resizeEvent(QResizeEvent *event);
+
+private:
+ QPixmap scaledPixmap() const;
+
+private:
+ QPixmap m_pixmap;
+};
+
+} // namespace QInstaller
+
+#endif // ASPECTRATIOLABEL_H