#include "qpaperedithandler.h" #include #include #include #include "QHBoxLayout" #include #include #include #include "..\Util\Util.h" int curItem = 0;//当前显示是哪一页 int index[64];//当前步 int total[64];//总步数 vector editedImglist; string SaveTempImg(QImage* pimage) { std::wstring strModuleDir; GetModuleDir(strModuleDir); strModuleDir.append(L"temppain\\"); char buf[32] = { 0 }; index[curItem] += 1; sprintf(buf, "%d_%d.jpg", curItem, index[curItem]); QString path; path = path.fromStdWString(strModuleDir); path = path + QString::fromLocal8Bit(buf); pimage->save(path, "JPG", 255); total[curItem] = index[curItem]; editedImglist[curItem] = path; return path.toLocal8Bit().toStdString(); } string getCurPath() { std::wstring strModuleDir; GetModuleDir(strModuleDir); strModuleDir.append(L"temppain\\"); char buf[32] = { 0 }; sprintf(buf, "%d_%d.jpg", curItem, index[curItem]); QString path; path = path.fromStdWString(strModuleDir); path = path + QString::fromLocal8Bit(buf); return path.toLocal8Bit().toStdString(); } //#include //#include //using namespace Gdiplus; void getDpiXY(string path, float &xDPI, float &yDPI) { /*Gdiplus::Status status = Gdiplus::GenericError; QString strtmp = QString::fromLocal8Bit(path.c_str()); Gdiplus::Image imgtemp(strtmp.toStdWString().c_str()); status = imgtemp.GetLastStatus(); if (status == Gdiplus::Ok) { yDPI = imgtemp.GetVerticalResolution(); xDPI = imgtemp.GetHorizontalResolution(); } else{ yDPI = 96; xDPI = 96; }*/ return; } MyItemPainter::MyItemPainter(QWidget *parent) : QStyledItemDelegate(parent) { } MyItemPainter::~MyItemPainter() { } //设置显示的总高度 QSize MyItemPainter::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const { //获取每一行的原始大小 QSize size = QStyledItemDelegate::sizeHint(option, index); //size.setHeight(60); //重写之前的默认返回值 return QStyledItemDelegate::sizeHint(option, index); } void MyItemPainter::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { QVariant variant = index.data(Qt::UserRole); ItemInfo user = variant.value(); QRect Rect = option.rect; Rect.adjust(2, 2, -2, -2); //取得对应项的数据 QString strDisplay = index.data(Qt::DisplayRole).toString();//名称 QString strTip = index.data(Qt::UserRole + 1).toString();//提示 QString strPath = index.data(Qt::UserRole + 2).toString();//图标路径 //显示操作:当选中某一项时 if (option.state & QStyle::State_On) { painter->setPen(QColor(0, 150, 0)); painter->drawRect(Rect); } else if (option.state & QStyle::State_Selected) { painter->setPen(QColor(22, 174, 105)); painter->drawRect(Rect); } else if (option.state & QStyle::State_MouseOver) { painter->setPen(QColor(65, 155, 249)); painter->drawRect(Rect); } { QRect dst = Rect; dst.adjust(1, 1, -1, -1); dst.setBottom(dst.bottom() - 21); painter->drawImage(dst, *user.pPreviewImg, QRect(0, 0, user.pPreviewImg->width(), user.pPreviewImg->height())); dst = Rect; dst.setTop(dst.bottom() - 21); if (curItem == user.id) { painter->setPen(QColor(22, 174, 105)); } else { painter->setPen(QColor(55, 55, 55)); } painter->drawText(dst, Qt::AlignCenter, QString::number(user.id + 1)); } //重写之前的默认返回值 return QStyledItemDelegate::paint(painter, option, index); } QPaperEditHandler::QPaperEditHandler(QWidget *parent) : QWidget(parent), itemPainter(this) { ui.setupUi(this); m_bShowMovie = false; startPoint = QPoint(0, 0); endPoint = QPoint(0, 0); ispressed = false; mousestatus = Mouse_Normal; room = 1.0f; for (int i = 0; i < 64; i++) { index[i] = 0; total[i] = 0; } bFirstResize = true; paper_id = 0; origionImgpath = ""; offset = QPoint(0, 0); eraserW = 17; eraserH = 13; curItem = 0; locateW = 40; locateH = 20; penW = 2; penColor = QColor(255, 0, 0); lineW = 2; lineColor = QColor(255, 0, 0); bLoadedPreview = false; //connect(&cutdlg, SIGNAL(focusOut()), this, SLOT(mergeImg())); m_titleInfo = ""; editedImglist.clear(); m_bIsEdited = false; ui.toolButton_preview->setAutoFillBackground(true); //QPalette patlette; //patlette.setColor(QPalette::ButtonText, Qt::red); // 设置button 文本颜色红色 //ui.toolButton_preview->setPalette(patlette); ui.horizontalLayoutWidget->hide(); ui.horizontalLayoutWidget->setStyleSheet("background-color:rgba(233,237,241,0.66);"); HideButtons(); setAttribute(Qt::WA_DeleteOnClose, true); //ui.toolButton_eraser->installEventFilter(this); this->setMouseTracking(true);// 追踪鼠标 ui.widget_Drag->hide(); SetPaper(1); QMovie *movie = new QMovie(QString::fromLocal8Bit(":/painter/Resources/painter/loading.gif")); ui.label_movie->setMovie(movie); movie->start(); ui.label_movie->hide(); ui.label_reidentify->hide(); ui.label_shibaiyuanyin->hide(); ClickDrag(); m_curpage = 0; } void QPaperEditHandler::ClickSwitchPage() { if (origionImglist.size() != 2) { return; } QString msg = QString::fromLocal8Bit("换页后,将清空所有对图片的修改,"); msg += QString::fromLocal8Bit("确定要换页吗?"); /*if (QBaseDialog::OkButton == QMessageDialog::information(this, QString::fromLocal8Bit("提示"), msg, QBaseDialog::OkCancelButton))*/ { index[curItem] = 0;//当前步 total[curItem] = 0;//总步数 origionImglist.push_back(origionImglist[0]); origionImglist.erase(origionImglist.begin()); oldImgpathlist.push_back(oldImgpathlist[0]); oldImgpathlist.erase(oldImgpathlist.begin()); editedImglist = origionImglist; SetOrigionImg(origionImglist[curItem],oldImgpathlist[curItem]); bLoadedPreview = false; m_bIsEdited = false; } } void QPaperEditHandler::SetPaper(int paper_id) { wstring strmoduledir; GetModuleDir(strmoduledir); wstring strImage1(strmoduledir); wstring strImage2(strmoduledir); strImage1.append(L"zipfile\\ZipFile20211211105822_177A20440374P1_20211230153445\\papers\\Doc1639191470_1.jpg"); strImage2.append(L"zipfile\\ZipFile20211211105822_177A20440374P1_20211230153445\\papers\\Doc1639191470_-1.jpg"); vector imglist; vector imgoldpathlist; imglist.push_back(QString::fromStdWString(strImage1.c_str())); imgoldpathlist.push_back(UnicodeToGB2312(strImage1.c_str())); imglist.push_back(QString::fromStdWString(strImage2.c_str())); imgoldpathlist.push_back(UnicodeToGB2312(strImage2.c_str())); SetImgList(imglist,imgoldpathlist); SetOrigionImg(QString::fromStdWString(strImage1.c_str()), UnicodeToGB2312(strImage1.c_str())); this->paper_id = paper_id; extern bool g_online_anwser_card; ui.toolButton_cur->hide(); ui.toolButton_conflict1->hide(); ui.toolButton_conflict2->hide(); ui.toolButton_conflict3->hide(); ui.toolButton_conflict4->hide(); ui.toolButton_conflict5->hide(); } void QPaperEditHandler::HideButtons() { ui.toolButton_locate1->hide(); ui.toolButton_locate2->hide(); ui.toolButton_locate3->hide(); ui.toolButton_line1->hide(); ui.toolButton_line2->hide(); ui.toolButton_line3->hide(); ui.toolButton_pen1->hide(); ui.toolButton_pen2->hide(); ui.toolButton_pen3->hide(); ui.toolButton_penred->hide(); ui.toolButton_penblack->hide(); ui.toolButton_line1->hide(); ui.toolButton_line2->hide(); ui.toolButton_line3->hide(); ui.toolButton_linered->hide(); ui.toolButton_lineblack->hide(); ui.toolButton_eraser1->hide(); ui.toolButton_eraser2->hide(); ui.toolButton_erase3->hide(); ui.toolButton_restore->hide(); ui.toolButton_redo->hide(); ui.toolButton_switchpage->hide(); } void QPaperEditHandler::Reset() { } QPaperEditHandler::~QPaperEditHandler() { ui.listWidget_preview->clear(); for (auto& it : iteminfos) { delete it.pPreviewImg; } } void QPaperEditHandler::ClickPreViewLable(int id) { id = 1; } void QPaperEditHandler::ClickButton() { if (mousestatus == Mouse_Cuting) { ClickCutDel(); } HideButtons(); 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_pen || sender == ui.toolButton_pen1 || sender == ui.toolButton_pen2 || sender == ui.toolButton_pen3 || sender == ui.toolButton_penred || sender == ui.toolButton_penblack) { ClickPen(sender); } else if (sender == ui.toolButton_line || sender == ui.toolButton_line1 || sender == ui.toolButton_line2 || sender == ui.toolButton_line3 || sender == ui.toolButton_linered || sender == ui.toolButton_lineblack) { ClickLine(sender); } else if (sender == ui.toolButton_eraser || sender == ui.toolButton_eraser1 || sender == ui.toolButton_eraser2 || sender == ui.toolButton_erase3) { ClickEraser(sender); } else if (sender == ui.toolButton_undo) { ClickUndo(); } else if (sender == ui.toolButton_redo) { ClickRedo(); } else if (sender == ui.toolButton_cut) { ClickCut(); } else if (sender == ui.toolButton_more) { ClickMore(); } else if (sender == ui.toolButton_pre || sender == ui.toolButton_left) { ClickPre(); } else if (sender == ui.toolButton_preview) { ClickPreView(); } else if (sender == ui.toolButton_restore) { ClickRestore(); } else if (sender == ui.toolButton_next || sender == ui.toolButton_right) { ClickNext(); } else if (sender == ui.toolButton_Switch) { ClickSwitchDrag(); //emit switchToShibieYichang(); } else if (sender == ui.toolButton_cur) { ClickCur(); } else if (sender == ui.toolButton_conflict1) { ClickConflict(1); } else if (sender == ui.toolButton_conflict2) { ClickConflict(2); } else if (sender == ui.toolButton_conflict3) { ClickConflict(3); } else if (sender == ui.toolButton_conflict4) { ClickConflict(4); } else if (sender == ui.toolButton_conflict5) { ClickConflict(5); } else if (sender == ui.toolButton_switchpage) { ClickSwitchPage(); } if (curItem == 0) { ui.toolButton_pre->setEnabled(false); ui.toolButton_left->setEnabled(false); } else { ui.toolButton_pre->setEnabled(true); ui.toolButton_left->setEnabled(true); } if (curItem == origionImglist.size() - 1) { ui.toolButton_next->setEnabled(false); ui.toolButton_right->setEnabled(false); } else { ui.toolButton_next->setEnabled(true); ui.toolButton_right->setEnabled(true); } } void QPaperEditHandler::ClickCur()//考号冲突 点击当前页 { /*ui.horizontalLayoutWidget->hide(); bLoadedPreview = false; ui.toolButton_preview->setChecked(false); SetViewMode(false); emit sig_SetViewMode(false); PAPER_DETAIL paper_detail; vector pageList; vector questionList; int ret = QueryPaperDetail(paper_id, paper_detail, pageList, questionList); vector imglist; vector imgoldpathlist; for (auto& it : pageList) { imglist.push_back(QString::fromLocal8Bit(it.img_path.c_str())); imgoldpathlist.push_back(it.img_oldpath); } SetImgList(imglist, imgoldpathlist); curItem = m_curpage; origionImgpath = QString::fromLocal8Bit(pageList[curItem].img_path.c_str()); oldimgpath = pageList[curItem].img_oldpath; QString path = QString::fromLocal8Bit(getCurPath().c_str()); bgimage.load(path); bgimage = bgimage.convertToFormat(QImage::Format_RGB32); update(); setFocus(); string sl = pageList[curItem].img_oldpath; emit PaperChange(QString::fromLocal8Bit(sl.c_str())); if (curItem == 0) { ui.toolButton_pre->setEnabled(false); ui.toolButton_left->setEnabled(false); } else { ui.toolButton_pre->setEnabled(true); ui.toolButton_left->setEnabled(true); } if (curItem == origionImglist.size() - 1) { ui.toolButton_next->setEnabled(false); ui.toolButton_right->setEnabled(false); } else { ui.toolButton_next->setEnabled(true); ui.toolButton_right->setEnabled(true); } char buf[16] = { 0 }; sprintf(buf, "%d/%d", curItem + 1, pageList.size()); ui.toolButton_preview->setText(buf);*/ } void QPaperEditHandler::ClickConflict(int index) { /*bLoadedPreview = false; ui.horizontalLayoutWidget->hide(); ui.toolButton_preview->setChecked(false); m_curpage = curItem; curItem = 0; SetViewMode(true); emit sig_SetViewMode(true); int paper_id = m_conflict_paper[index - 1]; PAPER_DETAIL paper_detail; vector pageList; vector questionList; int ret = QueryPaperDetail(paper_id, paper_detail, pageList, questionList); vector imglist; vector imgoldpathlist; for (auto& it : pageList) { imglist.push_back(QString::fromLocal8Bit(it.img_path.c_str())); imgoldpathlist.push_back(it.img_oldpath); } SetImgList(imglist, imgoldpathlist); bgimage.load(QString::fromLocal8Bit(pageList[curItem].img_path.c_str())); bgimage = bgimage.convertToFormat(QImage::Format_RGB32); update(); setFocus(); string sl = pageList[0].img_oldpath; emit PaperChange(QString::fromLocal8Bit(sl.c_str())); if (curItem == 0) { ui.toolButton_pre->setEnabled(false); ui.toolButton_left->setEnabled(false); } else { ui.toolButton_pre->setEnabled(true); ui.toolButton_left->setEnabled(true); } if (curItem == origionImglist.size() - 1) { ui.toolButton_next->setEnabled(false); ui.toolButton_right->setEnabled(false); } else { ui.toolButton_next->setEnabled(true); ui.toolButton_right->setEnabled(true); } char buf[16] = { 0 }; sprintf(buf, "%d/%d", 1, pageList.size()); ui.toolButton_preview->setText(buf);*/ } void QPaperEditHandler::ClickSwitchDrag()//切换到拖移模式 { if (ui.widget_Drag->isVisible()) { ui.widget_Drag->hide(); ui.toolButton_Switch->setStyleSheet(QString::fromUtf8("QToolButton{\n" " image:url(:/painter/Resources/painter/\346\230\276\347\244\272\346\250\241\346\235\277-\346\255\243\345\270\270.png);\n" "}\n" "QToolButton:hover{\n" " image:url(:/painter/Resources/painter/\346\230\276\347\244\272\346\250\241\346\235\277-\347\247\273\345\205\245.png);\n" "}")); ui.widget_Drag->OnDoFinish(); QString path = QString::fromLocal8Bit(getCurPath().c_str()); bgimage.load(path); bgimage = bgimage.convertToFormat(QImage::Format_RGB32); } else { ui.widget_Drag->show(); ui.toolButton_Switch->setStyleSheet(QString::fromUtf8("QToolButton{\n" " image:url(:/painter/Resources/painter/\351\232\220\350\227\217\346\250\241\346\235\277-\346\255\243\345\270\270.png);\n" "}\n" "QToolButton:hover{\n" " image:url(:/painter/Resources/painter/\351\232\220\350\227\217\346\250\241\346\235\277-\347\247\273\345\205\245.png);\n" "}")); ui.widget_Drag->setPaperInfo(paper_id); } } void QPaperEditHandler::ClickDrag() { if (ui.toolButton_drag->isChecked()) { mousestatus = Mouse_Drag; } else { mousestatus = Mouse_Normal; } setCursor(Qt::SizeAllCursor); } void QPaperEditHandler::ClickPen(QObject* sender) { if (sender == ui.toolButton_pen) { if (ui.toolButton_pen->isChecked()) { mousestatus = Mouse_Pen; ui.toolButton_pen1->show(); ui.toolButton_pen2->show(); ui.toolButton_pen3->show(); ui.toolButton_penred->show(); ui.toolButton_penblack->show(); } else { mousestatus = Mouse_Normal; ui.toolButton_pen1->hide(); ui.toolButton_pen2->hide(); ui.toolButton_pen3->hide(); ui.toolButton_penred->hide(); ui.toolButton_penblack->hide(); } } else if (sender == ui.toolButton_pen1) { penW = 1; } else if (sender == ui.toolButton_pen2) { penW = 2; } else if (sender == ui.toolButton_pen3) { penW = 3; } else if (sender == ui.toolButton_penred) { penColor = QColor(Qt::red); } else if (sender == ui.toolButton_penblack) { penColor = QColor(0, 0, 0); } setCursor(Qt::ArrowCursor); } void QPaperEditHandler::ClickEraser(QObject* sender) { if (sender == ui.toolButton_eraser) { if (ui.toolButton_eraser->isChecked()) { mousestatus = Mouse_Eraser; ui.toolButton_eraser1->show(); ui.toolButton_eraser2->show(); ui.toolButton_erase3->show(); } else { mousestatus = Mouse_Normal; ui.toolButton_eraser1->hide(); ui.toolButton_eraser2->hide(); ui.toolButton_erase3->hide(); } } else if (sender == ui.toolButton_eraser1) { eraserW = 13; eraserH = 9; } else if (sender == ui.toolButton_eraser2) { eraserW = 17; eraserH = 13; } else if (sender == ui.toolButton_erase3) { eraserW = 23; eraserH = 17; } QPixmap pixmap(eraserW + 1, eraserH + 1); QPainter painterim(&pixmap); painterim.setRenderHint(QPainter::Antialiasing); pixmap.fill(Qt::white); //填充1像素值 painterim.drawRect(0, 0, eraserW + 1, eraserH + 1); QCursor cursor(pixmap, 0, 0); //加载xpm生成的图标文件 setCursor(cursor); //设置自定义的鼠标样式 } void QPaperEditHandler::ClickLine(QObject* sender) { if (sender == ui.toolButton_line) { if (ui.toolButton_line->isChecked()) { mousestatus = Mouse_Line; ui.toolButton_line1->show(); ui.toolButton_line2->show(); ui.toolButton_line3->show(); ui.toolButton_linered->show(); ui.toolButton_lineblack->show(); } else { mousestatus = Mouse_Normal; ui.toolButton_line1->hide(); ui.toolButton_line2->hide(); ui.toolButton_line3->hide(); ui.toolButton_linered->hide(); ui.toolButton_lineblack->hide(); } } else if (sender == ui.toolButton_line1) { lineW = 1; } else if (sender == ui.toolButton_line2) { lineW = 2; } else if (sender == ui.toolButton_line3) { lineW = 3; } else if (sender == ui.toolButton_linered) { lineColor = QColor(255, 0, 0); } else if (sender == ui.toolButton_lineblack) { lineColor = QColor(0, 0, 0); } setCursor(Qt::ArrowCursor); } void QPaperEditHandler::ClickCut() { if (ui.toolButton_cut->isChecked()) { mousestatus = Mouse_Cut; } else { mousestatus = Mouse_Normal; } setCursor(Qt::ArrowCursor); } void QPaperEditHandler::ClickRoomin() { offset.setX(0); offset.setY(0); room = room*1.1; //bgimage.scaled(bgimage.width()*room, bgimage.height()* room, Qt::KeepAspectRatio); 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 QPaperEditHandler::ClickRoomout() { offset.setX(0); offset.setY(0); room = room / 1.1; //bgimage.scaled(bgimage.width()*room, bgimage.height()* room, Qt::KeepAspectRatio); 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 QPaperEditHandler::ClickRotate90() { offset.setX(0); offset.setY(0); QMatrix matrix; matrix.rotate(90.0); bgimage = bgimage.transformed(matrix, Qt::FastTransformation); update(); if (!ui.toolButton_cur->isChecked()) { return; } m_bIsEdited = true; SaveTempImg(&bgimage); } void QPaperEditHandler::ClickRotateN90() { offset.setX(0); offset.setY(0); QMatrix matrix; matrix.rotate(-90.0); bgimage = bgimage.transformed(matrix, Qt::FastTransformation); update(); if (!ui.toolButton_cur->isChecked()) { return; } m_bIsEdited = true; SaveTempImg(&bgimage); } void QPaperEditHandler::ClickUndo() { m_bIsEdited = true; if (index[curItem] == 0) { return; } index[curItem]--; if (index[curItem] == 0) { bgimage.load(origionImgpath); } else { QString path = QString::fromLocal8Bit(getCurPath().c_str()); bgimage.load(path); } bgimage = bgimage.convertToFormat(QImage::Format_RGB32); update(); } void QPaperEditHandler::ClickRedo() { m_bIsEdited = true; if (index[curItem] == total[curItem]) { return; } ++index[curItem]; QString path = QString::fromLocal8Bit(getCurPath().c_str()); bgimage.load(path); bgimage = bgimage.convertToFormat(QImage::Format_RGB32); update(); } void QPaperEditHandler::ClickLocate(QObject* sender) { int locX, locY; if (sender == ui.toolButton_locate) { if (ui.toolButton_locate->isChecked()) { mousestatus = Mouse_Locate; ui.toolButton_locate1->show(); ui.toolButton_locate2->show(); ui.toolButton_locate3->show(); if (ui.toolButton_locate1->isChecked()) { locX = 18; locY = 12; } else if (ui.toolButton_locate2->isChecked()) { locX = 30; locY = 18; } else if (ui.toolButton_locate3->isChecked()) { locX = 40; locY = 20; } } else { mousestatus = Mouse_Normal; ui.toolButton_locate1->hide(); ui.toolButton_locate2->hide(); ui.toolButton_locate3->hide(); } } else if (sender == ui.toolButton_locate1) { locX = 18; locY = 12; } else if (sender == ui.toolButton_locate2) { locX = 30; locY = 18; } else if (sender == ui.toolButton_locate3) { locX = 40; locY = 20; } float x, y; getDpiXY(origionImglist[0].toLocal8Bit().toStdString(), x, y); locateW = locX * (x / 96); locateH = locY * (y / 96); 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 QPaperEditHandler::ClickMore() { ui.toolButton_redo->show(); ui.toolButton_restore->show(); ui.toolButton_switchpage->show(); } void QPaperEditHandler::ClickPre() { long long currentTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); LoadPreview(); int id = preItem(); if (iteminfos.size() > 0) { origionImgpath = iteminfos[id].origion_imgpath; oldimgpath = iteminfos[id].img_oldpath; if (ui.toolButton_cur->isChecked()) { if (index[curItem] > 0) { QString path = QString::fromLocal8Bit(getCurPath().c_str()); bgimage.load(path); if (m_titleInfo.length() == 0) { string sl = iteminfos[id].img_oldpath; emit PaperChange(QString::fromLocal8Bit(sl.c_str())); } else { emit PaperChange(QString::fromLocal8Bit(m_titleInfo.c_str())); } } else { SetOrigionImg(origionImgpath,iteminfos[id].img_oldpath); } } else { SetOrigionImg(origionImgpath, iteminfos[id].img_oldpath); } bgimage = bgimage.convertToFormat(QImage::Format_RGB32); int aaa = QDateTime::currentDateTime().toMSecsSinceEpoch() - currentTime; update(); ui.listWidget_preview->setItemSelected(iteminfos[id].pItem, true); ui.listWidget_preview->setCurrentRow(id); char buf[8] = { 0 }; sprintf(buf, "%d/%d", id + 1, iteminfos.size()); ui.toolButton_preview->setText(buf); int bbb = QDateTime::currentDateTime().toMSecsSinceEpoch() - currentTime; bbb += 1; } } void QPaperEditHandler::ClickPreView() { LoadPreview(); if (ui.toolButton_preview->isChecked()) { ui.horizontalLayoutWidget->show(); } else { ui.horizontalLayoutWidget->hide(); } } void QPaperEditHandler::ClickNext() { LoadPreview(); int id = NextItem(); if (iteminfos.size() > 0) { oldimgpath = iteminfos[id].img_oldpath; origionImgpath = iteminfos[id].origion_imgpath; if (ui.toolButton_cur->isChecked()) { if (index[curItem] > 0) { QString path = QString::fromLocal8Bit(getCurPath().c_str()); bgimage.load(path); string sl = iteminfos[id].img_oldpath; if (m_titleInfo.length() == 0) { emit PaperChange(QString::fromLocal8Bit(sl.c_str())); } else { emit PaperChange(QString::fromLocal8Bit(m_titleInfo.c_str())); } } else { SetOrigionImg(origionImgpath, iteminfos[id].img_oldpath); } } else { SetOrigionImg(origionImgpath, iteminfos[id].img_oldpath); } bgimage = bgimage.convertToFormat(QImage::Format_RGB32); update(); ui.listWidget_preview->setItemSelected(iteminfos[id].pItem, true); ui.listWidget_preview->setCurrentRow(id); char buf[16] = { 0 }; sprintf(buf, "%d/%d", id + 1, iteminfos.size()); ui.toolButton_preview->setText(buf); } } void QPaperEditHandler::ClickRestore() { //QString msg = QString::fromLocal8Bit("还原后,将清空所有对图片的修改,"); //msg += QString::fromLocal8Bit("确定要还原吗?"); //if (QBaseDialog::OkButton == QMessageDialog::information(this, QString::fromLocal8Bit("提示"), msg, QBaseDialog::OkCancelButton)) //{ // room = 1.0f; // index[curItem] = 0;//当前步 // total[curItem] = 0;//总步数 // offset = QPoint(0, 0); // SetOrigionImg(origionImgpath,oldimgpath); // m_bIsEdited = false; //} } void QPaperEditHandler::ClickCutOK() { //ctlDlg.ui.label->hide(); //ctlDlg.ui.toolButton_ok->hide(); //ctlDlg.ui.toolButton_del1->hide(); //ctlDlg.ui.toolButton_save->show(); //ctlDlg.ui.toolButton_copy->show(); //ctlDlg.ui.toolButton_del2->show(); //ctlDlg.setStyleSheet("#PainterCutCtl{border:none;background - color: rgb(64, 64, 64);}"); } void QPaperEditHandler::ClickCutDel() { /*cutdlg.hide(); ctlDlg.hide(); mousestatus = Mouse_Cut;*/ } void QPaperEditHandler::ClickCutSave() { mergeImg(); ClickCutDel(); } void QPaperEditHandler::ClickCutCopy() { mergeImg(); } void QPaperEditHandler::paintEvent(QPaintEvent *e)//将上一个函数得到的全屏灰色图绘制在painter上,并添加宽高信息矩形和边角拖曳小正方形 { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.translate(offset.x(), offset.y()); painter.scale(room, room); painter.drawImage(QPoint(0, 0), bgimage); if (ispressed) { if (mousestatus == Mouse_Line) { pen.setColor(lineColor); pen.setWidth(lineW / room); painter.setPen(pen); painter.drawLine(PointSwitchToImg(startPoint), PointSwitchToImg(endPoint)); } else if (mousestatus == Mouse_Cut) { /* cutdlg.pen.setWidth(1 / room); painter.setPen(cutdlg.pen); painter.drawRect(QRect(PointSwitchToImg(startPoint), PointSwitchToImg(endPoint))); cutdlg.pen.setWidth(1);*/ } } if (m_bShowMovie) { //QPainter painter2(this); //painter2.setRenderHint(QPainter::Antialiasing); //QRect rc = ui.label_movie->geometry(); //QRect rcclient = geometry(); //rc.setTop(rc.bottom() + 5); //rc.setLeft(0); //rc.setBottom(rcclient.bottom()); //rc.setRight(rcclient.right()); //painter2.setPen(QColor(21, 174, 104)); //QFont font; //font.setFamily(QStringLiteral("Agency FB")); //font.setPointSize(30); //painter2.setFont(font); //painter2.drawText(rc, Qt::AlignHCenter | Qt::AlignTop, QString::fromLocal8Bit("重新识别中…")); } } void QPaperEditHandler::mousePressEvent(QMouseEvent *event) { /*if (!ui.toolButton_cur->isChecked()) { return; } HideButtons(); startPoint = event->pos(); endPoint = event->pos(); if (!ui.widget_Drag->isVisible()) { ispressed = true; }*/ } void QPaperEditHandler::mouseMoveEvent(QMouseEvent *event) { if (!ui.toolButton_cur->isChecked()) { return; } QPainter painterim(&bgimage); painterim.setRenderHint(QPainter::Antialiasing); if (ispressed) { if (mousestatus == Mouse_Pen) { pen.setWidth(penW / room); pen.setColor(penColor); painterim.setPen(pen); endPoint = event->pos(); painterim.drawLine(PointSwitchToImg(startPoint), PointSwitchToImg(endPoint)); startPoint = endPoint; update(); } else if (mousestatus == Mouse_Line) { endPoint = event->pos(); update(); } else if (mousestatus == Mouse_Eraser) { painterim.eraseRect(RectSwitchImg(QRect(event->pos().x(), event->pos().y(), eraserW, eraserH))); update(); } else if (mousestatus == Mouse_Drag) { endPoint = event->pos(); offset.setX(endPoint.x() - startPoint.x() + offset.x()); offset.setY(endPoint.y() - startPoint.y() + offset.y()); startPoint = endPoint; if (bgimage.width()*room <= geometry().width()) //不能拖动 { offset.setX(0); } else { int offxMax = 0, offxMin = geometry().width() - bgimage.width()*room; if (offset.x() < offxMin) { offset.setX(offxMin); } else if (offset.x() > offxMax) { offset.setX(offxMax); } } if (bgimage.height()*room <= geometry().height()) //不能拖动 { offset.setY(0); } else { int offyMax = 0, offyMin = geometry().height() - bgimage.height()*room; if (offset.y() < offyMin) { offset.setY(offyMin); } else if (offset.y() > offyMax) { offset.setY(offyMax); } } update(); } else if (mousestatus == Mouse_Cut) { endPoint = event->pos(); update(); } } } void QPaperEditHandler::mouseReleaseEvent(QMouseEvent *event) { //setCursor(Qt::ArrowCursor); if (!ui.toolButton_cur->isChecked()) { return; } ispressed = false; if (mousestatus == Mouse_Line) { QPainter painterim(&bgimage); painterim.setRenderHint(QPainter::Antialiasing); pen.setWidth(lineW / room); pen.setColor(lineColor); painterim.setPen(pen); endPoint = event->pos(); painterim.drawLine(PointSwitchToImg(startPoint), PointSwitchToImg(endPoint)); m_bIsEdited = true; SaveTempImg(&bgimage); update(); } else if (mousestatus == Mouse_Cut) { QRect rcimg(0, 0, bgimage.width(), bgimage.height()); QRect rcScope = RectSwitchToClient(rcimg); QRect rcclient = geometry(); rcScope.setX(max(rcScope.left(), 0)); rcScope.setY(max(rcScope.top(), 0)); rcScope.setRight(min(rcScope.right(), rcclient.right())); rcScope.setBottom(min(rcScope.bottom(), rcclient.bottom())); endPoint = event->pos(); QRect rcCut; rcCut.setX(min(startPoint.x(), endPoint.x()) - 2); rcCut.setY(min(startPoint.y(), endPoint.y()) - 2); rcCut.setRight(max(startPoint.x(), endPoint.x()) + 2); rcCut.setBottom(max(startPoint.y(), endPoint.y()) + 2); rcCut.setX(max(rcScope.left(), rcCut.left())); rcCut.setY(max(rcScope.top(), rcCut.top())); rcCut.setRight(min(rcScope.right(), rcCut.right())); rcCut.setBottom(min(rcScope.bottom(), rcCut.bottom())); /* cutdlg.setGeometry(rcCut); cutdlg.rcScope = rcScope;*/ rcCut.adjust(2, 2, -2, -2); /* cutdlg.bgimage = bgimage.copy(RectSwitchImg(rcCut)); cutdlg.show(); cutdlg.update(); cutdlg.setFocus();*/ rcCut.setTop(rcCut.bottom() + 3); rcCut.setBottom(rcCut.top() + 28); rcCut.setLeft(rcCut.right() - 250); if (rcCut.top() > rcScope.bottom() - 28) { rcCut.setTop(rcScope.bottom() - 35); } rcCut.setBottom(rcCut.top() + 28); if (rcCut.left() < 0) { rcCut.setLeft(0); rcCut.setRight(250); } /* ctlDlg.setGeometry(rcCut); ctlDlg.ui.label->show(); ctlDlg.ui.toolButton_ok->show(); ctlDlg.ui.toolButton_del1->show(); ctlDlg.ui.toolButton_save->hide(); ctlDlg.ui.toolButton_copy->hide(); ctlDlg.ui.toolButton_del2->hide(); ctlDlg.show();*/ //ctlDlg.setStyleSheet("#PainterCutCtl{\ // background - color: rgb(64, 64, 64);\ // border - radius: 4px;\ //border:1px groove gray;}" // ); update(); mousestatus = Mouse_Cuting; } else if (mousestatus == Mouse_Eraser) { QPainter painterim(&bgimage); painterim.setRenderHint(QPainter::Antialiasing); painterim.eraseRect(RectSwitchImg(QRect(event->pos().x(), event->pos().y(), eraserW, eraserH))); m_bIsEdited = true; SaveTempImg(&bgimage); update(); } else if (mousestatus == Mouse_Pen) { m_bIsEdited = true; SaveTempImg(&bgimage); m_bIsEdited = true; update(); } else if (mousestatus == Mouse_Locate) { QPainter painterim(&bgimage); painterim.setRenderHint(QPainter::SmoothPixmapTransform); QPoint pt = PointSwitchToImg(event->pos()); QRect rc(pt.x(), pt.y(), locateW, locateH); QRect target = rc; painterim.setBrush(Qt::black); painterim.drawRect(target); m_bIsEdited = true; SaveTempImg(&bgimage); update(); } } void QPaperEditHandler::wheelEvent(QWheelEvent *event) // 滚轮事件 { if (QApplication::keyboardModifiers() == Qt::ControlModifier) { if (event->delta() > 0) { // 当滚轮远离使用者时 ClickRoomin(); // 进行放大 } else { // 当滚轮向使用者方向旋转时 ClickRoomout(); // 进行缩小 } } } bool QPaperEditHandler::eventFilter(QObject *watched, QEvent *event) { //if (this == watched) { if (QEvent::Enter == event->type()) //鼠标进入 { setCursor(Qt::ArrowCursor); return true; //if (m_pStandardLabel->isHidden()) //{ //已经隐藏就显示出来 // m_pStandardLabel->show(); // QPoint point = ui->scoreStandardBtn->pos(); // point.rx() = point.x() - m_pStandardLabel->width() + 120; // point.ry() = point.y() + ui->scoreStandardBtn->height() + 40; // m_pStandardLabel->move(point); // m_pStandardLabel->raise();//显示最顶层 // return true; //} } else if (QEvent::Leave == event->type())//鼠标离开 { //if (!ui->scoreStandardBtn->geometry().contains(this->mapFromGlobal(QCursor::pos())) //判断鼠标是否在控件上 // && !m_pStandardLabel->geometry().contains(this->mapFromGlobal(QCursor::pos()))) //{ // m_pStandardLabel->hide(); // return true; //} //m_floatdlg->setModal(false); //m_floatdlg->hide(); return true; } } return QWidget::eventFilter(watched, event); } void QPaperEditHandler::resizeEvent(QResizeEvent *event) { if (bFirstResize) { bFirstResize = false; QRect rc = geometry(); float roomW = (float)rc.width() / bgimage.width(); float roomH = (float)rc.height() / bgimage.height(); room = roomW; if (roomH < room) { room = roomH; } } int w = 44; int h = 44; QRect rcclient = geometry(); ui.widget_Drag->setGeometry(rcclient); QRect temp1 = rcclient; QRect temp2; temp1.setLeft(rcclient.right() - w); temp1.setBottom(rcclient.top() + h); QRect rcUploadErrorInfo = rcclient; rcUploadErrorInfo.setTop(rcclient.top() + 25); rcUploadErrorInfo.setBottom(rcUploadErrorInfo.top() + 40); rcUploadErrorInfo.setLeft(rcUploadErrorInfo.left() + 100); rcUploadErrorInfo.setRight(rcUploadErrorInfo.right() - 100); ui.label_shibaiyuanyin->setGeometry(rcUploadErrorInfo);//上传失败原因 ui.toolButton_drag->setGeometry(temp1);//拖拽 temp1.moveTo(temp1.left(), temp1.bottom());//放大 ui.toolButton_roomin->setGeometry(temp1); temp1.moveTo(temp1.left(), temp1.bottom());//缩小 ui.toolButton_rommout->setGeometry(temp1); temp1.moveTo(temp1.left(), temp1.bottom());//正转 ui.toolButton_90->setGeometry(temp1); temp1.moveTo(temp1.left(), temp1.bottom());//逆转 ui.toolButton_N90->setGeometry(temp1); temp1.moveTo(temp1.left(), temp1.bottom());//定位点 ui.toolButton_locate->setGeometry(temp1); { temp2 = temp1; temp2.moveTo(temp2.left() - w, temp2.top()); ui.toolButton_locate1->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_locate2->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_locate3->setGeometry(temp2); } temp1.moveTo(temp1.left(), temp1.bottom()); ui.toolButton_pen->setGeometry(temp1); { temp2 = temp1; temp2.moveTo(temp1.left() - w, temp1.top()); ui.toolButton_pen1->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_pen2->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_pen3->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_penred->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_penblack->setGeometry(temp2); } temp1.moveTo(temp1.left(), temp1.bottom()); ui.toolButton_line->setGeometry(temp1); { temp2 = temp1; temp2.moveTo(temp1.left() - w, temp1.top()); ui.toolButton_line1->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_line2->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_line3->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_linered->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_lineblack->setGeometry(temp2); } temp1.moveTo(temp1.left(), temp1.bottom()); ui.toolButton_eraser->setGeometry(temp1); { temp2 = temp1; temp2.moveTo(temp2.left() - w, temp2.top()); ui.toolButton_eraser1->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_eraser2->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_erase3->setGeometry(temp2); } temp1.moveTo(temp1.left(), temp1.bottom()); ui.toolButton_undo->setGeometry(temp1); temp1.moveTo(temp1.left(), temp1.bottom()); ui.toolButton_cut->setGeometry(temp1); temp1.moveTo(temp1.left(), temp1.bottom()); ui.toolButton_more->setGeometry(temp1); { temp2 = temp1; temp2.moveTo(temp2.left() - w, temp2.top()); ui.toolButton_redo->setGeometry(temp2); temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_restore->setGeometry(temp2); if (origionImglist.size() == 2) { temp2.moveTo(temp2.left(), temp2.bottom()); ui.toolButton_switchpage->setGeometry(temp2); } } temp1 = rcclient; temp1.setLeft(rcclient.right() - w); temp1.setTop(rcclient.bottom() - h); ui.toolButton_next->setGeometry(temp1); temp1.moveTo(temp1.left(), temp1.top() - h + 1); ui.toolButton_preview->setGeometry(temp1); { temp2 = temp1; temp2.moveTo(temp2.left() - h - 18 + 1, temp2.top() + 1); ui.toolButton_right->setGeometry(temp2); temp2.moveTo(rcclient.left() + 18, temp2.top() + 1); ui.toolButton_left->setGeometry(temp2); temp2 = rcclient; temp2.setTop(rcclient.bottom() - 131); temp2.setRight(rcclient.right() - w); temp2.setLeft(rcclient.left()); //ui.listWidget_preview->setGeometry(temp2); ui.horizontalLayoutWidget->setGeometry(temp2); } temp1.moveTo(temp1.left(), temp1.top() - h + 1); ui.toolButton_pre->setGeometry(temp1); temp1.setLeft((rcclient.width() - 128) / 2); temp1.setWidth(128); temp1.setTop((rcclient.height() - 128) / 2); temp1.setHeight(128); ui.label_movie->setGeometry(temp1); temp1.setTop(temp1.bottom() + 1); temp1.setBottom(temp1.top() + 79); temp1.setLeft(temp1.left() - 61); temp1.setRight(temp1.right() + 65); ui.label_reidentify->setGeometry(temp1); } QPoint QPaperEditHandler::PointSwitchToImg(QPoint sPoint) { int x = sPoint.x() - offset.x(); x = x / room; int y = sPoint.y() - offset.y(); y = y / room; return QPoint(x, y); } QRect QPaperEditHandler::RectSwitchImg(QRect sRect) { QPoint lefttop = PointSwitchToImg(QPoint(sRect.left(), sRect.top())); QPoint rightbottom = PointSwitchToImg(QPoint(sRect.right(), sRect.bottom())); return QRect(lefttop, rightbottom); } QPoint QPaperEditHandler::PointSwitchToClient(QPoint sPoint) { int x = sPoint.x() * room; x = x + offset.x(); int y = sPoint.y() * room; y = y + offset.y(); return QPoint(x, y); } QRect QPaperEditHandler::RectSwitchToClient(QRect sRect) { QPoint lefttop = PointSwitchToClient(QPoint(sRect.left(), sRect.top())); QPoint rightbottom = PointSwitchToClient(QPoint(sRect.right(), sRect.bottom())); return QRect(lefttop, rightbottom); } void QPaperEditHandler::SetOrigionImg(QString path,string oldpath) { origionImgpath = path; oldimgpath = oldpath; bgimage.load(origionImgpath); bgimage = bgimage.convertToFormat(QImage::Format_RGB32); update(); setFocus(); if (ui.toolButton_cur->isChecked()) { QString path0 = QString::fromLocal8Bit(getCurPath().c_str()); bgimage.save(path0); } string sl = oldimgpath; if (m_titleInfo.length() == 0) { emit PaperChange(QString::fromLocal8Bit(sl.c_str())); } else { emit PaperChange(QString::fromLocal8Bit(m_titleInfo.c_str())); } } void QPaperEditHandler::LoadPreview() { if (bLoadedPreview) return; iteminfos.clear(); //ui.listWidget_preview->disconnect(); ui.listWidget_preview->clear(); ItemInfo info; for (int i = 0; i < origionImglist.size(); i++) { info.id = i; info.origion_imgpath = origionImglist[i]; info.pPreviewImg = new QImage; info.pPreviewImg->load(info.origion_imgpath); info.pItem = new QListWidgetItem(); info.img_oldpath = oldImgpathlist[i]; iteminfos.push_back(info); info.pItem->setSizeHint(QSize(156, 132)); info.pItem->setData(Qt::UserRole, QVariant::fromValue(iteminfos[iteminfos.size() - 1])); //info.pItem->setData(Qt::UserRole + 1, "This is Icon of Sage"); //info.pItem->setData(Qt::UserRole + 2, "D:/123/1.jpg"); ui.listWidget_preview->addItem(info.pItem); } ui.listWidget_preview->setViewMode(QListWidget::ListMode); ui.listWidget_preview->setFlow(QListWidget::LeftToRight); //ui.listWidget_preview->setMovement(QListWidget::Static); //设置显示模式为图标模式 ui.listWidget_preview->setViewMode(QListWidget::ListMode); //设置可以换行显示 ui.listWidget_preview->setLayoutMode(QListWidget::SinglePass); //不接受拖放 ui.listWidget_preview->setAcceptDrops(false); //开启排序功能 //ui.listWidget_preview->setSortingEnabled(true); itemPainter.setParent(ui.listWidget_preview); ui.listWidget_preview->setItemDelegate(&itemPainter); //ui.listWidget_preview->setEditTriggers(QListWidget::CurrentChanged); ui.listWidget_preview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); ui.listWidget_preview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); ui.listWidget_preview->setHorizontalScrollMode(QListWidget::ScrollPerPixel); QScroller::grabGesture(ui.listWidget_preview, QScroller::LeftMouseButtonGesture); //设置当前活动行为0 ui.listWidget_preview->setCurrentRow(curItem); ui.listWidget_preview->setItemSelected(iteminfos[curItem].pItem, true); connect(ui.listWidget_preview, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(ListItemChange(QListWidgetItem*))); bLoadedPreview = true; } void QPaperEditHandler::SetShowSchema(bool bshow) { if (bshow) { ui.toolButton_Switch->show(); } else { ui.toolButton_Switch->hide(); } } void QPaperEditHandler::SetImgList(vector imglist,vector oldpathlist) { this->origionImglist = imglist; this->oldImgpathlist = oldpathlist; editedImglist = imglist; char buf[16] = { 0 }; sprintf(buf, "%d/%d", 1, imglist.size()); ui.toolButton_preview->setText(buf); if (curItem == 0) { ui.toolButton_pre->setEnabled(false); ui.toolButton_left->setEnabled(false); } else { ui.toolButton_pre->setEnabled(true); ui.toolButton_left->setEnabled(true); } if (curItem == imglist.size() - 1) { ui.toolButton_next->setEnabled(false); ui.toolButton_right->setEnabled(false); } else { ui.toolButton_next->setEnabled(true); ui.toolButton_right->setEnabled(true); } } vector QPaperEditHandler::GetEditedImgs()//点击识别的时候调用 { if (ui.widget_Drag->isVisible()) { m_bIsEdited = ui.widget_Drag->IsEdited(); ui.widget_Drag->OnDoFinish(); } else { SaveTempImg(&bgimage); } vector imgs; for (int i = 0; i < origionImglist.size(); i++) { imgs.push_back(editedImglist[i].toLocal8Bit().toStdString()); } return imgs; } void QPaperEditHandler::ShowMovie(bool bshow) { if (bshow) { ui.label_movie->raise(); ui.label_movie->show(); ui.label_reidentify->show(); ui.label_reidentify->raise(); } else { ui.label_movie->hide(); ui.label_reidentify->hide(); } m_bShowMovie = bshow; update(); } void QPaperEditHandler::mergeImg() { /*QRect rc = cutdlg.geometry(); rc.adjust(2, 2, -2, -2); QRect target = RectSwitchImg(rc); QPainter painterim(&bgimage); painterim.setRenderHint(QPainter::Antialiasing); painterim.drawImage(target, cutdlg.bgimage, QRect(0, 0, cutdlg.bgimage.width(), cutdlg.bgimage.height())); update(); m_bIsEdited = true; SaveTempImg(&bgimage);*/ } int QPaperEditHandler::NextItem() { curItem++; if (curItem >= iteminfos.size()) { curItem = iteminfos.size() - 1; } return curItem; } int QPaperEditHandler::preItem() { curItem--; if (curItem < 0) { curItem = 0; } return curItem; } void QPaperEditHandler::ListItemChange(QListWidgetItem* pitem) { if (iteminfos.size()>0) { for (auto &it : iteminfos) { if (it.pItem == pitem) { curItem = it.id; origionImgpath = it.origion_imgpath; if (ui.toolButton_cur->isChecked()) { if (index[curItem] > 0) { QString path = QString::fromLocal8Bit(getCurPath().c_str()); bgimage.load(path); } else { SetOrigionImg(origionImgpath,it.img_oldpath); } } else { SetOrigionImg(origionImgpath,it.img_oldpath); } bgimage = bgimage.convertToFormat(QImage::Format_RGB32); update(); char buf[8] = { 0 }; sprintf(buf, "%d/%d", curItem + 1, iteminfos.size()); ui.toolButton_preview->setText(buf); } } } if (curItem == 0) { ui.toolButton_pre->setEnabled(false); ui.toolButton_left->setEnabled(false); } else { ui.toolButton_pre->setEnabled(true); ui.toolButton_left->setEnabled(true); } if (curItem == origionImglist.size() - 1) { ui.toolButton_next->setEnabled(false); ui.toolButton_right->setEnabled(false); } else { ui.toolButton_next->setEnabled(true); ui.toolButton_right->setEnabled(true); } return; } void QPaperEditHandler::SetViewMode(bool view) { if (view) { ui.toolButton_locate1->hide(); ui.toolButton_locate2->hide(); ui.toolButton_locate3->hide(); ui.toolButton_line1->hide(); ui.toolButton_line2->hide(); ui.toolButton_line3->hide(); ui.toolButton_pen1->hide(); ui.toolButton_pen2->hide(); ui.toolButton_pen3->hide(); ui.toolButton_penred->hide(); ui.toolButton_penblack->hide(); ui.toolButton_line1->hide(); ui.toolButton_line2->hide(); ui.toolButton_line3->hide(); ui.toolButton_linered->hide(); ui.toolButton_lineblack->hide(); ui.toolButton_eraser1->hide(); ui.toolButton_eraser2->hide(); ui.toolButton_erase3->hide(); ui.toolButton_cut->hide(); ui.toolButton_restore->hide(); ui.toolButton_redo->hide(); ui.toolButton_locate->hide(); ui.toolButton_pen->hide(); ui.toolButton_line->hide(); ui.toolButton_eraser->hide(); ui.toolButton_undo->hide(); ui.toolButton_more->hide(); ui.toolButton_Switch->hide(); ui.widget_Drag->hide(); ui.toolButton_switchpage->hide(); } else { ui.toolButton_cut->show(); ui.toolButton_locate->show(); ui.toolButton_pen->show(); ui.toolButton_line->show(); ui.toolButton_eraser->show(); ui.toolButton_undo->show(); ui.toolButton_more->show(); } } void QPaperEditHandler::SetTitleInfo(string info) { m_titleInfo = info; } void QPaperEditHandler::SetHandlerKaohaoyichang(bool bViewMode) { if (bViewMode) { ui.toolButton_locate->hide(); ui.toolButton_pen->hide(); ui.toolButton_line->hide(); ui.toolButton_eraser->hide(); ui.toolButton_undo->hide(); ui.toolButton_cut->hide(); ui.toolButton_more->hide(); } else { ui.toolButton_locate->show(); ui.toolButton_pen->show(); ui.toolButton_line->show(); ui.toolButton_eraser->show(); ui.toolButton_undo->show(); ui.toolButton_cut->show(); ui.toolButton_more->show(); } }