diff --git a/src/blackgui/components/hotkeydialog.cpp b/src/blackgui/components/hotkeydialog.cpp index 75a5494d0..1a246faa8 100644 --- a/src/blackgui/components/hotkeydialog.cpp +++ b/src/blackgui/components/hotkeydialog.cpp @@ -46,8 +46,7 @@ namespace BlackGui { namespace Components { - CKeySelectionBox::CKeySelectionBox(QWidget *parent) : - QComboBox(parent) + CKeySelectionBox::CKeySelectionBox(QWidget *parent) : CHorizontalComboBox(parent) { connect(this, static_cast(&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)); } } diff --git a/src/blackgui/components/hotkeydialog.h b/src/blackgui/components/hotkeydialog.h index ba9986628..011ae72d6 100644 --- a/src/blackgui/components/hotkeydialog.h +++ b/src/blackgui/components/hotkeydialog.h @@ -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 #include #include #include 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 diff --git a/src/blackgui/horizontalcombobox.cpp b/src/blackgui/horizontalcombobox.cpp new file mode 100644 index 000000000..db11045b2 --- /dev/null +++ b/src/blackgui/horizontalcombobox.cpp @@ -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()) + { + 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 diff --git a/src/blackgui/horizontalcombobox.h b/src/blackgui/horizontalcombobox.h new file mode 100644 index 000000000..68758ff96 --- /dev/null +++ b/src/blackgui/horizontalcombobox.h @@ -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 +#include + +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 diff --git a/src/blackgui/share/qss/stdwidget.qss b/src/blackgui/share/qss/stdwidget.qss index efc330459..ab68160ca 100644 --- a/src/blackgui/share/qss/stdwidget.qss +++ b/src/blackgui/share/qss/stdwidget.qss @@ -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;