Commit c8be3a3e authored by Daniel Molkentin's avatar Daniel Molkentin
Browse files

Preparation for plugifying the welcome screen.

Move WelcomeModeTreeWidget to utils, add d-ptr.
parent 4f5ce66d
......@@ -31,8 +31,8 @@ SOURCES += reloadpromptutils.cpp \
treewidgetcolumnstretcher.cpp \
checkablemessagebox.cpp \
styledbar.cpp \
stylehelper.cpp
stylehelper.cpp \
welcomemodetreewidget.cpp
win32 {
SOURCES += abstractprocess_win.cpp \
consoleprocess_win.cpp \
......@@ -71,8 +71,8 @@ HEADERS += utils_global.h \
checkablemessagebox.h \
qtcassert.h \
styledbar.h \
stylehelper.h
stylehelper.h \
welcomemodetreewidget.h
FORMS += filewizardpage.ui \
projectintropage.ui \
newclasswidget.ui \
......
/**************************************************************************
**
** 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
#define WELCOMEMODE_P_H
#ifndef WELCOMEMODETREEWIDGET_H
#define WELCOMEMODETREEWIDGET_H
#include <QtGui/QIcon>
#include <QtGui/QLabel>
#include <QtGui/QTreeWidget>
namespace Welcome {
class WelcomeModeButton : public QLabel
{
Q_OBJECT
public:
WelcomeModeButton(QWidget *parent = 0);
#include "utils_global.h"
signals:
void clicked();
#include <QtGui/QTreeWidget>
protected:
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void enterEvent(QEvent *event);
virtual void leaveEvent(QEvent *event);
namespace Core {
namespace Utils {
private:
bool m_isPressed;
bool m_isInited;
QString m_text;
QString m_hoverText;
};
struct WelcomeModeTreeWidgetPrivate;
class WelcomeModeTreeWidget : public QTreeWidget
class QTCREATOR_UTILS_EXPORT WelcomeModeTreeWidget : public QTreeWidget
{
Q_OBJECT
public:
WelcomeModeTreeWidget(QWidget *parent = 0);
~WelcomeModeTreeWidget();
QTreeWidgetItem *addItem(const QString &label, const QString &data);
public slots:
......@@ -81,9 +62,10 @@ private slots:
void slotItemClicked(QTreeWidgetItem *item);
private:
QIcon m_bullet;
WelcomeModeTreeWidgetPrivate *m_d;
};
}
}
#endif // WELCOMEMODE_P_H
#endif // WELCOMEMODETREEWIDGET_H
......@@ -3,20 +3,13 @@ TARGET = Welcome
QT += network
include(../../qtcreatorplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
HEADERS += welcomeplugin.h \
welcomemode.h \
welcomemode_p.h \
rssfetcher.h
welcomemode.h \
rssfetcher.h
SOURCES += welcomeplugin.cpp \
welcomemode.cpp \
rssfetcher.cpp
welcomemode.cpp \
rssfetcher.cpp
FORMS += welcomemode.ui
RESOURCES += welcome.qrc
DEFINES += WELCOME_LIBRARY
OTHER_FILES += Welcome.pluginspec
......@@ -39,10 +39,12 @@
#include <coreplugin/dialogs/newdialog.h>
#include <utils/styledbar.h>
#include <utils/welcomemodetreewidget.h>
#include <QtGui/QDesktopServices>
#include <QtGui/QMouseEvent>
#include <QtGui/QScrollArea>
#include <QtGui/QButtonGroup>
#include <QtCore/QDateTime>
#include <QtCore/QDir>
......@@ -469,106 +471,4 @@ QStringList WelcomeMode::tipsOfTheDay()
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
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Welcome::WelcomePage</class>
<widget class="QWidget" name="Welcome::WelcomePage">
<widget class="QWidget" name="Core::Utils::WelcomePage">
<property name="geometry">
<rect>
<x>0</x>
......@@ -417,7 +417,7 @@ QToolButton:pressed {
</widget>
</item>
<item row="1" column="0">
<widget class="Welcome::WelcomeModeTreeWidget" name="tutorialTreeWidget">
<widget class="Core::Utils::WelcomeModeTreeWidget" name="tutorialTreeWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -746,7 +746,7 @@ QToolButton:pressed {
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="Welcome::WelcomeModeTreeWidget" name="sessTreeWidget">
<widget class="Core::Utils::WelcomeModeTreeWidget" name="sessTreeWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -853,7 +853,7 @@ QToolButton:pressed {
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="Welcome::WelcomeModeTreeWidget" name="projTreeWidget">
<widget class="Core::Utils::WelcomeModeTreeWidget" name="projTreeWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -967,7 +967,7 @@ QToolButton:pressed {
</widget>
</item>
<item>
<widget class="Welcome::WelcomeModeTreeWidget" name="newsTreeWidget">
<widget class="Core::Utils::WelcomeModeTreeWidget" name="newsTreeWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -1051,7 +1051,7 @@ QToolButton:pressed {
</widget>
</item>
<item>
<widget class="Welcome::WelcomeModeTreeWidget" name="sitesTreeWidget">
<widget class="Core::Utils::WelcomeModeTreeWidget" name="sitesTreeWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -1221,9 +1221,9 @@ QToolButton:pressed {
</widget>
<customwidgets>
<customwidget>
<class>Welcome::WelcomeModeTreeWidget</class>
<class>Core::Utils::WelcomeModeTreeWidget</class>
<extends>QTreeWidget</extends>
<header>welcomemode_p.h</header>
<header>utils/welcomemodetreewidget.h</header>
</customwidget>
</customwidgets>
<resources>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment