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-09-30 13:25:30 +0200 (Thu, 30 Sep 2010) $
25
********************************************************************/
27
#include <QHBoxLayout>
28
#include <QGraphicsScene>
34
#include "sketchmainhelp.h"
35
#include "../utils/expandinglabel.h"
37
qreal SketchMainHelp::OpacityLevel = 0.5;
39
SketchMainHelpCloseButton::SketchMainHelpCloseButton(const QString &imagePath, QWidget *parent)
43
QString(":/resources/images/inViewHelpCloseButton%1.png").arg(imagePath));
45
setFixedHeight(m_pixmap.height());
48
void SketchMainHelpCloseButton::mousePressEvent(QMouseEvent * event) {
50
QLabel::mousePressEvent(event);
53
void SketchMainHelpCloseButton::doShow() {
57
void SketchMainHelpCloseButton::doHide() {
62
//////////////////////////////////////////////////////////////
64
SketchMainHelpPrivate::SketchMainHelpPrivate (
65
const QString &viewString,
66
const QString &htmlText,
67
SketchMainHelp *parent)
70
setObjectName("sketchMainHelp"+viewString);
73
QFrame *main = new QFrame(this);
74
QHBoxLayout *mainLayout = new QHBoxLayout(main);
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());
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);
94
mainLayout->setSpacing(6);
95
mainLayout->setMargin(2);
96
mainLayout->addWidget(imageLabel);
97
mainLayout->addWidget(textLabel);
100
QVBoxLayout *layout = new QVBoxLayout(this);
101
m_closeButton = new SketchMainHelpCloseButton(viewString,this);
102
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(doClose()));
104
QFrame *bottomMargin = new QFrame(this);
105
bottomMargin->setFixedHeight(m_closeButton->height());
107
layout->addWidget(m_closeButton);
108
layout->addWidget(main);
109
layout->addWidget(bottomMargin);
111
layout->setSpacing(0);
112
layout->setMargin(2);
114
m_shouldGetTransparent = false;
115
//m_closeButton->doHide();
117
QFile styleSheet(":/resources/styles/inviewhelp.qss");
118
if (!styleSheet.open(QIODevice::ReadOnly)) {
119
qWarning("Unable to open :/resources/styles/inviewhelp.qss");
121
setStyleSheet(styleSheet.readAll());
125
void SketchMainHelpPrivate::doClose() {
130
void SketchMainHelpPrivate::enterEvent(QEvent * event) {
132
QFrame::enterEvent(event);
135
void SketchMainHelpPrivate::enterEventAux() {
136
if(m_shouldGetTransparent) {
137
setWindowOpacity(1.0);
138
QTimer::singleShot(2000, this, SLOT(setTransparent()));
140
//m_closeButton->doShow();
143
void SketchMainHelpPrivate::setTransparent() {
144
setWindowOpacity(SketchMainHelp::OpacityLevel);
147
void SketchMainHelpPrivate::leaveEvent(QEvent * event) {
149
QFrame::leaveEvent(event);
152
void SketchMainHelpPrivate::leaveEventAux() {
153
if(m_shouldGetTransparent) {
156
//m_closeButton->doHide();
159
bool SketchMainHelpPrivate::forwardMousePressEvent(QMouseEvent * event)
161
QPoint p = m_closeButton->mapFromParent(event->pos());
162
if (m_closeButton->rect().contains(p)) {
170
//////////////////////////////////////////////////////////////
172
SketchMainHelp::SketchMainHelp (
173
const QString &viewString,
174
const QString &htmlText,
176
) : QGraphicsProxyWidget()
178
m_mouseWithin = false;
181
setObjectName("sketchMainHelp"+viewString);
182
m_son = new SketchMainHelpPrivate(viewString, htmlText, this);
184
if(!doShow) loadState();
187
SketchMainHelp::~SketchMainHelp()
189
if (m_pixmap != NULL) {
195
void SketchMainHelp::doClose() {
199
void SketchMainHelp::doSetVisible(bool visible) {
205
void SketchMainHelp::setTransparent() {
206
m_son->setWindowOpacity(OpacityLevel);
207
m_son->m_shouldGetTransparent = true;
210
void SketchMainHelp::saveState() {
212
QString prop = objectName()+"Visibility";
213
settings.setValue(prop,QVariant::fromValue(m_visible));
216
void SketchMainHelp::loadState() {
218
QString prop = objectName()+"Visibility";
219
bool visible = settings.contains(prop)
220
? settings.value(prop).toBool()
222
doSetVisible(visible);
225
const QPixmap & SketchMainHelp::getPixmap() {
226
if (m_pixmap == NULL) {
227
m_pixmap = new QPixmap(m_son->size());
228
m_son->render(m_pixmap);
234
bool SketchMainHelp::getVisible() {
238
bool SketchMainHelp::setMouseWithin(bool within) {
239
if (within == m_mouseWithin) return false;
245
m_mouseWithin = within;
246
(within) ? m_son->enterEventAux() : m_son->leaveEventAux();
250
bool SketchMainHelp::forwardMousePressEvent(QMouseEvent * event) {
251
bool result = m_son->forwardMousePressEvent(event);
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 <QHBoxLayout>
28
#include <QGraphicsScene>
34
#include "sketchmainhelp.h"
35
#include "../utils/expandinglabel.h"
37
double SketchMainHelp::OpacityLevel = 0.5;
39
SketchMainHelpCloseButton::SketchMainHelpCloseButton(const QString &imagePath, QWidget *parent)
43
QString(":/resources/images/inViewHelpCloseButton%1.png").arg(imagePath));
45
setFixedHeight(m_pixmap.height());
48
void SketchMainHelpCloseButton::mousePressEvent(QMouseEvent * event) {
50
QLabel::mousePressEvent(event);
53
void SketchMainHelpCloseButton::doShow() {
57
void SketchMainHelpCloseButton::doHide() {
62
//////////////////////////////////////////////////////////////
64
SketchMainHelpPrivate::SketchMainHelpPrivate (
65
const QString &viewString,
66
const QString &htmlText,
67
SketchMainHelp *parent)
70
setObjectName("sketchMainHelp"+viewString);
73
QFrame *main = new QFrame(this);
74
QHBoxLayout *mainLayout = new QHBoxLayout(main);
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());
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);
94
mainLayout->setSpacing(6);
95
mainLayout->setMargin(2);
96
mainLayout->addWidget(imageLabel);
97
mainLayout->addWidget(textLabel);
100
QVBoxLayout *layout = new QVBoxLayout(this);
101
m_closeButton = new SketchMainHelpCloseButton(viewString,this);
102
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(doClose()));
104
QFrame *bottomMargin = new QFrame(this);
105
bottomMargin->setFixedHeight(m_closeButton->height());
107
layout->addWidget(m_closeButton);
108
layout->addWidget(main);
109
layout->addWidget(bottomMargin);
111
layout->setSpacing(0);
112
layout->setMargin(2);
114
m_shouldGetTransparent = false;
115
//m_closeButton->doHide();
117
QFile styleSheet(":/resources/styles/inviewhelp.qss");
118
if (!styleSheet.open(QIODevice::ReadOnly)) {
119
qWarning("Unable to open :/resources/styles/inviewhelp.qss");
121
setStyleSheet(styleSheet.readAll());
125
void SketchMainHelpPrivate::doClose() {
130
void SketchMainHelpPrivate::enterEvent(QEvent * event) {
132
QFrame::enterEvent(event);
135
void SketchMainHelpPrivate::enterEventAux() {
136
if(m_shouldGetTransparent) {
137
setWindowOpacity(1.0);
138
QTimer::singleShot(2000, this, SLOT(setTransparent()));
140
//m_closeButton->doShow();
143
void SketchMainHelpPrivate::setTransparent() {
144
setWindowOpacity(SketchMainHelp::OpacityLevel);
147
void SketchMainHelpPrivate::leaveEvent(QEvent * event) {
149
QFrame::leaveEvent(event);
152
void SketchMainHelpPrivate::leaveEventAux() {
153
if(m_shouldGetTransparent) {
156
//m_closeButton->doHide();
159
bool SketchMainHelpPrivate::forwardMousePressEvent(QMouseEvent * event)
161
QPoint p = m_closeButton->mapFromParent(event->pos());
162
if (m_closeButton->rect().contains(p)) {
170
//////////////////////////////////////////////////////////////
172
SketchMainHelp::SketchMainHelp (
173
const QString &viewString,
174
const QString &htmlText,
176
) : QGraphicsProxyWidget()
178
m_mouseWithin = false;
181
setObjectName("sketchMainHelp"+viewString);
182
m_son = new SketchMainHelpPrivate(viewString, htmlText, this);
184
if(!doShow) loadState();
187
SketchMainHelp::~SketchMainHelp()
189
if (m_pixmap != NULL) {
195
void SketchMainHelp::doClose() {
199
void SketchMainHelp::doSetVisible(bool visible) {
205
void SketchMainHelp::setTransparent() {
206
m_son->setWindowOpacity(OpacityLevel);
207
m_son->m_shouldGetTransparent = true;
210
void SketchMainHelp::saveState() {
212
QString prop = objectName()+"Visibility";
213
settings.setValue(prop,QVariant::fromValue(m_visible));
216
void SketchMainHelp::loadState() {
218
QString prop = objectName()+"Visibility";
219
bool visible = settings.contains(prop)
220
? settings.value(prop).toBool()
222
doSetVisible(visible);
225
const QPixmap & SketchMainHelp::getPixmap() {
226
if (m_pixmap == NULL) {
227
m_pixmap = new QPixmap(m_son->size());
228
m_son->render(m_pixmap);
234
bool SketchMainHelp::getVisible() {
238
bool SketchMainHelp::setMouseWithin(bool within) {
239
if (within == m_mouseWithin) return false;
245
m_mouseWithin = within;
246
(within) ? m_son->enterEventAux() : m_son->leaveEventAux();
250
bool SketchMainHelp::forwardMousePressEvent(QMouseEvent * event) {
251
bool result = m_son->forwardMousePressEvent(event);