2015-02-13 03:53:02 -05:00
|
|
|
#include "qt_helpers.hpp"
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QFont>
|
2015-05-06 16:30:29 -04:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QVariant>
|
2020-07-27 14:50:34 -04:00
|
|
|
#include <QDateTime>
|
2015-02-13 03:53:02 -05:00
|
|
|
|
|
|
|
QString font_as_stylesheet (QFont const& font)
|
|
|
|
{
|
|
|
|
QString font_weight;
|
|
|
|
switch (font.weight ())
|
|
|
|
{
|
|
|
|
case QFont::Light: font_weight = "light"; break;
|
|
|
|
case QFont::Normal: font_weight = "normal"; break;
|
|
|
|
case QFont::DemiBold: font_weight = "demibold"; break;
|
|
|
|
case QFont::Bold: font_weight = "bold"; break;
|
|
|
|
case QFont::Black: font_weight = "black"; break;
|
|
|
|
}
|
2015-04-07 08:08:55 -04:00
|
|
|
return QString {
|
2015-02-13 03:53:02 -05:00
|
|
|
" font-family: %1;\n"
|
|
|
|
" font-size: %2pt;\n"
|
|
|
|
" font-style: %3;\n"
|
2015-04-07 08:08:55 -04:00
|
|
|
" font-weight: %4;\n"}
|
2015-02-13 03:53:02 -05:00
|
|
|
.arg (font.family ())
|
|
|
|
.arg (font.pointSize ())
|
|
|
|
.arg (font.styleName ())
|
|
|
|
.arg (font_weight);
|
|
|
|
}
|
2015-05-06 16:30:29 -04:00
|
|
|
|
|
|
|
void update_dynamic_property (QWidget * widget, char const * property, QVariant const& value)
|
|
|
|
{
|
|
|
|
widget->setProperty (property, value);
|
|
|
|
widget->style ()->unpolish (widget);
|
|
|
|
widget->style ()->polish (widget);
|
|
|
|
widget->update ();
|
|
|
|
}
|
2020-07-27 14:50:34 -04:00
|
|
|
|
2020-08-07 16:28:52 -04:00
|
|
|
QDateTime qt_round_date_time_to (QDateTime dt, int milliseconds)
|
2020-07-27 14:50:34 -04:00
|
|
|
{
|
2020-08-07 16:28:52 -04:00
|
|
|
dt.setMSecsSinceEpoch (dt.addMSecs (milliseconds / 2).toMSecsSinceEpoch () / milliseconds * milliseconds);
|
2020-07-27 14:50:34 -04:00
|
|
|
return dt;
|
|
|
|
}
|
|
|
|
|
2020-08-07 16:28:52 -04:00
|
|
|
QDateTime qt_truncate_date_time_to (QDateTime dt, int milliseconds)
|
2020-07-27 14:50:34 -04:00
|
|
|
{
|
2020-08-07 16:28:52 -04:00
|
|
|
dt.setMSecsSinceEpoch (dt.toMSecsSinceEpoch () / milliseconds * milliseconds);
|
2020-07-27 14:50:34 -04:00
|
|
|
return dt;
|
|
|
|
}
|