git-svn-id: svn://db.shs.com.ru/libs@379 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2018-05-17 15:54:19 +00:00
parent 56e250c150
commit d3e81d5efa
20 changed files with 1198 additions and 532 deletions

View File

@@ -1,41 +1,43 @@
#include <QCloseEvent>
#include "edockwidget.h"
#include "cdpultwindow.h"
#include "ui_cdpultwindow.h"
#include "cdutils_k.h"
#include "cdutils_core.h"
#include "qcd_core.h"
#include "qcd_kmodel.h"
#include "qcd_model.h"
#include "qcd_modedialog.h"
#include "chunkstream.h"
#include "qvariantedit.h"
#include <QFileDialog>
#include <QScrollBar>
CDPultWindow::CDPultWindow(QWidget *parent) : EMainWindow(parent), ui(new Ui::CDPultWindow) {
CDUtils::CDCore::instance()->initPult();
qRegisterMetaType<LogIcon>("LogIcon");
log_icons[OKIcon] = QIcon(":/icons/dialog-ok-apply.png");
log_icons[FailIcon] = QIcon(":/icons/dialog-cancel.png");
log_icons[WaitIcon] = QIcon(":/icons/timer.png");
ui->setupUi(this);
CDPultWindow::CDPultWindow(QWidget *parent) : EMainWindow(parent), Ui::CDPultWindow() {
setupUi(this);
centralWidget()->hide();
setRecentMenu(ui->menuOpen_recent);
CDUtils::CDCore::instance()->initPult();
widgetK->setType(CDUtils::CDType::cdK);
widgetX->setType(CDUtils::CDType::cdX);
editFileK->setValue(QVariant::fromValue(QAD::File("", "*.dat")));
editFileX->setValue(QVariant::fromValue(QAD::File("", "*.dat")));
editFileC->setValue(QVariant::fromValue(QAD::File("", "*.dat")));
log_icons[CDViewWidget::OKIcon] = QIcon(":/icons/dialog-ok-apply.png");
log_icons[CDViewWidget::FailIcon] = QIcon(":/icons/dialog-cancel.png");
log_icons[CDViewWidget::WaitIcon] = QIcon(":/icons/timer.png");
setRecentMenu(menuOpen_recent);
ribbon = new Ribbon(this);
session.setFile("session_cdpult.conf");
session.addEntry(this);
session.addEntry(ribbon->tabWidget());
session.load();
reset();
connect(ui->viewK, SIGNAL(KSendSucceed()), this, SLOT(KSended()));
connect(ui->viewK, SIGNAL(KReceiveSucceed()), this, SLOT(KReceived()));
connect(ui->viewK, SIGNAL(KSendFailed()), this, SLOT(KSendFailed()));
connect(ui->viewK, SIGNAL(KReceiveFailed()), this, SLOT(KReceiveFailed()));
connect(widgetK, SIGNAL(addToLog(CDViewWidget::LogIcon,QString)), this, SLOT(addToLog(CDViewWidget::LogIcon,QString)));
connect(widgetX, SIGNAL(addToLog(CDViewWidget::LogIcon,QString)), this, SLOT(addToLog(CDViewWidget::LogIcon,QString)));
if (windowState() == Qt::WindowMinimized)
setWindowState(Qt::WindowNoState);
}
CDPultWindow::~CDPultWindow() {
delete ui;
}
@@ -44,26 +46,6 @@ void CDPultWindow::loadFile(const QString & fp) {
}
void CDPultWindow::KReceived() {
addToLog(OKIcon, "K received succesfull");
}
void CDPultWindow::KSended() {
addToLog(OKIcon, "K sended succesfull");
}
void CDPultWindow::KSendFailed() {
addToLog(FailIcon, "K NOT sended");
}
void CDPultWindow::KReceiveFailed() {
addToLog(FailIcon, "K NOT received");
}
void CDPultWindow::closeEvent(QCloseEvent *e) {
EMainWindow::closeEvent(e);
if (!e->isAccepted())
@@ -76,29 +58,45 @@ void CDPultWindow::closeEvent(QCloseEvent *e) {
void CDPultWindow::reset(bool full) {
setWindowTitle(QString("CD Pult"));
ui->viewK->setKFile("");
// ui->viewK->clearK();
file_name.clear();
ui->viewK->refresh();
widgetK->reset();
setChanged(false);
}
bool CDPultWindow::load(const QString & path) {
ui->viewK->setKFile(path);
ui->viewK->loadK();
QFileInfo fi(path);
setWindowTitle(QString("CD Pult - %1").arg(fi.baseName()));
QPIConfig conf(path, QIODevice::ReadOnly);
QAD::File f = editFileK->value().value<QAD::File>();
checkSyncFiles->setChecked(false);
editFileK->setValue(QVariant::fromValue(QAD::File(conf.getValue("file_k").value(), f.filter)));
editFileX->setValue(QVariant::fromValue(QAD::File(conf.getValue("file_x").value(), f.filter)));
editFileC->setValue(QVariant::fromValue(QAD::File(conf.getValue("file_c").value(), f.filter)));
checkSyncFiles->setChecked(conf.getValue("sync_files"));
lineSessionName->setText(conf.getValue("session_name"));
checkHasK->setChecked(conf.getValue("has_k"));
checkHasX->setChecked(conf.getValue("has_x"));
checkHasC->setChecked(conf.getValue("has_c"));
setChanged(false);
file_name = path;
return true;
}
bool CDPultWindow::save(const QString & path) {
ui->viewK->setKFile(path);
ui->viewK->saveK();
QFileInfo fi(path);
setWindowTitle(QString("CD Pult - %1").arg(fi.baseName()));
QPIConfig conf(path, QIODevice::ReadWrite);
conf.clear();
conf.setValue("file_k", editFileK->value().value<QAD::File>().file);
conf.setValue("file_x", editFileX->value().value<QAD::File>().file);
conf.setValue("file_c", editFileC->value().value<QAD::File>().file);
conf.setValue("sync_files", checkSyncFiles->isChecked());
conf.setValue("session_name", lineSessionName->text());
conf.setValue("has_k", checkHasK->isChecked());
conf.setValue("has_x", checkHasX->isChecked());
conf.setValue("has_c", checkHasC->isChecked());
file_name = path;
return true;
//widgetK->setFile(path);
//widgetK->save();
}
@@ -112,42 +110,56 @@ void CDPultWindow::savingSession(QPIConfig & conf) {
}
void CDPultWindow::addToLog(LogIcon icon, const QString & msg) {
void CDPultWindow::addToLog(CDViewWidget::LogIcon icon, const QString & msg) {
QListWidgetItem * ni = new QListWidgetItem(log_icons[icon], "(" + QTime::currentTime().toString() + ") " + msg);
bool s = ui->listLog->verticalScrollBar()->value() == ui->listLog->verticalScrollBar()->maximum();
ui->listLog->addItem(ni);
if (s) ui->listLog->scrollToBottom();
bool s = listLog->verticalScrollBar()->value() == listLog->verticalScrollBar()->maximum();
listLog->addItem(ni);
if (s) listLog->scrollToBottom();
}
void CDPultWindow::on_actionSend_K_triggered() {
if (K.inProgress()) {addToLog(WaitIcon, "processing..."); return;}
addToLog(WaitIcon, "Sending K...");
ui->viewK->sendK();
}
void CDPultWindow::on_actionReceive_K_triggered() {
if (K.inProgress()) {addToLog(WaitIcon, "processing..."); return;}
addToLog(WaitIcon, "Receiving K...");
ui->viewK->receiveK();
}
void CDPultWindow::on_actionParse_triggered() {
QString path = QFileDialog::getOpenFileName(this, "Select header file", "", "K Description(k_description.h);;Headers(*.h)");
if (path.isEmpty()) return;
CDUtils::UpdateModeFlags mode = CDUtils::SaveByName;
if (!K.root().isEmpty()) {
QCDModeDialog cdm;
if (cdm.exec() != QDialog::Accepted) return;
mode = cdm.mode();
void CDPultWindow::on_editFileK_valueChanged(const QVariant & p) {
if (!checkSyncFiles->isChecked()) return;
QFileInfo fi(p.value<QAD::File>().file);
if (fi.path().isEmpty()) return;
QString n = fi.baseName();
QString xn(n), cn(n);
if (n.contains("k")) {
xn.replace(n.indexOf("k"), 1, "x");
cn.replace(n.indexOf("k"), 1, "c");
} else {
xn += "_x";
cn += "_c";
}
ui->viewK->buildFromHeader(path, mode);
QString ext = fi.suffix(), dot, dir;
QString kfn(fi.filePath());
if (!ext.isEmpty()) {
kfn.chop(ext.size());
if (kfn.endsWith(".")) {
kfn.chop(1);
dot = ".";
}
}
if (!fi.path().isEmpty() && fi.path() != ".") {
dir = fi.path();
if (!dir.endsWith("/"))
dir += "/";
}
QAD::File f = editFileK->value().value<QAD::File>();
f.file = dir + xn + dot + ext; editFileX->setValue(QVariant::fromValue(f));
f.file = dir + cn + dot + ext; editFileC->setValue(QVariant::fromValue(f));
}
void CDPultWindow::on_actionCalculate_K_triggered() {
ui->viewK->calculateK();
ui->viewK->refresh();
void CDPultWindow::on_buttonSessionApply_clicked() {
widgetK->setFile(editFileK->value().value<QAD::File>().file);
widgetX->setFile(editFileX->value().value<QAD::File>().file);
dockCDKView->setVisible(checkHasK->isChecked());
dockCDXView->setVisible(checkHasX->isChecked());
//dockCDCView->setVisible(checkHasC->isChecked());
}
void CDPultWindow::on_lineSessionName_textChanged(const QString & t) {
setWindowTitle(QString("CD Pult - %1").arg(t));
}