Welcome: Hide most of UI tour implemenatation in .cpp

Also, de-Q_OBJECT-ify, for slimmer interface.

Change-Id: Icfa80430c95318351f3ab9bfb46c3d03d9d02af3
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2024-07-08 12:34:44 +02:00
parent f6e99a6235
commit 9454c5c0e6
3 changed files with 80 additions and 87 deletions

View File

@@ -5,6 +5,7 @@
#include "welcometr.h"
#include <coreplugin/icore.h>
#include <utils/algorithm.h>
#include <utils/checkablemessagebox.h>
#include <utils/infobar.h>
@@ -13,48 +14,63 @@
#include <QEvent>
#include <QGuiApplication>
#include <QImage>
#include <QKeyEvent>
#include <QLabel>
#include <QPainter>
#include <QPushButton>
#include <QPointer>
#include <QVBoxLayout>
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<Item> m_items;
QPointer<QWidget> 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

View File

@@ -3,57 +3,9 @@
#pragma once
#include <QImage>
#include <QPointer>
#include <QWidget>
namespace Welcome::Internal {
#include <memory>
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<Item> m_items;
QPointer<QWidget> m_stepPointerAnchor;
uint m_step = 0;
};
} // namespace Internal
} // namespace Welcome
} // Welcome::Internal

View File

@@ -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;