LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
util.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #pragma once
10 
11 #include <QPoint>
12 #include <QPalette>
13 #include <QMimeData>
14 #include "guiconfig.h"
15 
16 class QSize;
17 class QRect;
18 class QPixmap;
19 class QLabel;
20 class QColor;
21 class QWidget;
22 class QStyleOptionViewItem;
23 
24 namespace LC::Util
25 {
43  UTIL_GUI_API QLabel* ShowPixmapLabel (const QPixmap& pixmap, const QPoint& pos = QPoint ());
44 
60  UTIL_GUI_API QColor TintColors (const QColor& c1, const QColor& c2, double alpha = 0.5);
61 
62  UTIL_GUI_API QString ElideProgressBarText (const QString& text, const QStyleOptionViewItem& option);
63 
83  UTIL_GUI_API void TintPalette (QWidget *widget,
84  const QColor& color,
85  double alpha = 0.5,
86  const QList<QPalette::ColorRole>& roles = { QPalette::ColorRole::Text, QPalette::ColorRole::WindowText });
87 
99  UTIL_GUI_API QString FormatName (const QString& name);
100 
101  UTIL_GUI_API QPixmap DrawOverlayText (QPixmap px, const QString& text, QFont font, const QPen& pen, const QBrush& brush);
102 
103  template<typename T>
104  void Save2MimeData (QMimeData *mimeData, const QString& name, const T& t)
105  {
106  QByteArray infosData;
107  QDataStream ostr { &infosData, QIODevice::WriteOnly };
108  ostr << t;
109 
110  mimeData->setData (name, infosData);
111  }
112 }
113 
114 namespace LC
115 {
116  // TODO make this consteval when clang will stop crashing on this being consteval
117  constexpr QColor operator"" _rgb (const char *str, std::size_t size)
118  {
119  if (size != 7)
120  throw std::runtime_error { "invalid color size" };
121 
122  constexpr auto digit = [] (char digit)
123  {
124  if (digit >= '0' && digit <= '9')
125  return digit - '0';
126  if (digit >= 'a' && digit <= 'f')
127  return digit - 'a' + 0xa;
128  if (digit >= 'A' && digit <= 'F')
129  return digit - 'A' + 0xa;
130 
131  throw std::runtime_error { "unable to parse" };
132  };
133 
134  constexpr auto group = [digit] (const char *str)
135  {
136  return digit (str [0]) * 16 + digit (str [1]);
137  };
138 
139  return QColor { group (str + 1), group (str + 3), group (str + 5) };
140  }
141 }
LC::Util::FormatName
QString FormatName(const QString &name)
HTML-formats the name to let the user know it is not a part of the fixed dialog text.
Definition: util.cpp:111
LC::Util::Save2MimeData
void Save2MimeData(QMimeData *mimeData, const QString &name, const T &t)
Definition: util.h:104
LC::Util::ElideProgressBarText
QString ElideProgressBarText(const QString &text, const QStyleOptionViewItem &option)
Definition: util.cpp:98
QList
Definition: ianrulesstorage.h:14
LC::Util::TintPalette
void TintPalette(QWidget *widget, const QColor &color, double alpha, const QList< QPalette::ColorRole > &roles)
Mixes some of the widget's palette roles with the given color.
Definition: util.cpp:103
LC::Util::DrawOverlayText
QPixmap DrawOverlayText(QPixmap px, const QString &text, QFont font, const QPen &pen, const QBrush &brush)
Definition: util.cpp:116
LC::Util
Definition: icoreproxy.h:33
LC::Util::TintColors
QColor TintColors(const QColor &c1, const QColor &c2, double alpha)
Mixes two colors with the given weights.
Definition: util.cpp:89
LC::Util::ShowPixmapLabel
QLabel * ShowPixmapLabel(const QPixmap &srcPx, const QPoint &pos)
Shows a pixmap at the given pos.
Definition: util.cpp:67
UTIL_GUI_API
#define UTIL_GUI_API
Definition: guiconfig.h:16
LC
Definition: constants.h:14
LC::EF::Text
const Q_DECL_IMPORT QString Text
Definition: anconstantsdefs.cpp:27
guiconfig.h