welcomemode.cpp 22.2 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** 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.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
26
** contact the sales department at http://www.qtsoftware.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "welcomemode.h"
31
#include "icore.h"
32
#include "iwizard.h"
con's avatar
con committed
33
34
35
#include "coreconstants.h"
#include "uniqueidmanager.h"
#include "modemanager.h"
36
#include "newdialog.h"
37
#include "rssfetcher.h"
con's avatar
con committed
38
39
40

#include <QtGui/QToolBar>
#include <QtGui/QDesktopServices>
41
#include <QtGui/QMouseEvent>
42
#include <QtGui/QScrollArea>
con's avatar
con committed
43

44
#include <QtCore/QDateTime>
45
#include <QtCore/QDir>
46
#include <QtCore/QFileInfo>
con's avatar
con committed
47
48
#include <QtCore/QDebug>
#include <QtCore/QUrl>
49
#include <QtCore/QSettings>
con's avatar
con committed
50

51
52
#include <cstdlib>

53
54
#include "ui_welcomemode.h"

con's avatar
con committed
55
56
57
namespace Core {
namespace Internal {

hjk's avatar
hjk committed
58
59
struct WelcomeModePrivate
{
con's avatar
con committed
60
61
    WelcomeModePrivate();

62
    QScrollArea *m_scrollArea;
con's avatar
con committed
63
    QWidget *m_widget;
64
    QWidget *m_welcomePage;
65
    QButtonGroup *btnGrp;
66
    Ui::WelcomePage ui;
67
    RSSFetcher *rssFetcher;
con's avatar
con committed
68
    WelcomeMode::WelcomePageData lastData;
69
    int currentTip;
con's avatar
con committed
70
71
};

72
WelcomeModePrivate::WelcomeModePrivate()
con's avatar
con committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
}

// ---  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;
}

103
104
// Format a title + ruler for title labels
static inline QString titleLabel(const QString &text)
105
106
107
108
109
110
111
112
113
114
115
{
    QString  rc = QLatin1String(
    "<html><head><style type=\"text/css\">p, li { white-space: pre-wrap; }</style></head>"
    "<body style=\" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;\">"
    "<p style=\" margin-top:16px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
    "<span style=\" font-size:x-large; color:#555555;\">");
    rc += text;
    rc += QLatin1String("</span></p><hr/></body></html>");
    return rc;
}

