diff --git a/src/dialogs/choosefiledialog.cpp b/src/dialogs/choosefiledialog.cpp
index 7b8d685..0f7cd46 100644
--- a/src/dialogs/choosefiledialog.cpp
+++ b/src/dialogs/choosefiledialog.cpp
@@ -1,55 +1,55 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2017>
Author: Lays Rodrigues - laysrodriguessilva@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "choosefiledialog.h"
#include
#include
#include
#include
#include
ChooseFileDialog::ChooseFileDialog(QWidget *parent, QList files) :
QDialog(parent)
{
auto layout = new QVBoxLayout;
auto label = new QLabel(i18n("Choose a file to print: "));
auto listWigdet = new QListWidget();
QStringList files_list;
foreach(const auto &file, files){
files_list.append(file.toLocalFile());
}
listWigdet->addItems(files_list);
- connect(listWigdet, &QListWidget::currentTextChanged, [ & ](const QString& t){
+ connect(listWigdet, &QListWidget::currentTextChanged, [ this ](const QString& t){
m_choosen_file = t;
});
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &ChooseFileDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ChooseFileDialog::reject);
layout->addWidget(label);
layout->addWidget(listWigdet);
layout->addWidget(buttonBox);
setLayout(layout);
}
ChooseFileDialog::~ChooseFileDialog()
{
}
const QString& ChooseFileDialog::choosenFile()
{
return m_choosen_file;
}
diff --git a/src/dialogs/profilesdialog.cpp b/src/dialogs/profilesdialog.cpp
index 712c803..d61c048 100644
--- a/src/dialogs/profilesdialog.cpp
+++ b/src/dialogs/profilesdialog.cpp
@@ -1,239 +1,239 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2016>
Author: Lays Rodrigues - laysrodrigues@gmail.com
Chris Rizzitello - rizzitello@kde.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "profilesdialog.h"
#include "ui_profilesdialog.h"
#include
#include
#include
//Do not include for windows/mac os
#ifndef Q_OS_WIN
#ifndef Q_OS_MAC
#include
#endif
#endif
ProfilesDialog::ProfilesDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ProfilesDialog)
{
ui->setupUi(this);
ui->firmwareCB->addItem(QStringLiteral("Auto-Detect"));
ui->firmwareCB->addItems(detectFWPlugins());
ui->baudCB->addItems(SERIAL::BAUDS);
ui->baudCB->setCurrentText(QLatin1String("115200"));
ui->profileCB->setAutoCompletion(true);
- connect(ui->profileCB, static_cast(&QComboBox::currentIndexChanged), [ = ] {
+ connect(ui->profileCB, static_cast(&QComboBox::currentIndexChanged), [ this ] {
loadSettings();
});
updateCBProfiles();
- connect(ui->buttonBox, &QDialogButtonBox::clicked, [ = ](QAbstractButton * btn) {
+ connect(ui->buttonBox, &QDialogButtonBox::clicked, [ this ](QAbstractButton * btn) {
switch (ui->buttonBox->buttonRole(btn)) {
case QDialogButtonBox::ResetRole:
loadSettings();
break;
case QDialogButtonBox::RejectRole:
close();
break;
default:
break;
}
});
- connect(ui->heatedBedCK, &QCheckBox::clicked, [ = ](const bool & status) {
+ connect(ui->heatedBedCK, &QCheckBox::clicked, [ this ](const bool & status) {
ui->bedTempSB->setEnabled(status);
});
- connect(ui->cartesianRB, &QRadioButton::clicked, [ = ]() {
+ connect(ui->cartesianRB, &QRadioButton::clicked, [ this ]() {
ui->cartesianGB->setHidden(false);
ui->deltaGB->setHidden(true);
});
- connect(ui->deltaRB, &QRadioButton::clicked, [ = ]() {
+ connect(ui->deltaRB, &QRadioButton::clicked, [ this ]() {
ui->cartesianGB->setHidden(true);
ui->deltaGB->setHidden(false);
});
connect(ui->removeProfilePB, &QPushButton::clicked, this, &ProfilesDialog::removeProfile);
#ifdef Q_OS_LINUX
ui->removeProfilePB->setIcon(QIcon::fromTheme("edit-delete"));
#else
ui->removeProfilePB->setIcon(style()->standardIcon(QStyle::SP_TrashIcon));
#endif
}
ProfilesDialog::~ProfilesDialog()
{
delete ui;
}
void ProfilesDialog::saveSettings()
{
settings.beginGroup(QStringLiteral("GeneralSettings"));
QStringList groups = settings.childGroups();
settings.endGroup();
QString currentProfile = ui->profileCB->currentText();
if (groups.contains(currentProfile)) {
int ret = QMessageBox::information(this, i18n("Save?"),
i18n("A profile with this name already exists. \n Are you sure you want to overwrite it?"),
QMessageBox::Save, QMessageBox::Cancel);
if (ret == QMessageBox::Cancel) {
return;
}
}
//Add indent to better view of the data
settings.beginGroup(QStringLiteral("GeneralSettings"));
settings.beginGroup(currentProfile);
//BED
if (ui->cartesianRB->isChecked()) {
settings.setValue(QStringLiteral("isCartesian"), true);
settings.setValue(QStringLiteral("dimensionX"), ui->x_dimensionSB->value());
settings.setValue(QStringLiteral("dimensionY"), ui->y_dimensionSB->value());
settings.setValue(QStringLiteral("dimensionZ"), ui->z_dimensionSB->value());
}
else {
settings.setValue(QStringLiteral("isCartesian"), false);
settings.setValue(QStringLiteral("radius"), ui->radiusSB->value());
settings.setValue(QStringLiteral("z_delta_dimension"), ui->z_dimensionSB->value());
}
settings.setValue(QStringLiteral("heatedBed"), ui->heatedBedCK->isChecked());
settings.setValue(QStringLiteral("maximumTemperatureBed"), ui->bedTempSB->value());
//HOTEND
settings.setValue(QStringLiteral("maximumTemperatureExtruder"), ui->extruderTempSB->value());
//Baud
settings.setValue(QStringLiteral("bps"), ui->baudCB->currentText());
settings.setValue(QStringLiteral("firmware"),ui->firmwareCB->currentText());
settings.setValue(QStringLiteral("postPause"), ui->postPauseLE->text());
settings.endGroup();
settings.endGroup();
//Load new profile
updateCBProfiles();
loadSettings(currentProfile);
emit updateProfiles();
}
void ProfilesDialog::loadSettings(const QString ¤tProfile)
{
settings.beginGroup(QStringLiteral("GeneralSettings"));
const QString profileName = currentProfile.isEmpty() ? ui->profileCB ->currentText() : currentProfile;
ui->profileCB->setCurrentText(profileName);
settings.beginGroup(profileName);
//BED
if (settings.value(QStringLiteral("isCartesian")).toBool()) {
ui->cartesianGB->setHidden(false);
ui->cartesianRB->setChecked(true);
ui->deltaRB->setChecked(false);
ui->deltaGB->setHidden(true);
ui->x_dimensionSB->setValue(settings.value(QStringLiteral("dimensionX"), QStringLiteral("0")).toInt());
ui->y_dimensionSB->setValue(settings.value(QStringLiteral("dimensionY"), QStringLiteral("0")).toInt());
ui->z_dimensionSB->setValue(settings.value(QStringLiteral("dimensionZ"), QStringLiteral("0")).toInt());
} else {
ui->deltaGB->setHidden(false);
ui->deltaRB->setChecked(true);
ui->cartesianRB->setChecked(false);
ui->cartesianGB->setHidden(true);
ui->radiusSB->setValue(settings.value(QStringLiteral("radius"), QStringLiteral("0")).toFloat());
ui->z_delta_dimensionSB->setValue(settings.value(QStringLiteral("z_delta_dimension"), QStringLiteral("0")).toFloat());
}
ui->heatedBedCK->setChecked(settings.value(QStringLiteral("heatedBed"), QStringLiteral("true")).toBool());
ui->bedTempSB->setEnabled(ui->heatedBedCK->isChecked());
ui->bedTempSB->setValue(settings.value(QStringLiteral("maximumTemperatureBed"), QStringLiteral("0")).toInt());
//HOTEND
ui->extruderTempSB->setValue(settings.value(QStringLiteral("maximumTemperatureExtruder"), QStringLiteral("0")).toInt());
//Baud
ui->baudCB->setCurrentText(settings.value(QStringLiteral("bps"), QStringLiteral("115200")).toString());
ui->firmwareCB->setCurrentText(settings.value(QStringLiteral("firmware"), QStringLiteral("Auto-Detect")).toString());
ui->postPauseLE->setText(settings.value(QStringLiteral("postPause"),QStringLiteral("")).toString());
settings.endGroup();
settings.endGroup();
}
void ProfilesDialog::updateCBProfiles()
{
settings.beginGroup(QStringLiteral("GeneralSettings"));
QStringList groups = settings.childGroups();
settings.endGroup();
if (groups.isEmpty()) {
ui->deltaGB->setHidden(true);
}
ui->profileCB->clear();
ui->profileCB->addItems(groups);
}
void ProfilesDialog::accept()
{
saveSettings();
}
void ProfilesDialog::removeProfile(){
QString currentProfile = ui->profileCB->currentText();
settings.beginGroup(QStringLiteral("GeneralSettings"));
settings.beginGroup(currentProfile);
settings.remove("");
settings.endGroup();
settings.remove(currentProfile);
settings.endGroup();
updateCBProfiles();
}
QStringList ProfilesDialog::detectFWPlugins() const
{
//Path used if for windows/ mac os only.
QDir pluginDir(qApp->applicationDirPath() + QStringLiteral("/plugins"));
#if defined(Q_OS_WIN)
pluginDir.setNameFilters(QStringList() << "*.dll");
#elif defined(Q_OS_MAC)
pluginDir.setNameFilters(QStringList() << "*.dylib");
#else //Not Windows || Not MAC
QStringList pathList = AtCoreDirectories::pluginDir;
pathList.append(QLibraryInfo::location(QLibraryInfo::PluginsPath) + QStringLiteral("/AtCore"));
for (const auto &path : pathList) {
if (QDir(path).exists()) {
//use path where plugins were detected.
pluginDir = QDir(path);
break;
}
}
pluginDir.setNameFilters(QStringList() << "*.so");
#endif
QStringList firmwares;
QStringList files = pluginDir.entryList(QDir::Files);
foreach (const QString &f, files) {
QString file = f;
file = file.split(QChar::fromLatin1('.')).at(0);
if (file.startsWith(QStringLiteral("lib"))) {
file = file.remove(QStringLiteral("lib"));
}
file = file.toLower().simplified();
firmwares.append(file);
}
return firmwares;
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 686502a..c5c191a 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,182 +1,182 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2016>
Author: Lays Rodrigues - laysrodrigues@gmail.com
Chris Rizzitello - rizzitello@kde.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
MainWindow::MainWindow(QWidget *parent) :
KXmlGuiWindow(parent),
ui(new Ui::MainWindow),
m_currEditorView(nullptr),
m_instances(new QTabWidget(this))
{
ui->setupUi(this);
initWidgets();
setupActions();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::initWidgets()
{
auto newInstanceWidget = new AtCoreInstanceWidget();
m_instances->addTab(newInstanceWidget, i18n("Connect your printer"));
setupLateralArea();
// View:
// Sidebar, Sidevar Controls, Printer Tabs.
// Sidevar Controls and Printer Tabs can be resized, Sidebar cant.
auto *centralLayout = new QHBoxLayout();
auto splitter = new QSplitter();
splitter->addWidget(m_lateral.m_stack);
splitter->addWidget(m_instances);
centralLayout->addWidget(m_lateral.m_toolBar);
centralLayout->addWidget(splitter);
ui->centralwidget->setLayout(centralLayout);
}
// Move to LateralArea.
void MainWindow::setupLateralArea()
{
m_lateral.m_toolBar = new QWidget();
m_lateral.m_stack = new QStackedWidget();
auto *buttonLayout = new QVBoxLayout();
auto setupButton = [this, buttonLayout](const QString& key, const QString& text, const QIcon& icon, QWidget *w) {
auto *btn = new QPushButton(m_lateral.m_toolBar);
btn->setToolTip(text);
btn->setAutoExclusive(true);
btn->setCheckable(true);
btn->setIcon(icon);
btn->setIconSize(QSize(64,64));
btn->setFlat(true);
m_lateral.m_stack->addWidget(w);
m_lateral.m_map[key] = {btn, w};
buttonLayout->addWidget(btn);
connect(btn, &QToolButton::toggled, [this, w](bool checked) {
if (checked)
m_lateral.m_stack->setCurrentWidget(w);
});
};
auto *gcodeEditor = new GCodeEditorWidget(this);
- connect(gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, [&](KTextEditor::View* view){
+ connect(gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, [this](KTextEditor::View* view){
guiFactory()->removeClient(m_currEditorView);
guiFactory()->addClient(view);
m_currEditorView = view;
});
setupButton("3d", i18n("&3D"), QIcon(":/icon/atelier"), new Viewer3D(this));
setupButton("gcode", i18n("&GCode"), QIcon(":/icon/atelier"), gcodeEditor);
setupButton("video", i18n("&Video"), QIcon(":/icon/atelier"), new VideoMonitorWidget(this));
buttonLayout->addStretch();
m_lateral.m_toolBar->setLayout(buttonLayout);
}
void MainWindow::setupActions()
{
// Actions for the Toolbar
QAction *action;
action = actionCollection()->addAction(QStringLiteral("open_gcode"));
action->setText(i18n("&Open GCode"));
connect(action, &QAction::triggered, this, &MainWindow::openFile);
action = actionCollection()->addAction(QStringLiteral("connect"));
action->setText(i18n("&Connect"));
connect(action, &QAction::triggered, [ & ]{
std::unique_ptr csd(new ConnectSettingsDialog);
- connect(csd.get(), &ConnectSettingsDialog::startConnection, [ & ](const QString& port, const QMap& data) {
+ connect(csd.get(), &ConnectSettingsDialog::startConnection, [this](const QString& port, const QMap& data) {
newConnection(port, data);
});
csd->exec();
});
action = actionCollection()->addAction(QStringLiteral("profiles"));
action->setText(i18n("&Profiles"));
- connect(action, &QAction::triggered, [ & ] {
+ connect(action, &QAction::triggered, [this] {
std::unique_ptr pd(new ProfilesDialog);
pd->exec();
});
#ifdef Q_OS_LINUX
//only set icons from theme on linux
actionCollection()->action(QStringLiteral("profiles"))->setIcon(QIcon::fromTheme("emblem-favorite"));
#endif
//use style's standardIcon for the icons we can.
actionCollection()->action(QStringLiteral("open_gcode"))->setIcon(style()->standardIcon(QStyle::SP_DirOpenIcon));
action = KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
setupGUI(Default, ":/atelierui");
}
void MainWindow::openFile()
{
QUrl fileName = QFileDialog::getOpenFileUrl(this, i18n("Open GCode"),
QDir::homePath(), i18n("GCode (*.gco *.gcode)"));
if (!fileName.isEmpty()) {
m_lateral.get("gcode")->loadFile(fileName);
m_lateral.get("3d")->drawModel(fileName.toString());
const int tabs = m_instances->count();
m_openFiles.append(fileName);
for(int i=0; i < tabs; ++i){
auto instance = qobject_cast(m_instances->widget(i));
instance->setOpenFiles(m_openFiles);
}
}
}
void MainWindow::newConnection(const QString& port, const QMap& profile)
{
const int tabs = m_instances->count();
if(tabs == 1){
auto instance = qobject_cast(m_instances->currentWidget());
if(!instance->connected()){
instance->startConnection(port, profile);
m_instances->setTabText(m_instances->currentIndex(), profile["name"].toString());
return;
}
}
auto newInstanceWidget = new AtCoreInstanceWidget();
m_instances->addTab(newInstanceWidget, profile["name"].toString());
newInstanceWidget->startConnection(port, profile);
}
diff --git a/src/widgets/atcoreinstancewidget.cpp b/src/widgets/atcoreinstancewidget.cpp
index 29a4602..81b70a4 100644
--- a/src/widgets/atcoreinstancewidget.cpp
+++ b/src/widgets/atcoreinstancewidget.cpp
@@ -1,370 +1,370 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2017>
Author: Lays Rodrigues - laysrodriguessilva@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "atcoreinstancewidget.h"
#include "ui_atcoreinstancewidget.h"
#include
#include
#include
#include
#include "choosefiledialog.h"
AtCoreInstanceWidget::AtCoreInstanceWidget(QWidget *parent):
QWidget(parent),
m_mainToolBar(nullptr),
m_toolBar(nullptr),
m_printAction(nullptr)
{
ui = new Ui::AtCoreInstanceWidget;
ui->setupUi(this);
ui->printProgressWidget->setVisible(false);
buildMainToolbar();
buildToolbar();
enableControls(false);
initConnectsToAtCore();
}
AtCoreInstanceWidget::~AtCoreInstanceWidget()
{
delete ui;
}
void AtCoreInstanceWidget::buildToolbar()
{
m_toolBar = new QToolBar();
auto lb = new QAction;
lb->setIcon(style()->standardIcon(QStyle::SP_DirHomeIcon));
lb->setDisabled(true);
m_toolBar->addAction(lb);
auto homeAll = new QAction("All");
- connect(homeAll, &QAction::triggered, [&]{
+ connect(homeAll, &QAction::triggered, [this]{
m_core.home();
});
m_toolBar->addAction(homeAll);
for(auto homes : std::map{{"X", AtCore::X}, {"Y", AtCore::Y}, {"Z", AtCore::Z}}) {
auto home = new QAction(homes.first);
- connect(home, &QAction::triggered, [&, homes] {
+ connect(home, &QAction::triggered, [this, homes] {
m_core.home(homes.second);
});
m_toolBar->addAction(home);
}
m_toolBar->addSeparator();
auto *axis = new QAction("Axis");
axis->setCheckable(true);
axis->setChecked(true);
connect(axis, &QAction::toggled, ui->axisViewWidget, &AxisControl::setVisible);
auto controls = new QAction("Controls");
controls->setCheckable(true);
controls->setChecked(true);
connect(controls, &QAction::toggled, ui->bedExtWidget, &BedExtruderWidget::setVisible);
auto plot = new QAction("Temperature Plot");
plot->setCheckable(true);
plot->setChecked(true);
connect(plot, &QAction::toggled, ui->plotWidget, &PlotWidget::setVisible);
m_toolBar->addAction(axis);
m_toolBar->addAction(controls);
m_toolBar->addAction(plot);
ui->toolBarLayout->addWidget(m_toolBar);
ui->toolBarLayout->addStretch();
}
void AtCoreInstanceWidget::buildMainToolbar(){
m_mainToolBar = new QToolBar();
m_mainToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
auto disconnectAction = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), i18n("Disconnect"));
connect(this, &AtCoreInstanceWidget::disableDisconnect, disconnectAction, &QAction::setDisabled);
- connect(disconnectAction, &QAction::triggered, [&](){
+ connect(disconnectAction, &QAction::triggered, [this](){
m_core.closeConnection();
});
m_mainToolBar->addAction(disconnectAction);
m_printAction = new QAction(style()->standardIcon(QStyle::SP_MediaPlay),i18n("Print"));
- connect(m_printAction, &QAction::triggered, [ & ](){
+ connect(m_printAction, &QAction::triggered, [ this ](){
if(m_core.state() == AtCore::BUSY) {
pausePrint();
return;
}
if (m_core.state() == AtCore::IDLE){
print();
} else if (m_core.state() == AtCore::PAUSE) {
m_core.resume();
}
});
m_mainToolBar->addAction(m_printAction);
auto stopAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Stop"));
connect(stopAction, &QAction::triggered, this, &AtCoreInstanceWidget::stopPrint);
- connect(stopAction, &QAction::triggered, [&](){
+ connect(stopAction, &QAction::triggered, [this](){
m_printAction->setText(i18n("Print"));
m_printAction->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
});
m_mainToolBar->addAction(stopAction);
auto disableMotorsAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop),i18n("Disable Motors"));
connect(disableMotorsAction, &QAction::triggered, this, &AtCoreInstanceWidget::disableMotors);
m_mainToolBar->addAction(disableMotorsAction);
ui->mainToolBarLayout->addWidget(m_mainToolBar);
ui->mainToolBarLayout->addStretch();
}
void AtCoreInstanceWidget::startConnection(const QString& serialPort, const QMap& profiles){
m_core.initSerial(serialPort, profiles["bps"].toInt());
if(m_core.state() == AtCore::CONNECTING){
QString fw = profiles["firmware"].toString();
if( fw != QString("Auto-Detect")){
m_core.loadFirmwarePlugin(fw);
}
}
}
void AtCoreInstanceWidget::initConnectsToAtCore()
{
// Handle AtCore status change
connect(&m_core, &AtCore::stateChanged, this, &AtCoreInstanceWidget::handlePrinterStatusChanged);
// If the number of extruders from the printer change, we need to update the radiobuttons on the widget
connect(this, &AtCoreInstanceWidget::extruderCountChanged, ui->bedExtWidget, &BedExtruderWidget::setExtruderCount);
// Bed and Extruder temperatures management
connect(ui->bedExtWidget, &BedExtruderWidget::bedTemperatureChanged, &m_core, &AtCore::setBedTemp);
connect(ui->bedExtWidget, &BedExtruderWidget::extTemperatureChanged, &m_core, &AtCore::setExtruderTemp);
// Connect AtCore temperatures changes on Atelier Plot
- connect(&m_core.temperature(), &Temperature::bedTemperatureChanged, [ & ](const float& temp) {
+ connect(&m_core.temperature(), &Temperature::bedTemperatureChanged, [ this ](const float& temp) {
checkTemperature(0x00, 0, temp);
ui->plotWidget->appendPoint(i18n("Actual Bed"), temp);
ui->plotWidget->update();
ui->bedExtWidget->updateBedTemp(temp);
});
- connect(&m_core.temperature(), &Temperature::bedTargetTemperatureChanged, [ & ](const float& temp) {
+ connect(&m_core.temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](const float& temp) {
checkTemperature(0x01, 0, temp);
ui->plotWidget->appendPoint(i18n("Target Bed"), temp);
ui->plotWidget->update();
ui->bedExtWidget->updateBedTargetTemp(temp);
});
- connect(&m_core.temperature(), &Temperature::extruderTemperatureChanged, [ & ](const float& temp) {
+ connect(&m_core.temperature(), &Temperature::extruderTemperatureChanged, [ this ](const float& temp) {
checkTemperature(0x02, 0, temp);
ui->plotWidget->appendPoint(i18n("Actual Ext.1"), temp);
ui->plotWidget->update();
ui->bedExtWidget->updateExtTemp(temp);
});
- connect(&m_core.temperature(), &Temperature::extruderTargetTemperatureChanged, [ & ](const float& temp) {
+ connect(&m_core.temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](const float& temp) {
checkTemperature(0x03, 0, temp);
ui->plotWidget->appendPoint(i18n("Target Ext.1"), temp);
ui->plotWidget->update();
ui->bedExtWidget->updateExtTargetTemp(temp);
});
- connect(ui->pushGCodeWidget, &PushGCodeWidget::push, [ & ](QString command) {
+ connect(ui->pushGCodeWidget, &PushGCodeWidget::push, [ this ](QString command) {
ui->logWidget->addLog("Push " + command);
m_core.pushCommand(command);
});
// Fan, Flow and Speed management
connect(ui->ratesControlWidget, &RatesControlWidget::fanSpeedChanged, &m_core, &AtCore::setFanSpeed);
connect(ui->ratesControlWidget, &RatesControlWidget::flowRateChanged, &m_core, &AtCore::setFlowRate);
connect(ui->ratesControlWidget, &RatesControlWidget::printSpeedChanged, &m_core, &AtCore::setPrinterSpeed);
connect(ui->axisViewWidget, &AxisControl::clicked, this, &AtCoreInstanceWidget::axisControlClicked);
}
void AtCoreInstanceWidget::printFile(const QUrl& fileName)
{
if (!fileName.isEmpty() && (m_core.state() == AtCore::IDLE)) {
m_core.print(fileName.toLocalFile());
}
}
void AtCoreInstanceWidget::print(){
switch (m_files.size()){
case 0:
QMessageBox::warning(this, i18n("Error"),
i18n("There's no GCode File open. \n Please select a file and try again."),
QMessageBox::Ok);
break;
case 1:
printFile(m_files.at(0));
break;
default:
auto dialog = new ChooseFileDialog(this, m_files);
if(dialog->exec() == QDialog::Accepted){
printFile(dialog->choosenFile());
}
}
}
void AtCoreInstanceWidget::pausePrint()
{
if(m_core.state() == AtCore::BUSY) {
m_core.pause(profileData["postPause"].toString());
} else if (m_core.state() == AtCore::PAUSE) {
m_core.resume();
}
}
void AtCoreInstanceWidget::stopPrint()
{
m_core.stop();
}
void AtCoreInstanceWidget::disableMotors()
{
m_core.disableMotors(0);
}
void AtCoreInstanceWidget::handlePrinterStatusChanged(AtCore::STATES newState)
{
static QString stateString;
switch (newState) {
case AtCore::CONNECTING: {
stateString = i18n("Connecting...");
connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand);
connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands);
} break;
case AtCore::IDLE: {
stateString = i18n("Connected to ") + m_core.serial()->portName();
emit extruderCountChanged(m_core.extruderCount());
ui->logWidget->addLog(i18n("Serial connected"));
emit disableDisconnect(false);
enableControls(true);
} break;
case AtCore::DISCONNECTED: {
stateString = i18n("Not Connected");
disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand);
disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands);
ui->logWidget->addLog(i18n("Serial disconnected"));
enableControls(false);
} break;
case AtCore::STARTPRINT: {
stateString = i18n("Starting Print");
ui->printProgressWidget->setVisible(true);
connect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar);
} break;
case AtCore::FINISHEDPRINT: {
stateString = i18n("Finished Print");
ui->printProgressWidget->setVisible(false);
disconnect(&m_core, &AtCore::printProgressChanged, ui->printProgressWidget, &PrintProgressWidget::updateProgressBar);
m_printAction->setText(i18n("Print"));
m_printAction->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
} break;
case AtCore::BUSY: {
stateString = i18n("Printing");
emit disableDisconnect(true);
m_printAction->setText(i18n("Pause"));
m_printAction->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
} break;
case AtCore::PAUSE: {
stateString = i18n("Paused");
m_printAction->setText(i18n("Resume"));
m_printAction->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
} break;
case AtCore::STOP: {
stateString = i18n("Stoping Print");
} break;
case AtCore::ERRORSTATE: {
stateString = i18n("Error");
} break;
default:
qWarning("AtCore State not Recognized.");
break;
}
ui->lblState->setText(stateString);
}
void AtCoreInstanceWidget::checkTemperature(uint sensorType, uint number, uint temp)
{
static QString msg;
switch (sensorType) {
case 0x00: // bed
msg = QString::fromLatin1("Bed Temperature ");
break;
case 0x01: // bed target
msg = QString::fromLatin1("Bed Target Temperature ");
break;
case 0x02: // extruder
msg = QString::fromLatin1("Extruder Temperature ");
break;
case 0x03: // extruder target
msg = QString::fromLatin1("Extruder Target Temperature ");
break;
case 0x04: // enclosure
msg = QString::fromLatin1("Enclosure Temperature ");
break;
case 0x05: // enclosure target
msg = QString::fromLatin1("Enclosure Target Temperature ");
break;
}
msg.append(QString::fromLatin1("[%1] : %2"));
msg = msg.arg(QString::number(number))
.arg(QString::number(temp));
ui->logWidget->addRLog(msg);
}
void AtCoreInstanceWidget::checkReceivedCommand(const QByteArray &message)
{
ui->logWidget->addRLog(QString::fromUtf8(message));
}
void AtCoreInstanceWidget::checkPushedCommands(const QByteArray &bmsg)
{
QString msg = QString::fromUtf8(bmsg);
QRegExp _newLine(QChar::fromLatin1('\n'));
QRegExp _return(QChar::fromLatin1('\r'));
msg.replace(_newLine, QStringLiteral("\\n"));
msg.replace(_return, QStringLiteral("\\r"));
ui->logWidget->addSLog(msg);
}
void AtCoreInstanceWidget::axisControlClicked(QChar axis, int value)
{
m_core.setRelativePosition();
m_core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value))));
m_core.setAbsolutePosition();
}
void AtCoreInstanceWidget::enableControls(bool b)
{
ui->mainTab->setEnabled(b);
m_mainToolBar->setEnabled(b);
m_toolBar->setEnabled(b);
}
bool AtCoreInstanceWidget::connected()
{
return (m_core.state() != AtCore::DISCONNECTED);
}
void AtCoreInstanceWidget::setOpenFiles(const QList& files)
{
m_files = files;
}
diff --git a/src/widgets/axiscontrol.cpp b/src/widgets/axiscontrol.cpp
index 51bba88..2167ffa 100644
--- a/src/widgets/axiscontrol.cpp
+++ b/src/widgets/axiscontrol.cpp
@@ -1,181 +1,181 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2016>
Author: Lays Rodrigues - laysrodriguessilva@gmail.com
Chris Rizzitello - rizzitello@kde.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "axiscontrol.h"
PieButton::PieButton(QLatin1Char axis, int value, int size, int angle) : _axis(axis), _value(value)
{
const int delta = 16; // Qt Docs: angle is 16th of a degree.
setBrush(_palette.button());
setStartAngle(angle * delta);
setSpanAngle(90 * delta);
setRect(QRect(QPoint(size * -1, size * -1), QPoint(size, size)));
setZValue(size * -1);
setAcceptHoverEvents(true);
setToolTip(QStringLiteral("Move the hotend to the %1 by %2 units").arg(axis).arg(value));
}
void PieButton::setPalette(QPalette palette)
{
_palette = palette;
}
void PieButton::mousePressEvent(QGraphicsSceneMouseEvent *)
{
emit clicked(_axis, _value);
}
void PieButton::hoverEnterEvent(QGraphicsSceneHoverEvent *)
{
setBrush(_palette.highlight());
}
void PieButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
{
setBrush(_palette.button());
}
RectButton::RectButton(QLatin1Char axis, int value, int size) : _axis(axis), _value(value)
{
setBrush(_palette.button());
setRect(QRect(QPoint(0, 0), QPoint(size, size)));
setAcceptHoverEvents(true);
setZValue(size * -1);
setToolTip(QStringLiteral("Move the hotend to the %1 by %2 units").arg(axis).arg(value));
}
void RectButton::setPalette(QPalette palette)
{
_palette = palette;
}
void RectButton::mousePressEvent(QGraphicsSceneMouseEvent *)
{
emit clicked(_axis, _value);
}
void RectButton::hoverEnterEvent(QGraphicsSceneHoverEvent *)
{
setBrush(_palette.highlight());
}
void RectButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
{
setBrush(_palette.button());
}
/* About the Magic Numbers
I don't have experience programming with QGraphicsScene,
Tomaz is helping me, but until we have a better solution, all the values
that are dividing or multiplying the items is based only in tests and errors.
Those values was choosen because it fit better on the alignment of the items
in the scene. If you have a better solution, please share with us.
Lays Rodrigues - Jan/2017
*/
AxisControl::AxisControl(QWidget *parent) :
QGraphicsView(parent)
{
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
setScene(new QGraphicsScene());
- auto createPie = [ = ](QLatin1Char axis, int value, int size, int angle) {
+ auto createPie = [ this ](QLatin1Char axis, int value, int size, int angle) {
auto pie = new PieButton(axis, value, size, angle);
pie->setPalette(this->palette());
connect(pie, &PieButton::clicked, this, &AxisControl::clicked);
if (abs(value) == 25) {
setLabels(pie, axis, value);
}
scene()->addItem(pie);
};
- auto createRect = [ = ](QLatin1Char axis, int value, int size, int xPos, int yPos) {
+ auto createRect = [ this ](QLatin1Char axis, int value, int size, int xPos, int yPos) {
auto z = new RectButton(axis, value, size);
z->setPalette(this->palette());
z->setPos(xPos, yPos);
connect(z, &RectButton::clicked, this, &AxisControl::clicked);
if (abs(value) == 25) {
setLabels(z, axis, value);
}
scene()->addItem(z);
};
int currPieSize = 25;
for (auto value : {
1, 10, 25
}) {
createPie(QLatin1Char('X'), value, currPieSize, -45); // Left
createPie(QLatin1Char('X'), value * -1, currPieSize, 135); // Right
createPie(QLatin1Char('Y'), value, currPieSize, 45); // Top
createPie(QLatin1Char('Y'), value * -1, currPieSize, 225); // Bottom
currPieSize += 25;
}
int currZSize = 25;
int xPos = sceneRect().width() - 50;
int yPos = -75; //Align with the origin of the scene 3 * 25
for (auto value : {
25, 10, 1, -1, -10, -25
}) {
createRect(QLatin1Char('Z'), value, currZSize, xPos, yPos);
yPos += currZSize;
}
setSceneRect(scene()->itemsBoundingRect());
}
void AxisControl::resizeEvent(QResizeEvent *)
{
fitInView(sceneRect(), Qt::KeepAspectRatio);
}
void AxisControl::setLabels(QGraphicsItem *item, QLatin1Char axis, int value)
{
auto *lb = new QGraphicsSimpleTextItem();
lb->setBrush(palette().buttonText());
if (this->logicalDpiX() <= 96) {
lb->setText((value < 0) ? QStringLiteral(" -") + axis : QStringLiteral(" ") + axis);
} else {
lb->setText((value < 0) ? QStringLiteral("-") + axis : QStringLiteral(" ") + axis);
}
if (axis.toLatin1() == 'X') {
lb->setY(item->y() - lb->boundingRect().width());
if (value < 0) {
lb->setX(item->x() - item->boundingRect().width() / 1.2 - lb->boundingRect().width() / 2);
} else {
lb->setX(item->x() + item->boundingRect().width() / 1.2 - lb->boundingRect().width() / 2);
}
} else if (axis.toLatin1() == 'Y') {
lb->setX(item->x() - lb->boundingRect().width() / 2);
if (value < 0) {
lb->setY(item->y() + item->boundingRect().height() / 1.5);
} else {
lb->setY(item->y() - item->boundingRect().height());
}
} else {
lb->setX(item->x() + lb->boundingRect().width() / fontMetrics().width(lb->text()));
#ifndef Q_OS_WIN
lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().xHeight());
#else
lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().height());
#endif
}
scene()->addItem(lb);
}
diff --git a/src/widgets/bedextruderwidget.cpp b/src/widgets/bedextruderwidget.cpp
index f1ba3c7..fb8148a 100644
--- a/src/widgets/bedextruderwidget.cpp
+++ b/src/widgets/bedextruderwidget.cpp
@@ -1,128 +1,128 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2016>
Author: Lays Rodrigues - laysrodriguessilva@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "bedextruderwidget.h"
#include "ui_bedextruderwidget.h"
#include
#include
BedExtruderWidget::BedExtruderWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::BedExtruderWidget)
{
ui->setupUi(this);
//Add Default Extruder
setExtruderCount(1);
connect(ui->heatBedPB, &QPushButton::clicked, this, &BedExtruderWidget::heatBedClicked);
connect(ui->heatExtPB, &QPushButton::clicked, this, &BedExtruderWidget::heatExtruderClicked);
- connect(ui->bedTempSB, static_cast(&QDoubleSpinBox::valueChanged), [ = ](double tmp) {
+ connect(ui->bedTempSB, static_cast(&QDoubleSpinBox::valueChanged), [ this ](double tmp) {
if (ui->heatBedPB->isChecked()) {
emit bedTemperatureChanged(tmp,ui->bedAndWaitCB->isChecked());
}
});
- connect(ui->extTempSB, static_cast(&QDoubleSpinBox::valueChanged), [ = ](double tmp) {
+ connect(ui->extTempSB, static_cast(&QDoubleSpinBox::valueChanged), [ this ](double tmp) {
if (ui->heatExtPB->isChecked()) {
emit extTemperatureChanged(tmp, currentExtruder(),ui->extAndWaitCB->isChecked());
}
});
}
BedExtruderWidget::~BedExtruderWidget()
{
delete ui;
}
void BedExtruderWidget::setExtruderCount(int value)
{
if (value == extruderCount) {
return;
} else if (extruderCount < value) {
//loop for the new buttons
for (int i = extruderCount; i < value; i++) {
auto *rb = new QRadioButton(QString::number(i + 1));
ui->extRadioButtonLayout->addWidget(rb);
extruderMap.insert(i, rb);
}
} else {
//remove buttons - need to test it!
for (int i = extruderCount; i >= value; i--) {
auto *rb = extruderMap.value(i);
ui->extRadioButtonLayout->removeWidget(rb);
extruderMap.remove(i);
delete (rb);
}
}
extruderCount = value;
}
void BedExtruderWidget::updateBedTemp(const float temp)
{
ui->bedCurrTempLB->setText(QString::number(temp));
}
void BedExtruderWidget::updateExtTemp(const float temp)
{
ui->extCurrTempLB->setText(QString::number(temp));
}
void BedExtruderWidget::updateBedTargetTemp(const float temp)
{
ui->bedTargetTempLB->setText(QString::number(temp) + " ºC");
}
void BedExtruderWidget::updateExtTargetTemp(const float temp)
{
ui->extTargetTempLB->setText(QString::number(temp) + " ºC");
}
void BedExtruderWidget::stopHeating()
{
emit bedTemperatureChanged(0,ui->bedAndWaitCB->isChecked());
for (int i = 0; i < extruderCount; i++) {
emit extTemperatureChanged(0, i,ui->extAndWaitCB->isChecked());
}
ui->heatBedPB->setChecked(false);
ui->heatExtPB->setChecked(false);
}
void BedExtruderWidget::heatExtruderClicked(bool clicked)
{
int temp = ui->extTempSB->value() * clicked;
emit extTemperatureChanged(temp, currentExtruder(),ui->extAndWaitCB->isChecked());
}
void BedExtruderWidget::heatBedClicked(bool clicked)
{
int temp = ui->bedTempSB->value() * clicked;
emit bedTemperatureChanged(temp,ui->bedAndWaitCB->isChecked());
}
int BedExtruderWidget::currentExtruder()
{
int currExt = 0;
for (int i = 0; i < extruderMap.size(); i++) {
if (extruderMap.value(i)->isChecked()) {
currExt = i;
break;
}
}
return currExt;
}
diff --git a/src/widgets/pushgcodewidget.cpp b/src/widgets/pushgcodewidget.cpp
index 888c2f6..a509771 100644
--- a/src/widgets/pushgcodewidget.cpp
+++ b/src/widgets/pushgcodewidget.cpp
@@ -1,45 +1,44 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2017>
Author: Lays Rodrigues - laysrodriguessilva@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "pushgcodewidget.h"
#include
#include
#include
#include
#include
PushGCodeWidget::PushGCodeWidget(QWidget *parent) : QWidget(parent),
input(new QLineEdit(this))
{
QVBoxLayout *layout = new QVBoxLayout();
QHBoxLayout *items = new QHBoxLayout();
QLabel *lb = new QLabel(i18n("Push Gcode"));
lb->setAlignment(Qt::AlignHCenter);
QPushButton *bt = new QPushButton(i18n("Send"));
items->setSpacing(3);
layout->addWidget(lb);
items->addWidget(input);
items->addWidget(bt);
layout->addItem(items);
this->setLayout(layout);
- connect(bt, &QPushButton::clicked, [ = ] {
+ connect(bt, &QPushButton::clicked, [ this ] {
push(input->text());
});
}
-
diff --git a/src/widgets/ratescontrolwidget.cpp b/src/widgets/ratescontrolwidget.cpp
index 48a83d6..976f6af 100644
--- a/src/widgets/ratescontrolwidget.cpp
+++ b/src/widgets/ratescontrolwidget.cpp
@@ -1,41 +1,41 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2017>
Author: Lays Rodrigues - laysrodriguessilva@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "ratescontrolwidget.h"
#include "ui_ratescontrolwidget.h"
RatesControlWidget::RatesControlWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::RatesControlWidget)
{
ui->setupUi(this);
- connect(ui->flowRateSB, static_cast(&QDoubleSpinBox::valueChanged), [ = ](float value){
+ connect(ui->flowRateSB, static_cast(&QDoubleSpinBox::valueChanged), [ this ](float value){
emit flowRateChanged(value);
});
- connect(ui->fanSpeedSB, static_cast(&QDoubleSpinBox::valueChanged), [ = ](float value){
+ connect(ui->fanSpeedSB, static_cast(&QDoubleSpinBox::valueChanged), [ this ](float value){
emit fanSpeedChanged(value);
});
- connect(ui->printSpeedSB, static_cast(&QDoubleSpinBox::valueChanged), [ = ](float value){
+ connect(ui->printSpeedSB, static_cast(&QDoubleSpinBox::valueChanged), [ this ](float value){
emit printSpeedChanged(value);
});
}
RatesControlWidget::~RatesControlWidget()
{
delete ui;
}
diff --git a/src/widgets/videomonitorwidget.cpp b/src/widgets/videomonitorwidget.cpp
index cbf2a21..076c166 100644
--- a/src/widgets/videomonitorwidget.cpp
+++ b/src/widgets/videomonitorwidget.cpp
@@ -1,99 +1,99 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2017>
Author: Lays Rodrigues - laysrodriguessilva@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "videomonitorwidget.h"
#include
#include
#include
#include
#include
#include
VideoMonitorWidget::VideoMonitorWidget(QWidget *parent) :
QWidget(parent),
_mediaplayer(nullptr, QMediaPlayer::VideoSurface)
{
auto _layout = new QGridLayout();
auto _label = new QLabel(i18n("Source url:"));
_layout->addWidget(_label, 0, 0);
auto _sourceCB = new QComboBox();
_sourceCB->setEditable(true);
_sourceCB->setToolTip(i18n("Valid Urls:\n\
http://www.example.com/stream.avi\n\
rtp://@:1234\n\
mms://mms.examples.com/stream.asx\n\
rtsp://server.example.org:8080/test.sdp"));
_layout->addWidget(_sourceCB, 0, 1);
auto _playPB = new QPushButton();
_playPB->setCheckable(true);
_playPB->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
_layout->addWidget(_playPB, 0, 2);
auto _videoWidget = new QVideoWidget();
_layout->addWidget(_videoWidget, 1, 0, -1, -1);
_errorlabel = new QLabel;
_layout->addWidget(_errorlabel, 2, 0, 0, -1);
this->setLayout(_layout);
_mediaplayer.setVideoOutput(_videoWidget);
#ifdef Q_OS_LINUX
QStringList sources;
sources << QString("video*");
_sourceCB->addItems(QDir("/dev/")\
.entryList(sources, QDir::System)\
.replaceInStrings( QRegExp("^"), "v4l2:///dev/"));
#endif
- connect(_playPB, &QPushButton::clicked, [=](bool b){
+ connect(_playPB, &QPushButton::clicked, [this, _playPB, _sourceCB](bool b){
if(b){
_playPB->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
QString source = _sourceCB->currentText();
_mediaplayer.setMedia(QUrl(source));
_mediaplayer.play();
}else{
_mediaplayer.pause();
_playPB->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
}
});
typedef void (QMediaPlayer::*ErrorSignal)(QMediaPlayer::Error);
connect(&_mediaplayer, static_cast(&QMediaPlayer::error),
this, &VideoMonitorWidget::handleError);
}
VideoMonitorWidget::~VideoMonitorWidget()
{
-
+
}
void VideoMonitorWidget::handleError()
{
const QString errorString = _mediaplayer.errorString();
QString message = "Error: ";
if (errorString.isEmpty())
message += " #" + QString::number(int(_mediaplayer.error()));
else
message += errorString;
_errorlabel->setText(message);
}