Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / libs / utils / welcomemodetreewidget.cpp
blobf5e72a74d367ca28690d004de75013d2d55bfe94
1 /**
2 ******************************************************************************
4 * @file welcomemodetreewidget.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @brief
8 * @see The GNU Public License (GPL) Version 3
9 * @defgroup
10 * @{
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "welcomemodetreewidget.h"
31 #include <QLabel>
32 #include <QAction>
33 #include <QBoxLayout>
34 #include <QHeaderView>
36 namespace Utils {
37 void WelcomeModeLabel::setStyledText(const QString &text)
39 QString rc = QLatin1String(
40 "<html><head><style type=\"text/css\">p, li { white-space: pre-wrap; }</style></head>"
41 "<body style=\" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;\">"
42 "<p style=\" margin-top:16px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
43 "<span style=\" font-size:x-large; color:#555555;\">");
45 rc += text;
46 rc += QLatin1String("</span></p><hr/></body></html>");
47 setText(rc);
50 struct WelcomeModeTreeWidgetPrivate {
51 WelcomeModeTreeWidgetPrivate() {}
52 QIcon bullet;
55 WelcomeModeTreeWidget::WelcomeModeTreeWidget(QWidget *parent) :
56 QTreeWidget(parent), m_d(new WelcomeModeTreeWidgetPrivate)
58 m_d->bullet = QIcon(QLatin1String(":/welcome/images/list_bullet_arrow.png"));
59 connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
60 SLOT(slotItemClicked(QTreeWidgetItem *)));
62 viewport()->setAutoFillBackground(false);
65 WelcomeModeTreeWidget::~WelcomeModeTreeWidget()
67 delete m_d;
70 QSize WelcomeModeTreeWidget::minimumSizeHint() const
72 return QSize();
75 QSize WelcomeModeTreeWidget::sizeHint() const
77 return QSize(QTreeWidget::sizeHint().width(), 30 * topLevelItemCount());
80 QTreeWidgetItem *WelcomeModeTreeWidget::addItem(const QString &label, const QString &data, const QString &toolTip)
82 QTreeWidgetItem *item = new QTreeWidgetItem(this);
84 item->setIcon(0, m_d->bullet);
85 item->setSizeHint(0, QSize(24, 30));
86 QLabel *lbl = new QLabel(label);
87 lbl->setTextInteractionFlags(Qt::NoTextInteraction);
88 lbl->setCursor(QCursor(Qt::PointingHandCursor));
89 lbl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
90 QBoxLayout *lay = new QVBoxLayout;
91 lay->setContentsMargins(3, 2, 0, 0);
92 lay->addWidget(lbl);
93 QWidget *wdg = new QWidget;
94 wdg->setLayout(lay);
95 setItemWidget(item, 1, wdg);
96 item->setData(0, Qt::UserRole, data);
97 if (!toolTip.isEmpty()) {
98 wdg->setToolTip(toolTip);
100 return item;
103 void WelcomeModeTreeWidget::slotAddNewsItem(const QString &title, const QString &description, const QString &link)
105 int itemWidth = width() - header()->sectionSize(0);
106 QFont f = font();
107 QString elidedText = QFontMetrics(f).elidedText(description, Qt::ElideRight, itemWidth);
109 f.setBold(true);
110 QString elidedTitle = QFontMetrics(f).elidedText(title, Qt::ElideRight, itemWidth);
111 QString data = QString::fromLatin1("<b>%1</b><br />%2").arg(elidedTitle).arg(elidedText);
112 addTopLevelItem(addItem(data, link, link));
115 void WelcomeModeTreeWidget::slotItemClicked(QTreeWidgetItem *item)
117 emit activated(item->data(0, Qt::UserRole).toString());