forked from qt-creator/qt-creator
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:
@@ -5,6 +5,7 @@
|
|||||||
#include "welcometr.h"
|
#include "welcometr.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/checkablemessagebox.h>
|
#include <utils/checkablemessagebox.h>
|
||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
@@ -13,48 +14,63 @@
|
|||||||
|
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
#include <QImage>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPushButton>
|
#include <QPointer>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace Welcome::Internal {
|
||||||
|
|
||||||
const char kTakeTourSetting[] = "TakeUITour";
|
const char kTakeTourSetting[] = "TakeUITour";
|
||||||
|
|
||||||
namespace Welcome {
|
struct Item
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
void IntroductionWidget::askUserAboutIntroduction(QWidget *parent)
|
|
||||||
{
|
{
|
||||||
// CheckableMessageBox for compatibility with Qt Creator < 4.11
|
QString pointerAnchorObjectName;
|
||||||
if (!CheckableDecider(Key(kTakeTourSetting)).shouldAskAgain()
|
QString title;
|
||||||
|| !Core::ICore::infoBar()->canInfoBeAdded(kTakeTourSetting))
|
QString brief;
|
||||||
return;
|
QString description;
|
||||||
|
};
|
||||||
|
|
||||||
Utils::InfoBarEntry
|
class IntroductionWidget : public QWidget
|
||||||
info(kTakeTourSetting,
|
{
|
||||||
Tr::tr("Would you like to take a quick UI tour? This tour highlights important user "
|
public:
|
||||||
"interface elements and shows how they are used. To take the tour later, "
|
IntroductionWidget();
|
||||||
"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);
|
|
||||||
}
|
|
||||||
|
|
||||||
IntroductionWidget::IntroductionWidget(QWidget *parent)
|
protected:
|
||||||
: QWidget(parent),
|
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")
|
m_borderImage(":/welcome/images/border.png")
|
||||||
{
|
{
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
setFocus();
|
setFocus();
|
||||||
parent->installEventFilter(this);
|
parentWidget()->installEventFilter(this);
|
||||||
|
|
||||||
QPalette p = palette();
|
QPalette p = palette();
|
||||||
p.setColor(QPalette::WindowText, QColor(220, 220, 220));
|
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));
|
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
|
||||||
|
|||||||
@@ -3,57 +3,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QImage>
|
namespace Welcome::Internal {
|
||||||
#include <QPointer>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
#include <memory>
|
void runUiTour();
|
||||||
|
void askUserAboutIntroduction();
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
} // Welcome::Internal
|
||||||
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
|
|
||||||
|
|||||||
@@ -92,19 +92,15 @@ public:
|
|||||||
m_welcomeMode = new WelcomeMode;
|
m_welcomeMode = new WelcomeMode;
|
||||||
|
|
||||||
auto introAction = new QAction(Tr::tr("UI Tour"), this);
|
auto introAction = new QAction(Tr::tr("UI Tour"), this);
|
||||||
connect(introAction, &QAction::triggered, this, []() {
|
connect(introAction, &QAction::triggered, &runUiTour);
|
||||||
auto intro = new IntroductionWidget(ICore::dialogParent());
|
|
||||||
intro->show();
|
|
||||||
});
|
|
||||||
Command *cmd = ActionManager::registerAction(introAction, "Welcome.UITour");
|
Command *cmd = ActionManager::registerAction(introAction, "Welcome.UITour");
|
||||||
ActionContainer *mhelp = ActionManager::actionContainer(Core::Constants::M_HELP);
|
ActionContainer *mhelp = ActionManager::actionContainer(Core::Constants::M_HELP);
|
||||||
if (QTC_GUARD(mhelp))
|
if (QTC_GUARD(mhelp))
|
||||||
mhelp->addAction(cmd, Core::Constants::G_HELP_HELP);
|
mhelp->addAction(cmd, Core::Constants::G_HELP_HELP);
|
||||||
|
|
||||||
if (!arguments.contains("-notour")) {
|
if (!arguments.contains("-notour")) {
|
||||||
connect(ICore::instance(), &ICore::coreOpened, this, []() {
|
connect(ICore::instance(), &ICore::coreOpened, this, [] { askUserAboutIntroduction(); },
|
||||||
IntroductionWidget::askUserAboutIntroduction(ICore::dialogParent());
|
Qt::QueuedConnection);
|
||||||
}, Qt::QueuedConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user