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

« back to all changes in this revision

Viewing changes to src/help/sketchmainhelp.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: 4483 $:
22
 
$Author: cohen@irascible.com $:
23
 
$Date: 2010-09-30 13:25:30 +0200 (Thu, 30 Sep 2010) $
24
 
 
25
 
********************************************************************/
26
 
 
27
 
#include <QHBoxLayout>
28
 
#include <QGraphicsScene>
29
 
#include <QFile>
30
 
#include <QTimer>
31
 
#include <QSettings>
32
 
#include <QPainter>
33
 
 
34
 
#include "sketchmainhelp.h"
35
 
#include "../utils/expandinglabel.h"
36
 
 
37
 
qreal SketchMainHelp::OpacityLevel = 0.5;
38
 
 
39
 
SketchMainHelpCloseButton::SketchMainHelpCloseButton(const QString &imagePath, QWidget *parent)
40
 
        :QLabel(parent)
41
 
{
42
 
        m_pixmap = QPixmap(
43
 
                QString(":/resources/images/inViewHelpCloseButton%1.png").arg(imagePath));
44
 
        setPixmap(m_pixmap);
45
 
        setFixedHeight(m_pixmap.height());
46
 
}
47
 
 
48
 
void SketchMainHelpCloseButton::mousePressEvent(QMouseEvent * event) {
49
 
        emit clicked();
50
 
        QLabel::mousePressEvent(event);
51
 
}
52
 
 
53
 
void SketchMainHelpCloseButton::doShow() {
54
 
        setPixmap(m_pixmap);
55
 
}
56
 
 
57
 
void SketchMainHelpCloseButton::doHide() {
58
 
        setPixmap(0);
59
 
}
60
 
 
61
 
 
62
 
//////////////////////////////////////////////////////////////
63
 
 
64
 
SketchMainHelpPrivate::SketchMainHelpPrivate (
65
 
                const QString &viewString,
66
 
                const QString &htmlText,
67
 
                SketchMainHelp *parent)
68
 
        : QFrame()
69
 
{
70
 
        setObjectName("sketchMainHelp"+viewString);
71
 
        m_parent = parent;
72
 
 
73
 
        QFrame *main = new QFrame(this);
74
 
        QHBoxLayout *mainLayout = new QHBoxLayout(main);
75
 
 
76
 
        QLabel *imageLabel = new QLabel(this);
77
 
        QLabel *imageLabelAux = new QLabel(imageLabel);
78
 
        imageLabelAux->setObjectName(QString("inviewHelpImage%1").arg(viewString));
79
 
        QPixmap pixmap(QString(":/resources/images/helpImage%1.png").arg(viewString));
80
 
        imageLabelAux->setPixmap(pixmap);
81
 
        imageLabel->setFixedWidth(pixmap.width());
82
 
        imageLabel->setFixedHeight(pixmap.height());
83
 
        imageLabelAux->setFixedWidth(pixmap.width());
84
 
        imageLabelAux->setFixedHeight(pixmap.height());
85
 
 
86
 
        ExpandingLabel *textLabel = new ExpandingLabel(this);
87
 
        textLabel->setLabelText(htmlText);
88
 
        textLabel->setFixedWidth(430 - 41 - pixmap.width());
89
 
        textLabel->allTextVisible();
90
 
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
91
 
        textLabel->setToolTip("");
92
 
        textLabel->setAlignment(Qt::AlignLeft);
93
 
 
94
 
        mainLayout->setSpacing(6);
95
 
        mainLayout->setMargin(2);
96
 
        mainLayout->addWidget(imageLabel);
97
 
        mainLayout->addWidget(textLabel);
98
 
        setFixedWidth(430);
99
 
 
100
 
        QVBoxLayout *layout = new QVBoxLayout(this);
101
 
        m_closeButton = new SketchMainHelpCloseButton(viewString,this);
102
 
        connect(m_closeButton, SIGNAL(clicked()), this, SLOT(doClose()));
103
 
 
104
 
        QFrame *bottomMargin = new QFrame(this);
105
 
        bottomMargin->setFixedHeight(m_closeButton->height());
106
 
 
107
 
        layout->addWidget(m_closeButton);
108
 
        layout->addWidget(main);
109
 
        layout->addWidget(bottomMargin);
110
 
 
111
 
        layout->setSpacing(0);
112
 
        layout->setMargin(2);
113
 
 
114
 
        m_shouldGetTransparent = false;
115
 
        //m_closeButton->doHide();
116
 
 
117
 
        QFile styleSheet(":/resources/styles/inviewhelp.qss");
118
 
    if (!styleSheet.open(QIODevice::ReadOnly)) {
119
 
                qWarning("Unable to open :/resources/styles/inviewhelp.qss");
120
 
        } else {
121
 
                setStyleSheet(styleSheet.readAll());
122
 
        }
123
 
}
124
 
 
125
 
