Permalink
Browse files

Add toolbar

  • Loading branch information...
feragon committed Jun 14, 2016
1 parent 6ea0ab8 commit 4e5ce512a5c7628055966b16280589004aa551bb
View
@@ -34,6 +34,8 @@ operations/qsnappedstate.h
operations/trimoperation.h
widgets/clicommand.h
widgets/luascript.h
widgets/toolbar.h
widgets/toolbartab.h
lua/qtbridge.h
lua/luaqobject.h)
@@ -48,12 +50,16 @@ operations/qsnappedstate.cpp
operations/trimoperation.cpp
widgets/clicommand.cpp
widgets/luascript.cpp
widgets/toolbar.cpp
widgets/toolbartab.cpp
lua/qtbridge.cpp
lua/luaqobject.cpp)
QT5_WRAP_UI(UI_HEADERS
widgets/clicommand.ui
widgets/luascript.ui)
widgets/luascript.ui
widgets/toolbar.ui
widgets/toolbartab.ui)
qt5_add_resources(UI_RESOURCES
ui/resource.qrc)
@@ -116,5 +122,5 @@ if(WITH_UNITTESTS)
target_link_libraries(lcui ${EXTRA_LIBS})
endif(WITH_UNITTESTS)
add_executable(librecad ${UI_srcs} ${UI_hdrs} ${UI_HEADERS})
add_executable(librecad ${UI_srcs} ${UI_hdrs} ${UI_HEADERS} ${UI_RESOURCES})
target_link_libraries(librecad ${EXTRA_LIBS})
View
@@ -47,6 +47,14 @@ void addQtBaseBindings(lua_State *L) {
.addConstructor(LUA_ARGS(QObject*))
.addFunction("setText", &QAction::setText)
.endClass()
.beginClass<QIcon>("QIcon")
.addConstructor(LUA_ARGS(QString))
.endClass()
.beginClass<QSize>("QSize")
.addConstructor(LUA_ARGS(int, int))
.endClass()
.endModule();
}
@@ -127,6 +135,9 @@ void addQtLayoutBindings(lua_State *L) {
.beginExtendClass<QVBoxLayout, QBoxLayout>("QVBoxLayout")
.addConstructor(LUA_ARGS())
.endClass()
.beginExtendClass<QGroupBox, QWidget>("QGroupBox")
.endClass()
.endModule();
}
@@ -135,10 +146,13 @@ void addQtWidgetsBindings(lua_State *L) {
.beginModule("qt")
.beginExtendClass<QAbstractButton, QWidget>("QAbstractButton")
.addFunction("setIcon", &QAbstractButton::setIcon)
.addFunction("setIconSize", &QAbstractButton::setIconSize)
.endClass()
.beginExtendClass<QPushButton, QAbstractButton>("QPushButton")
.addConstructor(LUA_ARGS(QString))
.addConstructor(LUA_ARGS(QString, LuaIntf::_opt<QWidget*>))
.addFunction("setFlat", &QPushButton::setFlat)
.endClass()
.endModule();
}
@@ -186,11 +200,37 @@ void addLCBindings(lua_State *L) {
.endClass()
.beginExtendClass<CliCommand, QDockWidget>("CliCommand")
.addConstructor(LUA_SP(std::shared_ptr<CliCommand>), LUA_ARGS(QWidget*))
.addConstructor(LUA_SP(std::shared_ptr<CliCommand>), LUA_ARGS(LuaIntf::_opt<QWidget*>))
.addFunction("addCommand", &CliCommand::addCommand)
.addFunction("write", &CliCommand::write, LUA_ARGS(const char*))
.endClass()
.beginExtendClass<Toolbar, QDockWidget>("Toolbar")
.addConstructor(LUA_SP(std::shared_ptr<Toolbar>), LUA_ARGS(LuaIntf::_opt<QWidget*>))
.addFunction("addTab", &Toolbar::addTab)
.addFunction("removeTab", &Toolbar::removeTab)
.addFunction("tabByName", &Toolbar::tabByName)
.endClass()
.beginExtendClass<ToolbarTab, QDockWidget>("ToolbarTab")
.addConstructor(LUA_SP(std::shared_ptr<ToolbarTab>), LUA_ARGS(LuaIntf::_opt<QWidget*>))
.addFunction("addButton", &ToolbarTab::addButton, LUA_ARGS(QGroupBox*,
QPushButton*,
LuaIntf::_opt<int>,
LuaIntf::_opt<int>,
LuaIntf::_opt<int>,
LuaIntf::_opt<int>))
.addFunction("addButtonStr", &ToolbarTab::addButtonStr, LUA_ARGS(QGroupBox*,
const char*,
LuaIntf::_opt<int>,
LuaIntf::_opt<int>,
LuaIntf::_opt<int>,
LuaIntf::_opt<int>))
.addFunction("addGroup", &ToolbarTab::addGroup)
.addFunction("buttonByText", &ToolbarTab::buttonByText)
.addFunction("groupByName", &ToolbarTab::groupByName)
.endClass()
.endModule();
}
View
@@ -27,6 +27,8 @@ extern "C"
#include "lcadviewer.h"
#include "widgets/luascript.h"
#include "widgets/clicommand.h"
#include "widgets/toolbar.h"
#include "widgets/toolbartab.h"
Q_DECLARE_METATYPE(lc::geo::Coordinate);
File renamed without changes.
File renamed without changes.
View
@@ -1 +1,6 @@
<RCC/>
<RCC>
<qresource prefix="/icons">
<file alias="linesfree.png">icons/linesfree.png</file>
<file alias="linesnormal.png">icons/linesnormal.png</file>
</qresource>
</RCC>
View
@@ -0,0 +1,40 @@
#include "toolbar.h"
#include "ui_toolbar.h"
Toolbar::Toolbar(QWidget *parent) :
QDockWidget(parent),
ui(new Ui::Toolbar) {
ui->setupUi(this);
setTitleBarWidget(0);
setWidget(ui->tabWidget);
}
Toolbar::~Toolbar() {
delete ui;
}
void Toolbar::addTab(const char* name, QWidget* page) {
ui->tabWidget->addTab(page, tr(name));
}
void Toolbar::removeTab(QWidget *page) {
if(page == nullptr) {
return;
}
auto index = ui->tabWidget->indexOf(page);
ui->tabWidget->removeTab(index);
}
QWidget *Toolbar::tabByName(const char *name) {
auto nbTab = ui->tabWidget->count();
for(int i = 0; i < nbTab; i++) {
if(ui->tabWidget->tabText(i) == name) {
return ui->tabWidget->widget(i);
}
}
return nullptr;
}
View
@@ -0,0 +1,21 @@
#pragma once
#include <QDockWidget>
namespace Ui {
class Toolbar;
}
class Toolbar : public QDockWidget {
public:
Toolbar(QWidget *parent = 0);
~Toolbar();
void addTab(const char* name, QWidget* page);
void removeTab(QWidget* page);
QWidget* tabByName(const char* name);
private:
Ui::Toolbar *ui;
};
View
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Toolbar</class>
<widget class="QDockWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>455</width>
<height>334</height>
</rect>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="features">
<set>QDockWidget::DockWidgetFeatureMask</set>
</property>
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>451</width>
<height>321</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,80 @@
#include "toolbartab.h"
#include "ui_toolbartab.h"
ToolbarTab::ToolbarTab(QWidget *parent) :
QWidget(parent),
ui(new Ui::ToolbarTab) {
ui->setupUi(this);
if(ui->container->layout() == 0) {
_layout = new QHBoxLayout();
ui->container->setLayout(_layout);
}
else {
_layout = dynamic_cast<QHBoxLayout*>(ui->container->layout());
if(!_layout) {
throw "Wrong layout for ToolbarTab container";
}
}
}
QGroupBox* ToolbarTab::addGroup(const char* name) {
auto group = new QGroupBox(tr(name));
group->setLayout(new QGridLayout());
_layout->insertWidget(_layout->count() - 1, group);
return group;
}
void ToolbarTab::addButton(QGroupBox *groupBox, QPushButton *button, int x, int y, int w, int h) {
if(groupBox == nullptr) {
return;
}
auto gridLayout = dynamic_cast<QGridLayout*>(groupBox->layout());
if(gridLayout) {
gridLayout->addWidget(button, y, x, h, w);
}
else {
groupBox->layout()->addWidget(button);
}
}
QPushButton* ToolbarTab::addButtonStr(QGroupBox* groupBox, const char* buttonName, int x, int y, int w, int h) {
auto button = new QPushButton(buttonName);
addButton(groupBox, button, x, y, w, h);
return button;
}
QGroupBox* ToolbarTab::groupByName(const char* groupName) {
auto nbGroups = _layout->count();
for (int i = 0; i < nbGroups; i++) {
auto groupBox = dynamic_cast<QGroupBox*>(_layout->itemAt(i));
if(groupBox && groupBox->title() == groupName) {
return groupBox;
}
}
return nullptr;
}
QPushButton *ToolbarTab::buttonByText(QGroupBox* groupBox, const char* buttonText) {
auto nbButtons = groupBox->layout()->count();
for (int i = 0; i < nbButtons; i++) {
auto button = dynamic_cast<QPushButton*>(groupBox->layout()->itemAt(i));
if(button && button->text() == buttonText) {
return button;
}
}
return nullptr;
}
View
@@ -0,0 +1,31 @@
#pragma once
#include <QWidget>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QPushButton>
#include <QScrollArea>
#include <QSpacerItem>
#include <iostream>
namespace Ui {
class ToolbarTab;
}
class ToolbarTab : public QWidget {
public:
ToolbarTab(QWidget* parent = 0);
QGroupBox* addGroup(const char* name);
void addButton(QGroupBox* groupBox, QPushButton* buttonName, int x = 0, int y = 0, int w = 1, int h = 1);
QPushButton* addButtonStr(QGroupBox* groupBox, const char* buttonName, int x = 0, int y = 0, int w = 1, int h = 1);
QGroupBox* groupByName(const char* groupName);
QPushButton* buttonByText(QGroupBox* groupBox, const char* buttonText);
private:
Ui::ToolbarTab* ui;
QHBoxLayout* _layout;
};
View
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ToolbarTab</class>
<widget class="QWidget" name="ToolbarTab">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="container">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>380</width>
<height>280</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Oops, something went wrong.

0 comments on commit 4e5ce51

Please sign in to comment.