From 07c90bed08f9c7428e631b250f9159ed23aa0bc4 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 30 May 2017 23:08:14 -0700 Subject: [PATCH 1/4] DolphinQt2: add QtUtils/ElidedButton --- Source/Core/DolphinQt2/CMakeLists.txt | 1 + Source/Core/DolphinQt2/DolphinQt2.vcxproj | 3 +- .../DolphinQt2/DolphinQt2.vcxproj.filters | 8 +++- .../Core/DolphinQt2/QtUtils/ElidedButton.cpp | 40 +++++++++++++++++++ Source/Core/DolphinQt2/QtUtils/ElidedButton.h | 20 ++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 Source/Core/DolphinQt2/QtUtils/ElidedButton.cpp create mode 100644 Source/Core/DolphinQt2/QtUtils/ElidedButton.h 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/DolphinQt2.vcxproj b/Source/Core/DolphinQt2/DolphinQt2.vcxproj index e0cd0e09b3..f807140e73 100644 --- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj +++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj @@ -157,6 +157,7 @@ + @@ -257,4 +258,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; +}; From b378ffb4ecafbdfd646f7b201f9df3da5984256b Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 30 May 2017 23:08:54 -0700 Subject: [PATCH 2/4] MappingButton: don't set text twice in constructor --- Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp index 12c1b939fc..017861d636 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp @@ -19,7 +19,6 @@ MappingButton::MappingButton(MappingWidget* widget, ControlReference* ref) : QPushButton(QString::fromStdString(ref->expression)), m_parent(widget), m_reference(ref) { - setText(QString::fromStdString(m_reference->expression)); Connect(); } From 046c6f468f6b34bfcc6bb56f21af14fe1bf61fd4 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 30 May 2017 23:09:43 -0700 Subject: [PATCH 3/4] MappingButton: derive from ElidedButton --- Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp | 2 +- Source/Core/DolphinQt2/Config/Mapping/MappingButton.h | 5 +++-- Source/Core/DolphinQt2/Config/Mapping/MappingWidget.cpp | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp index 017861d636..dcb92e6072 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp @@ -17,7 +17,7 @@ #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) { Connect(); } diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h index 304389297e..caaa9ad75f 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h @@ -5,15 +5,16 @@ #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); From 87a74ca3ae3829e86ad53b4078a090c962c97f7c Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 30 May 2017 23:10:46 -0700 Subject: [PATCH 4/4] MappingButton: remove unused includes --- Source/Core/DolphinQt2/Config/Mapping/MappingButton.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h index caaa9ad75f..27249c0685 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h @@ -4,9 +4,6 @@ #pragma once -#include -#include - #include "DolphinQt2/QtUtils/ElidedButton.h" class ControlReference;