void SketchMainHelpPrivate::doClose() {
126
 
        emit aboutToClose();
127
 
        m_parent->doClose();
128
 
}
129
 
 
130
 
void SketchMainHelpPrivate::enterEvent(QEvent * event) {
131
 
        enterEventAux();
132
 
        QFrame::enterEvent(event);
133
 
}
134
 
 
135
 
void SketchMainHelpPrivate::enterEventAux() {
136
 
        if(m_shouldGetTransparent) {
137
 
                setWindowOpacity(1.0);
138
 
                QTimer::singleShot(2000, this, SLOT(setTransparent()));
139
 
        }
140
 
        //m_closeButton->doShow();
141
 
}
142
 
 
143
 
void SketchMainHelpPrivate::setTransparent() {
144
 
        setWindowOpacity(SketchMainHelp::OpacityLevel);
145
 
}
146
 
 
147
 
void SketchMainHelpPrivate::leaveEvent(QEvent * event) {
148
 
        leaveEventAux();
149
 
        QFrame::leaveEvent(event);
150
 
}
151
 
 
152
 
void SketchMainHelpPrivate::leaveEventAux() {
153
 
        if(m_shouldGetTransparent) {
154
 
                setTransparent();
155
 
        }
156
 
        //m_closeButton->doHide();
157
 
}
158
 
 
159
 
bool SketchMainHelpPrivate::forwardMousePressEvent(QMouseEvent * event)
160
 
{
161
 
        QPoint p = m_closeButton->mapFromParent(event->pos());
162
 
        if (m_closeButton->rect().contains(p)) {
163
 
                doClose();
164
 
                return true;
165
 
        }
166
 
 
167
 
        return false;
168
 
}
169
 
 
170
 
//////////////////////////////////////////////////////////////
171
 
 
172
 
SketchMainHelp::SketchMainHelp (
173
 
                const QString &viewString,
174
 
                const QString &htmlText,
175
 
                bool doShow
176
 
        ) : QGraphicsProxyWidget()
177
 
{
178
 
        m_mouseWithin = false;
179
 
        m_visible = true;
180
 
        m_pixmap = NULL;
181
 
        setObjectName("sketchMainHelp"+viewString);
182
 
        m_son = new SketchMainHelpPrivate(viewString, htmlText, this);
183
 
        setWidget(m_son);
184
 
        if(!doShow) loadState();
185
 
}
186
 
 
187
 
SketchMainHelp::~SketchMainHelp()
188
 
{
189
 
        if (m_pixmap != NULL) {
190
 
                delete m_pixmap;
191
 
                m_pixmap = NULL;
192
 
        }
193
 
}
194
 
 
195
 
void SketchMainHelp::doClose() {
196
 
        doSetVisible(false);
197
 
}
198
 
 
199
 
void SketchMainHelp::doSetVisible(bool visible) {
200
 
        m_visible = visible;
201
 
        setVisible(visible);
202
 
        saveState();
203
 
}
204
 
 
205
 
void SketchMainHelp::setTransparent() {
206
 
        m_son->setWindowOpacity(OpacityLevel);
207
 
        m_son->m_shouldGetTransparent = true;
208
 
}
209
 
 
210
 
void SketchMainHelp::saveState() {
211
 
        QSettings settings;
212
 
        QString prop = objectName()+"Visibility";
213
 
        settings.setValue(prop,QVariant::fromValue(m_visible));
214
 
}
215
 
 
216
 
void SketchMainHelp::loadState() {
217
 
        QSettings settings;
218
 
        QString prop = objectName()+"Visibility";
219
 
        bool visible = settings.contains(prop)
220
 
                ? settings.value(prop).toBool()
221
 
                : true;
222
 
        doSetVisible(visible);
223
 
}
224
 
 
225
 
const QPixmap & SketchMainHelp::getPixmap() {
226
 
        if (m_pixmap == NULL) {
227
 
                m_pixmap = new QPixmap(m_son->size());
228
 
                m_son->render(m_pixmap);
229
 
        }
230
 
 
231
 
        return *m_pixmap;
232
 
}
233
 
 
234
 
bool SketchMainHelp::getVisible() {
235
 
        return m_visible;
236
 
}
237
 
 
238
 
bool SketchMainHelp::setMouseWithin(bool within) {
239
 
        if (within == m_mouseWithin) return false;
240
 
 
241
 
        if (m_pixmap) {
242
 
                delete m_pixmap;
243
 
                m_pixmap = NULL;
244
 
        }
245
 
        m_mouseWithin = within;
246
 
        (within) ? m_son->enterEventAux() : m_son->leaveEventAux();
247
 
        return true;
248
 
}
249
 
 
250
 
bool SketchMainHelp::forwardMousePressEvent(QMouseEvent * event) {
251
 
        bool result = m_son->forwardMousePressEvent(event);
252
 
 
253
 
        if (result) {
254
 
                if (m_pixmap) {
255
 
                        delete m_pixmap;
256
 
                        m_pixmap = NULL;
257
 
                }
258
 
        }
259
 
 
260
 
        return result;
261
 
}
 
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 <QHBoxLayout>
 
28
#include <QGraphicsScene>
 
29
#include <QFile>
 
30
#include <QTimer>
 
31
#include <QSettings>
 
32
#include <QPainter>
 
33
 
 
34
#include "sketchmainhelp.h"
 
35
#include "../utils/expandinglabel.h"
 
36
 
 
37
double SketchMainHelp::OpacityLevel = 0.5;
 
38
 
 
39
SketchMainHelpCloseButton::SketchMainHelpCloseButton(const QString &imagePath, QWidget *parent)
 
40
        :QLabel(parent)
 
41
{
 
42
        m_pixmap = QPixmap(
 
43
                QString(":/resources/images/inViewHelpCloseButton%1.png").arg(imagePath));
 
44
        setPixmap(m_pixmap);
 
45
        setFixedHeight(m_pixmap.height());
 
46
}
 
47
 
 
48
void SketchMainHelpCloseButton::mousePressEvent(QMouseEvent * event) {
 
49
        emit clicked();
 
50
        QLabel::mousePressEvent(event);
 
51
}
 
52
 
 
53
void SketchMainHelpCloseButton::doShow() {
 
54
        setPixmap(m_pixmap);
 
55
}
 
56
 
 
57
void SketchMainHelpCloseButton::doHide() {
 
58
        setPixmap(0);
 
59
}
 
60
 
 
61
 
 
62
//////////////////////////////////////////////////////////////
 
63
 
 
64
SketchMainHelpPrivate::SketchMainHelpPrivate (
 
65
                const QString &viewString,
 
66
                const QString &htmlText,
 
67
                SketchMainHelp *parent)
 
68
        : QFrame()
 
