添加OpenCv
This commit is contained in:
@@ -1,14 +1,165 @@
|
||||
#include "P14_AtlasPage.h"
|
||||
#include "ui_P14_AtlasPage.h"
|
||||
|
||||
P14_AtlasPage::P14_AtlasPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::P14_AtlasPage)
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QCoreApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QScrollArea>
|
||||
#include <QScrollBar>
|
||||
P14_AtlasPage::P14_AtlasPage(QWidget *parent)
|
||||
: QWidget(parent), ui(new Ui::P14_AtlasPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
WinInit();
|
||||
}
|
||||
|
||||
P14_AtlasPage::~P14_AtlasPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void P14_AtlasPage::WinInit()
|
||||
{
|
||||
|
||||
/* ----- 1. 扫描三组图 ----- */
|
||||
QString base = "./ProgramConfig/随机图册库";
|
||||
QDir dir1(base + "/电气图");
|
||||
QDir dir2(base + "/机械图");
|
||||
QDir dir3(base + "/液压图");
|
||||
|
||||
auto scan = [](QDir d, QMap<QString,QString> &map, QStringList &list){
|
||||
d.setNameFilters({"*.png","*.PNG"});
|
||||
d.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
||||
for (const QString &f : d.entryList()){
|
||||
map[f] = d.absoluteFilePath(f);
|
||||
list.append(f);
|
||||
}
|
||||
};
|
||||
|
||||
scan(dir1, Atlas1, AtStr1);
|
||||
scan(dir2, Atlas2, AtStr2);
|
||||
scan(dir3, Atlas3, AtStr3);
|
||||
|
||||
/* ----- 2. 界面初始 ----- */
|
||||
CurrentAtlas = 1;
|
||||
ui->LV_FileList->addItems(AtStr1);
|
||||
ui->Label_Img->setParent(nullptr);
|
||||
ui->scrollArea->setWidget(ui->Label_Img);
|
||||
ui->scrollArea->setWidgetResizable(false);
|
||||
ui->Label_Img->installEventFilter(this);
|
||||
ui->Label_Zoom->setText("100.00");
|
||||
on_LV_FileList_currentTextChanged(AtStr1[0]);
|
||||
|
||||
}
|
||||
|
||||
/* ---------- 列表换图 ---------- */
|
||||
void P14_AtlasPage::on_LV_FileList_currentTextChanged(const QString ¤tText)
|
||||
{
|
||||
|
||||
if (currentText.isEmpty()) return;
|
||||
ui->Label_Img->setText("");
|
||||
QString path;
|
||||
if(CurrentAtlas ==1){
|
||||
path = Atlas1.value(currentText); // 默认先电气图
|
||||
}else if(CurrentAtlas ==2){
|
||||
path = Atlas2.value(currentText); // 默认先电气图
|
||||
}else if(CurrentAtlas ==3){
|
||||
path = Atlas3.value(currentText); // 默认先电气图
|
||||
}
|
||||
|
||||
QPixmap pix(path);
|
||||
if (!pix.isNull()) {
|
||||
Img_W = pix.width();
|
||||
Img_H = pix.height();
|
||||
Img_Zoom = 0.238f;
|
||||
ui->Label_Zoom->setText("23.8 %");
|
||||
ui->Label_Img->setPixmap(pix);
|
||||
ui->Label_Img->resize(788, 557);
|
||||
ui->Label_Img->setScaledContents(true);
|
||||
} else {
|
||||
ui->Label_Img->clear();
|
||||
ui->Label_Img->setText("图册加载失败");
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 放大 ---------- */
|
||||
void P14_AtlasPage::on_But_Magnify_clicked()
|
||||
{
|
||||
if (Img_Zoom >= 1.3f) return;
|
||||
if(Img_Zoom < 0.25f)
|
||||
Img_Zoom = 0.25f;
|
||||
else
|
||||
Img_Zoom += 0.05f;
|
||||
ui->Label_Zoom->setText(QString::number(Img_Zoom*100) + " %");
|
||||
ui->Label_Img->resize(Img_W * Img_Zoom, Img_H * Img_Zoom);
|
||||
}
|
||||
|
||||
/* ---------- 缩小 ---------- */
|
||||
void P14_AtlasPage::on_But_Reduce_clicked()
|
||||
{
|
||||
if (Img_Zoom <= 0.238f) return;
|
||||
Img_Zoom -= 0.05f;
|
||||
if (Img_Zoom < 0.25f) Img_Zoom = 0.238f;
|
||||
ui->Label_Zoom->setText(QString::number(Img_Zoom*100) + " %");
|
||||
ui->Label_Img->resize(Img_W * Img_Zoom, Img_H * Img_Zoom);
|
||||
}
|
||||
|
||||
/* ---------- 底部三按钮 ---------- */
|
||||
void P14_AtlasPage::on_But_Atlas_1_clicked()
|
||||
{
|
||||
ui->LV_FileList->clear();
|
||||
ui->LV_FileList->addItems(AtStr1);
|
||||
CurrentAtlas = 1;
|
||||
}
|
||||
void P14_AtlasPage::on_But_Atlas_2_clicked()
|
||||
{
|
||||
ui->LV_FileList->clear();
|
||||
ui->LV_FileList->addItems(AtStr2);
|
||||
CurrentAtlas = 2;
|
||||
}
|
||||
void P14_AtlasPage::on_But_Atlas_3_clicked()
|
||||
{
|
||||
ui->LV_FileList->clear();
|
||||
ui->LV_FileList->addItems(AtStr3);
|
||||
CurrentAtlas = 3;
|
||||
}
|
||||
|
||||
/* ---------- 鼠标拖拽平移 ---------- */
|
||||
bool P14_AtlasPage::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
if (obj != ui->Label_Img) return false;
|
||||
|
||||
switch (ev->type()) {
|
||||
case QEvent::MouseButtonPress:
|
||||
if (static_cast<QMouseEvent*>(ev)->button() == Qt::LeftButton) {
|
||||
dragging = true;
|
||||
dragStart = static_cast<QMouseEvent*>(ev)->pos();
|
||||
ui->Label_Img->setCursor(Qt::ClosedHandCursor);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case QEvent::MouseMove:
|
||||
if (dragging) {
|
||||
auto *e = static_cast<QMouseEvent*>(ev);
|
||||
int dx = e->pos().x() - dragStart.x();
|
||||
int dy = e->pos().y() - dragStart.y();
|
||||
ui->scrollArea->horizontalScrollBar()->setValue(
|
||||
ui->scrollArea->horizontalScrollBar()->value() - dx);
|
||||
ui->scrollArea->verticalScrollBar()->setValue(
|
||||
ui->scrollArea->verticalScrollBar()->value() - dy);
|
||||
dragStart = e->pos();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
if (dragging && static_cast<QMouseEvent*>(ev)->button() == Qt::LeftButton) {
|
||||
dragging = false;
|
||||
ui->Label_Img->unsetCursor();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user