154 lines
3.9 KiB
C++
154 lines
3.9 KiB
C++
#include <QCloseEvent>
|
|
#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_modedialog.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);
|
|
centralWidget()->hide();
|
|
setRecentMenu(ui->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()));
|
|
if (windowState() == Qt::WindowMinimized)
|
|
setWindowState(Qt::WindowNoState);
|
|
}
|
|
|
|
|
|
CDPultWindow::~CDPultWindow() {
|
|
delete ui;
|
|
}
|
|
|
|
|
|
void CDPultWindow::loadFile(const QString & fp) {
|
|
load(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())
|
|
return;
|
|
QApplication::closeAllWindows();
|
|
session.save();
|
|
session.setFile(QString());
|
|
}
|
|
|
|
|
|
void CDPultWindow::reset(bool full) {
|
|
setWindowTitle(QString("CD Pult"));
|
|
ui->viewK->setKFile("");
|
|
// ui->viewK->clearK();
|
|
file_name.clear();
|
|
ui->viewK->refresh();
|
|
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()));
|
|
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()));
|
|
return true;
|
|
}
|
|
|
|
|
|
void CDPultWindow::loadingSession(QPIConfig & conf) {
|
|
setRecentFiles(conf.getValue("recent files", QStringList()));
|
|
}
|
|
|
|
|
|
void CDPultWindow::savingSession(QPIConfig & conf) {
|
|
conf.setValue("recent files", recentFiles());
|
|
}
|
|
|
|
|
|
void CDPultWindow::addToLog(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();
|
|
}
|
|
|
|
|
|
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();
|
|
}
|
|
ui->viewK->buildFromHeader(path, mode);
|
|
}
|
|
|
|
|
|
void CDPultWindow::on_actionCalculate_K_triggered() {
|
|
ui->viewK->calculateK();
|
|
ui->viewK->refresh();
|
|
}
|