-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdisubwindow.cpp
142 lines (132 loc) · 6.09 KB
/
mdisubwindow.cpp
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
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "mdisubwindow.h"
#include "graphicspixmapitem.h"
#include <QStandardPaths>
#include <QGuiApplication>
#include <QFileInfo>
#include <QDebug>
#include <QPixelFormat>
#include <QColor>
#include "fcolor.h"
#include "fgraphicsitem.h"
MdiSubWindow::MdiSubWindow(QActionGroup *tools, QWidget *parent, Qt::WindowFlags flags) : QMdiSubWindow(parent, flags) {
connect(this, SIGNAL(windowStateChanged(Qt::WindowStates, Qt::WindowStates)), this, SLOT(onWindowStateChanged(Qt::WindowStates, Qt::WindowStates)));
setAttribute(Qt::WA_DeleteOnClose);
Tools = tools;
//onToolsTriggered(Tools->checkedAction());
Scene = new GraphicsScene(this);
View = new GraphicsView(Scene, this);
connect(this, SIGNAL(toolChanged(GraphicsView::ToolType)), View, SLOT(setTool(GraphicsView::ToolType)));
setWidget(View);
//connect(Tools, SIGNAL(triggered(QAction*)), this, SLOT(onToolsTriggered(QAction*)));
//emit Tools->triggered(Tools->checkedAction());
}
void MdiSubWindow::onToolsTriggered(QAction *action) {
//qDebug() << "MdiSubWindow::onToolsTriggered" << action->objectName();
if (action->objectName() == "actionToolbarCursor")
emit toolChanged(GraphicsView::ToolDirectSelection);
else if (action->objectName() == "actionToolbarHand")
emit toolChanged(GraphicsView::ToolHand);
else if (action->objectName() == "actionToolbarZoom")
emit toolChanged(GraphicsView::ToolZoom);
}
void MdiSubWindow::loadImage(const QString &path, const QImage &image) {
//qDebug() << "MdiSubWindow::loadImage(" << path << ")";
Path = path;
_Image = image.copy();
setWindowTitle(QFileInfo(Path).fileName());
GraphicsPixmapItem *pixmapitem = new GraphicsPixmapItem(QPixmap::fromImage(_Image), "Background", _Image.resolution());
Scene->addItem(pixmapitem);
View->setSceneRect(0, 0, _Image.width(), _Image.height());
View->show();
}
void MdiSubWindow::newImage(const QString &name, int width, int height, int resolution, FImage::ImageMode mode, MdiSubWindow::Background bg, FColor bgcolor, QString profile) {
Q_UNUSED(bgcolor)
setWindowTitle(name);
FImage *image = new FImage(width, height, resolution, mode, profile);
qDebug() << image->mode();
if (bg == Background::Color) {
qDebug() << "color";
for (int y = 0; y < image->height(); y++) {
unsigned char *row = image->scanRow(y);
for (int x = 0; x < image->width(); x++) {
unsigned char *col = image->scanCol(row, x);
for (int c = 0; c < image->channels(); c ++) {
unsigned char *chan = image->scanChan(col, c);
if (image->mode() == FImage::Bitmap) {
switch(c) {
case FImage::Channel_BM_Black:
*chan = 0xFF;
break;
case FImage::Channel_BM_Alpha:
*chan = 0xFF;
break;
}
} else if (image->mode() == FImage::Grayscale) {
switch(c) {
case FImage::Channel_GS_Gray:
*chan = 0xFF;
break;
case FImage::Channel_GS_Alpha:
*chan = 0xFF;
break;
}
} else if (image->mode() == FImage::RGB) {
switch(c) {
case FImage::Channel_RGB_Red:
*chan = 0xFF;
break;
case FImage::Channel_RGB_Green:
*chan = 0x00;
break;
case FImage::Channel_RGB_Blue:
*chan = 0x00;
break;
case FImage::Channel_RGB_Alpha:
*chan = 0xFF;
break;
}
} else if (image->mode() == FImage::CMYK) {
switch(c) {
case FImage::Channel_CMYK_Cyan:
*chan = 0x00;
break;
case FImage::Channel_CMYK_Magenta:
*chan = 0xFF;
break;
case FImage::Channel_CMYK_Yellow:
*chan = 0x00;
break;
case FImage::Channel_CMYK_Black:
*chan = 0x00;
break;
case FImage::Channel_CMYK_Alpha:
*chan = 0xFF;
break;
}
}
}
}
}
} else
image->reset();
FGraphicsItem *item = new FGraphicsItem("Background", image);
Scene->addItem(item);
View->setSceneRect(0, 0, image->width(), image->height());
View->show();
}
void MdiSubWindow::onWindowStateChanged(Qt::WindowStates oldState, Qt::WindowStates newState) {
//qDebug() << this->windowTitle() << " MdiSubWindow::onWindowStateChanged(" << oldState << "," << newState << ")";
if (oldState == Qt::WindowActive && newState == Qt::WindowNoState) { /* INACTIVE */
//qDebug() << this->windowTitle() << "disconnect";
disconnect(Tools, SIGNAL(triggered(QAction *)), this, SLOT(onToolsTriggered(QAction *)));
} else if (oldState == Qt::WindowNoState && newState == Qt::WindowActive) { /* ACTIVE */
//qDebug() << this->windowTitle() << "connect and update";
connect(Tools, SIGNAL(triggered(QAction *)), this, SLOT(onToolsTriggered(QAction *)));
emit Tools->triggered(Tools->checkedAction());
} /*else {
qDebug() << this->windowTitle() << oldState << newState;
}*/
}
GraphicsView *MdiSubWindow::view() {
return View;
}