init
This commit is contained in:
69
ui/generic/actionlist.cpp
Normal file
69
ui/generic/actionlist.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
**********************************************************************************
|
||||
**
|
||||
** This file was created for the LibreCAD project (librecad.org), a 2D CAD program.
|
||||
**
|
||||
** Copyright (C) 2016 ravas (github.com/r-a-v-a-s)
|
||||
**
|
||||
** 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 2
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
** http://www.gnu.org/licenses/gpl-2.0.html
|
||||
**
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#include "actionlist.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
ActionList::ActionList(QWidget* parent)
|
||||
: QListWidget(parent)
|
||||
{}
|
||||
|
||||
|
||||
void ActionList::addActionItem(QAction* action)
|
||||
{
|
||||
auto item = new QListWidgetItem;
|
||||
item->setText(action->text().remove("&"));
|
||||
item->setIcon(action->icon());
|
||||
item->setWhatsThis(action->objectName());
|
||||
addItem(item);
|
||||
}
|
||||
|
||||
void ActionList::fromActionList(const QList<QAction*>& a_list)
|
||||
{
|
||||
action_list = a_list;
|
||||
foreach (QAction* a, a_list)
|
||||
{
|
||||
addActionItem(a);
|
||||
}
|
||||
}
|
||||
|
||||
void ActionList::fromActionMap(QMap<QString, QAction*>& a_map)
|
||||
{
|
||||
foreach (QAction* a, a_map)
|
||||
{
|
||||
addActionItem(a);
|
||||
}
|
||||
}
|
||||
|
||||
void ActionList::activateAction(QListWidgetItem* item)
|
||||
{
|
||||
foreach (QAction* a, action_list)
|
||||
{
|
||||
if (a->text() == item->text())
|
||||
a->activate(QAction::Trigger);
|
||||
}
|
||||
}
|
||||
23
ui/generic/actionlist.h
Normal file
23
ui/generic/actionlist.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef ACTIONLIST_H
|
||||
#define ACTIONLIST_H
|
||||
|
||||
#include <QListWidget>
|
||||
|
||||
class ActionList : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ActionList(QWidget* parent);
|
||||
void addActionItem(QAction* action);
|
||||
void fromActionList(const QList<QAction *>& a_list);
|
||||
void fromActionMap(QMap<QString, QAction*>& a_map);
|
||||
|
||||
public slots:
|
||||
void activateAction(QListWidgetItem*);
|
||||
|
||||
protected:
|
||||
QList<QAction*> action_list;
|
||||
};
|
||||
|
||||
#endif // ACTIONLIST_H
|
||||
41
ui/generic/colorcombobox.cpp
Normal file
41
ui/generic/colorcombobox.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
**********************************************************************************
|
||||
**
|
||||
** This file was created for the LibreCAD project (librecad.org), a 2D CAD program.
|
||||
**
|
||||
** Copyright (C) 2016 ravas (github.com/r-a-v-a-s)
|
||||
**
|
||||
** 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 2
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#include "colorcombobox.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QPixmap>
|
||||
|
||||
ColorComboBox::ColorComboBox(QWidget* parent)
|
||||
: QComboBox(parent)
|
||||
{
|
||||
setEditable(true);
|
||||
|
||||
foreach (auto color, QColor::colorNames())
|
||||
{
|
||||
QPixmap pixmap(32, 32);
|
||||
pixmap.fill(color);
|
||||
addItem(QIcon(pixmap), color);
|
||||
}
|
||||
}
|
||||
14
ui/generic/colorcombobox.h
Normal file
14
ui/generic/colorcombobox.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef COLORCOMBOBOX_H
|
||||
#define COLORCOMBOBOX_H
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
class ColorComboBox : public QComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ColorComboBox(QWidget* parent);
|
||||
};
|
||||
|
||||
#endif // COLORCOMBOBOX_H
|
||||
175
ui/generic/colorwizard.cpp
Normal file
175
ui/generic/colorwizard.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
**********************************************************************************
|
||||
**
|
||||
** This file was created for LibreCAD (https://github.com/LibreCAD/LibreCAD).
|
||||
**
|
||||
** Copyright (C) 2016 ravas (github.com/r-a-v-a-s)
|
||||
**
|
||||
** 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 2
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
** http://www.gnu.org/licenses/gpl-2.0.html
|
||||
**
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#include "colorwizard.h"
|
||||
#include "ui_colorwizard.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QColorDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QSettings>
|
||||
|
||||
ColorWizard::ColorWizard(QWidget *parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::ColorWizard)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->colorwin_button, &QToolButton::clicked,
|
||||
this, &ColorWizard::invokeColorDialog);
|
||||
|
||||
connect(ui->add_button, &QToolButton::clicked,
|
||||
this, &ColorWizard::addOrRemove);
|
||||
|
||||
connect(ui->fav_list, &QListWidget::itemDoubleClicked,
|
||||
this, &ColorWizard::handleDoubleClick);
|
||||
|
||||
ui->fav_list->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
ui->fav_list->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
|
||||
auto select = new QAction(QObject::tr("Select objects"), ui->fav_list);
|
||||
connect(select, &QAction::triggered, this, &ColorWizard::requestSelection);
|
||||
ui->fav_list->addAction(select);
|
||||
|
||||
auto apply = new QAction(QObject::tr("Apply to selected"), ui->fav_list);
|
||||
connect(apply, &QAction::triggered, this, &ColorWizard::requestColorChange);
|
||||
ui->fav_list->addAction(apply);
|
||||
|
||||
auto remove = new QAction(QObject::tr("Remove"), ui->fav_list);
|
||||
connect(remove, &QAction::triggered, this, &ColorWizard::removeFavorite);
|
||||
ui->fav_list->addAction(remove);
|
||||
|
||||
QSettings settings;
|
||||
auto favs = settings.value("Widgets/FavoriteColors").toStringList();
|
||||
foreach (auto fav, favs)
|
||||
{
|
||||
addFavorite(fav);
|
||||
}
|
||||
ui->combo->setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
ColorWizard::~ColorWizard()
|
||||
{
|
||||
auto favs = getFavList();
|
||||
QSettings settings;
|
||||
if (favs.size() > 0)
|
||||
settings.setValue("Widgets/FavoriteColors", favs);
|
||||
else
|
||||
settings.remove("Widgets/FavoriteColors");
|
||||
delete ui;
|
||||
|
||||
}
|
||||
|
||||
void ColorWizard::requestColorChange()
|
||||
{
|
||||
auto i = ui->fav_list->currentItem();
|
||||
if (i)
|
||||
emit requestingColorChange(QColor(i->text()));
|
||||
}
|
||||
|
||||
void ColorWizard::requestSelection()
|
||||
{
|
||||
auto i = ui->fav_list->currentItem();
|
||||
if (i)
|
||||
emit requestingSelection(QColor(i->text()));
|
||||
}
|
||||
|
||||
void ColorWizard::invokeColorDialog()
|
||||
{
|
||||
QColor current;
|
||||
current.setNamedColor(ui->combo->currentText());
|
||||
|
||||
QColorDialog dlg;
|
||||
dlg.setCustomColor(0, current);
|
||||
|
||||
QColor color = dlg.getColor(current, this, "Select Color", QColorDialog::DontUseNativeDialog);
|
||||
if (color.isValid())
|
||||
{
|
||||
QPixmap pixmap(32, 32);
|
||||
pixmap.fill(color);
|
||||
ui->combo->insertItem(0, QIcon(pixmap), color.name());
|
||||
ui->combo->setCurrentIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ColorWizard::addOrRemove()
|
||||
{
|
||||
auto color = ui->combo->currentText();
|
||||
if (color.isEmpty()) return;
|
||||
|
||||
auto list = ui->fav_list->findItems(color, Qt::MatchExactly);
|
||||
if (list.size() > 0)
|
||||
qDeleteAll(list);
|
||||
else
|
||||
addFavorite(color);
|
||||
|
||||
}
|
||||
|
||||
QStringList ColorWizard::getFavList()
|
||||
{
|
||||
QStringList s_list;
|
||||
|
||||
for (int i = 0; i < ui->fav_list->count(); ++i)
|
||||
{
|
||||
s_list << ui->fav_list->item(i)->text();
|
||||
}
|
||||
return s_list;
|
||||
}
|
||||
|
||||
void ColorWizard::addFavorite(QString color)
|
||||
{
|
||||
auto item = new QListWidgetItem;
|
||||
item->setText(color);
|
||||
QPixmap pixmap(32, 32);
|
||||
pixmap.fill(color);
|
||||
item->setIcon(QIcon(pixmap));
|
||||
ui->fav_list->addItem(item);
|
||||
}
|
||||
|
||||
void ColorWizard::removeFavorite()
|
||||
{
|
||||
delete ui->fav_list->currentItem();
|
||||
}
|
||||
|
||||
void ColorWizard::handleDoubleClick(QListWidgetItem* item)
|
||||
{
|
||||
auto name = item->text();
|
||||
auto color = QColor(name);
|
||||
auto i = ui->combo->findText(name);
|
||||
if (i != -1)
|
||||
{
|
||||
ui->combo->setCurrentIndex(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
QPixmap pixmap(32, 32);
|
||||
pixmap.fill(color);
|
||||
ui->combo->insertItem(0, QIcon(pixmap), name);
|
||||
ui->combo->setCurrentIndex(0);
|
||||
}
|
||||
emit colorDoubleClicked(color);
|
||||
}
|
||||
41
ui/generic/colorwizard.h
Normal file
41
ui/generic/colorwizard.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef COLORWIZARD_H
|
||||
#define COLORWIZARD_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QColor>
|
||||
|
||||
class QListWidgetItem;
|
||||
|
||||
namespace Ui {
|
||||
class ColorWizard;
|
||||
}
|
||||
|
||||
class ColorWizard : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ColorWizard(QWidget* parent = 0);
|
||||
~ColorWizard();
|
||||
|
||||
QStringList getFavList();
|
||||
void addFavorite(QString color);
|
||||
|
||||
private:
|
||||
Ui::ColorWizard* ui;
|
||||
|
||||
signals:
|
||||
void requestingColorChange(QColor);
|
||||
void requestingSelection(QColor);
|
||||
void colorDoubleClicked(QColor);
|
||||
|
||||
protected slots:
|
||||
void requestColorChange();
|
||||
void requestSelection();
|
||||
void invokeColorDialog();
|
||||
void addOrRemove();
|
||||
void removeFavorite();
|
||||
void handleDoubleClick(QListWidgetItem* item);
|
||||
};
|
||||
|
||||
#endif // COLORWIZARD_H
|
||||
96
ui/generic/colorwizard.ui
Normal file
96
ui/generic/colorwizard.ui
Normal file
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ColorWizard</class>
|
||||
<widget class="QFrame" name="ColorWizard">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>305</width>
|
||||
<height>200</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_0">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QToolButton" name="add_button">
|
||||
<property name="toolTip">
|
||||
<string>Add to favorites</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../res/extui/extui.qrc">
|
||||
<normaloff>:/extui/char_pm.png</normaloff>:/extui/char_pm.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>12</width>
|
||||
<height>12</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ColorComboBox" name="combo">
|
||||
<property name="toolTip">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="colorwin_button">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../res/ui/ui.qrc">
|
||||
<normaloff>:/ui/colorxx.png</normaloff>:/ui/colorxx.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>12</width>
|
||||
<height>12</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="fav_list"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ColorComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>colorcombobox.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../../res/extui/extui.qrc"/>
|
||||
<include location="../../../res/ui/ui.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
76
ui/generic/comboboxoption.cpp
Normal file
76
ui/generic/comboboxoption.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
**********************************************************************************
|
||||
**
|
||||
** This file was created for the LibreCAD project (librecad.org), a 2D CAD program.
|
||||
**
|
||||
** Copyright (C) 2016 ravas (github.com/r-a-v-a-s)
|
||||
**
|
||||
** 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 2
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#include "comboboxoption.h"
|
||||
#include "ui_comboboxoption.h"
|
||||
|
||||
ComboBoxOption::ComboBoxOption(QWidget* parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::ComboBoxOption)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->pushButton->setDisabled(true);
|
||||
connect(ui->pushButton, SIGNAL(released()), this, SLOT(saveIndexAndEmitOption()));
|
||||
connect(ui->comboBox, SIGNAL(activated(int)), this, SLOT(setButtonState(int)));
|
||||
}
|
||||
|
||||
ComboBoxOption::~ComboBoxOption()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
// ~ public ~
|
||||
|
||||
void ComboBoxOption::setTitle(const QString& title)
|
||||
{
|
||||
ui->groupBox->setTitle(title);
|
||||
}
|
||||
|
||||
void ComboBoxOption::setOptionsList(const QStringList& options)
|
||||
{
|
||||
ui->comboBox->addItems(options);
|
||||
}
|
||||
|
||||
void ComboBoxOption::setCurrentOption(const QString& option)
|
||||
{
|
||||
int index = ui->comboBox->findText(option);
|
||||
ui->comboBox->setCurrentIndex(index);
|
||||
last_saved_index = index;
|
||||
}
|
||||
|
||||
// ~ private slots ~
|
||||
|
||||
void ComboBoxOption::saveIndexAndEmitOption()
|
||||
{
|
||||
ui->pushButton->setDisabled(true);
|
||||
int index = ui->comboBox->currentIndex();
|
||||
QString option = ui->comboBox->itemText(index);
|
||||
last_saved_index = index;
|
||||
emit optionToSave(option);
|
||||
}
|
||||
|
||||
void ComboBoxOption::setButtonState(int index)
|
||||
{
|
||||
ui->pushButton->setDisabled((last_saved_index == index) ? true : false);
|
||||
}
|
||||
37
ui/generic/comboboxoption.h
Normal file
37
ui/generic/comboboxoption.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef COMBOBOXOPTION_H
|
||||
#define COMBOBOXOPTION_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QStringList>
|
||||
|
||||
namespace Ui {
|
||||
class ComboBoxOption;
|
||||
}
|
||||
|
||||
class ComboBoxOption : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ComboBoxOption(QWidget* parent);
|
||||
~ComboBoxOption();
|
||||
|
||||
void setTitle(const QString& title);
|
||||
void setOptionsList(const QStringList& options);
|
||||
void setCurrentOption(const QString& option);
|
||||
|
||||
protected:
|
||||
int last_saved_index;
|
||||
|
||||
signals:
|
||||
void optionToSave(QString);
|
||||
|
||||
private slots:
|
||||
void saveIndexAndEmitOption();
|
||||
void setButtonState(int);
|
||||
|
||||
private:
|
||||
Ui::ComboBoxOption* ui;
|
||||
};
|
||||
|
||||
#endif // COMBOBOXOPTION_H
|
||||
52
ui/generic/comboboxoption.ui
Normal file
52
ui/generic/comboboxoption.ui
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ComboBoxOption</class>
|
||||
<widget class="QFrame" name="ComboBoxOption">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>265</width>
|
||||
<height>82</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>GroupBox</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Set</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
216
ui/generic/customtoolbarcreator.cpp
Normal file
216
ui/generic/customtoolbarcreator.cpp
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
**********************************************************************************
|
||||
**
|
||||
** This file was created for LibreCAD (https://github.com/LibreCAD/LibreCAD).
|
||||
**
|
||||
** Copyright (C) 2016 ravas (https://github.com/r-a-v-a-s)
|
||||
**
|
||||
** 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 2
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
** http://www.gnu.org/licenses/gpl-2.0.html
|
||||
**
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#include "customtoolbarcreator.h"
|
||||
#include "ui_customtoolbarcreator.h"
|
||||
#include "lc_actiongroupmanager.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QLineEdit>
|
||||
|
||||
CustomToolbarCreator::CustomToolbarCreator(QWidget* parent,
|
||||
QMap<QString, QAction*>& action_map,
|
||||
LC_ActionGroupManager* agm)
|
||||
: QFrame(parent)
|
||||
, ui(new Ui::CustomToolbarCreator)
|
||||
, a_map(action_map)
|
||||
, ag_manager(agm)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
foreach (auto ag, ag_manager->findChildren<QActionGroup*>())
|
||||
{
|
||||
ui->categories_combobox->addItem(ag->objectName());
|
||||
}
|
||||
ui->categories_combobox->setCurrentIndex(-1);
|
||||
ui->chosen_actions->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
|
||||
ui->offered_actions->setSortingEnabled(true);
|
||||
|
||||
ui->offered_actions->fromActionMap(a_map);
|
||||
|
||||
connect(ui->add_button, SIGNAL(released()), this, SLOT(addChosenAction()));
|
||||
connect(ui->remove_button, SIGNAL(released()), this, SLOT(removeChosenAction()));
|
||||
|
||||
connect(ui->offered_actions, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(addChosenAction(QListWidgetItem*)));
|
||||
connect(ui->chosen_actions, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(removeChosenAction(QListWidgetItem*)));
|
||||
|
||||
connect(ui->add_widget_button, SIGNAL(released()), this, SLOT(addWidget()));
|
||||
connect(ui->remove_widget_button, SIGNAL(released()), this, SLOT(removeWidget()));
|
||||
|
||||
connect(ui->combo, SIGNAL(activated(QString)), this, SLOT(setLists(QString)));
|
||||
|
||||
connect(ui->save_button, SIGNAL(released()), this, SLOT(create()));
|
||||
|
||||
connect(ui->categories_combobox, SIGNAL(activated(QString)), this, SLOT(setCategory(QString)));
|
||||
}
|
||||
|
||||
CustomToolbarCreator::~CustomToolbarCreator()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CustomToolbarCreator::addChosenAction()
|
||||
{
|
||||
QListWidgetItem* item = ui->offered_actions->currentItem();
|
||||
if (item)
|
||||
{
|
||||
ui->chosen_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void CustomToolbarCreator::addChosenAction(QListWidgetItem* item)
|
||||
{
|
||||
ui->chosen_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
|
||||
void CustomToolbarCreator::removeChosenAction()
|
||||
{
|
||||
QListWidgetItem* item = ui->chosen_actions->currentItem();
|
||||
if (item)
|
||||
{
|
||||
ui->offered_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void CustomToolbarCreator::removeChosenAction(QListWidgetItem* item)
|
||||
{
|
||||
ui->offered_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
|
||||
QStringList CustomToolbarCreator::getChosenActions()
|
||||
{
|
||||
QStringList s_list;
|
||||
|
||||
for (int i = 0; i < ui->chosen_actions->count(); ++i)
|
||||
{
|
||||
s_list << ui->chosen_actions->item(i)->whatsThis();
|
||||
}
|
||||
return s_list;
|
||||
}
|
||||
|
||||
|
||||
void CustomToolbarCreator::addCustomWidgets(const QString& group)
|
||||
{
|
||||
w_group = group;
|
||||
|
||||
QSettings settings;
|
||||
|
||||
settings.beginGroup(group);
|
||||
foreach (auto key, settings.childKeys())
|
||||
{
|
||||
ui->combo->addItem(key);
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
ui->combo->lineEdit()->clear();
|
||||
}
|
||||
|
||||
void CustomToolbarCreator::addWidget()
|
||||
{
|
||||
w_key = ui->combo->lineEdit()->text();
|
||||
if(!w_key.isEmpty() && ui->combo->findText(w_key) == -1)
|
||||
ui->combo->addItem(w_key);
|
||||
}
|
||||
|
||||
void CustomToolbarCreator::removeWidget()
|
||||
{
|
||||
auto key = ui->combo->lineEdit()->text();
|
||||
if (key.isEmpty()) return;
|
||||
|
||||
int index = ui->combo->findText(key);
|
||||
if (index > -1)
|
||||
{
|
||||
ui->combo->removeItem(index);
|
||||
ui->combo->lineEdit()->clear();
|
||||
QSettings settings;
|
||||
settings.remove(QString("%1/%2").arg(w_group).arg(key));
|
||||
ui->chosen_actions->clear();
|
||||
emit widgetToDestroy(key);
|
||||
}
|
||||
}
|
||||
|
||||
void CustomToolbarCreator::setLists(QString key)
|
||||
{
|
||||
w_key = key;
|
||||
QSettings settings;
|
||||
auto widget = QString("%1/%2").arg(w_group).arg(key);
|
||||
QStringList s_list = settings.value(widget).toStringList();
|
||||
|
||||
if (s_list.isEmpty()) return;
|
||||
|
||||
ui->chosen_actions->clear();
|
||||
ui->offered_actions->clear();
|
||||
|
||||
ui->offered_actions->fromActionMap(a_map);
|
||||
|
||||
for(int i = 0; i < ui->offered_actions->count(); ++i)
|
||||
{
|
||||
auto item = ui->offered_actions->item(i);
|
||||
if (s_list.contains(item->whatsThis()))
|
||||
delete item;
|
||||
}
|
||||
|
||||
foreach (auto str, s_list)
|
||||
{
|
||||
ui->chosen_actions->addActionItem(a_map[str]);
|
||||
}
|
||||
}
|
||||
|
||||
QString CustomToolbarCreator::getToolbarName()
|
||||
{
|
||||
return ui->combo->lineEdit()->text();
|
||||
}
|
||||
|
||||
void CustomToolbarCreator::create()
|
||||
{
|
||||
QStringList a_list = getChosenActions();
|
||||
if (!a_list.isEmpty() && !w_key.isEmpty())
|
||||
{
|
||||
QSettings settings;
|
||||
auto widget = QString("%1/%2").arg(w_group).arg(w_key);
|
||||
settings.setValue(widget, a_list);
|
||||
emit widgetToCreate(w_key);
|
||||
}
|
||||
}
|
||||
|
||||
void CustomToolbarCreator::setCategory(QString category)
|
||||
{
|
||||
ui->offered_actions->clear();
|
||||
auto chosen_actions = getChosenActions();
|
||||
auto action_group = ag_manager->findChild<QActionGroup*>(category);
|
||||
foreach (auto action, action_group->actions())
|
||||
{
|
||||
if (!chosen_actions.contains(action->objectName()))
|
||||
ui->offered_actions->addActionItem(action);
|
||||
}
|
||||
}
|
||||
55
ui/generic/customtoolbarcreator.h
Normal file
55
ui/generic/customtoolbarcreator.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef CUSTOMTOOLBARCREATOR_H
|
||||
#define CUSTOMTOOLBARCREATOR_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QList>
|
||||
|
||||
class QListWidgetItem;
|
||||
class LC_ActionGroupManager;
|
||||
|
||||
namespace Ui {
|
||||
class CustomToolbarCreator;
|
||||
}
|
||||
|
||||
class CustomToolbarCreator : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CustomToolbarCreator(QWidget* parent,
|
||||
QMap<QString, QAction*>& action_map,
|
||||
LC_ActionGroupManager* agm);
|
||||
~CustomToolbarCreator();
|
||||
|
||||
QStringList getChosenActions();
|
||||
void addCustomWidgets(const QString& group);
|
||||
QString getToolbarName();
|
||||
|
||||
private:
|
||||
Ui::CustomToolbarCreator* ui;
|
||||
QMap<QString, QAction*>& a_map;
|
||||
LC_ActionGroupManager* ag_manager;
|
||||
QString w_group;
|
||||
QString w_key;
|
||||
|
||||
private slots:
|
||||
void addChosenAction();
|
||||
void addChosenAction(QListWidgetItem* item);
|
||||
|
||||
void removeChosenAction();
|
||||
void removeChosenAction(QListWidgetItem* item);
|
||||
|
||||
void setLists(QString);
|
||||
|
||||
void addWidget();
|
||||
void removeWidget();
|
||||
void create();
|
||||
|
||||
void setCategory(QString);
|
||||
|
||||
signals:
|
||||
void widgetToCreate(QString);
|
||||
void widgetToDestroy(QString);
|
||||
};
|
||||
|
||||
#endif // CUSTOMTOOLBARCREATOR_H
|
||||
211
ui/generic/customtoolbarcreator.ui
Normal file
211
ui/generic/customtoolbarcreator.ui
Normal file
@@ -0,0 +1,211 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CustomToolbarCreator</class>
|
||||
<widget class="QFrame" name="CustomToolbarCreator">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>651</width>
|
||||
<height>448</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_6">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QComboBox" name="categories_combobox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ActionList" name="offered_actions"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter|Qt::AlignVCenter">
|
||||
<widget class="QFrame" name="frame_5">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="add_button">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>></string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="remove_button">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="widget_list">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_3">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QToolButton" name="add_widget_button">
|
||||
<property name="text">
|
||||
<string>+</string>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="remove_widget_button">
|
||||
<property name="text">
|
||||
<string>-</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="combo">
|
||||
<property name="toolTip">
|
||||
<string>input a name and then press +</string>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ActionList" name="chosen_actions"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_4">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="save_button">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ActionList</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>actionlist.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
114
ui/generic/customwidgetcreator.cpp
Normal file
114
ui/generic/customwidgetcreator.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
**********************************************************************************
|
||||
**
|
||||
** This file was created for the LibreCAD project (librecad.org), a 2D CAD program.
|
||||
**
|
||||
** Copyright (C) 2016 ravas - https://github.com/r-a-v-a-s
|
||||
**
|
||||
** 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 2
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
** http://www.gnu.org/licenses/gpl-2.0.html
|
||||
**
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#include "customwidgetcreator.h"
|
||||
#include "ui_customwidgetcreator.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
CustomWidgetCreator::CustomWidgetCreator(QWidget* parent,
|
||||
QMap<QString, QAction*>& a_map)
|
||||
: QFrame(parent)
|
||||
, ui(new Ui::CustomWidgetCreator)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
QSettings settings;
|
||||
QStringList s_list = settings.value("CustomWidgets/DoubleClickMenu").toStringList();
|
||||
|
||||
foreach (auto key, s_list)
|
||||
{
|
||||
ui->chosen_actions->addActionItem(a_map[key]);
|
||||
}
|
||||
ui->chosen_actions->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
|
||||
ui->offered_actions->setSortingEnabled(true);
|
||||
ui->offered_actions->fromActionMap(a_map);
|
||||
for(int i = 0; i < ui->offered_actions->count(); ++i)
|
||||
{
|
||||
auto item = ui->offered_actions->item(i);
|
||||
if (s_list.contains(item->whatsThis()))
|
||||
delete item;
|
||||
}
|
||||
|
||||
connect(ui->add_button, SIGNAL(released()), this, SLOT(addChosenAction()));
|
||||
connect(ui->remove_button, SIGNAL(released()), this, SLOT(removeChosenAction()));
|
||||
|
||||
connect(ui->offered_actions, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(addChosenAction(QListWidgetItem*)));
|
||||
connect(ui->chosen_actions, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(removeChosenAction(QListWidgetItem*)));
|
||||
|
||||
connect(ui->save_button, SIGNAL(released()), parent, SLOT(accept()));
|
||||
}
|
||||
|
||||
CustomWidgetCreator::~CustomWidgetCreator()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CustomWidgetCreator::addChosenAction()
|
||||
{
|
||||
QListWidgetItem* item = ui->offered_actions->currentItem();
|
||||
if (item)
|
||||
{
|
||||
ui->chosen_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void CustomWidgetCreator::addChosenAction(QListWidgetItem* item)
|
||||
{
|
||||
ui->chosen_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
|
||||
void CustomWidgetCreator::removeChosenAction()
|
||||
{
|
||||
QListWidgetItem* item = ui->chosen_actions->currentItem();
|
||||
if (item)
|
||||
{
|
||||
ui->offered_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void CustomWidgetCreator::removeChosenAction(QListWidgetItem* item)
|
||||
{
|
||||
ui->offered_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
|
||||
QStringList CustomWidgetCreator::getChosenActions()
|
||||
{
|
||||
QStringList s_list;
|
||||
|
||||
for (int i = 0; i < ui->chosen_actions->count(); ++i)
|
||||
{
|
||||
s_list << ui->chosen_actions->item(i)->whatsThis();
|
||||
}
|
||||
return s_list;
|
||||
}
|
||||
35
ui/generic/customwidgetcreator.h
Normal file
35
ui/generic/customwidgetcreator.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef CUSTOMWIDGETCREATOR_H
|
||||
#define CUSTOMWIDGETCREATOR_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QList>
|
||||
|
||||
class QListWidgetItem;
|
||||
|
||||
namespace Ui {
|
||||
class CustomWidgetCreator;
|
||||
}
|
||||
|
||||
class CustomWidgetCreator : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CustomWidgetCreator(QWidget* parent, QMap<QString, QAction*>& a_map);
|
||||
~CustomWidgetCreator();
|
||||
|
||||
QStringList getChosenActions();
|
||||
|
||||
|
||||
protected slots:
|
||||
void addChosenAction();
|
||||
void addChosenAction(QListWidgetItem* item);
|
||||
|
||||
void removeChosenAction();
|
||||
void removeChosenAction(QListWidgetItem* item);
|
||||
|
||||
private:
|
||||
Ui::CustomWidgetCreator* ui;
|
||||
};
|
||||
|
||||
#endif // CUSTOMWIDGETCREATOR_H
|
||||
133
ui/generic/customwidgetcreator.ui
Normal file
133
ui/generic/customwidgetcreator.ui
Normal file
@@ -0,0 +1,133 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CustomWidgetCreator</class>
|
||||
<widget class="QFrame" name="CustomWidgetCreator">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>710</width>
|
||||
<height>458</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="ActionList" name="offered_actions"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter|Qt::AlignVCenter">
|
||||
<widget class="QFrame" name="frame_5">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="add_button">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>-></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="remove_button">
|
||||
<property name="text">
|
||||
<string><-</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_3">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="ActionList" name="chosen_actions"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_4">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="save_button">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ActionList</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>actionlist.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
25
ui/generic/linklist.cpp
Normal file
25
ui/generic/linklist.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "linklist.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
LinkList::LinkList(QWidget* parent)
|
||||
: QListWidget(parent)
|
||||
{
|
||||
|
||||
connect(this, SIGNAL(itemActivated(QListWidgetItem*)),
|
||||
this, SLOT(showWebPage(QListWidgetItem*)));
|
||||
}
|
||||
|
||||
void LinkList::addLink(const QString& text, const QString& url)
|
||||
{
|
||||
auto item = new QListWidgetItem;
|
||||
item->setText(text);
|
||||
item->setToolTip(url);
|
||||
addItem(item);
|
||||
}
|
||||
|
||||
void LinkList::showWebPage(QListWidgetItem* item)
|
||||
{
|
||||
QDesktopServices::openUrl(QUrl(item->toolTip()));
|
||||
}
|
||||
19
ui/generic/linklist.h
Normal file
19
ui/generic/linklist.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef LINKLIST_H
|
||||
#define LINKLIST_H
|
||||
|
||||
#include <QListWidget>
|
||||
|
||||
class LinkList : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LinkList(QWidget* parent);
|
||||
|
||||
void addLink(const QString& text, const QString& url);
|
||||
|
||||
protected slots:
|
||||
void showWebPage(QListWidgetItem*);
|
||||
};
|
||||
|
||||
#endif // LINKLIST_H
|
||||
73
ui/generic/textfileviewer.cpp
Normal file
73
ui/generic/textfileviewer.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
**********************************************************************************
|
||||
**
|
||||
** LibreCAD is a cross-platform 2D CAD program (github.com/LibreCAD/LibreCAD).
|
||||
**
|
||||
** Copyright (C) 2016 ravas (github.com/r-a-v-a-s)
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or
|
||||
** modify it under the terms of the GNU General Public License Version 2
|
||||
** as published by the Free Software Foundation.
|
||||
**
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
** http://www.gnu.org/licenses/gpl-2.0.html
|
||||
**
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#include "textfileviewer.h"
|
||||
#include "ui_textfileviewer.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QListWidget>
|
||||
|
||||
TextFileViewer::TextFileViewer(QWidget* parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::TextFileViewer)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->text_edit->setReadOnly(true);
|
||||
|
||||
connect(ui->list, &QListWidget::itemClicked, this, &TextFileViewer::loadFile);
|
||||
}
|
||||
|
||||
TextFileViewer::~TextFileViewer()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
bool TextFileViewer::addFile(QString name, QString path)
|
||||
{
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
return false;
|
||||
|
||||
QTextStream txt_stream(&file);
|
||||
auto txt = txt_stream.readAll();
|
||||
|
||||
auto item = new QListWidgetItem(name, ui->list);
|
||||
item->setWhatsThis(txt);
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextFileViewer::loadFile(QListWidgetItem* item)
|
||||
{
|
||||
ui->text_edit->setPlainText(item->whatsThis());
|
||||
}
|
||||
|
||||
void TextFileViewer::setFile(QString name)
|
||||
{
|
||||
auto item = ui->list->findItems(name, Qt::MatchExactly)[0];
|
||||
ui->list->setCurrentItem(item);
|
||||
loadFile(item);
|
||||
}
|
||||
56
ui/generic/textfileviewer.h
Normal file
56
ui/generic/textfileviewer.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
**********************************************************************************
|
||||
**
|
||||
** LibreCAD is a cross-platform 2D CAD program (github.com/LibreCAD/LibreCAD).
|
||||
**
|
||||
** Copyright (C) 2016 ravas (github.com/r-a-v-a-s)
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or
|
||||
** modify it under the terms of the GNU General Public License Version 2
|
||||
** as published by the Free Software Foundation.
|
||||
**
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
** http://www.gnu.org/licenses/gpl-2.0.html
|
||||
**
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef TEXTFILEVIEWER_H
|
||||
#define TEXTFILEVIEWER_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QString>
|
||||
|
||||
class QListWidgetItem;
|
||||
|
||||
namespace Ui {
|
||||
class TextFileViewer;
|
||||
}
|
||||
|
||||
class TextFileViewer : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TextFileViewer(QWidget* parent = 0);
|
||||
~TextFileViewer();
|
||||
|
||||
bool addFile(QString name, QString path);
|
||||
void setFile(QString name);
|
||||
|
||||
public slots:
|
||||
void loadFile(QListWidgetItem* item);
|
||||
|
||||
private:
|
||||
Ui::TextFileViewer* ui;
|
||||
};
|
||||
|
||||
#endif // TEXTFILEVIEWER_H
|
||||
56
ui/generic/textfileviewer.ui
Normal file
56
ui/generic/textfileviewer.ui
Normal file
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TextFileViewer</class>
|
||||
<widget class="QFrame" name="TextFileViewer">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>973</width>
|
||||
<height>632</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="list">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="text_edit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>600</width>
|
||||
<height>600</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="overwriteMode">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
271
ui/generic/widgetcreator.cpp
Normal file
271
ui/generic/widgetcreator.cpp
Normal file
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
**********************************************************************************
|
||||
**
|
||||
** This file was created for LibreCAD (https://github.com/LibreCAD/LibreCAD).
|
||||
**
|
||||
** Copyright (C) 2016 ravas (github.com/r-a-v-a-s)
|
||||
**
|
||||
** 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 2
|
||||
** 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, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
** http://www.gnu.org/licenses/gpl-2.0.html
|
||||
**
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#include "widgetcreator.h"
|
||||
#include "ui_widgetcreator.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QActionGroup>
|
||||
#include <QSettings>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
WidgetCreator::WidgetCreator(QWidget* parent,
|
||||
QMap<QString, QAction*>& actions,
|
||||
QMap<QString, QActionGroup*> action_groups,
|
||||
bool assigner)
|
||||
: QFrame(parent)
|
||||
, ui(new Ui::WidgetCreator)
|
||||
, a_map(actions)
|
||||
, ag_map(action_groups)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if (!assigner)
|
||||
{
|
||||
ui->assign_button->hide();
|
||||
ui->update_button->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
connect(ui->assign_button, SIGNAL(released()), this, SLOT(requestAssignment()));
|
||||
connect(ui->update_button, SIGNAL(released()), this, SLOT(requestUpdate()));
|
||||
}
|
||||
|
||||
ui->categories_combobox->addItem(QObject::tr("All"));
|
||||
foreach (auto ag, ag_map)
|
||||
{
|
||||
ui->categories_combobox->addItem(ag->objectName());
|
||||
}
|
||||
ui->categories_combobox->setCurrentIndex(-1);
|
||||
ui->chosen_actions->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
|
||||
ui->offered_actions->setSortingEnabled(true);
|
||||
|
||||
ui->offered_actions->fromActionMap(a_map);
|
||||
|
||||
connect(ui->add_button, SIGNAL(released()), this, SLOT(addChosenAction()));
|
||||
connect(ui->remove_button, SIGNAL(released()), this, SLOT(removeChosenAction()));
|
||||
|
||||
connect(ui->offered_actions, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(addChosenAction(QListWidgetItem*)));
|
||||
connect(ui->chosen_actions, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(removeChosenAction(QListWidgetItem*)));
|
||||
|
||||
connect(ui->combo, SIGNAL(activated(QString)), this, SLOT(setLists(QString)));
|
||||
|
||||
connect(ui->create_button, SIGNAL(released()), this, SLOT(createWidget()));
|
||||
connect(ui->destroy_button, SIGNAL(released()), this, SLOT(destroyWidget()));
|
||||
|
||||
connect(ui->categories_combobox, SIGNAL(activated(QString)), this, SLOT(setCategory(QString)));
|
||||
}
|
||||
|
||||
WidgetCreator::~WidgetCreator()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void WidgetCreator::addChosenAction()
|
||||
{
|
||||
QListWidgetItem* item = ui->offered_actions->currentItem();
|
||||
if (item)
|
||||
{
|
||||
ui->chosen_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetCreator::addChosenAction(QListWidgetItem* item)
|
||||
{
|
||||
ui->chosen_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
|
||||
void WidgetCreator::removeChosenAction()
|
||||
{
|
||||
QListWidgetItem* item = ui->chosen_actions->currentItem();
|
||||
if (item)
|
||||
{
|
||||
ui->offered_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetCreator::removeChosenAction(QListWidgetItem* item)
|
||||
{
|
||||
ui->offered_actions->addItem(item->clone());
|
||||
delete item;
|
||||
}
|
||||
|
||||
QStringList WidgetCreator::getChosenActions()
|
||||
{
|
||||
QStringList s_list;
|
||||
|
||||
for (int i = 0; i < ui->chosen_actions->count(); ++i)
|
||||
{
|
||||
s_list << ui->chosen_actions->item(i)->whatsThis();
|
||||
}
|
||||
return s_list;
|
||||
}
|
||||
|
||||
QString WidgetCreator::getWidgetName()
|
||||
{
|
||||
return ui->combo->lineEdit()->text();
|
||||
}
|
||||
|
||||
|
||||
void WidgetCreator::addCustomWidgets(const QString& group)
|
||||
{
|
||||
w_group = group;
|
||||
|
||||
QSettings settings;
|
||||
|
||||
settings.beginGroup(group);
|
||||
foreach (auto key, settings.childKeys())
|
||||
{
|
||||
ui->combo->addItem(key);
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
ui->combo->lineEdit()->clear();
|
||||
}
|
||||
|
||||
void WidgetCreator::setLists(QString key)
|
||||
{
|
||||
w_key = key;
|
||||
QSettings settings;
|
||||
auto widget = QString("%1/%2").arg(w_group).arg(key);
|
||||
QStringList s_list = settings.value(widget).toStringList();
|
||||
|
||||
if (s_list.isEmpty()) return;
|
||||
|
||||
ui->chosen_actions->clear();
|
||||
ui->offered_actions->clear();
|
||||
|
||||
ui->offered_actions->fromActionMap(a_map);
|
||||
int index = ui->categories_combobox->findText(QObject::tr("All"));
|
||||
ui->categories_combobox->setCurrentIndex(index);
|
||||
|
||||
for(int i = 0; i < ui->offered_actions->count(); ++i)
|
||||
{
|
||||
auto item = ui->offered_actions->item(i);
|
||||
if (s_list.contains(item->whatsThis()))
|
||||
delete item;
|
||||
}
|
||||
|
||||
foreach (auto str, s_list)
|
||||
{
|
||||
ui->chosen_actions->addActionItem(a_map[str]);
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetCreator::createWidget()
|
||||
{
|
||||
w_key = ui->combo->lineEdit()->text();
|
||||
if(!w_key.isEmpty() && ui->combo->findText(w_key) == -1)
|
||||
{
|
||||
w_key.replace("/", "-");
|
||||
ui->combo->addItem(w_key);
|
||||
}
|
||||
|
||||
QStringList a_list = getChosenActions();
|
||||
if (!a_list.isEmpty() && !w_key.isEmpty())
|
||||
{
|
||||
QSettings settings;
|
||||
auto widget = QString("%1/%2").arg(w_group).arg(w_key);
|
||||
settings.setValue(widget, a_list);
|
||||
emit widgetToCreate(w_key);
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetCreator::destroyWidget()
|
||||
{
|
||||
auto key = ui->combo->lineEdit()->text();
|
||||
if (key.isEmpty()) return;
|
||||
|
||||
int index = ui->combo->findText(key);
|
||||
if (index > -1)
|
||||
{
|
||||
ui->combo->removeItem(index);
|
||||
QSettings settings;
|
||||
settings.remove(QString("%1/%2").arg(w_group).arg(key));
|
||||
emit widgetToDestroy(key);
|
||||
ui->chosen_actions->clear();
|
||||
ui->combo->lineEdit()->clear();
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetCreator::setCategory(QString category)
|
||||
{
|
||||
if (category == QObject::tr("All"))
|
||||
{
|
||||
ui->offered_actions->clear();
|
||||
ui->offered_actions->fromActionMap(a_map);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ag_map.contains(category)) return;
|
||||
|
||||
ui->offered_actions->clear();
|
||||
auto chosen_actions = getChosenActions();
|
||||
auto action_group = ag_map[category];
|
||||
foreach (auto action, action_group->actions())
|
||||
{
|
||||
if (!chosen_actions.contains(action->objectName()))
|
||||
ui->offered_actions->addActionItem(action);
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetCreator::addButton(QPushButton* button)
|
||||
{
|
||||
ui->button_frame->layout()->addWidget(button);
|
||||
}
|
||||
|
||||
void WidgetCreator::requestAssignment()
|
||||
{
|
||||
auto widget_name = getWidgetName();
|
||||
if (hasBeenCreated(widget_name))
|
||||
emit widgetToAssign(widget_name);
|
||||
}
|
||||
|
||||
void WidgetCreator::requestUpdate()
|
||||
{
|
||||
auto widget_name = getWidgetName();
|
||||
if (hasBeenCreated(widget_name))
|
||||
{
|
||||
QSettings settings;
|
||||
auto widget = QString("%1/%2").arg(w_group).arg(w_key);
|
||||
QStringList a_list = getChosenActions();
|
||||
settings.setValue(widget, a_list);
|
||||
emit widgetToUpdate(widget_name);
|
||||
}
|
||||
}
|
||||
|
||||
bool WidgetCreator::hasBeenCreated(const QString& widget_name)
|
||||
{
|
||||
int index = ui->combo->findText(widget_name);
|
||||
return (index > -1) ? true : false;
|
||||
}
|
||||
82
ui/generic/widgetcreator.h
Normal file
82
ui/generic/widgetcreator.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#ifndef WIDGETCREATOR_H
|
||||
#define WIDGETCREATOR_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
|
||||
class QListWidgetItem;
|
||||
class QActionGroup;
|
||||
class QPushButton;
|
||||
|
||||
namespace Ui {
|
||||
class WidgetCreator;
|
||||
}
|
||||
|
||||
/**
|
||||
* This widget allows users to choose actions from a list
|
||||
* and save that list.
|
||||
*
|
||||
* @todo for 2.2.0 make this more generic, drop qt4 support, and then complete dox
|
||||
*/
|
||||
class WidgetCreator : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief WidgetCreator constructor.
|
||||
* @param parent - the parent widget (e.g. QDialog)
|
||||
* @param actions - a map with objectName keys and QAction* values
|
||||
* @param action_groups - a map with objectName keys and QActionGroup* values
|
||||
* @param assigner - when true: buttons are added for assignment and updating
|
||||
*/
|
||||
explicit WidgetCreator(QWidget* parent,
|
||||
QMap<QString, QAction*>& actions,
|
||||
QMap<QString, QActionGroup*> action_groups,
|
||||
bool assigner = false);
|
||||
~WidgetCreator();
|
||||
|
||||
|
||||
QStringList getChosenActions();
|
||||
QString getWidgetName();
|
||||
/**
|
||||
* @brief adds the keys from a group to the combobox
|
||||
* @param group - a QSettings group that has keys paired with stringlists
|
||||
*/
|
||||
void addCustomWidgets(const QString& group);
|
||||
void addButton(QPushButton* button);
|
||||
bool hasBeenCreated(const QString& widget_name);
|
||||
|
||||
private:
|
||||
Ui::WidgetCreator* ui;
|
||||
QMap<QString, QAction*>& a_map;
|
||||
QMap<QString, QActionGroup*> ag_map;
|
||||
QString w_group;
|
||||
QString w_key;
|
||||
|
||||
private slots:
|
||||
void addChosenAction();
|
||||
void addChosenAction(QListWidgetItem* item);
|
||||
|
||||
void removeChosenAction();
|
||||
void removeChosenAction(QListWidgetItem* item);
|
||||
|
||||
void setLists(QString);
|
||||
|
||||
void destroyWidget();
|
||||
void createWidget();
|
||||
void requestAssignment();
|
||||
void requestUpdate();
|
||||
|
||||
void setCategory(QString);
|
||||
|
||||
signals:
|
||||
void widgetToCreate(QString);
|
||||
void widgetToDestroy(QString);
|
||||
void widgetToAssign(QString);
|
||||
void widgetToUpdate(QString);
|
||||
};
|
||||
|
||||
#endif // WIDGETCREATOR_H
|
||||
241
ui/generic/widgetcreator.ui
Normal file
241
ui/generic/widgetcreator.ui
Normal file
@@ -0,0 +1,241 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>WidgetCreator</class>
|
||||
<widget class="QFrame" name="WidgetCreator">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>684</width>
|
||||
<height>522</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_6">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QComboBox" name="categories_combobox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>3</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ActionList" name="offered_actions"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter|Qt::AlignVCenter">
|
||||
<widget class="QFrame" name="frame_5">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="add_button">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>></string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="remove_button">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="widget_list">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_3">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="combo">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ActionList" name="chosen_actions"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QFrame" name="button_frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="create_button">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Create</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="destroy_button">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Destroy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="assign_button">
|
||||
<property name="text">
|
||||
<string>Assign</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="update_button">
|
||||
<property name="text">
|
||||
<string>Update</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ActionList</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>actionlist.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user