2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at qt-sales@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "welcomemode.h"
|
|
|
|
|
#include "coreconstants.h"
|
|
|
|
|
#include "uniqueidmanager.h"
|
|
|
|
|
#include "modemanager.h"
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QToolBar>
|
|
|
|
|
#include <QtGui/QDesktopServices>
|
2009-04-22 18:17:50 +02:00
|
|
|
#include <QtGui/QMouseEvent>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-15 18:34:03 +02:00
|
|
|
#include <QtCore/QDir>
|
2009-04-22 18:17:50 +02:00
|
|
|
#include <QtCore/QFileInfo>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QUrl>
|
|
|
|
|
|
2009-04-22 18:17:50 +02:00
|
|
|
#include "ui_welcomemode.h"
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2008-12-02 15:08:31 +01:00
|
|
|
struct WelcomeModePrivate
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
WelcomeModePrivate();
|
|
|
|
|
|
|
|
|
|
QWidget *m_widget;
|
2009-04-22 18:17:50 +02:00
|
|
|
QWidget *m_welcomePage;
|
2009-04-24 14:01:11 +02:00
|
|
|
Ui::WelcomePage ui;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
WelcomeMode::WelcomePageData lastData;
|
|
|
|
|
};
|
|
|
|
|
|
2009-04-22 18:17:50 +02:00
|
|
|
WelcomeModePrivate::WelcomeModePrivate()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- WelcomePageData
|
|
|
|
|
|
|
|
|
|
bool WelcomeMode::WelcomePageData::operator==(const WelcomePageData &rhs) const
|
|
|
|
|
{
|
|
|
|
|
return previousSession == rhs.previousSession
|
|
|
|
|
&& activeSession == rhs.activeSession
|
|
|
|
|
&& sessionList == rhs.sessionList
|
|
|
|
|
&& projectList == rhs.projectList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WelcomeMode::WelcomePageData::operator!=(const WelcomePageData &rhs) const
|
|
|
|
|
{
|
|
|
|
|
return previousSession != rhs.previousSession
|
|
|
|
|
|| activeSession != rhs.activeSession
|
|
|
|
|
|| sessionList != rhs.sessionList
|
|
|
|
|
|| projectList != rhs.projectList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDebug operator<<(QDebug dgb, const WelcomeMode::WelcomePageData &d)
|
|
|
|
|
{
|
|
|
|
|
dgb.nospace() << "PreviousSession=" << d.previousSession
|
|
|
|
|
<< " activeSession=" << d.activeSession
|
|
|
|
|
<< " sessionList=" << d.sessionList
|
|
|
|
|
<< " projectList=" << d.projectList;
|
|
|
|
|
return dgb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- WelcomeMode
|
|
|
|
|
WelcomeMode::WelcomeMode() :
|
|
|
|
|
m_d(new WelcomeModePrivate)
|
|
|
|
|
{
|
2009-04-22 18:17:50 +02:00
|
|
|
m_d->m_widget = new QWidget;
|
2008-12-02 12:01:29 +01:00
|
|
|
QVBoxLayout *l = new QVBoxLayout(m_d->m_widget);
|
|
|
|
|
l->setMargin(0);
|
|
|
|
|
l->setSpacing(0);
|
|
|
|
|
l->addWidget(new QToolBar(m_d->m_widget));
|
2009-04-22 18:17:50 +02:00
|
|
|
|
|
|
|
|
m_d->m_welcomePage = new QWidget(m_d->m_widget);
|
|
|
|
|
m_d->ui.setupUi(m_d->m_welcomePage);
|
|
|
|
|
m_d->ui.sessTreeWidget->viewport()->setAutoFillBackground(false);
|
|
|
|
|
m_d->ui.projTreeWidget->viewport()->setAutoFillBackground(false);
|
|
|
|
|
l->addWidget(m_d->m_welcomePage);
|
|
|
|
|
|
|
|
|
|
updateWelcomePage(WelcomePageData());
|
|
|
|
|
|
|
|
|
|
connect(m_d->ui.gettingStartedButton, SIGNAL(clicked()), SIGNAL(requestHelp()));
|
|
|
|
|
connect(m_d->ui.feedbackButton, SIGNAL(clicked()), SLOT(slotFeedback()));
|
|
|
|
|
connect(m_d->ui.restoreSessionButton, SIGNAL(clicked()), SLOT(slotRestoreLastSession()));
|
|
|
|
|
connect(m_d->ui.sessTreeWidget, SIGNAL(activated(QString)), SLOT(slotSessionClicked(QString)));
|
|
|
|
|
connect(m_d->ui.projTreeWidget, SIGNAL(activated(QString)), SLOT(slotProjectClicked(QString)));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WelcomeMode::~WelcomeMode()
|
|
|
|
|
{
|
|
|
|
|
delete m_d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString WelcomeMode::name() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("Welcome");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QIcon WelcomeMode::icon() const
|
|
|
|
|
{
|
2009-01-12 15:06:43 +01:00
|
|
|
return QIcon(QLatin1String(":/core/images/qtcreator_logo_32.png"));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int WelcomeMode::priority() const
|
|
|
|
|
{
|
|
|
|
|
return Constants::P_MODE_WELCOME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget* WelcomeMode::widget()
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* WelcomeMode::uniqueModeName() const
|
|
|
|
|
{
|
|
|
|
|
return Constants::MODE_WELCOME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<int> WelcomeMode::context() const
|
|
|
|
|
{
|
|
|
|
|
static QList<int> contexts = QList<int>()
|
2009-01-21 13:33:58 +01:00
|
|
|
<< UniqueIDManager::instance()->uniqueIdentifier(Constants::C_WELCOME_MODE);
|
2008-12-02 12:01:29 +01:00
|
|
|
return contexts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WelcomeMode::updateWelcomePage(const WelcomePageData &welcomePageData)
|
|
|
|
|
{
|
|
|
|
|
// Update only if data are modified
|
|
|
|
|
if (welcomePageData == m_d->lastData)
|
|
|
|
|
return;
|
|
|
|
|
m_d->lastData = welcomePageData;
|
|
|
|
|
|
2009-04-22 18:17:50 +02:00
|
|
|
m_d->m_widget->setUpdatesEnabled(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!welcomePageData.previousSession.isEmpty() || !welcomePageData.projectList.isEmpty()) {
|
2009-04-22 18:17:50 +02:00
|
|
|
m_d->ui.sessTreeWidget->clear();
|
|
|
|
|
m_d->ui.projTreeWidget->clear();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
if (welcomePageData.sessionList.count() > 1) {
|
2009-04-22 18:17:50 +02:00
|
|
|
foreach (const QString &s, welcomePageData.sessionList) {
|
|
|
|
|
QString str = s;
|
2008-12-02 12:01:29 +01:00
|
|
|
if (s == welcomePageData.previousSession)
|
2009-04-22 18:17:50 +02:00
|
|
|
str = tr("%1 (last session)").arg(s);
|
|
|
|
|
m_d->ui.sessTreeWidget->addItem(str, s);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-04-22 18:17:50 +02:00
|
|
|
m_d->ui.sessTreeWidget->updateGeometry();
|
|
|
|
|
m_d->ui.sessTreeWidget->show();
|
|
|
|
|
} else {
|
|
|
|
|
m_d->ui.sessTreeWidget->hide();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-04-22 18:17:50 +02:00
|
|
|
|
|
|
|
|
typedef QPair<QString, QString> QStringPair;
|
|
|
|
|
foreach (const QStringPair &it, welcomePageData.projectList) {
|
|
|
|
|
QTreeWidgetItem *item = m_d->ui.projTreeWidget->addItem(it.second, it.first);
|
|
|
|
|
const QFileInfo fi(it.first);
|
|
|
|
|
item->setToolTip(1, QDir::toNativeSeparators(fi.absolutePath()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-04-22 18:17:50 +02:00
|
|
|
m_d->ui.projTreeWidget->updateGeometry();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-22 18:17:50 +02:00
|
|
|
m_d->ui.recentSessionsFrame->show();
|
|
|
|
|
m_d->ui.recentProjectsFrame->show();
|
|
|
|
|
} else {
|
|
|
|
|
m_d->ui.recentSessionsFrame->hide();
|
|
|
|
|
m_d->ui.recentProjectsFrame->hide();
|
|
|
|
|
}
|
|
|
|
|
m_d->m_widget->setUpdatesEnabled(true);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-04-22 18:17:50 +02:00
|
|
|
void WelcomeMode::activateEditMode()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-21 13:33:58 +01:00
|
|
|
Core::ModeManager *modeManager = ModeManager::instance();
|
2009-04-22 18:17:50 +02:00
|
|
|
if (modeManager->currentMode() == this)
|
|
|
|
|
modeManager->activateMode(Core::Constants::MODE_EDIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WelcomeMode::slotSessionClicked(const QString &data)
|
|
|
|
|
{
|
|
|
|
|
emit requestSession(data);
|
|
|
|
|
activateEditMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WelcomeMode::slotProjectClicked(const QString &data)
|
|
|
|
|
{
|
|
|
|
|
emit requestProject(data);
|
|
|
|
|
activateEditMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WelcomeMode::slotRestoreLastSession()
|
|
|
|
|
{
|
|
|
|
|
emit requestSession(m_d->lastData.previousSession);
|
|
|
|
|
activateEditMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WelcomeMode::slotFeedback()
|
|
|
|
|
{
|
|
|
|
|
QDesktopServices::openUrl(QUrl(QLatin1String(
|
|
|
|
|
"http://www.qtsoftware.com/forms/feedback-forms/qt-creator-user-feedback/view")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- WelcomeModeButton
|
|
|
|
|
|
|
|
|
|
WelcomeModeButton::WelcomeModeButton(QWidget *parent) :
|
|
|
|
|
QLabel(parent),
|
|
|
|
|
m_isPressed(false)
|
|
|
|
|
{
|
|
|
|
|
setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WelcomeModeButton::mousePressEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
|
m_isPressed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WelcomeModeButton::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->button() == Qt::LeftButton && m_isPressed) {
|
|
|
|
|
m_isPressed = false;
|
|
|
|
|
if (rect().contains(event->pos()))
|
|
|
|
|
emit clicked();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-22 18:17:50 +02:00
|
|
|
// --- WelcomeModeTreeWidget
|
|
|
|
|
|
|
|
|
|
WelcomeModeTreeWidget::WelcomeModeTreeWidget(QWidget *parent) :
|
|
|
|
|
QTreeWidget(parent),
|
|
|
|
|
m_bullet(QLatin1String(":/core/images/welcomemode/list_bullet_arrow.png"))
|
|
|
|
|
{
|
|
|
|
|
connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
|
|
|
|
|
SLOT(slotItemClicked(QTreeWidgetItem *)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize WelcomeModeTreeWidget::sizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return QSize(QTreeWidget::sizeHint().width(), 30 * topLevelItemCount());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTreeWidgetItem *WelcomeModeTreeWidget::addItem(const QString &label, const QString &data)
|
|
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(this);
|
|
|
|
|
item->setIcon(0, m_bullet);
|
|
|
|
|
item->setSizeHint(0, QSize(24, 30));
|
|
|
|
|
QWidget *lbl = new QLabel(label);
|
|
|
|
|
lbl->setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
|
lbl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
|
QBoxLayout *lay = new QVBoxLayout;
|
|
|
|
|
lay->setContentsMargins(3, 2, 0, 0);
|
|
|
|
|
lay->addWidget(lbl);
|
|
|
|
|
QWidget *wdg = new QWidget;
|
|
|
|
|
wdg->setLayout(lay);
|
|
|
|
|
setItemWidget(item, 1, wdg);
|
|
|
|
|
item->setData(0, Qt::UserRole, data);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WelcomeModeTreeWidget::slotItemClicked(QTreeWidgetItem *item)
|
|
|
|
|
{
|
|
|
|
|
emit activated(item->data(0, Qt::UserRole).toString());
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Core
|