1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936 |
- #include "qpaperedithandler.h"
- #include <QScroller>
- #include <QLabel>
- #include <QScrollBar>
- #include "QHBoxLayout"
- #include <QDir>
- #include <QDateTime>
- #include <QMovie>
- #include "..\Util\Util.h"
- int curItem = 0;//当前显示是哪一页
- int index[64];//当前步
- int total[64];//总步数
- vector<QString> 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 <GdiPlus.h>
- //#include <comdef.h>
- //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<ItemInfo>();
- 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<QString> imglist;
- vector<string> 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<PAGE_DETAIL> pageList;
- vector<GROUP_QUESTION> questionList;
- int ret = QueryPaperDetail(paper_id, paper_detail, pageList, questionList);
- vector<QString> imglist;
- vector<string> 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<PAGE_DETAIL> pageList;
- vector<GROUP_QUESTION> questionList;
- int ret = QueryPaperDetail(paper_id, paper_detail, pageList, questionList);
- vector<QString> imglist;
- vector<string> 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<QString> imglist,vector<string> 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<string> QPaperEditHandler::GetEditedImgs()//点击识别的时候调用
- {
- if (ui.widget_Drag->isVisible())
- {
- m_bIsEdited = ui.widget_Drag->IsEdited();
- ui.widget_Drag->OnDoFinish();
- }
- else
- {
- SaveTempImg(&bgimage);
- }
- vector<string> 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();
- }
- }
|