~ubuntu-branches/ubuntu/precise/fritzing/precise

« back to all changes in this revision

Viewing changes to src/fsplashscreen.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Georges Khaznadar
  • Date: 2011-08-26 10:11:05 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110826101105-w5hmn7zcf93ig5v6
Tags: 0.6.3b-1
* upgrapded to the newer upstream version
* parameters of the function GraphicsUtils::distanceFromLine in 
  src/svg/groundplanegenerator.cpp:767 are now declared as doubles,
  which Closes: #636441
* the new version fixes src/utils/folderutils.cpp, which
  Closes: #636061

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************
2
 
 
3
 
Part of the Fritzing project - http://fritzing.org
4
 
Copyright (c) 2007-2010 Fachhochschule Potsdam - http://fh-potsdam.de
5
 
 
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.
10
 
 
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.
15
 
 
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/>.
18
 
 
19
 
********************************************************************
20
 
 
21
 
$Revision: 4183 $:
22
 
$Author: cohen@irascible.com $:
23
 
$Date: 2010-05-06 22:30:19 +0200 (Thu, 06 May 2010) $
24
 
 
25
 
********************************************************************/
26
 
 
27
 
#include "fsplashscreen.h"
28
 
#include "utils/misc.h"
29
 
 
30
 
#include <QTextDocument>
31
 
#include <QTextCursor>
32
 
 
33
 
FSplashScreen::FSplashScreen(const QPixmap & pixmap, Qt::WindowFlags f ) : QSplashScreen(pixmap, f)
34
 
{
35
 
}
36
 
 
37
 
FSplashScreen::~FSplashScreen() {
38
 
        foreach (MessageThing * messageThing, m_messages) {
39
 
                delete messageThing;
40
 
        }
41
 
        foreach (PixmapThing * pixmapThing, m_pixmaps) {
42
 
                delete pixmapThing;
43
 
        }
44
 
}
45
 
 
46
 
 
47
 
void FSplashScreen::showMessage(const QString &message, QRect rect, int alignment, const QColor &color)
48
 
{
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);
55
 
        repaint();
56
 
}
57
 
 
58
 
 
59
 
int FSplashScreen::showPixmap(const QPixmap & pixmap, QPoint point)
60
 
{
61
 
        PixmapThing * pixmapThing = new PixmapThing;
62
 
        pixmapThing->rect = QRect(point, QPoint(-1,-1));
63
 
        pixmapThing->pixmap = pixmap;
64
 
        m_pixmaps.append(pixmapThing);
65
 
        repaint();
66
 
 
67
 
        return m_pixmaps.count() - 1;
68
 
}
69
 
 
70
 
void FSplashScreen::showProgress(int index, qreal progress) {
71
 
        if (index < 0) return;
72
 
        if (index >= m_pixmaps.count()) return;
73
 
 
74
 
        int w = (int) (this->width() * progress);
75
 
        PixmapThing * pixmapThing = m_pixmaps[index];
76
 
        pixmapThing->rect.setWidth(w);
77
 
        repaint();
78
 
}
79
 
 
80
 
 
81
 
void FSplashScreen::drawContents ( QPainter * painter )
82
 
{
83
 
        // copied from QSplashScreen::drawContents
84
 
        painter->setRenderHint ( QPainter::Antialiasing, true );                                // TODO: might need to be in the stylesheet?
85
 
 
86
 
        // pixmaps first, since they go beneath text
87
 
        foreach (PixmapThing * pixmapThing, m_pixmaps) {
88
 
                painter->drawPixmap(pixmapThing->rect, pixmapThing->pixmap);
89
 
        }
90
 
 
91
 
        foreach (MessageThing * messageThing, m_messages) {
92
 
                painter->setPen(messageThing->color);
93
 
                if (Qt::mightBeRichText(messageThing->message)) {
94
 
                        QTextDocument doc;
95
 
        #ifdef QT_NO_TEXTHTMLPARSER
96
 
                        doc.setPlainText(messageThing->message);
97
 
        #else
98
 
                        doc.setHtml(messageThing->message);
99
 
        #endif
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);
106
 
                        painter->save();
107
 
                        painter->translate(messageThing->rect.topLeft());
108
 
                        doc.drawContents(painter);
109
 
                        painter->restore();
110
 
                } else {
111
 
                        painter->drawText(messageThing->rect, messageThing->alignment, messageThing->message);
112
 
                }
113
 
        }
