forked from qt-creator/qt-creator
Preparation for plugifying the welcome screen.
Move WelcomeModeTreeWidget to utils, add d-ptr.
This commit is contained in:
@@ -31,8 +31,8 @@ SOURCES += reloadpromptutils.cpp \
|
|||||||
treewidgetcolumnstretcher.cpp \
|
treewidgetcolumnstretcher.cpp \
|
||||||
checkablemessagebox.cpp \
|
checkablemessagebox.cpp \
|
||||||
styledbar.cpp \
|
styledbar.cpp \
|
||||||
stylehelper.cpp
|
stylehelper.cpp \
|
||||||
|
welcomemodetreewidget.cpp
|
||||||
win32 {
|
win32 {
|
||||||
SOURCES += abstractprocess_win.cpp \
|
SOURCES += abstractprocess_win.cpp \
|
||||||
consoleprocess_win.cpp \
|
consoleprocess_win.cpp \
|
||||||
@@ -71,8 +71,8 @@ HEADERS += utils_global.h \
|
|||||||
checkablemessagebox.h \
|
checkablemessagebox.h \
|
||||||
qtcassert.h \
|
qtcassert.h \
|
||||||
styledbar.h \
|
styledbar.h \
|
||||||
stylehelper.h
|
stylehelper.h \
|
||||||
|
welcomemodetreewidget.h
|
||||||
FORMS += filewizardpage.ui \
|
FORMS += filewizardpage.ui \
|
||||||
projectintropage.ui \
|
projectintropage.ui \
|
||||||
newclasswidget.ui \
|
newclasswidget.ui \
|
||||||
|
104
src/libs/utils/welcomemodetreewidget.cpp
Normal file
104
src/libs/utils/welcomemodetreewidget.cpp
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** Commercial Usage
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
** If you are unsure which license is appropriate for your use, please
|
||||||
|
** contact the sales department at http://www.qtsoftware.com/contact.
|
||||||
|
**
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#include "welcomemodetreewidget.h"
|
||||||
|
|
||||||
|
#include <QtGui/QLabel>
|
||||||
|
#include <QtGui/QBoxLayout>
|
||||||
|
#include <QtGui/QHeaderView>
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
struct WelcomeModeTreeWidgetPrivate
|
||||||
|
{
|
||||||
|
WelcomeModeTreeWidgetPrivate() {}
|
||||||
|
QIcon bullet;
|
||||||
|
};
|
||||||
|
|
||||||
|
WelcomeModeTreeWidget::WelcomeModeTreeWidget(QWidget *parent) :
|
||||||
|
QTreeWidget(parent), m_d(new WelcomeModeTreeWidgetPrivate)
|
||||||
|
{
|
||||||
|
m_d->bullet = QIcon(QLatin1String(":/welcome/images/list_bullet_arrow.png"));
|
||||||
|
connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
|
||||||
|
SLOT(slotItemClicked(QTreeWidgetItem *)));
|
||||||
|
}
|
||||||
|
|
||||||
|
WelcomeModeTreeWidget::~WelcomeModeTreeWidget()
|
||||||
|
{
|
||||||
|
delete m_d;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize WelcomeModeTreeWidget::minimumSizeHint() const
|
||||||
|
{
|
||||||
|
return QSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
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_d->bullet);
|
||||||
|
item->setSizeHint(0, QSize(24, 30));
|
||||||
|
QLabel *lbl = new QLabel(label);
|
||||||
|
lbl->setTextInteractionFlags(Qt::NoTextInteraction);
|
||||||
|
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::slotAddNewsItem(const QString &title, const QString &description, const QString &link)
|
||||||
|
{
|
||||||
|
int itemWidth = width()-header()->sectionSize(0);
|
||||||
|
QFont f = font();
|
||||||
|
QString elidedText = QFontMetrics(f).elidedText(description, Qt::ElideRight, itemWidth);
|
||||||
|
f.setBold(true);
|
||||||
|
QString elidedTitle = QFontMetrics(f).elidedText(title, Qt::ElideRight, itemWidth);
|
||||||
|
QString data = QString::fromLatin1("<b>%1</b><br />%2").arg(elidedTitle).arg(elidedText);
|
||||||
|
addTopLevelItem(addItem(data,link));
|
||||||
|
}
|
||||||
|
|
||||||
|
void WelcomeModeTreeWidget::slotItemClicked(QTreeWidgetItem *item)
|
||||||
|
{
|
||||||
|
emit activated(item->data(0, Qt::UserRole).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -27,44 +27,25 @@
|
|||||||
**
|
**
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#ifndef WELCOMEMODE_P_H
|
#ifndef WELCOMEMODETREEWIDGET_H
|
||||||
#define WELCOMEMODE_P_H
|
#define WELCOMEMODETREEWIDGET_H
|
||||||
|
|
||||||
|
#include "utils_global.h"
|
||||||
|
|
||||||
#include <QtGui/QIcon>
|
|
||||||
#include <QtGui/QLabel>
|
|
||||||
#include <QtGui/QTreeWidget>
|
#include <QtGui/QTreeWidget>
|
||||||
|
|
||||||
namespace Welcome {
|
namespace Core {
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
class WelcomeModeButton : public QLabel
|
struct WelcomeModeTreeWidgetPrivate;
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
class QTCREATOR_UTILS_EXPORT WelcomeModeTreeWidget : public QTreeWidget
|
||||||
WelcomeModeButton(QWidget *parent = 0);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void clicked();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void mousePressEvent(QMouseEvent *event);
|
|
||||||
virtual void mouseReleaseEvent(QMouseEvent *event);
|
|
||||||
virtual void enterEvent(QEvent *event);
|
|
||||||
virtual void leaveEvent(QEvent *event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_isPressed;
|
|
||||||
bool m_isInited;
|
|
||||||
QString m_text;
|
|
||||||
QString m_hoverText;
|
|
||||||
};
|
|
||||||
|
|
||||||
class WelcomeModeTreeWidget : public QTreeWidget
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WelcomeModeTreeWidget(QWidget *parent = 0);
|
WelcomeModeTreeWidget(QWidget *parent = 0);
|
||||||
|
~WelcomeModeTreeWidget();
|
||||||
QTreeWidgetItem *addItem(const QString &label, const QString &data);
|
QTreeWidgetItem *addItem(const QString &label, const QString &data);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@@ -81,9 +62,10 @@ private slots:
|
|||||||
void slotItemClicked(QTreeWidgetItem *item);
|
void slotItemClicked(QTreeWidgetItem *item);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QIcon m_bullet;
|
WelcomeModeTreeWidgetPrivate *m_d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // WELCOMEMODE_P_H
|
#endif // WELCOMEMODETREEWIDGET_H
|
@@ -3,20 +3,13 @@ TARGET = Welcome
|
|||||||
QT += network
|
QT += network
|
||||||
include(../../qtcreatorplugin.pri)
|
include(../../qtcreatorplugin.pri)
|
||||||
include(../../plugins/coreplugin/coreplugin.pri)
|
include(../../plugins/coreplugin/coreplugin.pri)
|
||||||
|
|
||||||
HEADERS += welcomeplugin.h \
|
HEADERS += welcomeplugin.h \
|
||||||
welcomemode.h \
|
welcomemode.h \
|
||||||
welcomemode_p.h \
|
rssfetcher.h
|
||||||
rssfetcher.h
|
|
||||||
|
|
||||||
SOURCES += welcomeplugin.cpp \
|
SOURCES += welcomeplugin.cpp \
|
||||||
welcomemode.cpp \
|
welcomemode.cpp \
|
||||||
rssfetcher.cpp
|
rssfetcher.cpp
|
||||||
|
|
||||||
FORMS += welcomemode.ui
|
FORMS += welcomemode.ui
|
||||||
|
|
||||||
RESOURCES += welcome.qrc
|
RESOURCES += welcome.qrc
|
||||||
|
|
||||||
DEFINES += WELCOME_LIBRARY
|
DEFINES += WELCOME_LIBRARY
|
||||||
|
|
||||||
OTHER_FILES += Welcome.pluginspec
|
OTHER_FILES += Welcome.pluginspec
|
||||||
|
@@ -39,10 +39,12 @@
|
|||||||
#include <coreplugin/dialogs/newdialog.h>
|
#include <coreplugin/dialogs/newdialog.h>
|
||||||
|
|
||||||
#include <utils/styledbar.h>
|
#include <utils/styledbar.h>
|
||||||
|
#include <utils/welcomemodetreewidget.h>
|
||||||
|
|
||||||
#include <QtGui/QDesktopServices>
|
#include <QtGui/QDesktopServices>
|
||||||
#include <QtGui/QMouseEvent>
|
#include <QtGui/QMouseEvent>
|
||||||
#include <QtGui/QScrollArea>
|
#include <QtGui/QScrollArea>
|
||||||
|
#include <QtGui/QButtonGroup>
|
||||||
|
|
||||||
#include <QtCore/QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
@@ -469,106 +471,4 @@ QStringList WelcomeMode::tipsOfTheDay()
|
|||||||
return tips;
|
return tips;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- WelcomeModeButton
|
|
||||||
|
|
||||||
WelcomeModeButton::WelcomeModeButton(QWidget *parent) :
|
|
||||||
QLabel(parent),
|
|
||||||
m_isPressed(false),
|
|
||||||
m_isInited(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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WelcomeModeButton::enterEvent(QEvent *)
|
|
||||||
{
|
|
||||||
if (!m_isInited) {
|
|
||||||
m_isInited = true;
|
|
||||||
m_text = text();
|
|
||||||
m_hoverText = m_text;
|
|
||||||
m_hoverText.replace(QLatin1String(".png"), QLatin1String("_hover.png"));
|
|
||||||
if (m_text == m_hoverText) {
|
|
||||||
m_text.clear();
|
|
||||||
m_hoverText.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!m_hoverText.isEmpty())
|
|
||||||
setText(m_hoverText);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WelcomeModeButton::leaveEvent(QEvent *)
|
|
||||||
{
|
|
||||||
if (!m_text.isEmpty())
|
|
||||||
setText(m_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- WelcomeModeTreeWidget
|
|
||||||
|
|
||||||
WelcomeModeTreeWidget::WelcomeModeTreeWidget(QWidget *parent) :
|
|
||||||
QTreeWidget(parent),
|
|
||||||
m_bullet(QLatin1String(":/welcome/images/list_bullet_arrow.png"))
|
|
||||||
{
|
|
||||||
connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
|
|
||||||
SLOT(slotItemClicked(QTreeWidgetItem *)));
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize WelcomeModeTreeWidget::minimumSizeHint() const
|
|
||||||
{
|
|
||||||
return QSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
|
||||||
QLabel *lbl = new QLabel(label);
|
|
||||||
lbl->setTextInteractionFlags(Qt::NoTextInteraction);
|
|
||||||
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::slotAddNewsItem(const QString &title, const QString &description, const QString &link)
|
|
||||||
{
|
|
||||||
int itemWidth = width()-header()->sectionSize(0);
|
|
||||||
QFont f = font();
|
|
||||||
QString elidedText = QFontMetrics(f).elidedText(description, Qt::ElideRight, itemWidth);
|
|
||||||
f.setBold(true);
|
|
||||||
QString elidedTitle = QFontMetrics(f).elidedText(title, Qt::ElideRight, itemWidth);
|
|
||||||
QString data = QString::fromLatin1("<b>%1</b><br />%2").arg(elidedTitle).arg(elidedText);
|
|
||||||
addTopLevelItem(addItem(data,link));
|
|
||||||
}
|
|
||||||
|
|
||||||
void WelcomeModeTreeWidget::slotItemClicked(QTreeWidgetItem *item)
|
|
||||||
{
|
|
||||||
emit activated(item->data(0, Qt::UserRole).toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Welcome
|
} // namespace Welcome
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>Welcome::WelcomePage</class>
|
<class>Welcome::WelcomePage</class>
|
||||||
<widget class="QWidget" name="Welcome::WelcomePage">
|
<widget class="QWidget" name="Core::Utils::WelcomePage">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
@@ -417,7 +417,7 @@ QToolButton:pressed {
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="Welcome::WelcomeModeTreeWidget" name="tutorialTreeWidget">
|
<widget class="Core::Utils::WelcomeModeTreeWidget" name="tutorialTreeWidget">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@@ -746,7 +746,7 @@ QToolButton:pressed {
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="3">
|
<item row="1" column="0" colspan="3">
|
||||||
<widget class="Welcome::WelcomeModeTreeWidget" name="sessTreeWidget">
|
<widget class="Core::Utils::WelcomeModeTreeWidget" name="sessTreeWidget">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@@ -853,7 +853,7 @@ QToolButton:pressed {
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="3">
|
<item row="1" column="0" colspan="3">
|
||||||
<widget class="Welcome::WelcomeModeTreeWidget" name="projTreeWidget">
|
<widget class="Core::Utils::WelcomeModeTreeWidget" name="projTreeWidget">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@@ -967,7 +967,7 @@ QToolButton:pressed {
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="Welcome::WelcomeModeTreeWidget" name="newsTreeWidget">
|
<widget class="Core::Utils::WelcomeModeTreeWidget" name="newsTreeWidget">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@@ -1051,7 +1051,7 @@ QToolButton:pressed {
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="Welcome::WelcomeModeTreeWidget" name="sitesTreeWidget">
|
<widget class="Core::Utils::WelcomeModeTreeWidget" name="sitesTreeWidget">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@@ -1221,9 +1221,9 @@ QToolButton:pressed {
|
|||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>Welcome::WelcomeModeTreeWidget</class>
|
<class>Core::Utils::WelcomeModeTreeWidget</class>
|
||||||
<extends>QTreeWidget</extends>
|
<extends>QTreeWidget</extends>
|
||||||
<header>welcomemode_p.h</header>
|
<header>utils/welcomemodetreewidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
|
Reference in New Issue
Block a user