mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
Ref T404, added horizontal combobox for hotkeys
This commit is contained in:
@@ -46,8 +46,7 @@ namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
CKeySelectionBox::CKeySelectionBox(QWidget *parent) :
|
||||
QComboBox(parent)
|
||||
CKeySelectionBox::CKeySelectionBox(QWidget *parent) : CHorizontalComboBox(parent)
|
||||
{
|
||||
connect(this, static_cast<void(CKeySelectionBox::*)(int)>(&CKeySelectionBox::currentIndexChanged), this, &CKeySelectionBox::updateSelectedIndex);
|
||||
}
|
||||
@@ -243,17 +242,17 @@ namespace BlackGui
|
||||
|
||||
void CHotkeyDialog::setupAdvancedFrame()
|
||||
{
|
||||
clearAdvancedFrame();
|
||||
auto allSupportedKeys = CKeyboardKeyList::allSupportedKeys();
|
||||
this->clearAdvancedFrame();
|
||||
const CKeyboardKeyList allSupportedKeys = CKeyboardKeyList::allSupportedKeys();
|
||||
|
||||
const QStringList splitKeys = m_actionHotkey.getCombination().toQString().split('+', QString::SkipEmptyParts);
|
||||
for (const auto &splitKey : splitKeys)
|
||||
for (const QString &splitKey : splitKeys)
|
||||
{
|
||||
if (splitKey == "+") continue;
|
||||
|
||||
int currentIndex = -1;
|
||||
CKeySelectionBox *ksb = new CKeySelectionBox(ui->qf_Advanced);
|
||||
for (const auto &supportedKey : allSupportedKeys)
|
||||
for (const CKeyboardKey &supportedKey : allSupportedKeys)
|
||||
{
|
||||
QString supportedKeyAsString = supportedKey.toQString();
|
||||
ksb->addItem(supportedKeyAsString, QVariant::fromValue(supportedKey));
|
||||
@@ -267,6 +266,9 @@ namespace BlackGui
|
||||
const int position = ui->qf_Advanced->layout()->count() - 1;
|
||||
ksb->setProperty("position", position);
|
||||
connect(ksb, &CKeySelectionBox::keySelectionChanged, this, &CHotkeyDialog::advancedKeyChanged);
|
||||
|
||||
const int width = qRound(1.5 * this->width());
|
||||
ksb->setPopupWidth(qMin(width, 600));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,18 +12,17 @@
|
||||
#ifndef BLACKGUI_COMPONENTS_HOTKEYDIALOG_H
|
||||
#define BLACKGUI_COMPONENTS_HOTKEYDIALOG_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/models/actionmodel.h"
|
||||
#include "blackgui/horizontalcombobox.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/identifierlist.h"
|
||||
#include "blackmisc/input/actionhotkey.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
|
||||
class QItemSelection;
|
||||
class QWidget;
|
||||
|
||||
namespace BlackCore { class CInputManager; }
|
||||
namespace BlackMisc { namespace Input { class CHotkeyCombination; } }
|
||||
@@ -35,7 +34,7 @@ namespace BlackGui
|
||||
/*!
|
||||
* ComboBox for selecting keyboard keys
|
||||
*/
|
||||
class BLACKGUI_EXPORT CKeySelectionBox : public QComboBox
|
||||
class BLACKGUI_EXPORT CKeySelectionBox : public CHorizontalComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
50
src/blackgui/horizontalcombobox.cpp
Normal file
50
src/blackgui/horizontalcombobox.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/* Copyright (C) 2014
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "horizontalcombobox.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
CHorizontalComboBox::CHorizontalComboBox(QWidget *parent) : QComboBox(parent)
|
||||
{
|
||||
m_view = new QListView(this);
|
||||
m_view->setFlow(QListView::LeftToRight);
|
||||
this->setView(m_view);
|
||||
for (QWidget *o : findChildren<QWidget *>())
|
||||
{
|
||||
if (o->inherits("QComboBoxPrivateContainer"))
|
||||
{
|
||||
//popup
|
||||
o->setFixedHeight(view()->height());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CHorizontalComboBox::showPopup()
|
||||
{
|
||||
QComboBox::showPopup();
|
||||
int w = m_popupWidth;
|
||||
if (w < 0)
|
||||
{
|
||||
w = 0;
|
||||
for (int i = 0; i < count(); i++)
|
||||
{
|
||||
const QModelIndex ix = model()->index(i, modelColumn(), rootModelIndex());
|
||||
w += view()->visualRect(ix).width();
|
||||
}
|
||||
}
|
||||
view()->setFixedWidth(w);
|
||||
}
|
||||
|
||||
void CHorizontalComboBox::setPopupWidth(int w)
|
||||
{
|
||||
m_popupWidth = w;
|
||||
}
|
||||
} // ns
|
||||
41
src/blackgui/horizontalcombobox.h
Normal file
41
src/blackgui/horizontalcombobox.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* Copyright (C) 2018
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_HORIZONTALCOMBOBOX_H
|
||||
#define BLACKGUI_HORIZONTALCOMBOBOX_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QListView>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
//! A combobox where the dropdown is horizontally and not vertically
|
||||
class CHorizontalComboBox : public QComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! ComboBox displaying the values horizontally
|
||||
explicit CHorizontalComboBox(QWidget *parent = nullptr);
|
||||
|
||||
//! \copydoc QComboBox::showPopup
|
||||
virtual void showPopup() override;
|
||||
|
||||
//! Width of the popup
|
||||
void setPopupWidth(int w);
|
||||
|
||||
private:
|
||||
QListView *m_view = nullptr;
|
||||
int m_popupWidth = -1;
|
||||
};
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
@@ -413,6 +413,12 @@ QComboBox QAbstractItemView {
|
||||
qproperty-textElideMode: ElideMiddle;
|
||||
}
|
||||
|
||||
/**
|
||||
QComboBox::drop-down { background-color: yellow; }
|
||||
QComboBox QListView { }
|
||||
**/
|
||||
|
||||
|
||||
QDoubleSpinBox {
|
||||
border: 1px solid green;
|
||||
border-radius: 5px;
|
||||
|
||||
Reference in New Issue
Block a user