-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
73 lines (66 loc) · 1.96 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QPixmap>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::doMessage(QString str){
QMessageBox qmb(this);
qmb.setText(str);
qmb.exec();
}
QString MainWindow::doSelectingImg(bool mustExist){
QFileDialog qfd(this);
qfd.setNameFilter(tr("Images (*.bmp *.jpg *.png)"));
qfd.setAcceptMode(mustExist?QFileDialog::AcceptOpen:QFileDialog::AcceptSave);
if(qfd.exec())return qfd.selectedFiles().at(0);
else return NULL;
}
void MainWindow::on_actionImport_triggered()
{
doMessage(imgstr=doSelectingImg(true));
scena = new QGraphicsScene(ui->graphicsView);
mapPxs = new QPixmap(imgstr);
view = ui->graphicsView;
view->setFixedHeight(mapPxs->height());
view->setFixedWidth(mapPxs->width());
scena->addPixmap(*mapPxs);
view->setScene(scena);
view->fitInView(scena->itemsBoundingRect(),Qt::KeepAspectRatio);
view->show();
}
void MainWindow::on_actionExport_triggered()
{
doMessage(doSelectingImg(false));
}
void MainWindow::on_pushButton_clicked()
{
QImage img = mapPxs->toImage();
int shift=ui->spinBox->value();
for(int w=0;w<img.width();++w){
for(int h=0;h<img.height();++h){
QColor prev=img.pixel(w,h);
int r=((prev.red()>>shift)|(prev.red()<<(8-shift)))%256;
int g=((prev.green()>>shift)|(prev.green()<<(8-shift)))%256;
int b=((prev.blue()>>shift)|(prev.blue()<<(8-shift)))%256;
img.setPixelColor(w,h,QColor(r,g,b));
}
}
mapPxs = new QPixmap(QPixmap::fromImage(img));
scena = new QGraphicsScene(ui->graphicsView);
scena->addPixmap(*mapPxs);
view->setScene(scena);
view->fitInView(scena->itemsBoundingRect(),Qt::KeepAspectRatio);
view->show();
qDebug("end");
}