mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-28 00:35:34 +00:00
DolphinQt: Add generic tooltip controls
This commit is contained in:
parent
613d8b1cba
commit
af0161cafd
@ -171,6 +171,17 @@ add_executable(dolphin-emu
|
||||
Config/PropertiesDialog.h
|
||||
Config/SettingsWindow.cpp
|
||||
Config/SettingsWindow.h
|
||||
Config/ToolTipControls/ToolTipCheckBox.cpp
|
||||
Config/ToolTipControls/ToolTipCheckBox.h
|
||||
Config/ToolTipControls/ToolTipComboBox.cpp
|
||||
Config/ToolTipControls/ToolTipComboBox.h
|
||||
Config/ToolTipControls/ToolTipRadioButton.cpp
|
||||
Config/ToolTipControls/ToolTipRadioButton.h
|
||||
Config/ToolTipControls/ToolTipSlider.cpp
|
||||
Config/ToolTipControls/ToolTipSlider.h
|
||||
Config/ToolTipControls/ToolTipSpinBox.cpp
|
||||
Config/ToolTipControls/ToolTipSpinBox.h
|
||||
Config/ToolTipControls/ToolTipWidget.h
|
||||
Config/VerifyWidget.cpp
|
||||
Config/VerifyWidget.h
|
||||
Debugger/BreakpointWidget.cpp
|
||||
|
@ -0,0 +1,27 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt/Config/ToolTipControls/ToolTipCheckBox.h"
|
||||
|
||||
#include <QStyle>
|
||||
#include <QStyleOption>
|
||||
|
||||
ToolTipCheckBox::ToolTipCheckBox(const QString& label) : ToolTipWidget(label)
|
||||
{
|
||||
SetTitle(label);
|
||||
}
|
||||
|
||||
QPoint ToolTipCheckBox::GetToolTipPosition() const
|
||||
{
|
||||
int checkbox_width = 18;
|
||||
if (style())
|
||||
{
|
||||
QStyleOptionButton opt;
|
||||
initStyleOption(&opt);
|
||||
checkbox_width =
|
||||
style()->subElementRect(QStyle::SubElement::SE_CheckBoxIndicator, &opt, this).width();
|
||||
}
|
||||
|
||||
return pos() + QPoint(checkbox_width / 2, height() / 2);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DolphinQt/Config/ToolTipControls/ToolTipWidget.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
|
||||
class ToolTipCheckBox : public ToolTipWidget<QCheckBox>
|
||||
{
|
||||
public:
|
||||
explicit ToolTipCheckBox(const QString& label);
|
||||
|
||||
private:
|
||||
QPoint GetToolTipPosition() const override;
|
||||
};
|
@ -0,0 +1,10 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt/Config/ToolTipControls/ToolTipComboBox.h"
|
||||
|
||||
QPoint ToolTipComboBox::GetToolTipPosition() const
|
||||
{
|
||||
return pos() + QPoint(width() / 2, height() / 2);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DolphinQt/Config/ToolTipControls/ToolTipWidget.h"
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
class ToolTipComboBox : public ToolTipWidget<QComboBox>
|
||||
{
|
||||
private:
|
||||
QPoint GetToolTipPosition() const override;
|
||||
};
|
@ -0,0 +1,27 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt/Config/ToolTipControls/ToolTipRadioButton.h"
|
||||
|
||||
#include <QStyle>
|
||||
#include <QStyleOption>
|
||||
|
||||
ToolTipRadioButton::ToolTipRadioButton(const QString& label) : ToolTipWidget(label)
|
||||
{
|
||||
SetTitle(label);
|
||||
}
|
||||
|
||||
QPoint ToolTipRadioButton::GetToolTipPosition() const
|
||||
{
|
||||
int radio_button_width = 18;
|
||||
if (style())
|
||||
{
|
||||
QStyleOptionButton opt;
|
||||
initStyleOption(&opt);
|
||||
radio_button_width =
|
||||
style()->subElementRect(QStyle::SubElement::SE_RadioButtonIndicator, &opt, this).width();
|
||||
}
|
||||
|
||||
return pos() + QPoint(radio_button_width / 2, height() / 2);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DolphinQt/Config/ToolTipControls/ToolTipWidget.h"
|
||||
|
||||
#include <QRadioButton>
|
||||
|
||||
class ToolTipRadioButton : public ToolTipWidget<QRadioButton>
|
||||
{
|
||||
public:
|
||||
explicit ToolTipRadioButton(const QString& label);
|
||||
|
||||
private:
|
||||
QPoint GetToolTipPosition() const override;
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt/Config/ToolTipControls/ToolTipSlider.h"
|
||||
|
||||
#include <QStyle>
|
||||
#include <QStyleOption>
|
||||
|
||||
ToolTipSlider::ToolTipSlider(Qt::Orientation orientation) : ToolTipWidget(orientation)
|
||||
{
|
||||
}
|
||||
|
||||
QPoint ToolTipSlider::GetToolTipPosition() const
|
||||
{
|
||||
QRect handle_rect(0, 0, 15, 15);
|
||||
if (style())
|
||||
{
|
||||
QStyleOptionSlider opt;
|
||||
initStyleOption(&opt);
|
||||
handle_rect = style()->subControlRect(QStyle::ComplexControl::CC_Slider, &opt,
|
||||
QStyle::SubControl::SC_SliderHandle, this);
|
||||
}
|
||||
|
||||
return pos() + handle_rect.center();
|
||||
}
|
18
Source/Core/DolphinQt/Config/ToolTipControls/ToolTipSlider.h
Normal file
18
Source/Core/DolphinQt/Config/ToolTipControls/ToolTipSlider.h
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DolphinQt/Config/ToolTipControls/ToolTipWidget.h"
|
||||
|
||||
#include <QSlider>
|
||||
|
||||
class ToolTipSlider : public ToolTipWidget<QSlider>
|
||||
{
|
||||
public:
|
||||
explicit ToolTipSlider(Qt::Orientation orientation);
|
||||
|
||||
private:
|
||||
QPoint GetToolTipPosition() const override;
|
||||
};
|
@ -0,0 +1,10 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt/Config/ToolTipControls/ToolTipSpinBox.h"
|
||||
|
||||
QPoint ToolTipSpinBox::GetToolTipPosition() const
|
||||
{
|
||||
return pos() + QPoint(width() / 2, height() / 2);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DolphinQt/Config/ToolTipControls/ToolTipWidget.h"
|
||||
|
||||
#include <QSpinBox>
|
||||
|
||||
class ToolTipSpinBox : public ToolTipWidget<QSpinBox>
|
||||
{
|
||||
private:
|
||||
QPoint GetToolTipPosition() const override;
|
||||
};
|
55
Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h
Normal file
55
Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright 2020 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "DolphinQt/Config/Graphics/BalloonTip.h"
|
||||
|
||||
template <class Derived>
|
||||
class ToolTipWidget : public Derived
|
||||
{
|
||||
public:
|
||||
using Derived::Derived;
|
||||
|
||||
void SetTitle(QString title) { m_title = std::move(title); }
|
||||
|
||||
void SetDescription(QString description) { m_description = std::move(description); }
|
||||
|
||||
private:
|
||||
void enterEvent(QEvent* event) override
|
||||
{
|
||||
if (m_timer_id)
|
||||
return;
|
||||
m_timer_id = this->startTimer(300);
|
||||
}
|
||||
|
||||
void leaveEvent(QEvent* event) override
|
||||
{
|
||||
if (m_timer_id)
|
||||
{
|
||||
this->killTimer(*m_timer_id);
|
||||
m_timer_id.reset();
|
||||
}
|
||||
BalloonTip::HideBalloon();
|
||||
}
|
||||
|
||||
void timerEvent(QTimerEvent* event) override
|
||||
{
|
||||
this->killTimer(*m_timer_id);
|
||||
m_timer_id.reset();
|
||||
|
||||
BalloonTip::ShowBalloon(QIcon(), m_title, m_description,
|
||||
this->parentWidget()->mapToGlobal(GetToolTipPosition()), this);
|
||||
}
|
||||
|
||||
virtual QPoint GetToolTipPosition() const = 0;
|
||||
|
||||
std::optional<int> m_timer_id;
|
||||
QString m_title;
|
||||
QString m_description;
|
||||
};
|
@ -105,6 +105,11 @@
|
||||
<ClCompile Include="Config\PatchesWidget.cpp" />
|
||||
<ClCompile Include="Config\PropertiesDialog.cpp" />
|
||||
<ClCompile Include="Config\SettingsWindow.cpp" />
|
||||
<ClCompile Include="Config\ToolTipControls\ToolTipCheckBox.cpp" />
|
||||
<ClCompile Include="Config\ToolTipControls\ToolTipComboBox.cpp" />
|
||||
<ClCompile Include="Config\ToolTipControls\ToolTipRadioButton.cpp" />
|
||||
<ClCompile Include="Config\ToolTipControls\ToolTipSlider.cpp" />
|
||||
<ClCompile Include="Config\ToolTipControls\ToolTipSpinBox.cpp" />
|
||||
<ClCompile Include="Config\VerifyWidget.cpp" />
|
||||
<ClCompile Include="ConvertDialog.cpp" />
|
||||
<ClCompile Include="Debugger\BreakpointWidget.cpp" />
|
||||
@ -263,6 +268,12 @@
|
||||
<QtMoc Include="Config\Mapping\WiimoteEmuMotionControlIMU.h" />
|
||||
<QtMoc Include="Config\PropertiesDialog.h" />
|
||||
<QtMoc Include="Config\SettingsWindow.h" />
|
||||
<ClInclude Include="Config\ToolTipControls\ToolTipCheckBox.h" />
|
||||
<ClInclude Include="Config\ToolTipControls\ToolTipComboBox.h" />
|
||||
<ClInclude Include="Config\ToolTipControls\ToolTipRadioButton.h" />
|
||||
<ClInclude Include="Config\ToolTipControls\ToolTipSlider.h" />
|
||||
<ClInclude Include="Config\ToolTipControls\ToolTipSpinBox.h" />
|
||||
<ClInclude Include="Config\ToolTipControls\ToolTipWidget.h" />
|
||||
<QtMoc Include="Config\VerifyWidget.h" />
|
||||
<QtMoc Include="ConvertDialog.h" />
|
||||
<QtMoc Include="Debugger\BreakpointWidget.h" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user