69
{
 
70
        setObjectName("sketchMainHelp"+viewString);
 
71
        m_parent = parent;
 
72
 
 
73
        QFrame *main = new QFrame(this);
 
74
        QHBoxLayout *mainLayout = new QHBoxLayout(main);
 
75
 
 
76
        QLabel *imageLabel = new QLabel(this);
 
77
        QLabel *imageLabelAux = new QLabel(imageLabel);
 
78
        imageLabelAux->setObjectName(QString("inviewHelpImage%1").arg(viewString));
 
79
        QPixmap pixmap(QString(":/resources/images/helpImage%1.png").arg(viewString));
 
80
        imageLabelAux->setPixmap(pixmap);
 
81
        imageLabel->setFixedWidth(pixmap.width());
 
82
        imageLabel->setFixedHeight(pixmap.height());
 
83
        imageLabelAux->setFixedWidth(pixmap.width());
 
84
        imageLabelAux->setFixedHeight(pixmap.height());
 
85
 
 
86
        ExpandingLabel *textLabel = new ExpandingLabel(this);
 
87
        textLabel->setLabelText(htmlText);
 
88
        textLabel->setFixedWidth(430 - 41 - pixmap.width());
 
89
        textLabel->allTextVisible();
 
90
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
 
91
        textLabel->setToolTip("");
 
92
        textLabel->setAlignment(Qt::AlignLeft);
 
93
 
 
94
        mainLayout->setSpacing(6);
 
95
        mainLayout->setMargin(2);
 
96
        mainLayout->addWidget(imageLabel);
 
97
        mainLayout->addWidget(textLabel);
 
98
        setFixedWidth(430);
 
99
 
 
100
        QVBoxLayout *layout = new QVBoxLayout(this);
 
101
        m_closeButton = new SketchMainHelpCloseButton(viewString,this);
 
102
        connect(m_closeButton, SIGNAL(clicked()), this, SLOT(doClose()));
 
103
 
 
104
        QFrame *bottomMargin = new QFrame(this);
 
105
        bottomMargin->setFixedHeight(m_closeButton->height());
 
106
 
 
107
        layout->addWidget(m_closeButton);
 
108
        layout->addWidget(main);
 
109
        layout->addWidget(bottomMargin);
 
110
 
 
111
        layout->setSpacing(0);
 
112
        layout->setMargin(2);
 
113
 
 
114
        m_shouldGetTransparent = false;
 
115
        //m_closeButton->doHide();
 
116
 
 
117
        QFile styleSheet(":/resources/styles/inviewhelp.qss");
 
118
    if (!styleSheet.open(QIODevice::ReadOnly)) {
 
119
                qWarning("Unable to open :/resources/styles/inviewhelp.qss");
 
120
        } else {
 
121
                setStyleSheet(styleSheet.readAll());
 
122
        }
 
123
}
 
124
 
 
125
void SketchMainHelpPrivate::doClose() {
 
126
        emit aboutToClose();
 
127
        m_parent->doClose();
 
128
}
 
129
 
 
130
void SketchMainHelpPrivate::enterEvent(QEvent * event) {
 
131
        enterEventAux();
 
132
        QFrame::enterEvent(event);
 
133
}
 
134
 
 
135
void SketchMainHelpPrivate::enterEventAux() {
 
136
        if(m_shouldGetTransparent) {
 
137
                setWindowOpacity(1.0);
 
138
                QTimer::singleShot(2000, this, SLOT(setTransparent()));
 
139
        }
 
140
        //m_closeButton->doShow();
 
141
}
 
142
 
 
143
void SketchMainHelpPrivate::setTransparent() {
 
144
        setWindowOpacity(SketchMainHelp::OpacityLevel);
 
145
}
 
146
 
 
147
void SketchMainHelpPrivate::leaveEvent(QEvent * event) {
 
148
        leaveEventAux();
 
149
        QFrame::leaveEvent(event);
 
150
}
 
