2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-04 11:36:55 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-01-04 11:36:55 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-04 11:36:55 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-01-04 11:36:55 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-04 11:36:55 +01:00
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
#include "iwelcomepage.h"
|
|
|
|
|
|
2017-01-06 21:41:46 +01:00
|
|
|
#include "icore.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/icon.h>
|
|
|
|
|
#include <utils/theme/theme.h>
|
|
|
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QMetaEnum>
|
2017-02-24 18:41:22 +01:00
|
|
|
#include <QPainter>
|
2017-01-06 21:41:46 +01:00
|
|
|
#include <QPixmap>
|
2013-03-18 14:47:33 +01:00
|
|
|
#include <QUrl>
|
|
|
|
|
|
2017-01-06 21:41:46 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2014-12-19 12:05:40 +01:00
|
|
|
namespace Core {
|
2009-07-27 13:55:30 +02:00
|
|
|
|
2017-12-08 17:20:48 +01:00
|
|
|
static QList<IWelcomePage *> g_welcomePages;
|
|
|
|
|
|
|
|
|
|
const QList<IWelcomePage *> IWelcomePage::allWelcomePages()
|
|
|
|
|
{
|
|
|
|
|
return g_welcomePages;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
IWelcomePage::IWelcomePage()
|
|
|
|
|
{
|
2017-12-08 17:20:48 +01:00
|
|
|
g_welcomePages.append(this);
|
2009-07-27 13:55:30 +02:00
|
|
|
}
|
2009-10-26 18:11:58 +01:00
|
|
|
|
|
|
|
|
IWelcomePage::~IWelcomePage()
|
|
|
|
|
{
|
2017-12-08 17:20:48 +01:00
|
|
|
g_welcomePages.removeOne(this);
|
2009-10-26 18:11:58 +01:00
|
|
|
}
|
2011-08-17 12:54:58 +02:00
|
|
|
|
2017-01-06 21:41:46 +01:00
|
|
|
static QPalette buttonPalette(bool isActive, bool isCursorInside, bool forText)
|
|
|
|
|
{
|
|
|
|
|
QPalette pal;
|
|
|
|
|
Theme *theme = Utils::creatorTheme();
|
|
|
|
|
if (isActive) {
|
|
|
|
|
if (forText) {
|
2019-08-29 11:40:38 +02:00
|
|
|
pal.setColor(QPalette::Window, theme->color(Theme::Welcome_ForegroundPrimaryColor));
|
2017-01-06 21:41:46 +01:00
|
|
|
pal.setColor(QPalette::WindowText, theme->color(Theme::Welcome_BackgroundColor));
|
|
|
|
|
} else {
|
2019-08-29 11:40:38 +02:00
|
|
|
pal.setColor(QPalette::Window, theme->color(Theme::Welcome_ForegroundPrimaryColor));
|
|
|
|
|
pal.setColor(QPalette::WindowText, theme->color(Theme::Welcome_ForegroundPrimaryColor));
|
2017-01-06 21:41:46 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (isCursorInside) {
|
|
|
|
|
if (forText) {
|
2019-08-29 11:40:38 +02:00
|
|
|
pal.setColor(QPalette::Window, theme->color(Theme::Welcome_HoverColor));
|
2017-01-06 21:41:46 +01:00
|
|
|
pal.setColor(QPalette::WindowText, theme->color(Theme::Welcome_TextColor));
|
|
|
|
|
} else {
|
2019-08-29 11:40:38 +02:00
|
|
|
pal.setColor(QPalette::Window, theme->color(Theme::Welcome_HoverColor));
|
|
|
|
|
pal.setColor(QPalette::WindowText, theme->color(Theme::Welcome_ForegroundSecondaryColor));
|
2017-01-06 21:41:46 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (forText) {
|
2019-08-29 11:40:38 +02:00
|
|
|
pal.setColor(QPalette::Window, theme->color(Theme::Welcome_ForegroundPrimaryColor));
|
2017-01-06 21:41:46 +01:00
|
|
|
pal.setColor(QPalette::WindowText, theme->color(Theme::Welcome_TextColor));
|
|
|
|
|
} else {
|
2019-08-29 11:40:38 +02:00
|
|
|
pal.setColor(QPalette::Window, theme->color(Theme::Welcome_BackgroundColor));
|
|
|
|
|
pal.setColor(QPalette::WindowText, theme->color(Theme::Welcome_ForegroundSecondaryColor));
|
2017-01-06 21:41:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return pal;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-24 18:41:22 +01:00
|
|
|
WelcomePageFrame::WelcomePageFrame(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
setContentsMargins(1, 1, 1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WelcomePageFrame::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QWidget::paintEvent(event);
|
|
|
|
|
|
|
|
|
|
const QRectF adjustedRect(QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5));
|
|
|
|
|
QPen pen(palette().color(QPalette::WindowText));
|
|
|
|
|
pen.setJoinStyle(Qt::MiterJoin);
|
|
|
|
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
|
p.setPen(pen);
|
|
|
|
|
p.drawRect(adjustedRect);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 21:41:46 +01:00
|
|
|
class WelcomePageButtonPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
WelcomePageButtonPrivate(WelcomePageButton *parent) : q(parent) {}
|
|
|
|
|
bool isActive() const;
|
|
|
|
|
void doUpdate(bool cursorInside);
|
|
|
|
|
|
|
|
|
|
WelcomePageButton *q;
|
2017-01-17 12:40:47 +01:00
|
|
|
QHBoxLayout *m_layout = nullptr;
|
|
|
|
|
QLabel *m_label = nullptr;
|
2017-01-06 21:41:46 +01:00
|
|
|
QLabel *m_icon = nullptr;
|
|
|
|
|
|
|
|
|
|
std::function<void()> onClicked;
|
|
|
|
|
std::function<bool()> activeChecker;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
WelcomePageButton::WelcomePageButton(QWidget *parent)
|
2017-02-24 18:41:22 +01:00
|
|
|
: WelcomePageFrame(parent), d(new WelcomePageButtonPrivate(this))
|
2017-01-06 21:41:46 +01:00
|
|
|
{
|
|
|
|
|
setAutoFillBackground(true);
|
|
|
|
|
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
|