diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1780bab..78bed35 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,17 +1,18 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTORCC ON)
set(atelier_SRCS
main.cpp
mainwindow.cpp
)
add_subdirectory(dialogs)
add_subdirectory(widgets)
+add_subdirectory(QtAwesome)
-add_executable(atelier ${atelier_SRCS} icons.qrc)
+add_executable(atelier ${atelier_SRCS} icons.qrc QtAwesome/QtAwesome.qrc)
ecm_create_qm_loader(atelier_SRCS atelier)
-target_link_libraries(atelier AtelierWidgets AtelierDialogs Atelier3D AtCore::AtCore KF5::Solid KF5::XmlGui KF5::ConfigWidgets)
+target_link_libraries(atelier AtelierWidgets AtelierDialogs Atelier3D QtAwesome AtCore::AtCore KF5::Solid KF5::XmlGui KF5::ConfigWidgets)
install(TARGETS atelier RUNTIME DESTINATION bin)
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index a76e3cb..b64e417 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,185 +1,219 @@
/* 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 "widgets/atcoreinstancewidget.h"
#include "widgets/gcodeeditorwidget.h"
#include
#include "widgets/3dview/viewer3d.h"
#include "widgets/videomonitorwidget.h"
+#include "QtAwesome/QtAwesome.h"
MainWindow::MainWindow(QWidget *parent) :
KXmlGuiWindow(parent),
ui(new Ui::MainWindow),
profilesDialog(new ProfilesDialog(this)),
connectSettingsDialog(new ConnectSettingsDialog(this)),
m_curr_editor_view(nullptr),
m_instances(new QTabWidget(this))
{
ui->setupUi(this);
setupActions();
+ setupQtAwesome();
initWidgets();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::initWidgets()
{
auto *newInstanceWidget = new AtCoreInstanceWidget();
m_instances->addTab(newInstanceWidget, i18n("Connect your printer"));
// When a new profile is added on the Profile Dialog it needs to update the profiles on connection dialog
connect(profilesDialog, &ProfilesDialog::updateProfiles,
connectSettingsDialog, &ConnectSettingsDialog::updateProfiles);
connect(connectSettingsDialog, &ConnectSettingsDialog::startConnection, this, &MainWindow::newConnection);
connectSettingsDialog->setFirmwareList(newInstanceWidget->firmwares());
profilesDialog->setBaudRates(newInstanceWidget->baudRates());
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->setIconSize(QSize(28,28));
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){
guiFactory()->removeClient(m_curr_editor_view);
guiFactory()->addClient(view);
m_curr_editor_view = 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));
+ setupButton("3d", i18n("&3D"), m_qtawesome.icon("cube"), new Viewer3D(this));
+ setupButton("gcode", i18n("&GCode"), m_qtawesome.icon("edit"), gcodeEditor);
+ setupButton("video", i18n("&Video"), m_qtawesome.icon("videocamera"), 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, connectSettingsDialog, &ConnectSettingsDialog::show);
action = actionCollection()->addAction(QStringLiteral("profiles"));
action->setText(i18n("&Profiles"));
connect(action, &QAction::triggered, profilesDialog, &ProfilesDialog::show);
#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.rc");
}
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);
}
+
+void MainWindow::setupQtAwesome(){
+
+ m_qtawesome.initFontAwesome();
+ QColor textColor = palette().color(QPalette::Text);
+ qreal h, s, l, a;
+ textColor.getHslF(&h, &s, &l, &a);
+
+ if (l <= 0.6) { // moderated dark text. get a somewhat bright background
+ QColor grey(189, 195, 199);
+ m_qtawesome.setDefaultOption("color", grey);
+ m_qtawesome.setDefaultOption("color-disabled", grey);
+ m_qtawesome.setDefaultOption("color-active", grey);
+ m_qtawesome.setDefaultOption("color-selected", grey);
+ m_qtawesome.setDefaultOption("color-off", grey);
+ m_qtawesome.setDefaultOption("color-disabled-off", grey);
+ m_qtawesome.setDefaultOption("color-active-off", grey);
+ m_qtawesome.setDefaultOption("color-selected-off", grey);
+
+ } else {
+ QColor white(255, 255, 255);
+ m_qtawesome.setDefaultOption("color", white);
+ m_qtawesome.setDefaultOption("color-disabled", white);
+ m_qtawesome.setDefaultOption("color-active", white);
+ m_qtawesome.setDefaultOption("color-selected", white);
+ m_qtawesome.setDefaultOption("color-off", white);
+ m_qtawesome.setDefaultOption("color-disabled-off", white);
+ m_qtawesome.setDefaultOption("color-active-off", white);
+ m_qtawesome.setDefaultOption("color-selected-off", white);
+
+ } // light text. get a dark background.
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 4d93615..aa798a7 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -1,77 +1,80 @@
/* Atelier KDE Printer Host for 3D Printing
Copyright (C) <2016>
Author: Lays Rodrigues - laysrodrigues@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 .
*/
#pragma once
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
+#include "QtAwesome/QtAwesome.h"
namespace Ui
{
class MainWindow;
}
struct LateralArea {
// Area with the the lateral buttons that will open the views.
// Kind like the KDevelop stuff but way simpler.
using Btn2Widget = QPair;
using WidgetMap = QMap;
QWidget *m_toolBar;
QStackedWidget *m_stack;
WidgetMap m_map;
template T* get(const QString& s) {
return qobject_cast(m_map[s].second);
}
};
class MainWindow : public KXmlGuiWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
QStringList firmwaresList;
QList m_openFiles;
ProfilesDialog *profilesDialog;
ConnectSettingsDialog *connectSettingsDialog;
KTextEditor::View *m_curr_editor_view;
LateralArea m_lateral;
QTabWidget *m_instances;
+ QtAwesome m_qtawesome;
void setupLateralArea();
void initWidgets();
void setupActions();
void openFile();
void newConnection(const QString& port, const QMap& profile);
+ void setupQtAwesome();
};