From 9454c5c0e60b4c22d2f313128e3244138b95e5c2 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 8 Jul 2024 12:34:44 +0200 Subject: [PATCH] Welcome: Hide most of UI tour implemenatation in .cpp Also, de-Q_OBJECT-ify, for slimmer interface. Change-Id: Icfa80430c95318351f3ab9bfb46c3d03d9d02af3 Reviewed-by: Christian Stenger --- src/plugins/welcome/introductionwidget.cpp | 101 +++++++++++++++------ src/plugins/welcome/introductionwidget.h | 56 +----------- src/plugins/welcome/welcomeplugin.cpp | 10 +- 3 files changed, 80 insertions(+), 87 deletions(-) diff --git a/src/plugins/welcome/introductionwidget.cpp b/src/plugins/welcome/introductionwidget.cpp index 41bd1a93bf1..03f1891181c 100644 --- a/src/plugins/welcome/introductionwidget.cpp +++ b/src/plugins/welcome/introductionwidget.cpp @@ -5,6 +5,7 @@ #include "welcometr.h" #include + #include #include #include @@ -13,48 +14,63 @@ #include #include +#include #include #include #include -#include +#include #include +using namespace Core; using namespace Utils; +namespace Welcome::Internal { + const char kTakeTourSetting[] = "TakeUITour"; -namespace Welcome { -namespace Internal { - -void IntroductionWidget::askUserAboutIntroduction(QWidget *parent) +struct Item { - // CheckableMessageBox for compatibility with Qt Creator < 4.11 - if (!CheckableDecider(Key(kTakeTourSetting)).shouldAskAgain() - || !Core::ICore::infoBar()->canInfoBeAdded(kTakeTourSetting)) - return; + QString pointerAnchorObjectName; + QString title; + QString brief; + QString description; +}; - Utils::InfoBarEntry - info(kTakeTourSetting, - Tr::tr("Would you like to take a quick UI tour? This tour highlights important user " - "interface elements and shows how they are used. To take the tour later, " - "select Help > UI Tour."), - Utils::InfoBarEntry::GlobalSuppression::Enabled); - info.addCustomButton(Tr::tr("Take UI Tour"), [parent] { - Core::ICore::infoBar()->removeInfo(kTakeTourSetting); - Core::ICore::infoBar()->globallySuppressInfo(kTakeTourSetting); - auto intro = new IntroductionWidget(parent); - intro->show(); - }); - Core::ICore::infoBar()->addInfo(info); -} +class IntroductionWidget : public QWidget +{ +public: + IntroductionWidget(); -IntroductionWidget::IntroductionWidget(QWidget *parent) - : QWidget(parent), +protected: + bool event(QEvent *e) override; + bool eventFilter(QObject *obj, QEvent *ev) override; + void paintEvent(QPaintEvent *ev) override; + void keyPressEvent(QKeyEvent *ke) override; + void mouseReleaseEvent(QMouseEvent *me) override; + +private: + void finish(); + void step(); + void setStep(uint index); + void resizeToParent(); + + QWidget *m_textWidget; + QLabel *m_stepText; + QLabel *m_continueLabel; + QImage m_borderImage; + QString m_bodyCss; + std::vector m_items; + QPointer m_stepPointerAnchor; + uint m_step = 0; +}; + +IntroductionWidget::IntroductionWidget() + : QWidget(ICore::dialogParent()), m_borderImage(":/welcome/images/border.png") { setFocusPolicy(Qt::StrongFocus); setFocus(); - parent->installEventFilter(this); + parentWidget()->installEventFilter(this); QPalette p = palette(); p.setColor(QPalette::WindowText, QColor(220, 220, 220)); @@ -381,5 +397,34 @@ void IntroductionWidget::resizeToParent() m_textWidget->setGeometry(QRect(width()/4, height()/4, width()/2, height()/2)); } -} // namespace Internal -} // namespace Welcome + +// Public access. + +void runUiTour() +{ + auto intro = new IntroductionWidget; + intro->show(); +} + +void askUserAboutIntroduction() +{ + // CheckableMessageBox for compatibility with Qt Creator < 4.11 + if (!CheckableDecider(Key(kTakeTourSetting)).shouldAskAgain() + || !ICore::infoBar()->canInfoBeAdded(kTakeTourSetting)) + return; + + InfoBarEntry + info(kTakeTourSetting, + Tr::tr("Would you like to take a quick UI tour? This tour highlights important user " + "interface elements and shows how they are used. To take the tour later, " + "select Help > UI Tour."), + InfoBarEntry::GlobalSuppression::Enabled); + info.addCustomButton(Tr::tr("Take UI Tour"), [] { + ICore::infoBar()->removeInfo(kTakeTourSetting); + ICore::infoBar()->globallySuppressInfo(kTakeTourSetting); + runUiTour(); + }); + ICore::infoBar()->addInfo(info); +} + +} // Welcome::Internal diff --git a/src/plugins/welcome/introductionwidget.h b/src/plugins/welcome/introductionwidget.h index 4b1f99c5ae3..9c6e3b32479 100644 --- a/src/plugins/welcome/introductionwidget.h +++ b/src/plugins/welcome/introductionwidget.h @@ -3,57 +3,9 @@ #pragma once -#include -#include -#include +namespace Welcome::Internal { -#include +void runUiTour(); +void askUserAboutIntroduction(); -QT_BEGIN_NAMESPACE -class QLabel; -QT_END_NAMESPACE - -namespace Welcome { -namespace Internal { - -struct Item -{ - QString pointerAnchorObjectName; - QString title; - QString brief; - QString description; -}; - -class IntroductionWidget : public QWidget -{ - Q_OBJECT -public: - explicit IntroductionWidget(QWidget *parent = nullptr); - - static void askUserAboutIntroduction(QWidget *parent); - -protected: - bool event(QEvent *e) override; - bool eventFilter(QObject *obj, QEvent *ev) override; - void paintEvent(QPaintEvent *ev) override; - void keyPressEvent(QKeyEvent *ke) override; - void mouseReleaseEvent(QMouseEvent *me) override; - -private: - void finish(); - void step(); - void setStep(uint index); - void resizeToParent(); - - QWidget *m_textWidget; - QLabel *m_stepText; - QLabel *m_continueLabel; - QImage m_borderImage; - QString m_bodyCss; - std::vector m_items; - QPointer m_stepPointerAnchor; - uint m_step = 0; -}; - -} // namespace Internal -} // namespace Welcome +} // Welcome::Internal diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp index 81623e1e72d..9cc21213823 100644 --- a/src/plugins/welcome/welcomeplugin.cpp +++ b/src/plugins/welcome/welcomeplugin.cpp @@ -92,19 +92,15 @@ public: m_welcomeMode = new WelcomeMode; auto introAction = new QAction(Tr::tr("UI Tour"), this); - connect(introAction, &QAction::triggered, this, []() { - auto intro = new IntroductionWidget(ICore::dialogParent()); - intro->show(); - }); + connect(introAction, &QAction::triggered, &runUiTour); Command *cmd = ActionManager::registerAction(introAction, "Welcome.UITour"); ActionContainer *mhelp = ActionManager::actionContainer(Core::Constants::M_HELP); if (QTC_GUARD(mhelp)) mhelp->addAction(cmd, Core::Constants::G_HELP_HELP); if (!arguments.contains("-notour")) { - connect(ICore::instance(), &ICore::coreOpened, this, []() { - IntroductionWidget::askUserAboutIntroduction(ICore::dialogParent()); - }, Qt::QueuedConnection); + connect(ICore::instance(), &ICore::coreOpened, this, [] { askUserAboutIntroduction(); }, + Qt::QueuedConnection); } return true;