123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- #include "paperedithandle.h"
- #include "qpainter.h"
- #include <QMouseEvent>
- #include <QDateTime>
- #include <QMessageBox>
- #include <QDir>
- #define painter_offset 46
- CPaperEditHandle::CPaperEditHandle(QWidget *parent)
- : QWidget(parent), m_room(1.0f), m_offset(QPoint(0, 0)), m_mousestatus(Mouse_Normal),
- m_bpressed(false), m_startPoint(QPoint(0, 0)), m_endPoint(QPoint(0, 0)), m_pBatchInfo(nullptr),
- m_pPapers(nullptr), m_nCurrentPaper(0), m_locateW(0), m_locateH(0), m_bLocateChecked(false),
- m_bEraserChecked(false)
- {
- ui.setupUi(this);
- ui.widget_eraser->hide();
- ui.widget_locate->hide();
- ClickDrag();
- connect(ui.toolButton_drag, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_roomin, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_rommout, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_90, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_N90, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_locate, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_eraser, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_switchpage, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_undo, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_restore, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_locate1, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_locate2, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_locate3, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_eraser1, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_eraser2, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_eraser3, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_page0, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_page1, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_paper_pre, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- connect(ui.toolButton_paper_next, SIGNAL(clicked()), this, SLOT(slot_onButtonClick()));
- ui.widget_painter->m_bgimage = &m_bgimage;
- ui.widget_painter->m_offset = &m_offset;
- ui.widget_painter->m_room = &m_room;
- this->setMouseTracking(true);// 追踪鼠标
-
- }
- CPaperEditHandle::~CPaperEditHandle()
- {
-
- }
- void CPaperEditHandle::slot_onButtonClick()
- {
- ui.widget_locate->hide();
- ui.widget_eraser->hide();
- QObject* sender = this->sender();
- if (sender == ui.toolButton_drag)
- {
- ClickDrag();
- }
- else if (sender == ui.toolButton_roomin)
- {
- ClickRoomin();
- }
- else if (sender == ui.toolButton_rommout)
- {
- ClickRoomout();
- }
- else if (sender == ui.toolButton_90)
- {
- ClickRotate90();
- }
- else if (sender == ui.toolButton_N90)
- {
- ClickRotateN90();
- }
- else if (sender == ui.toolButton_locate || sender == ui.toolButton_locate1 || sender == ui.toolButton_locate2 || sender == ui.toolButton_locate3)
- {
- ClickLocate(sender);
- }
- else if (sender == ui.toolButton_eraser || sender == ui.toolButton_eraser1 || sender == ui.toolButton_eraser2 || sender == ui.toolButton_eraser3)
- {
- ClickEraser(sender);
- }
- else if (sender == ui.toolButton_switchpage)
- {
- ClickSwitchPage();
- }
- else if (sender == ui.toolButton_undo)
- {
- ClickUndo();
- }
- else if (sender == ui.toolButton_restore)
- {
- ClickRestore();
- }
- else if (sender == ui.toolButton_page0 || sender == ui.toolButton_page1)
- {
- if (!m_pPapers || (*m_pPapers).size() == 0 || m_nCurrentPaper >= (*m_pPapers).size())
- {
- return;
- }
- if (sender == ui.toolButton_page0)
- {
- m_nCurrentPage = 0;
- }
- else
- {
- m_nCurrentPage = 1;
- }
- m_bgimage = QImage(m_mapStackPage[m_nCurrentPage].top().c_str());
- CalcRoom();
- update();
- }
- else if (sender == ui.toolButton_paper_next || sender == ui.toolButton_paper_pre)
- {
- if (!m_pPapers || (*m_pPapers).size() == 0 || m_nCurrentPaper >= (*m_pPapers).size())
- {
- return;
- }
- if (sender == ui.toolButton_paper_pre)
- {
- if (m_nCurrentPaper == 0)
- {
- return;
- }
- m_nCurrentPaper--;
- }
- else
- {
- if (m_nCurrentPaper + 1 == (*m_pPapers).size())
- {
- return;
- }
- m_nCurrentPaper++;
- }
- ui.label_total_count->setText(QString::fromStdWString(L"%1/%2").arg(m_nCurrentPaper + 1).arg((*m_pPapers).size()));
- ui.toolButton_page0->setChecked(true);
- m_nCurrentPage = 0;
- m_bgimage = QImage((*m_pPapers)[m_nCurrentPaper].page0_path);
- CalcRoom();
- m_mapStackPage.clear();
- m_mapStackPage[0].push_back((*m_pPapers)[m_nCurrentPaper].page0_path);
- m_mapStackPage[1].push_back((*m_pPapers)[m_nCurrentPaper].page1_path);
- update();
- }
- }
- void CPaperEditHandle::ClickDrag()
- {
- if (ui.toolButton_drag->isChecked())
- {
- m_mousestatus = Mouse_Drag;
- }
- else
- {
- m_mousestatus = Mouse_Normal;
- }
- setCursor(Qt::SizeAllCursor);
- m_bLocateChecked = false;
- m_bEraserChecked = false;
- }
- void CPaperEditHandle::ClickRoomin()
- {
- m_offset.setX(0);
- m_offset.setY(0);
- m_room *= 1.1f;
- update();
- //if (mousestatus == Mouse_Locate)
- //{
- // QPixmap pixmap((locateW + 1)*room, (locateH + 1)*room);
- // QPainter painterim(&pixmap);
- // painterim.setRenderHint(QPainter::Antialiasing);
- // pixmap.fill(Qt::black); //填充1像素值
- // painterim.drawRect(0, 0, (locateW + 1)*room, (locateH + 1)*room);
- // QCursor cursor(pixmap, 0, 0); //加载xpm生成的图标文件
- // setCursor(cursor); //设置自定义的鼠标样式
- //}
- }
- void CPaperEditHandle::ClickRoomout()
- {
- m_offset.setX(0);
- m_offset.setY(0);
- m_room /= 1.1f;
- update();
- //if (mousestatus == Mouse_Locate)
- //{
- // QPixmap pixmap((locateW + 1)*room, (locateH + 1)*room);
- // QPainter painterim(&pixmap);
- // painterim.setRenderHint(QPainter::Antialiasing);
- // pixmap.fill(Qt::black); //填充1像素值
- // painterim.drawRect(0, 0, (locateW + 1)*room, (locateH + 1)*room);
- // QCursor cursor(pixmap, 0, 0); //加载xpm生成的图标文件
- // setCursor(cursor); //设置自定义的鼠标样式
- //}
- }
- void CPaperEditHandle::ClickRotate90()
- {
- m_offset.setX(0);
- m_offset.setY(0);
- QMatrix matrix;
- matrix.rotate(90.0);
- m_bgimage = m_bgimage.transformed(matrix, Qt::FastTransformation);
- update();
- SaveTempImg();
- /*if (!ui.toolButton_cur->isChecked())
- {
- return;
- }
- m_bIsEdited = true;
- SaveTempImg(&bgimage);*/
- }
- void CPaperEditHandle::ClickRotateN90()
- {
- m_offset.setX(0);
- m_offset.setY(0);
- QMatrix matrix;
- matrix.rotate(-90.0);
- m_bgimage = m_bgimage.transformed(matrix, Qt::FastTransformation);
- update();
- SaveTempImg();
- /*if (!ui.toolButton_cur->isChecked())
- {
- return;
- }
- m_bIsEdited = true;
- SaveTempImg(&bgimage);*/
- }
- void CPaperEditHandle::ClickLocate(QObject* sender)
- {
- int locX, locY;
- if (sender == ui.toolButton_locate)
- {
- m_bEraserChecked = false;
- if (ui.toolButton_locate->isChecked() && m_bLocateChecked == false)
- {
- m_mousestatus = Mouse_Locate;
- m_bLocateChecked = true;
- ui.widget_locate->show();
- if (ui.toolButton_locate1->isChecked())
- {
- locX = 18;
- locY = 12;
- }
- else if (ui.toolButton_locate2->isChecked())
- {
- locX = 40;
- locY = 20;
- }
- else if (ui.toolButton_locate3->isChecked())
- {
- locX = 50;
- locY = 28;
- }
- }
- else
- {
- /*m_mousestatus = Mouse_Normal;
- ui.widget_locate->hide();*/
- m_bLocateChecked = false;
- ui.toolButton_drag->setChecked(true);
- ClickDrag();
- return;
- }
- }
- else if (sender == ui.toolButton_locate1)
- {
- locX = 18;
- locY = 12;
- }
- else if (sender == ui.toolButton_locate2)
- {
- locX = 40;
- locY = 20;
- }
- else if (sender == ui.toolButton_locate3)
- {
- locX = 50;
- locY = 28;
- }
- double pdiX = m_bgimage.dotsPerMeterX();
- double pdiY = m_bgimage.dotsPerMeterY();
- int x = qRound(pdiX*0.0254);
- int y = qRound(pdiY*0.0254);
- m_locateW = locX * (x / 96);
- m_locateH = locY * (y / 96);
- QPixmap pixmap((m_locateW + 1)*m_room, (m_locateH + 1)*m_room);
- QPainter painterim(&pixmap);
- painterim.setRenderHint(QPainter::Antialiasing);
- pixmap.fill(Qt::black); //填充1像素值
- painterim.drawRect(0, 0, (m_locateW + 1)*m_room, (m_locateH + 1)*m_room);
- QCursor cursor(pixmap, 0, 0); //加载xpm生成的图标文件
- setCursor(cursor); //设置自定义的鼠标样式
- }
- void CPaperEditHandle::ClickEraser(QObject* sender)
- {
- if (sender == ui.toolButton_eraser)
- {
- m_bLocateChecked = false;
- if (ui.toolButton_eraser->isChecked() && m_bEraserChecked == false)
- {
- m_mousestatus = Mouse_Eraser;
- m_bEraserChecked = true;
- ui.widget_eraser->show();
- }
- else
- {
- /*m_mousestatus = Mouse_Normal;
- ui.widget_eraser->hide();*/
- m_bEraserChecked = false;
- ui.toolButton_drag->setChecked(true);
- ClickDrag();
- return;
- }
- m_eraserW = 17;
- m_eraserH = 13;
- }
- else if (sender == ui.toolButton_eraser1)
- {
- m_eraserW = 13;
- m_eraserH = 9;
- }
- else if (sender == ui.toolButton_eraser2)
- {
- m_eraserW = 17;
- m_eraserH = 13;
- }
- else if (sender == ui.toolButton_eraser3)
- {
- m_eraserW = 23;
- m_eraserH = 17;
- }
- QPixmap pixmap(m_eraserW + 1, m_eraserH + 1);
- QPainter painterim(&pixmap);
- painterim.setRenderHint(QPainter::Antialiasing);
- pixmap.fill(Qt::white); //填充1像素值
- painterim.drawRect(0, 0, m_eraserW + 1, m_eraserH + 1);
- QCursor cursor(pixmap, 0, 0); //加载xpm生成的图标文件
- setCursor(cursor); //设置自定义的鼠标样式
- }
- void CPaperEditHandle::ClickSwitchPage()
- {
- QString msg = QString::fromLocal8Bit("换页后,将清空所有对图片的修改,");
- msg += QString::fromLocal8Bit("确定要换页吗?");
- QMessageBox::StandardButton result = QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), msg, QMessageBox::Yes | QMessageBox::No);
- if (result == QMessageBox::Yes)
- {
- if (!m_pPapers || (*m_pPapers).size() == 0 || m_nCurrentPaper >= (*m_pPapers).size())
- {
- return;
- }
- string strPath0 = (*m_pPapers)[m_nCurrentPaper].page0_path;
- string strPath1 = (*m_pPapers)[m_nCurrentPaper].page1_path;
- strcpy_s((*m_pPapers)[m_nCurrentPaper].page0_path, strPath1.c_str());
- strcpy_s((*m_pPapers)[m_nCurrentPaper].page1_path, strPath0.c_str());
- m_bgimage = QImage((*m_pPapers)[m_nCurrentPaper].page0_path);
- m_mapStackPage.clear();
- m_mapStackPage[0].push_back((*m_pPapers)[m_nCurrentPaper].page0_path);
- m_mapStackPage[1].push_back((*m_pPapers)[m_nCurrentPaper].page1_path);
- ui.toolButton_page0->click();
- }
- }
- void CPaperEditHandle::ClickUndo()
- {
- if (m_mapStackPage[m_nCurrentPage].size() == 1) // 只有原始试卷的路径
- {
- return;
- }
-
- m_mapStackPage[m_nCurrentPage].pop();
- m_bgimage = QImage(m_mapStackPage[m_nCurrentPage].top().c_str());
- update();
- }
- void CPaperEditHandle::ClickRestore()
- {
- QString msg = QString::fromLocal8Bit("还原后,将清空所有对图片的修改,");
- while (m_mapStackPage[m_nCurrentPage].size() > 1)
- {
- m_mapStackPage[m_nCurrentPage].pop();
- }
- m_bgimage = QImage(m_mapStackPage[m_nCurrentPage].top().c_str());
- update();
- }
- void CPaperEditHandle::resizeEvent(QResizeEvent *event)
- {
- QRect rcClient = geometry();
- QRect rcTool = rcClient;
- rcTool.setBottom(rcTool.top() + ui.widget_tool->height());
- ui.widget_tool->setGeometry(rcTool);
-
- QRect rcLocate = ui.toolButton_locate->geometry();
- rcLocate.setTop(rcLocate.bottom() + 2);
- rcLocate.setBottom(rcLocate.top() + 44);
- rcLocate.setLeft(245);
- rcLocate.setRight(rcLocate.left() + 162);
- ui.widget_locate->setGeometry(rcLocate);
- QRect rcEraser = ui.toolButton_eraser->geometry();
- rcEraser.setTop(rcEraser.bottom() + 2);
- rcEraser.setBottom(rcEraser.top() + 44);
- rcEraser.setLeft(297);
- rcEraser.setRight(rcEraser.left() + 162);
- ui.widget_eraser->setGeometry(rcEraser);
- QRect rcLeft = ui.toolButton_drag->geometry();
- rcLeft.setTop(rcLeft.bottom() + 2);
- rcLeft.setBottom(rcLeft.top() + ui.widget_leftbutton->height());
- rcLeft.setRight(rcLeft.x() + ui.widget_leftbutton->width());
- ui.widget_leftbutton->setGeometry(rcLeft);
- QRect rcRight = rcTool;
- rcRight.setTop(rcRight.bottom() + 2);
- rcRight.setBottom(rcRight.top() + ui.widget_rightbutton->height());
- rcRight.setLeft(rcRight.x() + ui.widget_tool->width() - ui.widget_rightbutton->width());
- ui.widget_rightbutton->setGeometry(rcRight);
- QRect rcPainter = rcClient;
- rcPainter.setLeft(painter_offset);
- rcPainter.setTop(painter_offset);
- rcPainter.setWidth(rcClient.width() - painter_offset * 2);
- rcPainter.setHeight(rcClient.height() - painter_offset);
- ui.widget_painter->setGeometry(rcPainter);
- }
- QPoint CPaperEditHandle::PointSwitchToImg(QPoint sPoint)
- {
- sPoint.setX(sPoint.x() - painter_offset);
- sPoint.setY(sPoint.y() - painter_offset);
- int x = sPoint.x() - m_offset.x();
- x = x / m_room;
- int y = sPoint.y() - m_offset.y();
- y = y / m_room;
- return QPoint(x, y);
- }
- QRect CPaperEditHandle::RectSwitchImg(QRect sRect)
- {
- QPoint lefttop = PointSwitchToImg(QPoint(sRect.left(), sRect.top()));
- QPoint rightbottom = PointSwitchToImg(QPoint(sRect.right(), sRect.bottom()));
- return QRect(lefttop, rightbottom);
- }
- void CPaperEditHandle::SaveTempImg()
- {
- QDateTime currentTime = QDateTime::currentDateTime();
- char path[512] = { 0 };
- sprintf(path, "%stemp/%s.jpg", m_pBatchInfo->work_dir, currentTime.toString("yyyyMMddhhmmsszzz").toStdString().c_str());
- m_bgimage.save(path, "JPG", 255);
- m_mapStackPage[m_nCurrentPage].push(path);
- }
- void CPaperEditHandle::mouseMoveEvent(QMouseEvent *event)
- {
- QPoint pos(event->pos());
-
- QPainter painterim(&m_bgimage);
- painterim.setRenderHint(QPainter::Antialiasing);
- if (m_bpressed)
- {
- if (m_mousestatus == Mouse_Eraser)
- {
- painterim.eraseRect(RectSwitchImg(QRect(pos.x(), pos.y(), m_eraserW, m_eraserH)));
- update();
- SaveTempImg();
- }
- else if (m_mousestatus == Mouse_Drag)
- {
- m_endPoint = pos;
- m_offset.setX(m_endPoint.x() - m_startPoint.x() + m_offset.x());
- m_offset.setY(m_endPoint.y() - m_startPoint.y() + m_offset.y());
- m_startPoint = m_endPoint;
- QRect rcClient = ui.widget_painter->geometry();
- if (m_bgimage.width() * m_room <= rcClient.width()) //不能拖动
- {
- m_offset.setX(0);
- }
- else
- {
- int offxMax = 0, offxMin = rcClient.width() - m_bgimage.width() * m_room;
- if (m_offset.x() < offxMin)
- {
- m_offset.setX(offxMin);
- }
- else if (m_offset.x() > offxMax)
- {
- m_offset.setX(offxMax);
- }
- }
- if (m_bgimage.height()*m_room <= rcClient.height()) //不能拖动
- {
- m_offset.setY(0);
- }
- else
- {
- int offyMax = 0, offyMin = rcClient.height() - m_bgimage.height()*m_room;
- if (m_offset.y() < offyMin)
- {
- m_offset.setY(offyMin);
- }
- else if (m_offset.y() > offyMax)
- {
- m_offset.setY(offyMax);
- }
- }
- update();
- }
- }
- }
- void CPaperEditHandle::mouseReleaseEvent(QMouseEvent *event)
- {
- QPoint pos(event->pos());
- m_bpressed = false;
- if (m_mousestatus == Mouse_Eraser)
- {
- QPainter painterim(&m_bgimage);
- painterim.setRenderHint(QPainter::Antialiasing);
- painterim.eraseRect(RectSwitchImg(QRect(pos.x(), pos.y(), m_eraserW, m_eraserH)));
- SaveTempImg();
- update();
- }
- else if (m_mousestatus == Mouse_Locate)
- {
- QPainter painterim(&m_bgimage);
- painterim.setRenderHint(QPainter::SmoothPixmapTransform);
- QPoint pt = PointSwitchToImg(pos);
- QRect rc(pt.x(), pt.y(), m_locateW, m_locateH);
- QRect target = rc;
- painterim.setBrush(Qt::black);
- painterim.drawRect(target);
- SaveTempImg();
- update();
- }
- }
- void CPaperEditHandle::mousePressEvent(QMouseEvent *event)
- {
- ui.widget_locate->hide();
- ui.widget_eraser->hide();
- QPoint pos(event->pos());
- m_startPoint = pos;
- m_endPoint = pos;
- /*if (!ui.widget_Drag->isVisible())
- {
- ispressed = true;
- }*/
- m_bpressed = true;
- }
- void CPaperEditHandle::paintEvent(QPaintEvent *e)
- {
- /*QRect rc(this->rect());
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
- painter.translate(m_offset.x() + 50, m_offset.y() + 50);
- painter.scale(m_room, m_room);
- painter.drawImage(QPoint(0, 0), m_bgimage);*/
- }
- void CPaperEditHandle::setCurrentBatch(batch_info* batchInfo, vector<paper_info>* papers)
- {
- m_pBatchInfo = batchInfo;
- m_pPapers = papers;
- m_nCurrentPaper = 0;
- m_nCurrentPage = 0;
- m_room = 1.0f;
- m_locateW = 0;
- m_locateH = 0;
- m_offset = QPoint(0, 0);
- ui.toolButton_drag->setChecked(true);
- ui.widget_locate->hide();
- ui.widget_eraser->hide();
- ClickDrag();
- m_mapStackPage.clear();
- if (!m_pPapers || (*m_pPapers).size() == 0)
- {
- return;
- }
- QString temp_path(m_pBatchInfo->work_dir);
- temp_path.append("temp");
- QDir dir(temp_path);
- if (!dir.exists())
- {
- dir.mkpath(temp_path);
- }
- ui.label_total_count->setText(QString::fromStdWString(L"%1/%2").arg(m_nCurrentPaper + 1).arg((*m_pPapers).size()));
- m_bgimage = QImage((*m_pPapers)[m_nCurrentPaper].page0_path);
- CalcRoom();
- // m_stackImage.push_back(m_bgimage);
- m_mapStackPage[0].push_back((*m_pPapers)[m_nCurrentPaper].page0_path);
- m_mapStackPage[1].push_back((*m_pPapers)[m_nCurrentPaper].page1_path);
- update();
- }
- void CPaperEditHandle::GetCurrentPaper(paper_info& paperInfo)
- {
- if (!m_pPapers || (*m_pPapers).size() == 0 || m_nCurrentPaper >= (*m_pPapers).size() || m_mapStackPage.size() == 0)
- {
- return;
- }
- paperInfo.id = (*m_pPapers)[m_nCurrentPaper].id;
- strcpy_s(paperInfo.page0_path, m_mapStackPage[0].top().c_str());
- strcpy_s(paperInfo.page1_path, m_mapStackPage[1].top().c_str());
- }
- void CPaperEditHandle::CalcRoom()
- {
- if (m_bgimage.width() == 0 || m_bgimage.height() == 0)
- {
- return;
- }
- QRect rcClient = geometry();
- int _width = rcClient.width() - 2 * painter_offset;
- int _height = rcClient.height() - painter_offset;
- if (m_bgimage.width() > _width || m_bgimage.height() > _height)
- {
- m_room = min(_width / (float)m_bgimage.width(), _height / (float)m_bgimage.height());
- }
- }
- void CPaperEditHandle::wheelEvent(QWheelEvent *event) // 滚轮事件
- {
- /*if (QApplication::keyboardModifiers() == Qt::ControlModifier)*/
- {
- if (event->delta() > 0)
- { // 当滚轮远离使用者时
- ClickRoomin(); // 进行放大
- }
- else
- { // 当滚轮向使用者方向旋转时
- ClickRoomout(); // 进行缩小
- }
- }
- }
|