PageRenderTime 28ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/qtopiacore/qt/tools/assistant/tools/assistant/aboutdialog.cpp

https://github.com/Fale/qtmoko
C++ | 171 lines | 108 code | 23 blank | 40 comment | 17 complexity | 551b7e505140d9ce87e2a2dc692f5041 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, LGPL-3.0, BSD-3-Clause, GPL-3.0
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
  4. ** Contact: Qt Software Information (qt-info@nokia.com)
  5. **
  6. ** This file is part of the Qt Assistant of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial Usage
  10. ** Licensees holding valid Qt Commercial licenses may use this file in
  11. ** accordance with the Qt Commercial License Agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and Nokia.
  14. **
  15. ** GNU Lesser General Public License Usage
  16. ** Alternatively, this file may be used under the terms of the GNU Lesser
  17. ** General Public License version 2.1 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.LGPL included in the
  19. ** packaging of this file. Please review the following information to
  20. ** ensure the GNU Lesser General Public License version 2.1 requirements
  21. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  22. **
  23. ** In addition, as a special exception, Nokia gives you certain
  24. ** additional rights. These rights are described in the Nokia Qt LGPL
  25. ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
  26. ** package.
  27. **
  28. ** GNU General Public License Usage
  29. ** Alternatively, this file may be used under the terms of the GNU
  30. ** General Public License version 3.0 as published by the Free Software
  31. ** Foundation and appearing in the file LICENSE.GPL included in the
  32. ** packaging of this file. Please review the following information to
  33. ** ensure the GNU General Public License version 3.0 requirements will be
  34. ** met: http://www.gnu.org/copyleft/gpl.html.
  35. **
  36. ** If you are unsure which license is appropriate for your use, please
  37. ** contact the sales department at qt-sales@nokia.com.
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #include <QtCore/QBuffer>
  42. #include <QtGui/QLabel>
  43. #include <QtGui/QPushButton>
  44. #include <QtGui/QLayout>
  45. #include <QtGui/QApplication>
  46. #include <QtGui/QDesktopWidget>
  47. #include <QtGui/QMessageBox>
  48. #include <QtGui/QDesktopServices>
  49. #include "aboutdialog.h"
  50. QT_BEGIN_NAMESPACE
  51. AboutLabel::AboutLabel(QWidget *parent)
  52. : QTextBrowser(parent)
  53. {
  54. setFrameStyle(QFrame::NoFrame);
  55. QPalette p;
  56. p.setColor(QPalette::Base, p.color(QPalette::Background));
  57. setPalette(p);
  58. }
  59. void AboutLabel::setText(const QString &text, const QByteArray &resources)
  60. {
  61. QDataStream in(resources);
  62. in >> m_resourceMap;
  63. QTextBrowser::setText(text);
  64. }
  65. QSize AboutLabel::minimumSizeHint() const
  66. {
  67. QTextDocument *doc = document();
  68. doc->adjustSize();
  69. return QSize(int(doc->size().width()), int(doc->size().height()));
  70. }
  71. QVariant AboutLabel::loadResource(int type, const QUrl &name)
  72. {
  73. if (type == 2 || type == 3) {
  74. if (m_resourceMap.contains(name.toString())) {
  75. return m_resourceMap.value(name.toString());
  76. }
  77. }
  78. return QVariant();
  79. }
  80. void AboutLabel::setSource(const QUrl &url)
  81. {
  82. if (url.isValid()
  83. && (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("ftp")
  84. || url.scheme() == QLatin1String("mailto") || url.path().endsWith(QLatin1String("pdf")))) {
  85. if (!QDesktopServices::openUrl(url)) {
  86. QMessageBox::warning(this, tr("Warning"),
  87. tr("Unable to launch external application.\n"),
  88. tr("OK"));
  89. }
  90. }
  91. }
  92. AboutDialog::AboutDialog(QWidget *parent)
  93. : QDialog(parent, Qt::MSWindowsFixedSizeDialogHint|Qt::WindowTitleHint|Qt::WindowSystemMenuHint)
  94. {
  95. m_pixmapLabel = 0;
  96. m_aboutLabel = new AboutLabel();
  97. m_closeButton = new QPushButton();
  98. m_closeButton->setText(tr("&Close"));
  99. connect(m_closeButton, SIGNAL(clicked()),
  100. this, SLOT(close()));
  101. m_layout = new QGridLayout(this);
  102. m_layout->addWidget(m_aboutLabel, 1, 0, 1, -1);
  103. m_layout->addItem(new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed), 2, 1, 1, 1);
  104. m_layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding), 3, 0, 1, 1);
  105. m_layout->addWidget(m_closeButton, 3, 1, 1, 1);
  106. m_layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding), 3, 2, 1, 1);
  107. }
  108. void AboutDialog::setText(const QString &text, const QByteArray &resources)
  109. {
  110. m_aboutLabel->setText(text, resources);
  111. updateSize();
  112. }
  113. void AboutDialog::setPixmap(const QPixmap &pixmap)
  114. {
  115. if (!m_pixmapLabel) {
  116. m_pixmapLabel = new QLabel();
  117. m_layout->addWidget(m_pixmapLabel, 0, 0, 1, -1, Qt::AlignCenter);
  118. }
  119. m_pixmapLabel->setPixmap(pixmap);
  120. updateSize();
  121. }
  122. QString AboutDialog::documentTitle() const
  123. {
  124. return m_aboutLabel->documentTitle();
  125. }
  126. void AboutDialog::updateSize()
  127. {
  128. QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();
  129. int limit = qMin(screenSize.width()/2, 500);
  130. #ifdef Q_WS_MAC
  131. limit = qMin(screenSize.width()/2, 420);
  132. #endif
  133. layout()->activate();
  134. int width = layout()->totalMinimumSize().width();
  135. if (width > limit)
  136. width = limit;
  137. QFontMetrics fm(qApp->font("QWorkspaceTitleBar"));
  138. int windowTitleWidth = qMin(fm.width(windowTitle()) + 50, limit);
  139. if (windowTitleWidth > width)
  140. width = windowTitleWidth;
  141. layout()->activate();
  142. int height = (layout()->hasHeightForWidth())
  143. ? layout()->totalHeightForWidth(width)
  144. : layout()->totalMinimumSize().height();
  145. setFixedSize(width, height);
  146. QCoreApplication::removePostedEvents(this, QEvent::LayoutRequest);
  147. }
  148. QT_END_NAMESPACE