1
/*******************************************************************
3
Part of the Fritzing project - http://fritzing.org
4
Copyright (c) 2007-2010 Fachhochschule Potsdam - http://fh-potsdam.de
6
Fritzing is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
11
Fritzing is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
19
********************************************************************
22
$Author: cohen@irascible.com $:
23
$Date: 2010-05-06 22:30:19 +0200 (Thu, 06 May 2010) $
25
********************************************************************/
27
#include "fsplashscreen.h"
28
#include "utils/misc.h"
30
#include <QTextDocument>
31
#include <QTextCursor>
33
FSplashScreen::FSplashScreen(const QPixmap & pixmap, Qt::WindowFlags f ) : QSplashScreen(pixmap, f)
37
FSplashScreen::~FSplashScreen() {
38
foreach (MessageThing * messageThing, m_messages) {
41
foreach (PixmapThing * pixmapThing, m_pixmaps) {
47
void FSplashScreen::showMessage(const QString &message, QRect rect, int alignment, const QColor &color)
49
MessageThing * messageThing = new MessageThing;
50
messageThing->alignment = alignment;
51
messageThing->color = color;
52
messageThing->rect = rect;
53
messageThing->message = message;
54
m_messages.append(messageThing);
59
int FSplashScreen::showPixmap(const QPixmap & pixmap, QPoint point)
61
PixmapThing * pixmapThing = new PixmapThing;
62
pixmapThing->rect = QRect(point, QPoint(-1,-1));
63
pixmapThing->pixmap = pixmap;
64
m_pixmaps.append(pixmapThing);
67
return m_pixmaps.count() - 1;
70
void FSplashScreen::showProgress(int index, qreal progress) {
71
if (index < 0) return;
72
if (index >= m_pixmaps.count()) return;
74
int w = (int) (this->width() * progress);
75
PixmapThing * pixmapThing = m_pixmaps[index];
76
pixmapThing->rect.setWidth(w);
81
void FSplashScreen::drawContents ( QPainter * painter )
83
// copied from QSplashScreen::drawContents
84
painter->setRenderHint ( QPainter::Antialiasing, true ); // TODO: might need to be in the stylesheet?
86
// pixmaps first, since they go beneath text
87
foreach (PixmapThing * pixmapThing, m_pixmaps) {
88
painter->drawPixmap(pixmapThing->rect, pixmapThing->pixmap);
91
foreach (MessageThing * messageThing, m_messages) {
92
painter->setPen(messageThing->color);
93
if (Qt::mightBeRichText(messageThing->message)) {
95
#ifdef QT_NO_TEXTHTMLPARSER
96
doc.setPlainText(messageThing->message);
98
doc.setHtml(messageThing->message);
100
doc.setTextWidth(messageThing->rect.width());
101
QTextCursor cursor(&doc);
102
cursor.select(QTextCursor::Document);
103
QTextBlockFormat fmt;
104
fmt.setAlignment(Qt::Alignment(messageThing->alignment));
105
cursor.mergeBlockFormat(fmt);
107
painter->translate(messageThing->rect.topLeft());
108
doc.drawContents(painter);
111
painter->drawText(messageThing->rect, messageThing->alignment, messageThing->message);
1
/*******************************************************************
3
Part of the Fritzing project - http://fritzing.org
4
Copyright (c) 2007-2011 Fachhochschule Potsdam - http://fh-potsdam.de
6
Fritzing is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
11
Fritzing is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
19
********************************************************************
22
$Author: cohen@irascible.com $:
23
$Date: 2011-07-30 21:17:22 +0200 (Sat, 30 Jul 2011) $
25
********************************************************************/
27
#include "fsplashscreen.h"
28
#include "utils/misc.h"
30
#include <QTextDocument>
31
#include <QTextCursor>
33
FSplashScreen::FSplashScreen(const QPixmap & pixmap, Qt::WindowFlags f ) : QSplashScreen(pixmap, f)
37
FSplashScreen::~FSplashScreen() {
38
foreach (MessageThing * messageThing, m_messages) {
41
foreach (PixmapThing * pixmapThing, m_pixmaps) {
47
void FSplashScreen::showMessage(const QString &message, QRect rect, int alignment, const QColor &color)
49
MessageThing * messageThing = new MessageThing;
50
messageThing->alignment = alignment;
51
messageThing->color = color;
52
messageThing->rect = rect;
53
messageThing->message = message;
54
m_messages.append(messageThing);
59
int FSplashScreen::showPixmap(const QPixmap & pixmap, QPoint point)
61
PixmapThing * pixmapThing = new PixmapThing;
62
pixmapThing->rect = QRect(point, QPoint(-1,-1));
63
pixmapThing->pixmap = pixmap;
64
m_pixmaps.append(pixmapThing);
67
return m_pixmaps.count() - 1;
70
void FSplashScreen::showProgress(int index, double progress) {
71
if (index < 0) return;
72
if (index >= m_pixmaps.count()) return;
74
int w = (int) (this->width() * progress);
75
PixmapThing * pixmapThing = m_pixmaps[index];
76
pixmapThing->rect.setWidth(w);
81
void FSplashScreen::drawContents ( QPainter * painter )
83
// copied from QSplashScreen::drawContents
84
painter->setRenderHint ( QPainter::Antialiasing, true ); // TODO: might need to be in the stylesheet?
86
// pixmaps first, since they go beneath text
87
foreach (PixmapThing * pixmapThing, m_pixmaps) {
88
painter->drawPixmap(pixmapThing->rect, pixmapThing->pixmap);
91
foreach (MessageThing * messageThing, m_messages) {
92
painter->setPen(messageThing->color);
93
if (Qt::mightBeRichText(messageThing->message)) {
95
#ifdef QT_NO_TEXTHTMLPARSER
96
doc.setPlainText(messageThing->message);
98
doc.setHtml(messageThing->message);
100
doc.setTextWidth(messageThing->rect.width());
101
QTextCursor cursor(&doc);
102
cursor.select(QTextCursor::Document);
103
QTextBlockFormat fmt;
104
fmt.setAlignment(Qt::Alignment(messageThing->alignment));
105
cursor.mergeBlockFormat(fmt);
107
painter->translate(messageThing->rect.topLeft());
108
doc.drawContents(painter);
111
painter->drawText(messageThing->rect, messageThing->alignment, messageThing->message);