con's avatar
con committed
116
117
118
119
// ---  WelcomeMode
WelcomeMode::WelcomeMode() :
    m_d(new WelcomeModePrivate)
{
120
    m_d->m_widget = new QWidget;
con's avatar
con committed
121
122
123
124
    QVBoxLayout *l = new QVBoxLayout(m_d->m_widget);
    l->setMargin(0);
    l->setSpacing(0);
    l->addWidget(new QToolBar(m_d->m_widget));
125
    m_d->rssFetcher = new RSSFetcher(7, this);
126
127
    m_d->m_welcomePage = new QWidget(m_d->m_widget);
    m_d->ui.setupUi(m_d->m_welcomePage);
128
129
    m_d->ui.projTitleLabel->setText(titleLabel(tr("Open Recent Project")));
    m_d->ui.recentSessionsTitleLabel->setText(titleLabel(tr("Resume Session")));
130
    m_d->ui.tutorialsTitleLabel->setText(titleLabel(tr("Tutorials")));
131
    m_d->ui.demoTitleLabel->setText(titleLabel(tr("Explore Qt Examples")));
132
133
    m_d->ui.didYouKnowTitleLabel->setText(titleLabel(tr("Did You Know?")));
    m_d->ui.labsTitleLabel->setText(titleLabel(tr("News From the Qt Labs")));
134
    m_d->ui.sitesTitleLabel->setText(titleLabel(tr("Qt Websites")));
135
136
    m_d->ui.sessTreeWidget->viewport()->setAutoFillBackground(false);
    m_d->ui.projTreeWidget->viewport()->setAutoFillBackground(false);
137
138
139
    m_d->ui.newsTreeWidget->viewport()->setAutoFillBackground(false);
    m_d->ui.sitesTreeWidget->viewport()->setAutoFillBackground(false);
    m_d->ui.tutorialTreeWidget->viewport()->setAutoFillBackground(false);
140
    m_d->ui.didYouKnowTextBrowser->viewport()->setAutoFillBackground(false);
141
142
    m_d->ui.helpUsLabel->setAttribute(Qt::WA_LayoutUsesWidgetRect);
    m_d->ui.feedbackButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
143
144
    l->addWidget(m_d->m_welcomePage);

145
146
147
148
149
    m_d->m_scrollArea = new QScrollArea;
    m_d->m_scrollArea->setFrameStyle(QFrame::NoFrame);
    m_d->m_scrollArea->setWidget(m_d->m_widget);
    m_d->m_scrollArea->setWidgetResizable(true);

150
151
    updateWelcomePage(WelcomePageData());

152
153
154
155
    m_d->btnGrp = new QButtonGroup(this);
    m_d->btnGrp->addButton(m_d->ui.gettingStartedSectButton, 0);
    m_d->btnGrp->addButton(m_d->ui.developSectButton, 1);
    m_d->btnGrp->addButton(m_d->ui.communitySectButton, 2);
156

157
    connect(m_d->btnGrp, SIGNAL(buttonClicked(int)), m_d->ui.stackedWidget, SLOT(setCurrentIndex(int)));
158

159
    connect(m_d->ui.feedbackButton, SIGNAL(clicked()), SLOT(slotFeedback()));
160
161
    connect(m_d->ui.manageSessionsButton, SIGNAL(clicked()), SIGNAL(manageSessions()));
    connect(m_d->ui.createNewProjectButton, SIGNAL(clicked()), SLOT(slotCreateNewProject()));
162
163
    connect(m_d->ui.sessTreeWidget, SIGNAL(activated(QString)), SLOT(slotSessionClicked(QString)));
    connect(m_d->ui.projTreeWidget, SIGNAL(activated(QString)), SLOT(slotProjectClicked(QString)));
164
165
    connect(m_d->ui.newsTreeWidget, SIGNAL(activated(QString)), SLOT(slotUrlClicked(QString)));
    connect(m_d->ui.sitesTreeWidget, SIGNAL(activated(QString)), SLOT(slotUrlClicked(QString)));
166
    connect(m_d->ui.tutorialTreeWidget, SIGNAL(activated(QString)), SIGNAL(openHelpPage(const QString&)));
167
168
169
    connect(m_d->ui.openExampleButton, SIGNAL(clicked()), SLOT(slotOpenExample()));
    connect(m_d->ui.examplesComboBox, SIGNAL(currentIndexChanged(int)), SLOT(slotEnableExampleButton(int)));

170
171
    connect(this, SIGNAL(updatedExamples(QString, QString)),
            this, SLOT(slotUpdateExamples(QString, QString)));
172

173
174
    connect(m_d->rssFetcher, SIGNAL(newsItemReady(QString, QString, QString)),
        m_d->ui.newsTreeWidget, SLOT(slotAddNewsItem(QString, QString, QString)));
175
176

    //: Add localized feed here only if one exists
177
    m_d->rssFetcher->fetch(QUrl(tr("http://labs.trolltech.com/blogs/feed")));
178

179
    m_d->ui.sitesTreeWidget->addItem(tr("Qt Home"), QLatin1String("http://qtsoftware.com"));
180
    m_d->ui.sitesTreeWidget->addItem(tr("Qt Labs"), QLatin1String("http://labs.trolltech.com"));
181
182
    m_d->ui.sitesTreeWidget->addItem(tr("Qt Git Hosting"), QLatin1String("http://qt.gitorious.org"));
    m_d->ui.sitesTreeWidget->addItem(tr("Qt Centre"), QLatin1String("http://www.qtcentre.org"));
183
    m_d->ui.sitesTreeWidget->addItem(tr("Qt for S60 at Forum Nokia"), QLatin1String("http://discussion.forum.nokia.com/forum/forumdisplay.php?f=196"));
184

185
    m_d->ui.tutorialTreeWidget->addItem(tr("<b>Qt Creator - A quick tour</b>"),
186
187
                                        QString("qthelp://com.nokia.qtcreator.%1%2/doc/index.html").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
    m_d->ui.tutorialTreeWidget->addItem(tr("Creating an address book"),
188
                                        QLatin1String("qthelp://com.nokia.qtcreator/doc/tutorials-addressbook-sdk.html"));
189
190
    m_d->ui.tutorialTreeWidget->addItem(tr("Understanding widgets"),
                                        QLatin1String("qthelp://com.trolltech.qt/qdoc/widgets-tutorial.html"));
191
192
193
194
195
    m_d->ui.tutorialTreeWidget->addItem(tr("Building with qmake"),
                                        QLatin1String("qthelp://com.trolltech.qmake/qdoc/qmake-tutorial.html"));
    m_d->ui.tutorialTreeWidget->addItem(tr("Writing test cases"),
                                        QLatin1String("qthelp://com.trolltech.qt/qdoc/qtestlib-tutorial.html"));

196
197
198
199
200
201
202
203
204
205
206
207
    srand(QDateTime::currentDateTime().toTime_t());
    QStringList tips = tipsOfTheDay();
    m_d->currentTip = rand()%tips.count();

    QTextDocument *doc = m_d->ui.didYouKnowTextBrowser->document();
    doc->setDefaultStyleSheet("a:link {color:black;}");
    m_d->ui.didYouKnowTextBrowser->setDocument(doc);
    m_d->ui.didYouKnowTextBrowser->setText(tips.at(m_d->currentTip));

    connect(m_d->ui.nextTipBtn, SIGNAL(clicked()), this, SLOT(slotNextTip()));
    connect(m_d->ui.prevTipBtn, SIGNAL(clicked()), this, SLOT(slotPrevTip()));

208
209
    QSettings *settings = ICore::instance()->settings();
    int id = settings->value("General/WelcomeTab", 0).toInt();
210
211
    m_d->btnGrp->button(id)->setChecked(true);
    m_d->ui.stackedWidget->setCurrentIndex(id);
con's avatar
con committed
212
213
214
215
}

WelcomeMode::~WelcomeMode()
{
216
217
    QSettings *settings = ICore::instance()->settings();
    settings->setValue("General/WelcomeTab", m_d->btnGrp->checkedId());
dt's avatar
dt committed
218
    delete m_d->m_widget;
con's avatar
con committed
219
220
221
222
223
    delete m_d;
}

QString WelcomeMode::name() const
{
224
    return tr("Welcome");
con's avatar
con committed
225
226
227
228
}

QIcon WelcomeMode::icon() const
{
229
    return QIcon(QLatin1String(":/core/images/qtcreator_logo_32.png"));
con's avatar
con committed
230
231
232
233
234
235
236
237
238
}

int WelcomeMode::priority() const
{
    return Constants::P_MODE_WELCOME;
}

QWidget* WelcomeMode::widget()
{
239
    return m_d->m_scrollArea;
con's avatar
con committed
240
241
242
243
244
245
246
247
248
249
}

const char* WelcomeMode::uniqueModeName() const
{
    return Constants::MODE_WELCOME;
}

QList<int> WelcomeMode::context() const
{
    static QList<int> contexts = QList<int>()
250
                                 << UniqueIDManager::instance()->uniqueIdentifier(Constants::C_WELCOME_MODE);
con's avatar
con committed
251
252
253
254
255
256
257
258
259
260
    return contexts;
}

void WelcomeMode::updateWelcomePage(const WelcomePageData &welcomePageData)
{
    // Update only if data are modified
    if (welcomePageData == m_d->lastData)
        return;
    m_d->lastData = welcomePageData;

261
    m_d->m_widget->setUpdatesEnabled(false);
262
263
264
265
266
267
268
269
270
    m_d->ui.sessTreeWidget->clear();
    m_d->ui.projTreeWidget->clear();

    if (welcomePageData.sessionList.count() > 0) {
        foreach (const QString &s, welcomePageData.sessionList) {
            QString str = s;
            if (s == welcomePageData.previousSession)
                str = tr("%1 (last session)").arg(s);
            m_d->ui.sessTreeWidget->addItem(str, s);
con's avatar
con committed
271
        }
272
273
274
275
276
        m_d->ui.sessTreeWidget->updateGeometry();
        m_d->ui.sessTreeWidget->show();
    } else {
        m_d->ui.sessTreeWidget->hide();
    }
277

278
279
    typedef QPair<QString, QString> QStringPair;
    if (welcomePageData.projectList.count() > 0) {
280
        foreach (const QStringPair &it, welcomePageData.projectList) {
281
282
283
            QTreeWidgetItem *item = m_d->ui.projTreeWidget->addItem(it.second, it.first);
            const QFileInfo fi(it.first);
            item->setToolTip(1, QDir::toNativeSeparators(fi.absolutePath()));
con's avatar
con committed
284
        }
285
    } else {
286
        m_d->ui.projTreeWidget->hide();
287
    }
288
    m_d->ui.projTreeWidget->updateGeometry();
289
    m_d->m_widget->setUpdatesEnabled(true);
con's avatar
con committed
290
291
}

292
void WelcomeMode::activateEditMode()
con's avatar
con committed
293
{
294
    Core::ModeManager *modeManager = ModeManager::instance();
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
    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();
}

311
312
313
314
315
void WelcomeMode::slotUrlClicked(const QString &data)
{
    QDesktopServices::openUrl(QUrl(data));
}

316
void WelcomeMode::slotUpdateExamples(const QString& examplePath, const QString& demosPath)
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
{
    QString demoxml = demosPath + "/qtdemo/xml/examples.xml";
    if (!QFile::exists(demoxml))
        return;

    QFile description(demoxml);
    if (!description.open(QFile::ReadOnly))
        return;

    m_d->ui.examplesComboBox->clear();
    m_d->ui.examplesComboBox->setEnabled(true);

    m_d->ui.examplesComboBox->addItem(tr("Choose an example..."));
    QFont f = widget()->font();
    f.setItalic(true);
    m_d->ui.examplesComboBox->setItemData(0, f, Qt::FontRole);
    f.setItalic(false);
    bool inExamples = false;
    QString dirName;
    QXmlStreamReader reader(&description);
    while (!reader.atEnd()) {
        switch (reader.readNext()) {
            case QXmlStreamReader::StartElement:
            if (reader.name() == "category") {
                QString name = reader.attributes().value(QLatin1String("name")).toString();
                if (name.contains("tutorial"))
                    break;
                dirName = reader.attributes().value(QLatin1String("dirname")).toString();
                m_d->ui.examplesComboBox->addItem(name);
                f.setBold(true);
                m_d->ui.examplesComboBox->setItemData(m_d->ui.examplesComboBox->count()-1, f, Qt::FontRole);
                f.setBold(false);
                inExamples = true;
            }
            if (inExamples && reader.name() == "example") {
                QString name = reader.attributes().value(QLatin1String("name")).toString();
                QString fn = reader.attributes().value(QLatin1String("filename")).toString();
                QString fileName = examplePath + '/' + dirName + '/' + fn + '/' + fn + ".pro";
                QString helpPath = "qthelp://com.trolltech.qt/qdoc/" + dirName.replace("/", "-") + "-" + fn + ".html";

                m_d->ui.examplesComboBox->addItem("  " + name, fileName);
                m_d->ui.examplesComboBox->setItemData(m_d->ui.examplesComboBox->count()-1, helpPath, Qt::UserRole+1);
            }
            break;
            case QXmlStreamReader::EndElement:
            if (reader.name() == "category")
                inExamples = false;
            break;
            default:
            break;
        }
    }
}

void WelcomeMode::slotEnableExampleButton(int index)
{
    QString fileName = m_d->ui.examplesComboBox->itemData(index, Qt::UserRole).toString();
    m_d->ui.openExampleButton->setEnabled(!fileName.isEmpty());
}

void WelcomeMode::slotOpenExample()
{
    QComboBox *box = m_d->ui.examplesComboBox;
    QString proFile = box->itemData(box->currentIndex(), Qt::UserRole).toString();
    QString helpFile = box->itemData(box->currentIndex(), Qt::UserRole + 1).toString();
    QStringList files;
    QFileInfo fi(proFile);
    QString tryFile = fi.path() + "/main.cpp";
    files << proFile;
    if(!QFile::exists(tryFile))
        tryFile = fi.path() + '/' + fi.baseName() + ".cpp";
    if(QFile::exists(tryFile))
        files << tryFile;
    Core::ICore::instance()->openFiles(files);
    emit openContextHelpPage(helpFile);
}

394
void WelcomeMode::slotFeedback()
395
{
396
    QDesktopServices::openUrl(QUrl(QLatin1String(
397
            "http://qtsoftware.com/forms/feedback-forms/qt-creator-user-feedback/view")));
398
399
}

400
void WelcomeMode::slotCreateNewProject()
401
{
402
403
    Core::ICore::instance()->showNewItemDialog(tr("New Project..."),
                                               Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard));
404
405
}

