mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-11-01 03:00:05 +00:00
Use unit library to perform font size conversions
This commit is contained in:
parent
10a1755056
commit
9ea3ed47a6
3 changed files with 36 additions and 6 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
#define NOMINMAX
|
||||||
|
|
||||||
#include <scwx/qt/config/radar_site.hpp>
|
#include <scwx/qt/config/radar_site.hpp>
|
||||||
#include <scwx/qt/main/main_window.hpp>
|
#include <scwx/qt/main/main_window.hpp>
|
||||||
#include <scwx/qt/main/versions.hpp>
|
#include <scwx/qt/main/versions.hpp>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,31 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <units/core.h>
|
||||||
|
|
||||||
|
namespace units
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace dimension
|
||||||
|
{
|
||||||
|
|
||||||
|
struct font_size_tag
|
||||||
|
{
|
||||||
|
static constexpr const char* const name = "font size";
|
||||||
|
static constexpr const char* const abbreviation = "px";
|
||||||
|
};
|
||||||
|
|
||||||
|
using font_size = make_dimension<font_size_tag>;
|
||||||
|
|
||||||
|
} // namespace dimension
|
||||||
|
|
||||||
|
UNIT_ADD(font_size,
|
||||||
|
pixels,
|
||||||
|
px,
|
||||||
|
conversion_factor<std::ratio<1>, dimension::font_size>)
|
||||||
|
UNIT_ADD(font_size, points, pt, conversion_factor<std::ratio<4, 3>, pixels<>>)
|
||||||
|
|
||||||
|
} // namespace units
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
namespace qt
|
namespace qt
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include <scwx/qt/util/tooltip.hpp>
|
#include <scwx/qt/util/tooltip.hpp>
|
||||||
#include <scwx/qt/manager/settings_manager.hpp>
|
#include <scwx/qt/manager/settings_manager.hpp>
|
||||||
#include <scwx/qt/settings/text_settings.hpp>
|
#include <scwx/qt/settings/text_settings.hpp>
|
||||||
|
#include <scwx/qt/types/font_types.hpp>
|
||||||
#include <scwx/qt/util/imgui.hpp>
|
#include <scwx/qt/util/imgui.hpp>
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
|
|
||||||
|
|
@ -101,21 +102,22 @@ void Show(const std::string& text, const QPointF& mouseGlobalPos)
|
||||||
else if (tooltipMethod_ == TooltipMethod::QLabel)
|
else if (tooltipMethod_ == TooltipMethod::QLabel)
|
||||||
{
|
{
|
||||||
// Get monospace font size
|
// Get monospace font size
|
||||||
std::size_t fontSize = 16;
|
units::font_size::pixels<double> fontSize {16};
|
||||||
auto fontSizes =
|
auto fontSizes =
|
||||||
manager::SettingsManager::general_settings().font_sizes().GetValue();
|
manager::SettingsManager::general_settings().font_sizes().GetValue();
|
||||||
if (fontSizes.size() > 1)
|
if (fontSizes.size() > 1)
|
||||||
{
|
{
|
||||||
fontSize = fontSizes[1];
|
fontSize = units::font_size::pixels<double> {fontSizes[1]};
|
||||||
}
|
}
|
||||||
else if (fontSizes.size() > 0)
|
else if (fontSizes.size() > 0)
|
||||||
{
|
{
|
||||||
fontSize = fontSizes[0];
|
fontSize = units::font_size::pixels<double> {fontSizes[0]};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the label
|
// Configure the label
|
||||||
tooltipLabel_->setFont(
|
QFont font("Inconsolata");
|
||||||
QFont("Inconsolata", static_cast<int>(std::round(fontSize * 0.72))));
|
font.setPointSizeF(units::font_size::points<double>(fontSize).value());
|
||||||
|
tooltipLabel_->setFont(font);
|
||||||
tooltipLabel_->setText(QString::fromStdString(displayText));
|
tooltipLabel_->setText(QString::fromStdString(displayText));
|
||||||
|
|
||||||
// Get the screen the label will be displayed on
|
// Get the screen the label will be displayed on
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue