Hotkey dialog style

This commit is contained in:
Klaus Basan
2018-11-13 22:49:18 +01:00
parent fe8548a5d4
commit b937f10992
4 changed files with 35 additions and 36 deletions

View File

@@ -46,23 +46,6 @@ namespace BlackGui
{ {
namespace Components namespace Components
{ {
CKeySelectionBox::CKeySelectionBox(QWidget *parent) : CHorizontalComboBox(parent)
{
connect(this, static_cast<void(CKeySelectionBox::*)(int)>(&CKeySelectionBox::currentIndexChanged), this, &CKeySelectionBox::updateSelectedIndex);
}
void CKeySelectionBox::setSelectedIndex(int index)
{
m_oldIndex = index;
setCurrentIndex(m_oldIndex);
}
void CKeySelectionBox::updateSelectedIndex(int index)
{
emit keySelectionChanged(m_oldIndex, index);
m_oldIndex = index;
}
CHotkeyDialog::CHotkeyDialog(const CActionHotkey &actionHotkey, const CIdentifierList &identifiers, QWidget *parent) : CHotkeyDialog::CHotkeyDialog(const CActionHotkey &actionHotkey, const CIdentifierList &identifiers, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::CHotkeyDialog), ui(new Ui::CHotkeyDialog),
@@ -74,8 +57,8 @@ namespace BlackGui
ui->setupUi(this); ui->setupUi(this);
ui->qf_Advanced->hide(); ui->qf_Advanced->hide();
ui->tv_Actions->setModel(&m_actionModel);
ui->pb_AdvancedMode->setIcon(CIcons::arrowMediumSouth16()); ui->pb_AdvancedMode->setIcon(CIcons::arrowMediumSouth16());
ui->tv_Actions->setModel(&m_actionModel);
selectAction(); selectAction();
if (!actionHotkey.getCombination().isEmpty()) { ui->pb_SelectedHotkey->setText(actionHotkey.getCombination().toQString()); } if (!actionHotkey.getCombination().isEmpty()) { ui->pb_SelectedHotkey->setText(actionHotkey.getCombination().toQString()); }
@@ -131,6 +114,23 @@ namespace BlackGui
CHotkeyDialog::~CHotkeyDialog() CHotkeyDialog::~CHotkeyDialog()
{ } { }
CKeySelectionBox::CKeySelectionBox(QWidget *parent) : CHorizontalComboBox(parent)
{
connect(this, static_cast<void(CKeySelectionBox::*)(int)>(&CKeySelectionBox::currentIndexChanged), this, &CKeySelectionBox::updateSelectedIndex);
}
void CKeySelectionBox::setSelectedIndex(int index)
{
m_oldIndex = index;
setCurrentIndex(m_oldIndex);
}
void CKeySelectionBox::updateSelectedIndex(int index)
{
emit keySelectionChanged(m_oldIndex, index);
m_oldIndex = index;
}
void CHotkeyDialog::initStyleSheet() void CHotkeyDialog::initStyleSheet()
{ {
if (!sGui) { return; } if (!sGui) { return; }
@@ -196,7 +196,7 @@ namespace BlackGui
void CHotkeyDialog::changeApplicableMachine(int index) void CHotkeyDialog::changeApplicableMachine(int index)
{ {
Q_UNUSED(index); Q_UNUSED(index);
QVariant userData = ui->cb_Identifier->currentData(); const QVariant userData = ui->cb_Identifier->currentData();
Q_ASSERT(userData.canConvert<CIdentifier>()); Q_ASSERT(userData.canConvert<CIdentifier>());
m_actionHotkey.setApplicableMachine(userData.value<CIdentifier>()); m_actionHotkey.setApplicableMachine(userData.value<CIdentifier>());
} }
@@ -299,16 +299,15 @@ namespace BlackGui
void CHotkeyDialog::selectAction() void CHotkeyDialog::selectAction()
{ {
if (m_actionHotkey.getAction().isEmpty()) return; if (m_actionHotkey.getAction().isEmpty()) { return; }
const QStringList tokens = m_actionHotkey.getAction().split("/", QString::SkipEmptyParts);
const auto tokens = m_actionHotkey.getAction().split("/", QString::SkipEmptyParts);
QModelIndex parentIndex = QModelIndex(); QModelIndex parentIndex = QModelIndex();
for (const auto &token : tokens) for (const QString &token : tokens)
{ {
const QModelIndex startIndex = m_actionModel.index(0, 0, parentIndex); const QModelIndex startIndex = m_actionModel.index(0, 0, parentIndex);
const auto indexList = m_actionModel.match(startIndex, Qt::DisplayRole, QVariant::fromValue(token)); const QModelIndexList indexList = m_actionModel.match(startIndex, Qt::DisplayRole, QVariant::fromValue(token));
if (indexList.isEmpty()) return; if (indexList.isEmpty()) { return; }
parentIndex = indexList.first(); parentIndex = indexList.first();
ui->tv_Actions->expand(parentIndex); ui->tv_Actions->expand(parentIndex);
} }

View File

@@ -105,7 +105,7 @@ namespace BlackGui
QScopedPointer<Ui::CHotkeyDialog> ui; QScopedPointer<Ui::CHotkeyDialog> ui;
BlackMisc::Input::CActionHotkey m_actionHotkey; BlackMisc::Input::CActionHotkey m_actionHotkey;
BlackGui::Models::CActionModel m_actionModel; BlackGui::Models::CActionModel m_actionModel;
}; };
} // ns } // ns
} // ns } // ns

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>269</width> <width>290</width>
<height>384</height> <height>430</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -136,6 +136,13 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="3" column="1">
<widget class="QPushButton" name="pb_Accept">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
<item row="3" column="0"> <item row="3" column="0">
<spacer name="hs_Dialog"> <spacer name="hs_Dialog">
<property name="orientation"> <property name="orientation">
@@ -149,13 +156,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="3" column="1">
<widget class="QPushButton" name="pb_Accept">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
<item row="3" column="2"> <item row="3" column="2">
<widget class="QPushButton" name="pb_Cancel"> <widget class="QPushButton" name="pb_Cancel">
<property name="text"> <property name="text">

View File

@@ -46,7 +46,7 @@ namespace BlackGui
CActionModel(QObject *parent = nullptr); CActionModel(QObject *parent = nullptr);
//! Destructor //! Destructor
virtual ~CActionModel(); virtual ~CActionModel() override;
//! \copydoc QAbstractItemModel::data //! \copydoc QAbstractItemModel::data
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;