-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWidgetSubstrate.cpp
More file actions
127 lines (103 loc) · 3.4 KB
/
WidgetSubstrate.cpp
File metadata and controls
127 lines (103 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <QAction>
#include <QApplication>
#include <QClipboard>
#include <QFileDialog>
#include <QKeyEvent>
#include "WidgetSubstrate.h"
#include "Substrate.h"
WidgetSubstrate::WidgetSubstrate(Substrate *s) : QWidget()
{
numeroSubstrate = 0;
substrate = QPointer<Substrate>(s);
setFixedSize(s->getRect().size()*s->getFacteurEchelle());
pixmap = new QPixmap(size());
pixmap->fill(QColor(0, 0, 0, 0));
hide();
s->setParent(this);
connect(s, SIGNAL(arrete()), this, SLOT(deleteLater()));
connect(s, SIGNAL(termine()), this, SLOT(creerActions()));
setWindowIcon(QIcon(":/Images/Substrate.png"));
}
WidgetSubstrate::~WidgetSubstrate()
{
if (substrate)
{
substrate->arreter();
delete substrate;
}
if (!pixmap->isNull())
delete pixmap;
}
void WidgetSubstrate::creerActions()
{
update();
QAction *actionEnregistrer = new QAction(tr("&Enregistrer comme image"), this);
actionEnregistrer->setShortcut(QKeySequence::Save);
QAction *actionCopier = new QAction(tr("&Copier comme image"), this);
actionCopier->setShortcut(QKeySequence::Copy);
addAction(actionEnregistrer);
addAction(actionCopier);
connect(actionEnregistrer, SIGNAL(triggered()), this, SLOT(enregistrerCommeImage()));
connect(actionCopier, SIGNAL(triggered()), this, SLOT(copierCommeImage()));
setContextMenuPolicy(Qt::ActionsContextMenu);
numeroSubstrate = substrate->getNumeroSubstrate();
delete substrate;
substrate = 0;
}
void WidgetSubstrate::enregistrerCommeImage()
{
QString texte = QFileDialog::getSaveFileName(this, tr("Choisir un fichier de destination"),
tr("Substrate n°%1.png").arg(numeroSubstrate),
tr("Images (*.bmp *.jpeg *.jpg *.png *.tiff)"));
if (texte.isNull())
return;
pixmap->save(texte, 0, 100);
}
void WidgetSubstrate::copierCommeImage()
{
QApplication::clipboard()->setPixmap(*pixmap);
}
QPixmap * WidgetSubstrate::getPixmap() const
{
return pixmap;
}
void WidgetSubstrate::paintEvent(QPaintEvent *event)
{
QWidget::paintEvent(event);
QPainter painter(this);
//painter.setRenderHints(QPainter::SmoothPixmapTransform);
painter.drawPixmap(0, 0, *pixmap);
if (substrate)
{
if (!substrate->getEstTermine())
{
QFontMetrics fm(painter.font());
QString const texte = tr("Génération en cours... (%1%)").arg(substrate->getChargement());
QRectF r = fm.boundingRect(texte);
r.setWidth(r.width()+10);
r.moveTo(QPointF(width(), height())-QPointF(r.width(), r.height()));
QColor c = Qt::black;//palette().color(QPalette::ToolTipBase);
c.setAlpha(128);
QPen pen = painter.pen();
pen.setColor(c);
painter.setPen(pen);
painter.fillRect(r, c);
c = Qt::white;//c = palette().color(QPalette::ToolTipText);
c.setAlpha(128);
pen.setColor(c);
painter.setPen(pen);
painter.drawText(r, Qt::AlignCenter, texte);
}
}
}
void WidgetSubstrate::closeEvent(QCloseEvent *event)
{
QWidget::closeEvent(event);
deleteLater();
}
void WidgetSubstrate::keyPressEvent(QKeyEvent *event)
{
QWidget::keyPressEvent(event);
if (event->key() == Qt::Key_Escape)// && isFullScreen())
close();
}