Gui: fix missing separator item in Customize -> Toolbar
This commit is contained in:
@@ -79,6 +79,7 @@ DlgCustomKeyboardImp::DlgCustomKeyboardImp( QWidget* parent )
|
||||
ui->setupUi(this);
|
||||
|
||||
conn = initCommandWidgets(ui->commandTreeWidget,
|
||||
nullptr,
|
||||
ui->categoryBox,
|
||||
ui->editCommand,
|
||||
ui->assignedTreeWidget,
|
||||
@@ -129,8 +130,49 @@ void DlgCustomKeyboardImp::initCommandCompleter(QLineEdit *edit, QComboBox *comb
|
||||
});
|
||||
}
|
||||
|
||||
void DlgCustomKeyboardImp::populateCommandList(QTreeWidget *commandTreeWidget,
|
||||
QTreeWidgetItem *separatorItem,
|
||||
QComboBox *combo)
|
||||
{
|
||||
QByteArray current;
|
||||
if (auto item = commandTreeWidget->currentItem())
|
||||
current = item->data(1, Qt::UserRole).toByteArray();
|
||||
|
||||
if (separatorItem)
|
||||
commandTreeWidget->takeTopLevelItem(commandTreeWidget->indexOfTopLevelItem(separatorItem));
|
||||
commandTreeWidget->clear();
|
||||
if (separatorItem)
|
||||
commandTreeWidget->addTopLevelItem(separatorItem);
|
||||
CommandManager & cCmdMgr = Application::Instance->commandManager();
|
||||
auto group = combo->itemData(combo->currentIndex(), Qt::UserRole).toByteArray();
|
||||
auto cmds = group == "All" ? cCmdMgr.getAllCommands()
|
||||
: cCmdMgr.getGroupCommands(group.constData());
|
||||
QTreeWidgetItem *currentItem = nullptr;
|
||||
for (const Command *cmd : cmds) {
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem(commandTreeWidget);
|
||||
item->setText(1, Action::commandMenuText(cmd));
|
||||
item->setToolTip(1, Action::commandToolTip(cmd));
|
||||
item->setData(1, Qt::UserRole, QByteArray(cmd->getName()));
|
||||
item->setSizeHint(0, QSize(32, 32));
|
||||
if (auto pixmap = cmd->getPixmap())
|
||||
item->setIcon(0, BitmapFactory().iconFromTheme(pixmap));
|
||||
item->setText(2, cmd->getShortcut());
|
||||
if (auto accel = cmd->getAccel())
|
||||
item->setText(3, QKeySequence(QString::fromLatin1(accel)).toString());
|
||||
|
||||
if (current == cmd->getName())
|
||||
currentItem = item;
|
||||
}
|
||||
if (currentItem)
|
||||
commandTreeWidget->setCurrentItem(currentItem);
|
||||
commandTreeWidget->resizeColumnToContents(2);
|
||||
commandTreeWidget->resizeColumnToContents(3);
|
||||
}
|
||||
|
||||
boost::signals2::connection
|
||||
DlgCustomKeyboardImp::initCommandList(QTreeWidget *commandTreeWidget, QComboBox *combo)
|
||||
DlgCustomKeyboardImp::initCommandList(QTreeWidget *commandTreeWidget,
|
||||
QTreeWidgetItem *separatorItem,
|
||||
QComboBox *combo)
|
||||
{
|
||||
QStringList labels;
|
||||
labels << tr("Icon") << tr("Command") << tr("Shortcut") << tr("Default");
|
||||
@@ -140,53 +182,25 @@ DlgCustomKeyboardImp::initCommandList(QTreeWidget *commandTreeWidget, QComboBox
|
||||
commandTreeWidget->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
||||
commandTreeWidget->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||
|
||||
QObject::connect(combo, QOverload<int>::of(&QComboBox::activated), [=](int index) {
|
||||
QByteArray current;
|
||||
if (auto item = commandTreeWidget->currentItem())
|
||||
current = item->data(1, Qt::UserRole).toByteArray();
|
||||
|
||||
commandTreeWidget->clear();
|
||||
CommandManager & cCmdMgr = Application::Instance->commandManager();
|
||||
auto group = combo->itemData(index, Qt::UserRole).toByteArray();
|
||||
auto cmds = group == "All" ? cCmdMgr.getAllCommands()
|
||||
: cCmdMgr.getGroupCommands(group.constData());
|
||||
QTreeWidgetItem *currentItem = nullptr;
|
||||
for (const Command *cmd : cmds) {
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem(commandTreeWidget);
|
||||
item->setText(1, Action::commandMenuText(cmd));
|
||||
item->setToolTip(1, Action::commandToolTip(cmd));
|
||||
item->setData(1, Qt::UserRole, QByteArray(cmd->getName()));
|
||||
item->setSizeHint(0, QSize(32, 32));
|
||||
if (auto pixmap = cmd->getPixmap())
|
||||
item->setIcon(0, BitmapFactory().iconFromTheme(pixmap));
|
||||
item->setText(2, cmd->getShortcut());
|
||||
if (auto accel = cmd->getAccel())
|
||||
item->setText(3, QKeySequence(QString::fromLatin1(accel)).toString());
|
||||
|
||||
if (current == cmd->getName())
|
||||
currentItem = item;
|
||||
}
|
||||
if (currentItem)
|
||||
commandTreeWidget->setCurrentItem(currentItem);
|
||||
commandTreeWidget->resizeColumnToContents(2);
|
||||
commandTreeWidget->resizeColumnToContents(3);
|
||||
});
|
||||
|
||||
QObject::connect(ShortcutManager::instance(), &ShortcutManager::shortcutChanged,
|
||||
combo, [combo]() { combo->activated(combo->currentIndex()); });
|
||||
|
||||
populateCommandGroups(combo);
|
||||
|
||||
// Using a timer to respond for command change for performance, and also
|
||||
// Using a timer to respond to command change for performance, and also
|
||||
// because macro command may be added before proper initialization (null
|
||||
// menu text, etc.)
|
||||
QTimer *timer = new QTimer(combo);
|
||||
timer->setSingleShot(true);
|
||||
QObject::connect(timer, &QTimer::timeout, [combo](){
|
||||
|
||||
QObject::connect(timer, &QTimer::timeout, [=](){
|
||||
populateCommandGroups(combo);
|
||||
combo->activated(combo->currentIndex());
|
||||
populateCommandList(commandTreeWidget, separatorItem, combo);
|
||||
});
|
||||
|
||||
QObject::connect(ShortcutManager::instance(), &ShortcutManager::shortcutChanged,
|
||||
[timer]() { timer->start(100); });
|
||||
|
||||
QObject::connect(combo, QOverload<int>::of(&QComboBox::activated),
|
||||
[timer]() { timer->start(100); });
|
||||
|
||||
return Application::Instance->commandManager().signalChanged.connect([timer](){
|
||||
timer->start(100);
|
||||
});
|
||||
@@ -239,6 +253,7 @@ void DlgCustomKeyboardImp::initPriorityList(QTreeWidget *priorityList,
|
||||
|
||||
boost::signals2::connection
|
||||
DlgCustomKeyboardImp::initCommandWidgets(QTreeWidget *commandTreeWidget,
|
||||
QTreeWidgetItem *separatorItem,
|
||||
QComboBox *comboGroups,
|
||||
QLineEdit *editCommand,
|
||||
QTreeWidget *priorityList,
|
||||
@@ -248,7 +263,7 @@ DlgCustomKeyboardImp::initCommandWidgets(QTreeWidget *commandTreeWidget,
|
||||
AccelLineEdit *currentShortcut)
|
||||
{
|
||||
initCommandCompleter(editCommand, comboGroups, commandTreeWidget);
|
||||
auto conn = initCommandList(commandTreeWidget, comboGroups);
|
||||
auto conn = initCommandList(commandTreeWidget, separatorItem, comboGroups);
|
||||
|
||||
if (priorityList && buttonUp && buttonDown) {
|
||||
initPriorityList(priorityList, buttonUp, buttonDown);
|
||||
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
/** Public helper function for handling command widgets
|
||||
*
|
||||
* @param commandTreeWidget: a tree widget listing commands
|
||||
* @param separatorItem: optional separator item
|
||||
* @param comboGroups: a combo box widget for choosing categories of commands
|
||||
* @param editCommand: a line edit for searching command with auto complete
|
||||
* @param priroityList: a tree widget listing commands with the same shortcut in order of priority
|
||||
@@ -74,6 +75,7 @@ public:
|
||||
*/
|
||||
static boost::signals2::connection
|
||||
initCommandWidgets(QTreeWidget *commandTreeWidget,
|
||||
QTreeWidgetItem *separatorItem,
|
||||
QComboBox *comboGroups,
|
||||
QLineEdit *editCommand,
|
||||
QTreeWidget *priorityList = nullptr,
|
||||
@@ -89,9 +91,10 @@ protected:
|
||||
*/
|
||||
//@{
|
||||
static void initCommandCompleter(QLineEdit *, QComboBox *combo, QTreeWidget *treeWidget);
|
||||
static boost::signals2::connection initCommandList(QTreeWidget *, QComboBox *combo);
|
||||
static boost::signals2::connection initCommandList(QTreeWidget *, QTreeWidgetItem *, QComboBox *combo);
|
||||
static void initPriorityList(QTreeWidget *, QAbstractButton *buttonUp, QAbstractButton *buttonDown);
|
||||
static void populateCommandGroups(QComboBox *);
|
||||
static void populateCommandList(QTreeWidget *, QTreeWidgetItem *, QComboBox *);
|
||||
static void populatePriorityList(QTreeWidget *priorityList,
|
||||
AccelLineEdit *editor,
|
||||
AccelLineEdit *current);
|
||||
|
||||
@@ -67,11 +67,16 @@ DlgCustomToolbars::DlgCustomToolbars(DlgCustomToolbars::Type t, QWidget* parent)
|
||||
ui->moveActionDownButton->setIcon(BitmapFactory().iconFromTheme("button_down"));
|
||||
ui->moveActionUpButton->setIcon(BitmapFactory().iconFromTheme("button_up"));
|
||||
|
||||
auto sepItem = new QTreeWidgetItem;
|
||||
sepItem->setText(1, tr("<Separator>"));
|
||||
sepItem->setData(1, Qt::UserRole, QByteArray("Separator"));
|
||||
sepItem->setSizeHint(0, QSize(32, 32));
|
||||
|
||||
conn = DlgCustomKeyboardImp::initCommandWidgets(ui->commandTreeWidget,
|
||||
sepItem,
|
||||
ui->categoryBox,
|
||||
ui->editCommand);
|
||||
|
||||
|
||||
// fills the combo box with all available workbenches
|
||||
QStringList workbenches = Application::Instance->workbenches();
|
||||
workbenches.sort();
|
||||
@@ -96,7 +101,6 @@ DlgCustomToolbars::DlgCustomToolbars(DlgCustomToolbars::Type t, QWidget* parent)
|
||||
ui->toolbarTreeWidget->setHeaderLabels(labels);
|
||||
ui->toolbarTreeWidget->header()->hide();
|
||||
|
||||
on_categoryBox_activated(ui->categoryBox->currentIndex());
|
||||
Workbench* w = WorkbenchManager::instance()->active();
|
||||
if (w) {
|
||||
QString name = QString::fromLatin1(w->name().c_str());
|
||||
@@ -148,13 +152,8 @@ void DlgCustomToolbars::hideEvent(QHideEvent * event)
|
||||
CustomizeActionPage::hideEvent(event);
|
||||
}
|
||||
|
||||
void DlgCustomToolbars::on_categoryBox_activated(int)
|
||||
void DlgCustomToolbars::onActivateCategoryBox()
|
||||
{
|
||||
QTreeWidgetItem* sepitem = new QTreeWidgetItem;
|
||||
sepitem->setText(1, tr("<Separator>"));
|
||||
sepitem->setData(1, Qt::UserRole, QByteArray("Separator"));
|
||||
sepitem->setSizeHint(0, QSize(32, 32));
|
||||
ui->commandTreeWidget->insertTopLevelItem(0, sepitem);
|
||||
}
|
||||
|
||||
void DlgCustomToolbars::on_workbenchBox_activated(int index)
|
||||
@@ -505,13 +504,14 @@ void DlgCustomToolbars::onModifyMacroAction(const QByteArray& macro)
|
||||
QTreeWidgetItem* item = toplevel->child(j);
|
||||
QByteArray command = item->data(0, Qt::UserRole).toByteArray();
|
||||
if (command == macro) {
|
||||
item->setText(0, QString::fromUtf8(pCmd->getMenuText()));
|
||||
item->setText(0, Action::commandMenuText(pCmd));
|
||||
item->setToolTip(0, Action::commandToolTip(pCmd));
|
||||
if (pCmd->getPixmap())
|
||||
item->setIcon(0, BitmapFactory().iconFromTheme(pCmd->getPixmap()));
|
||||
}
|
||||
}
|
||||
}
|
||||
on_categoryBox_activated(ui->categoryBox->currentIndex());
|
||||
ui->categoryBox->activated(ui->categoryBox->currentIndex());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,7 +530,7 @@ void DlgCustomToolbars::changeEvent(QEvent *e)
|
||||
ui->categoryBox->setItemText(i, text);
|
||||
}
|
||||
}
|
||||
on_categoryBox_activated(ui->categoryBox->currentIndex());
|
||||
ui->categoryBox->activated(ui->categoryBox->currentIndex());
|
||||
}
|
||||
else if (e->type() == QEvent::StyleChange)
|
||||
ui->categoryBox->activated(ui->categoryBox->currentIndex());
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "PropertyPage.h"
|
||||
#include <memory>
|
||||
|
||||
class QTreeWidgetItem;
|
||||
|
||||
namespace Gui {
|
||||
namespace Dialog {
|
||||
class Ui_DlgCustomToolbars;
|
||||
@@ -51,7 +53,6 @@ protected:
|
||||
~DlgCustomToolbars() override;
|
||||
|
||||
protected Q_SLOTS:
|
||||
void on_categoryBox_activated(int index);
|
||||
void on_workbenchBox_activated(int index);
|
||||
void on_moveActionRightButton_clicked();
|
||||
void on_moveActionLeftButton_clicked();
|
||||
@@ -74,6 +75,7 @@ protected:
|
||||
virtual void removeCustomCommand(const QString&, const QByteArray&);
|
||||
virtual void moveUpCustomCommand(const QString&, const QByteArray&);
|
||||
virtual void moveDownCustomCommand(const QString&, const QByteArray&);
|
||||
void onActivateCategoryBox();
|
||||
|
||||
private:
|
||||
void importCustomToolbars(const QByteArray&);
|
||||
|
||||
Reference in New Issue
Block a user