forked from qt-creator/qt-creator
Welcome: Start some performance improvements
This is essentially a widgets based re-implementation
of the current design. It is still using the QAIM based
interface layer between to the real data and display even
though this is not needed with this approach.
Removal of this layer would further reduce code size
and cycle counts.
For now:
old new
Load time 215ms 182ms
delete 22ms 2ms
Change-Id: I90d779a60a47a78399eaad0f1bc032d39f3ae3c0
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -25,8 +25,19 @@
|
||||
|
||||
#include "iwelcomepage.h"
|
||||
|
||||
#include "icore.h"
|
||||
|
||||
#include <utils/icon.h>
|
||||
#include <utils/theme/theme.h>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMetaEnum>
|
||||
#include <QPixmap>
|
||||
#include <QUrl>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace Core {
|
||||
|
||||
IWelcomePage::IWelcomePage()
|
||||
@@ -37,4 +48,159 @@ IWelcomePage::~IWelcomePage()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
int IWelcomePage::screenDependHeightDistance()
|
||||
{
|
||||
return std::min(50, std::max(16, ICore::mainWindow()->height() / 30));
|
||||
}
|
||||
|
||||
static QPalette buttonPalette(bool isActive, bool isCursorInside, bool forText)
|
||||
{
|
||||
QPalette pal;
|
||||
Theme *theme = Utils::creatorTheme();
|
||||
if (isActive) {
|
||||
if (forText) {
|
||||
pal.setColor(QPalette::Background, theme->color(Theme::Welcome_ForegroundPrimaryColor));
|
||||
pal.setColor(QPalette::Foreground, theme->color(Theme::Welcome_ForegroundPrimaryColor));
|
||||
pal.setColor(QPalette::WindowText, theme->color(Theme::Welcome_BackgroundColor));
|
||||
} else {
|
||||
pal.setColor(QPalette::Background, theme->color(Theme::Welcome_ForegroundPrimaryColor));
|
||||
pal.setColor(QPalette::Foreground, theme->color(Theme::Welcome_ForegroundPrimaryColor));
|
||||
}
|
||||
} else {
|
||||
if (isCursorInside) {
|
||||
if (forText) {
|
||||
pal.setColor(QPalette::Background, theme->color(Theme::Welcome_HoverColor));
|
||||
pal.setColor(QPalette::Foreground, theme->color(Theme::Welcome_HoverColor));
|
||||
pal.setColor(QPalette::WindowText, theme->color(Theme::Welcome_TextColor));
|
||||
} else {
|
||||
pal.setColor(QPalette::Background, theme->color(Theme::Welcome_HoverColor));
|
||||
pal.setColor(QPalette::Foreground, theme->color(Theme::Welcome_ForegroundSecondaryColor));
|
||||
}
|
||||
} else {
|
||||
if (forText) {
|
||||
pal.setColor(QPalette::Background, theme->color(Theme::Welcome_ForegroundPrimaryColor));
|
||||
pal.setColor(QPalette::Foreground, theme->color(Theme::Welcome_BackgroundColor));
|
||||
pal.setColor(QPalette::WindowText, theme->color(Theme::Welcome_TextColor));
|
||||
} else {
|
||||
pal.setColor(QPalette::Background, theme->color(Theme::Welcome_BackgroundColor));
|
||||
pal.setColor(QPalette::Foreground, theme->color(Theme::Welcome_ForegroundSecondaryColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
return pal;
|
||||
}
|
||||
|
||||
class WelcomePageButtonPrivate
|
||||
{
|
||||
public:
|
||||
WelcomePageButtonPrivate(WelcomePageButton *parent) : q(parent) {}
|
||||
bool isActive() const;
|
||||
void doUpdate(bool cursorInside);
|
||||
|
||||
WelcomePageButton *q;
|
||||
QHBoxLayout *m_layout;
|
||||
QLabel *m_label;
|
||||
QLabel *m_icon = nullptr;
|
||||
|
||||
std::function<void()> onClicked;
|
||||
std::function<bool()> activeChecker;
|
||||
};
|
||||
|
||||
WelcomePageButton::WelcomePageButton(QWidget *parent)
|
||||
: QFrame(parent), d(new WelcomePageButtonPrivate(this))
|
||||
{
|
||||
setAutoFillBackground(true);
|
||||
setFrameShape(QFrame::Box);
|
||||
setFrameShadow(QFrame::Plain);
|
||||
setPalette(buttonPalette(false, false, false));
|
||||
|
||||
QFont f = font();
|
||||
f.setPixelSize(15);
|
||||
d->m_label = new QLabel(this);
|
||||
d->m_label->setFont(f);
|
||||
d->m_label->setPalette(buttonPalette(false, false, true));
|
||||
|
||||
d->m_layout = new QHBoxLayout;
|
||||
d->m_layout->setContentsMargins(13, 5, 20, 5);
|
||||
d->m_layout->setSpacing(0);
|
||||
d->m_layout->addWidget(d->m_label);
|
||||
setLayout(d->m_layout);
|
||||
}
|
||||
|
||||
WelcomePageButton::~WelcomePageButton()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void WelcomePageButton::mousePressEvent(QMouseEvent *)
|
||||
{
|
||||
if (d->onClicked)
|
||||
d->onClicked();
|
||||
}
|
||||
|
||||
void WelcomePageButton::enterEvent(QEvent *)
|
||||
{
|
||||
d->doUpdate(true);
|
||||
}
|
||||
|
||||
void WelcomePageButton::leaveEvent(QEvent *)
|
||||
{
|
||||
d->doUpdate(false);
|
||||
}
|
||||
|
||||
bool WelcomePageButtonPrivate::isActive() const
|
||||
{
|
||||
return activeChecker && activeChecker();
|
||||
}
|
||||
|
||||
void WelcomePageButtonPrivate::doUpdate(bool cursorInside)
|
||||
{
|
||||
const bool active = isActive();
|
||||
q->setPalette(buttonPalette(active, cursorInside, false));
|
||||
const QPalette lpal = buttonPalette(active, cursorInside, true);
|
||||
m_label->setPalette(lpal);
|
||||
if (m_icon)
|
||||
m_icon->setPalette(lpal);
|
||||
q->update();
|
||||
}
|
||||
|
||||
void WelcomePageButton::setText(const QString &text)
|
||||
{
|
||||
d->m_label->setText(text);
|
||||
}
|
||||
|
||||
void WelcomePageButton::setIcon(const QPixmap &pixmap)
|
||||
{
|
||||
if (!d->m_icon) {
|
||||
d->m_icon = new QLabel(this);
|
||||
d->m_layout->insertWidget(0, d->m_icon);
|
||||
d->m_layout->insertSpacing(1, 10);
|
||||
}
|
||||
d->m_icon->setPixmap(pixmap);
|
||||
}
|
||||
|
||||
void WelcomePageButton::setActiveChecker(const std::function<bool ()> &value)
|
||||
{
|
||||
d->activeChecker = value;
|
||||
}
|
||||
|
||||
void WelcomePageButton::recheckActive()
|
||||
{
|
||||
bool isActive = d->isActive();
|
||||
d->doUpdate(isActive);
|
||||
}
|
||||
|
||||
void WelcomePageButton::click()
|
||||
{
|
||||
if (d->onClicked)
|
||||
d->onClicked();
|
||||
}
|
||||
|
||||
void WelcomePageButton::setOnClicked(const std::function<void ()> &value)
|
||||
{
|
||||
d->onClicked = value;
|
||||
if (d->isActive())
|
||||
click();
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
Reference in New Issue
Block a user