151
 
 
152
void SketchMainHelpPrivate::leaveEventAux() {
 
153
        if(m_shouldGetTransparent) {
 
154
                setTransparent();
 
155
        }
 
156
        //m_closeButton->doHide();
 
157
}
 
158
 
 
159
bool SketchMainHelpPrivate::forwardMousePressEvent(QMouseEvent * event)
 
160
{
 
161
        QPoint p = m_closeButton->mapFromParent(event->pos());
 
162
        if (m_closeButton->rect().contains(p)) {
 
163
                doClose();
 
164
                return true;
 
165
        }
 
166
 
 
167
        return false;
 
168
}
 
169
 
 
170
//////////////////////////////////////////////////////////////
 
171
 
 
172
SketchMainHelp::SketchMainHelp (
 
173
                const QString &viewString,
 
174
                const QString &htmlText,
 
175
                bool doShow
 
176
        ) : QGraphicsProxyWidget()
 
177
{
 
178
        m_mouseWithin = false;
 
179
        m_visible = true;
 
180
        m_pixmap = NULL;
 
181
        setObjectName("sketchMainHelp"+viewString);
 
182
        m_son = new SketchMainHelpPrivate(viewString, htmlText, this);
 
183
        setWidget(m_son);
 
184
        if(!doShow) loadState();
 
185
}
 
186
 
 
187
SketchMainHelp::~SketchMainHelp()
 
188
{
 
189
        if (m_pixmap != NULL) {
 
190
                delete m_pixmap;
 
191
                m_pixmap = NULL;
 
192
        }
 
193
}
 
194
 
 
195
void SketchMainHelp::doClose() {
 
196
        doSetVisible(false);
 
197
}
 
198
 
 
199
void SketchMainHelp::doSetVisible(bool visible) {
 
200
        m_visible = visible;
 
201
        setVisible(visible);
 
202
        saveState();
 
203
}
 
204
 
 
205
void SketchMainHelp::setTransparent() {
 
206
        m_son->setWindowOpacity(OpacityLevel);
 
207
        m_son->m_shouldGetTransparent = true;
 
208
}
 
209
 
 
210
void SketchMainHelp::saveState() {
 
211
        QSettings settings;
 
212
        QString prop = objectName()+"Visibility";
 
213
        settings.setValue(prop,QVariant::fromValue(m_visible));
 
214
}
 
215
 
 
216
void SketchMainHelp::loadState() {
 
217
        QSettings settings;
 
218
        QString prop = objectName()+"Visibility";
 
219
        bool visible = settings.contains(prop)
 
220
                ? settings.value(prop).toBool()
 
221
                : true;
 
222
        doSetVisible(visible);
 
223
}
 
224
 
 
225
const QPixmap & SketchMainHelp::getPixmap() {
 
226
        if (m_pixmap == NULL) {
 
227
                m_pixmap = new QPixmap(m_son->size());
 
228
                m_son->render(m_pixmap);
 
229
        }
 
230
 
 
231
        return *m_pixmap;
 
232
}
 
233
 
 
234
bool SketchMainHelp::getVisible() {
 
235
        return m_visible;
 
236
}
 
237
 
 
238
bool SketchMainHelp::setMouseWithin(bool within) {
 
239
        if (within == m_mouseWithin) return false;
 
240
 
 
241
        if (m_pixmap) {
 
242
                delete m_pixmap;
 
243
                m_pixmap = NULL;
 
244
        }
 
245
        m_mouseWithin = within;
 
246
        (within) ? m_son->enterEventAux() : m_son->leaveEventAux();
 
247
        return true;
 
248
}
 
249
 
 
250
bool SketchMainHelp::forwardMousePressEvent(QMouseEvent * event) {
 
251
        bool result = m_son->forwardMousePressEvent(event);
 
252
 
 
253
        if (result) {
 
254
                if (m_pixmap) {
 
255
                        delete m_pixmap;
 
256
                        m_pixmap = NULL;
 
257
                }
 
258
        }
 
259
 
 
260
        return result;
 
261
}