#include <QWidget>
#include <QLayout>
#include <QList>
+#include <QMap>
#include <QToolButton>
#include <QLineEdit>
#include <QPushButton>
#include <QBrush>
#include <QColor>
+#include <QHeaderView>
#include <QKeyEvent>
#include <QKeySequence>
setSelectionMode(QAbstractItemView::SingleSelection);
setColumnWidth(0, COLUMN_SIZE);
setSortingEnabled(false); // Items are sorted in the same way, as in ShortcutContainer.
- headerItem()->setHidden(true);
+ header()->setSectionResizeMode(QHeaderView::Interactive);
+ {
+ QMap<int, QString> labelMap;
+ labelMap[QtxShortcutTree::ElementIdx::Name] = tr("Action");
+ labelMap[QtxShortcutTree::ElementIdx::KeySequence] = tr("Key sequence");
+ setHeaderLabels(labelMap.values());
+ }
setExpandsOnDoubleClick(false); // Open shortcut editor on double click instead.
setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
- setToolTip(tr("Double click to edit key sequence."));
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
myEditDialog = new QtxEditKeySequenceDialog(this);
{
auto item = new QtxShortcutTreeItem(theModuleID, QString());
- QFont font = item->font(ElementIdx::Name);
+ QFont font = item->font(QtxShortcutTree::ElementIdx::Name);
font.setBold(true);
- item->setFont(ElementIdx::Name, font);
+ item->setFont(QtxShortcutTree::ElementIdx::Name, font);
return item;
}
return nullptr;
}
- return new QtxShortcutTreeItem(theModuleID, theInModuleActionID);
+ auto item = new QtxShortcutTreeItem(theModuleID, theInModuleActionID);
+ item->setToolTip(QtxShortcutTree::ElementIdx::KeySequence, QtxShortcutTree::tr("Double click to edit key sequence."));
+ return item;
}
bool QtxShortcutTreeItem::isFolder() const
static const QBrush fgHighlitingBrush = QBrush(Qt::white);
static const QBrush noBrush = QBrush();
- setBackground(ElementIdx::KeySequence, theHighlight ? bgHighlitingBrush : noBrush);
- setForeground(ElementIdx::KeySequence, theHighlight ? fgHighlitingBrush : noBrush);
+ setBackground(QtxShortcutTree::ElementIdx::KeySequence, theHighlight ? bgHighlitingBrush : noBrush);
+ setForeground(QtxShortcutTree::ElementIdx::KeySequence, theHighlight ? fgHighlitingBrush : noBrush);
}
void QtxShortcutTreeItem::setName(const QString& theName)
{
- setText(ElementIdx::Name, theName);
+ const QString& name = theName.isEmpty() ? myInModuleActionID : theName;
+ setText(QtxShortcutTree::ElementIdx::Name, name);
+ if (!isFolder())
+ setToolTip(QtxShortcutTree::ElementIdx::Name, name + (name.at(name.length()-1) == "." ? "\n" : ".\n") + QtxShortcutTree::tr("Double click to edit key sequence."));
}
QString QtxShortcutTreeItem::name() const
{
- return text(ElementIdx::Name);
+ return text(QtxShortcutTree::ElementIdx::Name);
}
void QtxShortcutTreeItem::setKeySequence(const QString& theKeySequence)
{
- setText(ElementIdx::KeySequence, theKeySequence);
+ setText(QtxShortcutTree::ElementIdx::KeySequence, theKeySequence);
}
QString QtxShortcutTreeItem::keySequence() const
{
- return text(ElementIdx::KeySequence);
+ return text(QtxShortcutTree::ElementIdx::KeySequence);
}
\ No newline at end of file
Q_OBJECT
public:
+ enum ElementIdx {
+ Name = 0,
+ KeySequence = 1, // Empty, if item is used as folder.
+ };
+
QtxShortcutTree(
std::shared_ptr<SUIT_ShortcutContainer> theContainer = std::shared_ptr<SUIT_ShortcutContainer>(),
QWidget* theParent = nullptr
private:
QtxShortcutTreeItem(const QString& theModuleID, const QString& theInModuleActionID);
- enum ElementIdx {
- Name = 0,
- KeySequence = 1, // Empty, if item is used as folder.
- };
-
public:
static QtxShortcutTreeItem* createFolderItem(const QString& theModuleID);
static QtxShortcutTreeItem* createShortcutItem(const QString& theModuleID, const QString& theInModuleActionID);