LeechCraft  0.6.70-18450-gabe19ee3b0
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 <QIODevice>
15 #include "guiconfig.h"
16 
17 class QSize;
18 class QRect;
19 class QPixmap;
20 class QLabel;
21 class QColor;
22 class QWidget;
23 class QStyleOptionViewItem;
24 
25 namespace LC::Util
26 {
44  UTIL_GUI_API QLabel* ShowPixmapLabel (const QPixmap& pixmap, const QPoint& pos = QPoint ());
45 
61  UTIL_GUI_API QColor TintColors (const QColor& c1, const QColor& c2, double alpha = 0.5);
62 
63  UTIL_GUI_API QString ElideProgressBarText (const QString& text, const QStyleOptionViewItem& option);
64 
84  UTIL_GUI_API void TintPalette (QWidget *widget,
85  const QColor& color,
86  double alpha = 0.5,
87  const QList<QPalette::ColorRole>& roles = { QPalette::ColorRole::Text, QPalette::ColorRole::WindowText });
88 
100  UTIL_GUI_API QString FormatName (const QString& name);
101 
102  UTIL_GUI_API QPixmap DrawOverlayText (QPixmap px, const QString& text, QFont font, const QPen& pen, const QBrush& brush);
103 
104  UTIL_GUI_API QIcon FixupTrayIcon (const QIcon& icon);
105 
107  {
108  QString Description_;
109  QLatin1String Extension_;
110  };
111 
112  UTIL_GUI_API QString MakeFileDialogFilter (std::initializer_list<FileDialogFilterEntry> entries);
113 
115 
116  template<typename T>
117  void Save2MimeData (QMimeData *mimeData, const QString& name, const T& t)
118  {
119  QByteArray infosData;
120  QDataStream ostr { &infosData, QIODevice::WriteOnly };
121  ostr << t;
122 
123  mimeData->setData (name, infosData);
124  }
125 }
126 
127 namespace LC
128 {
129  // TODO make this consteval when clang will stop crashing on this being consteval
130  constexpr QColor operator""_rgb (const char *str, std::size_t size)
131  {
132  if (size != 7)
133  throw std::runtime_error { "invalid color size" };
134 
135  constexpr auto digit = [] (char digit)
136  {
137  if (digit >= '0' && digit <= '9')
138  return digit - '0';
139  if (digit >= 'a' && digit <= 'f')
140  return digit - 'a' + 0xa;
141  if (digit >= 'A' && digit <= 'F')
142  return digit - 'A' + 0xa;
143 
144  throw std::runtime_error { "unable to parse" };
145  };
146 
147  constexpr auto group = [digit] (const char *str)
148  {
149  return digit (str [0]) * 16 + digit (str [1]);
150  };
151 
152  return QColor { group (str + 1), group (str + 3), group (str + 5) };
153  }
154 }
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:114
QLatin1String Extension_
Definition: util.h:109
QString ElideProgressBarText(const QString &text, const QStyleOptionViewItem &option)
Definition: util.cpp:101
QPixmap DrawOverlayText(QPixmap px, const QString &text, QFont font, const QPen &pen, const QBrush &brush)
Definition: util.cpp:119
Definition: util.h:106
#define UTIL_GUI_API
Definition: guiconfig.h:16
void TintPalette(QWidget *widget, const QColor &color, double alpha, const QList< QPalette::ColorRole > &roles)
Mixes some of the widget&#39;s palette roles with the given color.
Definition: util.cpp:106
QColor TintColors(const QColor &c1, const QColor &c2, double alpha)
Mixes two colors with the given weights.
Definition: util.cpp:92
QLabel * ShowPixmapLabel(const QPixmap &srcPx, const QPoint &centerPos)
Shows a pixmap at the given pos.
Definition: util.cpp:62
QString Description_
Definition: util.h:108
QString MakeFileDialogFilter(std::initializer_list< FileDialogFilterEntry > entries)
Definition: util.cpp:169
QIcon FixupTrayIcon(const QIcon &icon)
Definition: util.cpp:151
Q_DECL_IMPORT const QString Text
void Save2MimeData(QMimeData *mimeData, const QString &name, const T &t)
Definition: util.h:117