mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
refactor: Remove non-standard horizontal combobox
This commit is contained in:
@@ -616,8 +616,6 @@ add_library(gui SHARED
|
||||
guiapplication.h
|
||||
guiutility.cpp
|
||||
guiutility.h
|
||||
horizontalcombobox.cpp
|
||||
horizontalcombobox.h
|
||||
infoarea.cpp
|
||||
infoarea.h
|
||||
labelandicon.cpp
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace swift::gui::components
|
||||
|
||||
CHotkeyDialog::~CHotkeyDialog() {}
|
||||
|
||||
CKeySelectionBox::CKeySelectionBox(QWidget *parent) : CHorizontalComboBox(parent)
|
||||
CKeySelectionBox::CKeySelectionBox(QWidget *parent) : QComboBox(parent)
|
||||
{
|
||||
connect(this, qOverload<int>(&CKeySelectionBox::currentIndexChanged), this,
|
||||
&CKeySelectionBox::updateSelectedIndex);
|
||||
@@ -199,7 +199,6 @@ namespace swift::gui::components
|
||||
const CKeyboardKey &keyboardKey)
|
||||
{
|
||||
int currentIndex = 0;
|
||||
const int width = qRound(1.5 * this->width());
|
||||
const bool select = !keyboardKey.isUnknown();
|
||||
|
||||
CKeySelectionBox *ksb = new CKeySelectionBox(ui->qf_Advanced);
|
||||
@@ -211,7 +210,6 @@ namespace swift::gui::components
|
||||
}
|
||||
|
||||
ksb->setSelectedIndex(currentIndex);
|
||||
ksb->setPopupWidth(qMin(width, 600));
|
||||
ksb->addItem(noKeyButton(), QVariant::fromValue(CKeyboardKey())); // at back (easier to find it is there twice)
|
||||
|
||||
ui->qf_Advanced->layout()->addWidget(ksb);
|
||||
@@ -226,7 +224,6 @@ namespace swift::gui::components
|
||||
const CJoystickButton &joystickButton)
|
||||
{
|
||||
int currentIndex = -1;
|
||||
const int width = qRound(1.5 * this->width());
|
||||
|
||||
CKeySelectionBox *ksb = new CKeySelectionBox(ui->qf_Advanced);
|
||||
ksb->addItem(noKeyButton(), QVariant::fromValue(CJoystickButton())); // at front
|
||||
@@ -241,7 +238,6 @@ namespace swift::gui::components
|
||||
}
|
||||
|
||||
ksb->setSelectedIndex(currentIndex);
|
||||
ksb->setPopupWidth(qMin(width, 600));
|
||||
ksb->addItem(noKeyButton(),
|
||||
QVariant::fromValue(CJoystickButton())); // at back (easier to find it is there twice)
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
|
||||
#include "gui/horizontalcombobox.h"
|
||||
#include "gui/models/actionmodel.h"
|
||||
#include "gui/swiftguiexport.h"
|
||||
#include "misc/identifierlist.h"
|
||||
@@ -36,7 +35,7 @@ namespace swift::gui::components
|
||||
/*!
|
||||
* ComboBox for selecting keyboard keys
|
||||
*/
|
||||
class SWIFT_GUI_EXPORT CKeySelectionBox : public CHorizontalComboBox
|
||||
class SWIFT_GUI_EXPORT CKeySelectionBox : public QComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
#include "horizontalcombobox.h"
|
||||
|
||||
namespace swift::gui
|
||||
{
|
||||
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; }
|
||||
} // namespace swift::gui
|
||||
@@ -1,35 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef SWIFT_GUI_HORIZONTALCOMBOBOX_H
|
||||
#define SWIFT_GUI_HORIZONTALCOMBOBOX_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QListView>
|
||||
|
||||
namespace swift::gui
|
||||
{
|
||||
//! 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;
|
||||
};
|
||||
} // namespace swift::gui
|
||||
|
||||
#endif // SWIFT_GUI_HORIZONTALCOMBOBOX_H
|
||||
Reference in New Issue
Block a user