LeechCraft  0.6.70-10870-g558588d6ec
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  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #pragma once
31 
32 #include <QPoint>
33 #include <QPalette>
34 #include <QMimeData>
35 #include "guiconfig.h"
36 
37 class QSize;
38 class QRect;
39 class QPixmap;
40 class QLabel;
41 class QColor;
42 class QWidget;
43 class QStyleOptionViewItem;
44 
45 namespace LeechCraft
46 {
47 namespace Util
48 {
53  enum FitFlag
54  {
58 
66  NoOverlap = 0x01
67  };
68 
69  Q_DECLARE_FLAGS (FitFlags, FitFlag);
70 
95  UTIL_GUI_API QPoint FitRectScreen (QPoint pos, const QSize& size,
96  FitFlags flags = NoFlags, const QPoint& shiftAdd = QPoint (0, 0));
97 
124  UTIL_GUI_API QPoint FitRect (QPoint pos, const QSize& size, const QRect& geometry,
125  FitFlags flags = NoFlags, const QPoint& shiftAdd = QPoint (0, 0));
126 
144  UTIL_GUI_API QLabel* ShowPixmapLabel (const QPixmap& pixmap, const QPoint& pos = QPoint ());
145 
161  UTIL_GUI_API QColor TintColors (const QColor& c1, const QColor& c2, double alpha = 0.5);
162 
163  UTIL_GUI_API QString ElideProgressBarText (const QString& text, const QStyleOptionViewItem& option);
164 
184  UTIL_GUI_API void TintPalette (QWidget *widget,
185  const QColor& color,
186  double alpha = 0.5,
187  const QList<QPalette::ColorRole>& roles = { QPalette::ColorRole::Text, QPalette::ColorRole::WindowText });
188 
200  UTIL_GUI_API QString FormatName (const QString& name);
201 
202  template<typename T>
203  void Save2MimeData (QMimeData *mimeData, const QString& name, const T& t)
204  {
205  QByteArray infosData;
206  QDataStream ostr { &infosData, QIODevice::WriteOnly };
207  ostr << t;
208 
209  mimeData->setData (name, infosData);
210  }
211 }
212 }
213 
214 Q_DECLARE_OPERATORS_FOR_FLAGS (LeechCraft::Util::FitFlags)
QLabel * ShowPixmapLabel(const QPixmap &srcPx, const QPoint &pos)
Shows a pixmap at the given pos.
Definition: util.cpp:120
detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, boost::mpl::int_< Idx > > pos
Definition: oral.h:922
QString ElideProgressBarText(const QString &text, const QStyleOptionViewItem &option)
Definition: util.cpp:150
QPoint FitRectScreen(QPoint pos, const QSize &size, FitFlags flags, const QPoint &shiftAdd)
Tries to fit a rectangle (like a dialog or popup) into screen.
Definition: util.cpp:45
void Save2MimeData(QMimeData *mimeData, const QString &name, const T &t)
Definition: util.h:203
#define UTIL_GUI_API
Definition: guiconfig.h:37
QColor TintColors(const QColor &c1, const QColor &c2, double alpha)
Mixes two colors with the given weights.
Definition: util.cpp:141
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:163
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:155
QPoint FitRect(QPoint pos, const QSize &size, const QRect &geometry, FitFlags flags, const QPoint &shiftAdd)
Tries to fit a rectangle (like a dialog or popup) into geometry.
Definition: util.cpp:50
Q_DECLARE_FLAGS(FitFlags, FitFlag)