406
407
408
void WelcomeMode::slotNextTip()
{
    QStringList tips = tipsOfTheDay();
409
410
    m_d->currentTip = ((m_d->currentTip+1)%tips.count());
    m_d->ui.didYouKnowTextBrowser->setText(tips.at(m_d->currentTip));
411
412
413
414
415
}

void WelcomeMode::slotPrevTip()
{
    QStringList tips = tipsOfTheDay();
416
    m_d->currentTip = ((m_d->currentTip-1)+tips.count())%tips.count();
417
    m_d->ui.didYouKnowTextBrowser->setText(tips.at(m_d->currentTip));
418
419
420
}

QStringList WelcomeMode::tipsOfTheDay()
421
422
423
{
    static QStringList tips;
    if (tips.isEmpty()) {
424
        QString altShortcut =
con's avatar
con committed
425
#ifdef Q_WS_MAC
426
            tr("Cmd", "Shortcut key");
con's avatar
con committed
427
#else
428
            tr("Alt", "Shortcut key");
con's avatar
con committed
429
#endif
430
431
432
433
434
        tips.append(tr("You can switch between Qt Creator's modes using <tt>Ctrl+number</tt>:<ul>"
                       "<li>1 - Welcome</li><li>2 - Edit</li><li>3 - Debug</li><li>4 - Projects</li><li>5 - Help</li>"
                       "<li></li><li>6 - Output</li></ul>"));
        //:%1 gets replaced by Alt (Win/Unix) or Cmd (Mac)
        tips.append(tr("You can show and hide the side bar using <tt>%1+0<tt>.").arg(altShortcut));
435
436
        tips.append(tr("You can fine tune the <tt>Find</tt> function by selecting &quot;Whole Words&quot; "
                       "or &quot;Case Sensitive&quot;. Simply click on the icons on the right end of the line edit."));                       
437
        tips.append(tr("If you add <a href=\"qthelp://com.nokia.qtcreator/doc/creator-external-library-handling.html\""
438
439
                       ">external libraries</a>, Qt Creator will automatically offer syntax highlighting "
                        "and code completion."));
Daniel Molkentin's avatar
Daniel Molkentin committed
440
441
442
        tips.append(tr("The code completion is CamelCase-aware. For example, to complete <tt>namespaceUri</tt> "
                       "you can just type <tt>nU</tt> and hit <tt>Ctrl+Space</tt>."));
        tips.append(tr("You can force code completion at any time using <tt>Ctrl+Space</tt>."));
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
        tips.append(tr("You can start Qt Creator with a session by calling <tt>qtcreator &lt;sessionname&gt;</tt>."));
        tips.append(tr("You can return to edit mode from any other mode at any time by hitting <tt>Escape</tt>."));
        //:%1 gets replaced by Alt (Win/Unix) or Cmd (Mac)
        tips.append(tr("You can switch between the output pane by hitting <tt>%1+n</tt> where n is the number denoted "
                       "on the buttons at the window bottom:"
                       "<ul><li>1 - Build Issues</li><li>2 - Search Results</li><li>3 - Application Output</li>"
                       "<li>4 - Compile Output</li></ul>").arg(altShortcut));
        tips.append(tr("You can quickly search methods, classes, help and more using the "
                       "<a href=\"qthelp://com.nokia.qtcreator/doc/creator-navigation.html\">Locator bar</a> (<tt>Ctrl+K</tt>)."));
        tips.append(tr("You can add custom build steps in the "
                       "<a href=\"qthelp://com.nokia.qtcreator/doc/creator-build-settings.html\">build settings</a>."));
        tips.append(tr("Within a session, you can add "
                       "<a href=\"qthelp://com.nokia.qtcreator/doc/creator-build-settings.html#dependencies\">dependencies</a> between projects."));
        tips.append(tr("You can set the preferred editor encoding for every project in <tt>Projects -> Editor Settings -> Default Encoding</tt>."));
        tips.append(tr("You can modify the binary that is being executed when you press the <tt>Run</tt> button: Add a <tt>Custom Executable</tt> "
                       "by clicking the <tt>+</tt> button in <tt>Projects -> Run Settings -> Run Configuration</tt> and then select the new "
                       "target in the combo box."));
        tips.append(tr("You can use Qt Creator with a number of <a href=\"qthelp://com.nokia.qtcreator/doc/creator-version-control.html\">"
                       "revision control systems</a> such as Subversion, Perforce and Git."));
        tips.append(tr("In the editor, <tt>F2</tt> toggles declaration and definition while <tt>F4</tt> toggles header file and source file."));
463
    }
464
    return tips;
465
466
}

467
468
469
470
// ---  WelcomeModeButton

WelcomeModeButton::WelcomeModeButton(QWidget *parent) :
        QLabel(parent),
471
472
        m_isPressed(false),
        m_isInited(false)
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
{
    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();
con's avatar
con committed
489
490
491
    }
}

492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
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);
}

514
515
516
517
518
519
520
521
522
523
// ---  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 *)));
}

524
525
526
527
528
QSize WelcomeModeTreeWidget::minimumSizeHint() const
{
    return QSize();
}

529
530
531
532
533
534
535
536
537
538
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));
539
540
    QLabel *lbl = new QLabel(label);
    lbl->setTextInteractionFlags(Qt::NoTextInteraction);
541
542
543
544
545
546
547
548
549
550
551
552
    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;
}

553
void WelcomeModeTreeWidget::slotAddNewsItem(const QString &title, const QString &description, const QString &link)
554
{
555
556
557
558
559
560
561
    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));
562
563
}

564
565
566
567
568
void WelcomeModeTreeWidget::slotItemClicked(QTreeWidgetItem *item)
{
    emit activated(item->data(0, Qt::UserRole).toString());
}

con's avatar
con committed
569
570
} // namespace Internal
} // namespace Core