forked from qt-creator/qt-creator
Macros: Inline macrooptionswidget.ui
Change-Id: Ib35fd2816b7da5d2720f09ca89903549c7d3e66f Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "macrooptionswidget.h"
|
||||
#include "ui_macrooptionswidget.h"
|
||||
|
||||
#include "macrosconstants.h"
|
||||
#include "macromanager.h"
|
||||
#include "macro.h"
|
||||
@@ -34,48 +34,77 @@
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QGroupBox>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QTreeWidget>
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
namespace {
|
||||
int NAME_ROLE = Qt::UserRole;
|
||||
int WRITE_ROLE = Qt::UserRole+1;
|
||||
}
|
||||
namespace Macros::Internal {
|
||||
|
||||
using namespace Macros;
|
||||
using namespace Macros::Internal;
|
||||
const int NAME_ROLE = Qt::UserRole;
|
||||
const int WRITE_ROLE = Qt::UserRole + 1;
|
||||
|
||||
|
||||
MacroOptionsWidget::MacroOptionsWidget() :
|
||||
m_ui(new Ui::MacroOptionsWidget)
|
||||
MacroOptionsWidget::MacroOptionsWidget()
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_treeWidget = new QTreeWidget;
|
||||
m_treeWidget->setTextElideMode(Qt::ElideLeft);
|
||||
m_treeWidget->setUniformRowHeights(true);
|
||||
m_treeWidget->setSortingEnabled(true);
|
||||
m_treeWidget->setColumnCount(3);
|
||||
m_treeWidget->header()->setSortIndicatorShown(true);
|
||||
m_treeWidget->header()->setStretchLastSection(true);
|
||||
m_treeWidget->header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||
m_treeWidget->setHeaderLabels({tr("Name"), tr("Description)"), tr("Shortcut")});
|
||||
|
||||
connect(m_ui->treeWidget, &QTreeWidget::currentItemChanged,
|
||||
m_description = new QLineEdit;
|
||||
|
||||
m_removeButton = new QPushButton(tr("Remove"));
|
||||
|
||||
m_macroGroup = new QGroupBox(tr("Macro"), this);
|
||||
|
||||
using namespace Utils::Layouting;
|
||||
|
||||
Row {
|
||||
tr("Description:"), m_description
|
||||
}.attachTo(m_macroGroup);
|
||||
|
||||
Column {
|
||||
Group {
|
||||
Title(tr("Preferences")),
|
||||
Row {
|
||||
m_treeWidget,
|
||||
Column { m_removeButton, Stretch() },
|
||||
}
|
||||
},
|
||||
m_macroGroup
|
||||
}.attachTo(this);
|
||||
|
||||
connect(m_treeWidget, &QTreeWidget::currentItemChanged,
|
||||
this, &MacroOptionsWidget::changeCurrentItem);
|
||||
connect(m_ui->removeButton, &QPushButton::clicked,
|
||||
connect(m_removeButton, &QPushButton::clicked,
|
||||
this, &MacroOptionsWidget::remove);
|
||||
connect(m_ui->description, &QLineEdit::textChanged,
|
||||
connect(m_description, &QLineEdit::textChanged,
|
||||
this, &MacroOptionsWidget::changeDescription);
|
||||
|
||||
m_ui->treeWidget->header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
MacroOptionsWidget::~MacroOptionsWidget()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
MacroOptionsWidget::~MacroOptionsWidget() = default;
|
||||
|
||||
void MacroOptionsWidget::initialize()
|
||||
{
|
||||
m_macroToRemove.clear();
|
||||
m_macroToChange.clear();
|
||||
m_ui->treeWidget->clear();
|
||||
m_treeWidget->clear();
|
||||
changeCurrentItem(nullptr);
|
||||
|
||||
// Create the treeview
|
||||
createTable();
|
||||
@@ -88,7 +117,7 @@ void MacroOptionsWidget::createTable()
|
||||
for (Macro *macro : MacroManager::macros()) {
|
||||
QFileInfo fileInfo(macro->fileName());
|
||||
if (fileInfo.absoluteDir() == dir.absolutePath()) {
|
||||
auto macroItem = new QTreeWidgetItem(m_ui->treeWidget);
|
||||
auto macroItem = new QTreeWidgetItem(m_treeWidget);
|
||||
macroItem->setText(0, macro->displayName());
|
||||
macroItem->setText(1, macro->description());
|
||||
macroItem->setData(0, NAME_ROLE, macro->displayName());
|
||||
@@ -107,22 +136,20 @@ void MacroOptionsWidget::createTable()
|
||||
void MacroOptionsWidget::changeCurrentItem(QTreeWidgetItem *current)
|
||||
{
|
||||
m_changingCurrent = true;
|
||||
m_removeButton->setEnabled(current);
|
||||
m_macroGroup->setEnabled(current);
|
||||
if (!current) {
|
||||
m_ui->removeButton->setEnabled(false);
|
||||
m_ui->description->clear();
|
||||
m_ui->macroGroup->setEnabled(false);
|
||||
m_description->clear();
|
||||
} else {
|
||||
m_ui->removeButton->setEnabled(true);
|
||||
m_ui->description->setText(current->text(1));
|
||||
m_ui->description->setEnabled(current->data(0, WRITE_ROLE).toBool());
|
||||
m_ui->macroGroup->setEnabled(true);
|
||||
m_description->setText(current->text(1));
|
||||
m_description->setEnabled(current->data(0, WRITE_ROLE).toBool());
|
||||
}
|
||||
m_changingCurrent = false;
|
||||
}
|
||||
|
||||
void MacroOptionsWidget::remove()
|
||||
{
|
||||
QTreeWidgetItem *current = m_ui->treeWidget->currentItem();
|
||||
QTreeWidgetItem *current = m_treeWidget->currentItem();
|
||||
m_macroToRemove.append(current->data(0, NAME_ROLE).toString());
|
||||
delete current;
|
||||
}
|
||||
@@ -145,7 +172,7 @@ void MacroOptionsWidget::apply()
|
||||
|
||||
void MacroOptionsWidget::changeDescription(const QString &description)
|
||||
{
|
||||
QTreeWidgetItem *current = m_ui->treeWidget->currentItem();
|
||||
QTreeWidgetItem *current = m_treeWidget->currentItem();
|
||||
if (m_changingCurrent || !current)
|
||||
return;
|
||||
|
||||
@@ -156,3 +183,5 @@ void MacroOptionsWidget::changeDescription(const QString &description)
|
||||
font.setItalic(true);
|
||||
current->setFont(1, font);
|
||||
}
|
||||
|
||||
} // Macros::Internal
|
||||
|
||||
Reference in New Issue
Block a user