diff --git a/Source/Core/DolphinQt2/CMakeLists.txt b/Source/Core/DolphinQt2/CMakeLists.txt index faf8b468f5..e9886ea4e0 100644 --- a/Source/Core/DolphinQt2/CMakeLists.txt +++ b/Source/Core/DolphinQt2/CMakeLists.txt @@ -39,6 +39,7 @@ set(SRCS GameList/GameListModel.cpp GameList/GameTracker.cpp GameList/ListProxyModel.cpp + QtUtils/ElidedButton.cpp Settings/GeneralPane.cpp Settings/InterfacePane.cpp ) diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp index 12c1b939fc..dcb92e6072 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp @@ -17,9 +17,8 @@ #include "InputCommon/ControllerInterface/ControllerInterface.h" MappingButton::MappingButton(MappingWidget* widget, ControlReference* ref) - : QPushButton(QString::fromStdString(ref->expression)), m_parent(widget), m_reference(ref) + : ElidedButton(QString::fromStdString(ref->expression)), m_parent(widget), m_reference(ref) { - setText(QString::fromStdString(m_reference->expression)); Connect(); } diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h index 304389297e..27249c0685 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h @@ -4,16 +4,14 @@ #pragma once -#include -#include -#include +#include "DolphinQt2/QtUtils/ElidedButton.h" class ControlReference; class MappingWidget; class QEvent; class QMouseEvent; -class MappingButton : public QPushButton +class MappingButton : public ElidedButton { public: MappingButton(MappingWidget* widget, ControlReference* ref); diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.cpp b/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.cpp index 6daa56dfdd..bb711f3058 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.cpp +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingWidget.cpp @@ -49,6 +49,7 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con for (auto& control : group->controls) { auto* button = new MappingButton(this, control->control_ref.get()); + button->setMinimumWidth(125); button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); form_layout->addRow(QString::fromStdString(control->name), button); m_buttons.push_back(button); diff --git a/Source/Core/DolphinQt2/DolphinQt2.vcxproj b/Source/Core/DolphinQt2/DolphinQt2.vcxproj index cf67948adb..888b126218 100644 --- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj +++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj @@ -154,6 +154,7 @@ + @@ -254,4 +255,4 @@ - \ No newline at end of file + diff --git a/Source/Core/DolphinQt2/DolphinQt2.vcxproj.filters b/Source/Core/DolphinQt2/DolphinQt2.vcxproj.filters index 0a4627d729..5e25b8b58f 100644 --- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj.filters +++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj.filters @@ -116,6 +116,9 @@ + + QtUtils + @@ -177,6 +180,9 @@ {42f8a963-563e-420d-8aca-5761657dcff5} + + {fb4b5691-df66-4984-af40-fcc2b37f3622} + {d2a31121-7903-4a66-9b42-9358e92d36ff} @@ -184,4 +190,4 @@ - \ No newline at end of file + diff --git a/Source/Core/DolphinQt2/QtUtils/ElidedButton.cpp b/Source/Core/DolphinQt2/QtUtils/ElidedButton.cpp new file mode 100644 index 0000000000..309c4b5d29 --- /dev/null +++ b/Source/Core/DolphinQt2/QtUtils/ElidedButton.cpp @@ -0,0 +1,40 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "DolphinQt2/QtUtils/ElidedButton.h" + +#include +#include +#include + +ElidedButton::ElidedButton(const QString& text, Qt::TextElideMode elide_mode) + : QPushButton(text, nullptr), m_elide_mode{elide_mode} +{ +} + +Qt::TextElideMode ElidedButton::elideMode() const +{ + return m_elide_mode; +} + +void ElidedButton::setElideMode(Qt::TextElideMode elide_mode) +{ + if (elide_mode == m_elide_mode) + return; + + m_elide_mode = elide_mode; + repaint(); +} + +void ElidedButton::paintEvent(QPaintEvent* event) +{ + QStyleOptionButton option; + initStyleOption(&option); + + option.text = fontMetrics().elidedText( + text(), m_elide_mode, + style()->subElementRect(QStyle::SE_PushButtonContents, &option, this).width()); + + QStylePainter{this}.drawControl(QStyle::CE_PushButton, option); +} diff --git a/Source/Core/DolphinQt2/QtUtils/ElidedButton.h b/Source/Core/DolphinQt2/QtUtils/ElidedButton.h new file mode 100644 index 0000000000..bce6593f8d --- /dev/null +++ b/Source/Core/DolphinQt2/QtUtils/ElidedButton.h @@ -0,0 +1,20 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +class ElidedButton : public QPushButton +{ +public: + ElidedButton(const QString& text = QStringLiteral(""), + Qt::TextElideMode elide_mode = Qt::ElideRight); + Qt::TextElideMode elideMode() const; + void setElideMode(Qt::TextElideMode elide_mode); + +private: + void paintEvent(QPaintEvent* event); + Qt::TextElideMode m_elide_mode; +};