aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/widgets
diff options
context:
space:
mode:
authorAlessandro Portale <alessandro.portale@qt.io>2019-12-11 15:55:03 +0100
committerAlessandro Portale <alessandro.portale@qt.io>2019-12-19 14:02:10 +0000
commitcd86aa05d6e85e1f10e2c1c41205696b770ccd48 (patch)
treee58a27d9d8037a7ccadd7c07c3349bbc4270383e /tests/manual/widgets
parentc2501dc9389fd3e16792e3119008231cf85df82e (diff)
Utils: Introduce InfoLabel
Utils::InfoLabel is meant to replace around 30 custom implementations of a QHBoxLayout with an pixmap QLabel and a text QLabel. Instead of fiddling with pixmaps, the user of InfoLabel can set an enum for info/warning/etc... type. Internally, a globally shared QIcon is used. The usage of QIcon ensures that @1x, @2x and hybrid cases are handled. Task-number: QTCREATORBUG-23346 Change-Id: I0f91a21e64f095db14837512263c4becbb2c13d7 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'tests/manual/widgets')
-rw-r--r--tests/manual/widgets/CMakeLists.txt1
-rw-r--r--tests/manual/widgets/crumblepath/CMakeLists.txt3
-rw-r--r--tests/manual/widgets/crumblepath/crumblepath.pro2
-rw-r--r--tests/manual/widgets/crumblepath/tst_manual_widgets_crumblepath.cpp2
-rw-r--r--tests/manual/widgets/crumblepath/tst_manual_widgets_crumblepath.qrc9
-rw-r--r--tests/manual/widgets/infolabel/CMakeLists.txt6
-rw-r--r--tests/manual/widgets/infolabel/infolabel.pro13
-rw-r--r--tests/manual/widgets/infolabel/tst_manual_widgets_infolabel.cpp113
-rw-r--r--tests/manual/widgets/themes.qrc10
-rw-r--r--tests/manual/widgets/widgets.pro3
10 files changed, 149 insertions, 13 deletions
diff --git a/tests/manual/widgets/CMakeLists.txt b/tests/manual/widgets/CMakeLists.txt
index 3a529bd91e..0313840362 100644
--- a/tests/manual/widgets/CMakeLists.txt
+++ b/tests/manual/widgets/CMakeLists.txt
@@ -1 +1,2 @@
add_subdirectory(crumblepath)
+add_subdirectory(infolabel)
diff --git a/tests/manual/widgets/crumblepath/CMakeLists.txt b/tests/manual/widgets/crumblepath/CMakeLists.txt
index 01dffb3361..ac36a76bfd 100644
--- a/tests/manual/widgets/crumblepath/CMakeLists.txt
+++ b/tests/manual/widgets/crumblepath/CMakeLists.txt
@@ -1,5 +1,6 @@
add_qtc_executable(tst_manual_widgets_crumblepath
DEPENDS Qt5::Gui Utils Core
SOURCES
- tst_manual_widgets_crumblepath.cpp tst_manual_widgets_crumblepath.qrc
+ tst_manual_widgets_crumblepath.cpp
+ ../themes.qrc
)
diff --git a/tests/manual/widgets/crumblepath/crumblepath.pro b/tests/manual/widgets/crumblepath/crumblepath.pro
index 6645136aaf..555b63c9a0 100644
--- a/tests/manual/widgets/crumblepath/crumblepath.pro
+++ b/tests/manual/widgets/crumblepath/crumblepath.pro
@@ -2,7 +2,7 @@ SOURCES += \
tst_manual_widgets_crumblepath.cpp
RESOURCES += \
- tst_manual_widgets_crumblepath.qrc
+ ../themes.qrc
QTC_LIB_DEPENDS += \
utils
diff --git a/tests/manual/widgets/crumblepath/tst_manual_widgets_crumblepath.cpp b/tests/manual/widgets/crumblepath/tst_manual_widgets_crumblepath.cpp
index b2815cea83..f7dcad8222 100644
--- a/tests/manual/widgets/crumblepath/tst_manual_widgets_crumblepath.cpp
+++ b/tests/manual/widgets/crumblepath/tst_manual_widgets_crumblepath.cpp
@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
Theme theme("");
- QSettings settings(":/flat.creatortheme", QSettings::IniFormat);
+ QSettings settings(":/themes/flat.creatortheme", QSettings::IniFormat);
theme.readSettings(settings);
setCreatorTheme(&theme);
StyleHelper::setBaseColor(QColor(StyleHelper::DEFAULT_BASE_COLOR));
diff --git a/tests/manual/widgets/crumblepath/tst_manual_widgets_crumblepath.qrc b/tests/manual/widgets/crumblepath/tst_manual_widgets_crumblepath.qrc
deleted file mode 100644
index d596e9c0eb..0000000000
--- a/tests/manual/widgets/crumblepath/tst_manual_widgets_crumblepath.qrc
+++ /dev/null
@@ -1,9 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/">
- <file alias="dark.creatortheme">../../../../share/qtcreator/themes/dark.creatortheme</file>
- <file alias="default.creatortheme">../../../../share/qtcreator/themes/default.creatortheme</file>
- <file alias="flat-dark.creatortheme">../../../../share/qtcreator/themes/flat-dark.creatortheme</file>
- <file alias="flat-light.creatortheme">../../../../share/qtcreator/themes/flat-light.creatortheme</file>
- <file alias="flat.creatortheme">../../../../share/qtcreator/themes/flat.creatortheme</file>
-</qresource>
-</RCC>
diff --git a/tests/manual/widgets/infolabel/CMakeLists.txt b/tests/manual/widgets/infolabel/CMakeLists.txt
new file mode 100644
index 0000000000..510261ec04
--- /dev/null
+++ b/tests/manual/widgets/infolabel/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_qtc_executable(tst_manual_widgets_infolabel
+ DEPENDS Qt5::Gui Utils Core
+ SOURCES
+ tst_manual_widgets_infolabel.cpp
+ ../themes.qrc
+)
diff --git a/tests/manual/widgets/infolabel/infolabel.pro b/tests/manual/widgets/infolabel/infolabel.pro
new file mode 100644
index 0000000000..a38b3c8e75
--- /dev/null
+++ b/tests/manual/widgets/infolabel/infolabel.pro
@@ -0,0 +1,13 @@
+SOURCES += \
+ tst_manual_widgets_infolabel.cpp
+
+RESOURCES += \
+ ../themes.qrc
+
+QTC_LIB_DEPENDS += \
+ utils
+
+QTC_PLUGIN_DEPENDS += \
+ coreplugin
+
+include(../../../auto/qttest.pri)
diff --git a/tests/manual/widgets/infolabel/tst_manual_widgets_infolabel.cpp b/tests/manual/widgets/infolabel/tst_manual_widgets_infolabel.cpp
new file mode 100644
index 0000000000..1b4a4061c3
--- /dev/null
+++ b/tests/manual/widgets/infolabel/tst_manual_widgets_infolabel.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** 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.
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QLayout>
+#include <QMessageBox>
+#include <QSettings>
+
+#include <utils/infolabel.h>
+#include <utils/stylehelper.h>
+#include <utils/theme/theme.h>
+#include <utils/theme/theme_p.h>
+
+#include <coreplugin/manhattanstyle.h>
+
+using namespace Utils;
+
+int main(int argc, char *argv[])
+{
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+
+ QApplication app(argc, argv);
+
+ Theme theme("");
+ QSettings settings(":/themes/flat.creatortheme", QSettings::IniFormat);
+ theme.readSettings(settings);
+ setCreatorTheme(&theme);
+ StyleHelper::setBaseColor(QColor(StyleHelper::DEFAULT_BASE_COLOR));
+ QApplication::setStyle(new ManhattanStyle(creatorTheme()->preferredStyles().value(0)));
+
+ auto widget = new QWidget;
+ auto mainLayout = new QVBoxLayout(widget);
+ auto variationsLayout = new QGridLayout;
+ mainLayout->addLayout(variationsLayout);
+
+ const static struct {
+ const InfoLabel::InfoType type;
+ const char *text;
+ } labels[] = {
+ {InfoLabel::Information, "Information"},
+ {InfoLabel::Warning, "Warning"},
+ {InfoLabel::Error, "Error"},
+ {InfoLabel::Ok, "Ok"},
+ {InfoLabel::NotOk, "NotOk"},
+ {InfoLabel::None, "None"},
+ };
+
+ int gridRow = 0;
+ for (auto filled : {false, true}) {
+ for (auto label : labels) {
+ for (auto enabled : {true, false}) {
+ auto infoLabel = new Utils::InfoLabel(
+ label.text + QLatin1String(filled ? " (filled)" : "")
+ + QLatin1String(enabled ? "" : " (disabled)"), label.type);
+ infoLabel->setEnabled(enabled);
+ infoLabel->setFilled(filled);
+ variationsLayout->addWidget(infoLabel, gridRow, enabled ? 0 : 1);
+ }
+ gridRow++;
+ }
+ variationsLayout->addItem(new QSpacerItem(0, 10), gridRow++, 0);
+ }
+
+ auto withLink = new Utils::InfoLabel("With <a href=\"link clicked!\">link</a>", InfoLabel::Error);
+ withLink->setElideMode(Qt::ElideNone);
+ QObject::connect(withLink, &QLabel::linkActivated, [widget](const QString& link){
+ QMessageBox::information(widget, {}, link);
+ });
+ mainLayout->addWidget(withLink);
+
+ auto stretching = new Utils::InfoLabel("Stretching and centering vertically", InfoLabel::Warning);
+ stretching->setFilled(true);
+ mainLayout->addWidget(stretching, 2);
+
+ const QString lorem =
+ "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt "
+ "ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
+ "ullamco laboris nisi ut aliquid ex ea commodi consequat.";
+
+ mainLayout->addWidget(new Utils::InfoLabel("Qt::ElideRight: " + lorem, InfoLabel::Information));
+
+ auto elideNone = new Utils::InfoLabel("Qt::ElideNone: " + lorem, InfoLabel::Information);
+ elideNone->setElideMode(Qt::ElideNone);
+ elideNone->setWordWrap(true);
+ mainLayout->addWidget(elideNone);
+
+ widget->resize(350, 500);
+ widget->show();
+
+ return app.exec();
+}
diff --git a/tests/manual/widgets/themes.qrc b/tests/manual/widgets/themes.qrc
new file mode 100644
index 0000000000..c6fe4b1d1a
--- /dev/null
+++ b/tests/manual/widgets/themes.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/themes">
+ <file alias="dark.creatortheme">../../../share/qtcreator/themes/dark.creatortheme</file>
+ <file alias="default.creatortheme">../../../share/qtcreator/themes/default.creatortheme</file>
+ <file alias="flat-dark.creatortheme">../../../share/qtcreator/themes/flat-dark.creatortheme</file>
+ <file alias="flat-light.creatortheme">../../../share/qtcreator/themes/flat-light.creatortheme</file>
+ <file alias="flat.creatortheme">../../../share/qtcreator/themes/flat.creatortheme</file>
+ <file alias="design.creatortheme">../../../share/qtcreator/themes/design.creatortheme</file>
+</qresource>
+</RCC>
diff --git a/tests/manual/widgets/widgets.pro b/tests/manual/widgets/widgets.pro
index aa0a4e874e..00f36c1c94 100644
--- a/tests/manual/widgets/widgets.pro
+++ b/tests/manual/widgets/widgets.pro
@@ -1,3 +1,4 @@
TEMPLATE = subdirs
SUBDIRS = \
- crumblepath
+ crumblepath \
+ infolabel