LeechCraft 0.6.70-19424-g027e980fd1
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
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
17class QSize;
18class QRect;
19class QPixmap;
20class QLabel;
21class QColor;
22class QWidget;
23class QStyleOptionViewItem;
24class QAbstractItemView;
25class QModelIndex;
26
27namespace LC::Util
28{
46 UTIL_GUI_API QLabel* ShowPixmapLabel (const QPixmap& pixmap, const QPoint& pos = QPoint ());
47
61 UTIL_GUI_API void SetCurrentRow (QAbstractItemView& view, const QModelIndex& index);
62
78 UTIL_GUI_API QColor TintColors (const QColor& c1, const QColor& c2, double alpha = 0.5);
79
80 UTIL_GUI_API QString ElideProgressBarText (const QString& text, const QStyleOptionViewItem& option);
81
101 UTIL_GUI_API void TintPalette (QWidget *widget,
102 const QColor& color,
103 double alpha = 0.5,
104 const QList<QPalette::ColorRole>& roles = { QPalette::ColorRole::Text, QPalette::ColorRole::WindowText });
105
117 UTIL_GUI_API QString FormatName (const QString& name);
118
124 UTIL_GUI_API QString FormatHumanReadableList (QStringList items);
125
134 UTIL_GUI_API QString FormatHumanReadableList (const QStringList& items,
135 const QString& one, const QString& few, const QString& many);
136
137 UTIL_GUI_API QPixmap DrawOverlayText (QPixmap px, const QString& text, QFont font, const QPen& pen, const QBrush& brush);
138
139 UTIL_GUI_API QIcon FixupTrayIcon (const QIcon& icon);
140
142 {
144 QLatin1String Extension_;
145 };
146
147 UTIL_GUI_API QString MakeFileDialogFilter (std::initializer_list<FileDialogFilterEntry> entries);
148
150
151 template<typename T>
152 void Save2MimeData (QMimeData *mimeData, const QString& name, const T& t)
153 {
154 QByteArray infosData;
155 QDataStream ostr { &infosData, QIODevice::WriteOnly };
156 ostr << t;
157
158 mimeData->setData (name, infosData);
159 }
160}
161
162namespace LC
163{
164 consteval QColor operator""_rgb (const char *str, std::size_t size)
165 {
166 if (size != 7)
167 throw std::runtime_error { "invalid color size" };
168
169 constexpr auto digit = [] (char digit)
170 {
171 if (digit >= '0' && digit <= '9')
172 return digit - '0';
173 if (digit >= 'a' && digit <= 'f')
174 return digit - 'a' + 0xa;
175 if (digit >= 'A' && digit <= 'F')
176 return digit - 'A' + 0xa;
177
178 throw std::runtime_error { "unable to parse" };
179 };
180
181 constexpr auto group = [digit] (const char *str)
182 {
183 return digit (str [0]) * 16 + digit (str [1]);
184 };
185
186 return QColor { group (str + 1), group (str + 3), group (str + 5) };
187 }
188}
QLabel * ShowPixmapLabel(const QPixmap &srcPx, const QPoint &centerPos)
Shows a pixmap at the given pos.
Definition util.cpp:64
QColor TintColors(const QColor &c1, const QColor &c2, double alpha)
Mixes two colors with the given weights.
Definition util.cpp:99
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:113
void SetCurrentRow(QAbstractItemView &view, const QModelIndex &index)
Makes the given row current and the only selected one.
Definition util.cpp:94
#define UTIL_GUI_API
Definition guiconfig.h:16
QString ElideProgressBarText(const QString &text, const QStyleOptionViewItem &option)
Definition util.cpp:108
QPixmap DrawOverlayText(QPixmap px, const QString &text, QFont font, const QPen &pen, const QBrush &brush)
Definition util.cpp:158
QString FormatHumanReadableList(QStringList items)
Joins items for use in a sentence.
Definition util.cpp:126
QString MakeFileDialogFilter(std::initializer_list< FileDialogFilterEntry > entries)
Definition util.cpp:208
QIcon FixupTrayIcon(const QIcon &icon)
Definition util.cpp:190
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:121
void Save2MimeData(QMimeData *mimeData, const QString &name, const T &t)
Definition util.h:152
Definition constants.h:15
Definition util.h:142
QLatin1String Extension_
Definition util.h:144
QString Description_
Definition util.h:143