114
 
}
115
 
 
 
1
/*******************************************************************
 
2
 
 
3
Part of the Fritzing project - http://fritzing.org
 
4
Copyright (c) 2007-2011 Fachhochschule Potsdam - http://fh-potsdam.de
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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/>.
 
18
 
 
19
********************************************************************
 
20
 
 
21
$Revision: 5309 $:
 
22
$Author: cohen@irascible.com $:
 
23
$Date: 2011-07-30 21:17:22 +0200 (Sat, 30 Jul 2011) $
 
24
 
 
25
********************************************************************/
 
26
 
 
27
#include "fsplashscreen.h"
 
28
#include "utils/misc.h"
 
29
 
 
30
#include <QTextDocument>
 
31
#include <QTextCursor>
 
32
 
 
33
FSplashScreen::FSplashScreen(const QPixmap & pixmap, Qt::WindowFlags f ) : QSplashScreen(pixmap, f)
 
34
{
 
35
}
 
36
 
 
37
FSplashScreen::~FSplashScreen() {
 
38
        foreach (MessageThing * messageThing, m_messages) {
 
39
                delete messageThing;
 
40
        }
 
41
        foreach (PixmapThing * pixmapThing, m_pixmaps) {
 
42
                delete pixmapThing;
 
43
        }
 
44
}
 
45
 
 
46
 
 
47
void FSplashScreen::showMessage(const QString &message, QRect rect, int alignment, const QColor &color)
 
48
{
 
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);
 
55
        repaint();
 
56
}
 
57
 
 
58
 
 
59
int FSplashScreen::showPixmap(const QPixmap & pixmap, QPoint point)
 
60
{
 
61
        PixmapThing * pixmapThing = new PixmapThing;
 
62
        pixmapThing->rect = QRect(point, QPoint(-1,-1));
 
63
        pixmapThing->pixmap = pixmap;
 
64
        m_pixmaps.append(pixmapThing);
 
65
        repaint();
 
66
 
 
67
        return m_pixmaps.count() - 1;
 
68
}
 
69
 
 
70
void FSplashScreen::showProgress(int index, double progress) {
 
71
        if (index < 0) return;
 
72
        if (index >= m_pixmaps.count()) return;
 
73
 
 
74
        int w = (int) (this->width() * progress);
 
75
        PixmapThing * pixmapThing = m_pixmaps[index];
 
76
        pixmapThing->rect.setWidth(w);
 
77
        repaint();
 
78
}
 
79
 
 
80
 
 
81
void FSplashScreen::drawContents ( QPainter * painter )
 
82
{
 
83
        // copied from QSplashScreen::drawContents
 
84
        painter->setRenderHint ( QPainter::Antialiasing, true );                                // TODO: might need to be in the stylesheet?
 
85
 
 
86
        // pixmaps first, since they go beneath text
 
87
        foreach (PixmapThing * pixmapThing, m_pixmaps) {
 
88
                painter->drawPixmap(pixmapThing->rect, pixmapThing->pixmap);
 
89
        }
 
90
 
 
91
        foreach (MessageThing * messageThing, m_messages) {
 
92
                painter->setPen(messageThing->color);
 
93
                if (Qt::mightBeRichText(messageThing->message)) {
 
94
                        QTextDocument doc;
 
95
        #ifdef QT_NO_TEXTHTMLPARSER
 
96
                        doc.setPlainText(messageThing->message);
 
97
        #else
 
98
                        doc.setHtml(messageThing->message);
 
99
        #endif
 
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);
 
106
                        painter->save();
 
107
                        painter->translate(messageThing->rect.topLeft());
 
108
                        doc.drawContents(painter);
 
109
                        painter->restore();
 
110
                } else {
 
111
                        painter->drawText(messageThing->rect, messageThing->alignment, messageThing->message);
 
112
                }
 
113
        }
 
114
}
 
115