2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef GUTIL_H
|
|
|
|
#define GUTIL_H
|
|
|
|
|
|
|
|
#include "tcommon.h"
|
|
|
|
#include <QImage>
|
|
|
|
#include <QFrame>
|
|
|
|
#include <QColor>
|
|
|
|
#include "traster.h"
|
|
|
|
|
|
|
|
#undef DVAPI
|
|
|
|
#undef DVVAR
|
|
|
|
#ifdef TOONZQT_EXPORTS
|
|
|
|
#define DVAPI DV_EXPORT_API
|
|
|
|
#define DVVAR DV_EXPORT_VAR
|
|
|
|
#else
|
|
|
|
#define DVAPI DV_IMPORT_API
|
|
|
|
#define DVVAR DV_IMPORT_VAR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// forward declaration
|
|
|
|
class TMouseEvent;
|
|
|
|
class QMouseEvent;
|
|
|
|
class QTabletEvent;
|
|
|
|
class QKeyEvent;
|
|
|
|
class QUrl;
|
|
|
|
class TFilePath;
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// Constant definition
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
2016-03-19 06:57:51 +13:00
|
|
|
const QColor grey120(120, 120, 120);
|
|
|
|
const QColor grey210(210, 210, 210);
|
|
|
|
const QColor grey225(225, 225, 225);
|
|
|
|
const QColor grey190(190, 190, 190);
|
|
|
|
const QColor grey150(150, 150, 150);
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
} // namespace
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
class QPainter;
|
|
|
|
class QIcon;
|
|
|
|
class TFilePath;
|
|
|
|
class QPainterPath;
|
|
|
|
class TStroke;
|
|
|
|
|
2016-04-26 19:39:20 +12:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
QString DVAPI fileSizeString(qint64 size, int precision = 2);
|
|
|
|
|
2016-04-26 19:39:20 +12:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QImage DVAPI rasterToQImage(const TRasterP &ras, bool premultiplied = true,
|
|
|
|
bool mirrored = true);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-08-18 19:24:14 +12:00
|
|
|
QPixmap DVAPI rasterToQPixmap(const TRaster32P &ras, bool premultiplied = true,
|
|
|
|
bool setDevPixRatio = false);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRaster32P DVAPI rasterFromQImage(QImage image, bool premultiply = true,
|
|
|
|
bool mirror = true);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TRaster32P DVAPI rasterFromQPixmap(QPixmap pixmap, bool premultiply = true,
|
|
|
|
bool mirror = true);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DVAPI drawPolygon(QPainter &p, const std::vector<QPointF> &points,
|
|
|
|
bool fill = false, const QColor colorFill = Qt::white,
|
|
|
|
const QColor colorLine = Qt::black);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DVAPI drawArrow(QPainter &p, const QPointF a, const QPointF b,
|
|
|
|
const QPointF c, bool fill = false,
|
|
|
|
const QColor colorFill = Qt::white,
|
|
|
|
const QColor colorLine = Qt::black);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QPixmap DVAPI scalePixmapKeepingAspectRatio(QPixmap p, QSize size,
|
|
|
|
QColor color = Qt::white);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-08-18 19:24:14 +12:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
QPixmap DVAPI
|
|
|
|
svgToPixmap(const QString &svgFilePath, const QSize &size = QSize(),
|
|
|
|
Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio,
|
|
|
|
QColor bgColor = Qt::transparent);
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// returns device-pixel ratio. It is 1 for normal monitors and 2 (or higher
|
|
|
|
// ratio) for high DPI monitors. Setting "Display > Set custom text size(DPI)"
|
|
|
|
// for Windows corresponds to this ratio.
|
|
|
|
int DVAPI getDevPixRatio();
|
|
|
|
|
2016-03-19 06:57:51 +13:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
QIcon DVAPI createQIcon(const char *iconSVGName);
|
|
|
|
QIcon DVAPI createQIconPNG(const char *iconPNGName);
|
|
|
|
QIcon DVAPI createQIconOnOff(const char *iconSVGName, bool withOver = true);
|
|
|
|
QIcon DVAPI createQIconOnOffPNG(const char *iconPNGName, bool withOver = true);
|
|
|
|
|
2017-05-19 22:20:33 +12:00
|
|
|
inline QSize dimension2QSize(const TDimension &sz) {
|
2016-06-15 18:43:10 +12:00
|
|
|
return QSize(sz.lx, sz.ly);
|
|
|
|
}
|
2017-05-19 22:20:33 +12:00
|
|
|
inline TDimension qsize2Dimension(const QSize &sz) {
|
2016-06-15 18:43:10 +12:00
|
|
|
return TDimension(sz.width(), sz.height());
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
QString DVAPI toQString(const TFilePath &path);
|
|
|
|
bool DVAPI isSpaceString(const QString &str);
|
|
|
|
bool DVAPI isValidFileName(const QString &fileName);
|
|
|
|
bool DVAPI isValidFileName_message(const QString &fileName);
|
2019-12-03 17:59:36 +13:00
|
|
|
bool DVAPI isReservedFileName(const QString &fileName);
|
|
|
|
bool DVAPI isReservedFileName_message(const QString &fileName);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QString DVAPI elideText(const QString &columnName, const QFont &font,
|
|
|
|
int width);
|
|
|
|
QString DVAPI elideText(const QString &columnName, const QFontMetrics &fm,
|
|
|
|
int width, const QString &elideSymbol);
|
2016-03-19 06:57:51 +13:00
|
|
|
QUrl DVAPI pathToUrl(const TFilePath &path);
|
|
|
|
|
|
|
|
bool DVAPI isResource(const QString &path);
|
|
|
|
bool DVAPI isResource(const QUrl &url);
|
|
|
|
bool DVAPI isResourceOrFolder(const QUrl &url);
|
|
|
|
|
|
|
|
bool DVAPI acceptResourceDrop(const QList<QUrl> &urls);
|
|
|
|
bool DVAPI acceptResourceOrFolderDrop(const QList<QUrl> &urls);
|
|
|
|
|
2017-05-19 22:20:33 +12:00
|
|
|
inline QPointF toQPointF(const TPointD &p) { return QPointF(p.x, p.y); }
|
|
|
|
inline QPointF toQPointF(const TPoint &p) { return QPointF(p.x, p.y); }
|
|
|
|
inline QPoint toQPoint(const TPoint &p) { return QPoint(p.x, p.y); }
|
2017-07-20 22:46:27 +12:00
|
|
|
inline TPointD toTPointD(const QPointF &p) { return TPointD(p.x(), p.y()); }
|
|
|
|
inline TPointD toTPointD(const QPoint &p) { return TPointD(p.x(), p.y()); }
|
2017-05-19 22:20:33 +12:00
|
|
|
inline TPoint toTPoint(const QPoint &p) { return TPoint(p.x(), p.y()); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2017-05-19 22:20:33 +12:00
|
|
|
inline QRect toQRect(const TRect &r) {
|
2016-06-15 18:43:10 +12:00
|
|
|
return QRect(r.x0, r.y0, r.getLx(), r.getLy());
|
|
|
|
}
|
2017-05-19 22:20:33 +12:00
|
|
|
inline QRectF toQRectF(const TRectD &r) {
|
2016-06-15 18:43:10 +12:00
|
|
|
return QRectF(r.x0, r.y0, r.getLx(), r.getLy());
|
|
|
|
}
|
2017-05-19 22:20:33 +12:00
|
|
|
inline QRectF toQRectF(const TRect &r) {
|
2016-06-15 18:43:10 +12:00
|
|
|
return QRectF(r.x0, r.y0, r.getLx(), r.getLy());
|
|
|
|
}
|
2017-05-19 22:20:33 +12:00
|
|
|
inline TRect toTRect(const QRect &r) {
|
2016-06-15 18:43:10 +12:00
|
|
|
return TRect(r.left(), r.top(), r.right(), r.bottom());
|
|
|
|
}
|
2017-05-19 22:20:33 +12:00
|
|
|
inline TRectD toTRectD(const QRectF &r) {
|
2016-06-15 18:43:10 +12:00
|
|
|
return TRectD(r.left(), r.top(), r.right(), r.bottom());
|
|
|
|
}
|
2017-05-19 22:20:33 +12:00
|
|
|
inline TRectD toTRectD(const QRect &r) {
|
2016-06-15 18:43:10 +12:00
|
|
|
return TRectD(r.left(), r.top(), r.right() + 1, r.bottom() + 1);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
QPainterPath DVAPI strokeToPainterPath(TStroke *stroke);
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This widget is only used to set the background color of the tabBar
|
|
|
|
// using the styleSheet.
|
|
|
|
// It is also used to take 6px on the left before the tabBar
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI TabBarContainter final : public QFrame {
|
2017-03-16 00:48:06 +13:00
|
|
|
Q_OBJECT
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
TabBarContainter(QWidget *parent = 0);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
protected:
|
2017-03-16 00:48:06 +13:00
|
|
|
QColor m_bottomBelowLineColor, m_bottomAboveLineColor;
|
|
|
|
Q_PROPERTY(QColor BottomBelowLineColor READ getBottomBelowLineColor WRITE
|
|
|
|
setBottomBelowLineColor);
|
|
|
|
Q_PROPERTY(QColor BottomAboveLineColor READ getBottomAboveLineColor WRITE
|
|
|
|
setBottomAboveLineColor);
|
2016-06-19 20:06:29 +12:00
|
|
|
void paintEvent(QPaintEvent *event) override;
|
2017-03-16 00:48:06 +13:00
|
|
|
void setBottomBelowLineColor(const QColor &color) {
|
|
|
|
m_bottomBelowLineColor = color;
|
|
|
|
}
|
|
|
|
QColor getBottomBelowLineColor() const { return m_bottomBelowLineColor; }
|
|
|
|
void setBottomAboveLineColor(const QColor &color) {
|
|
|
|
m_bottomAboveLineColor = color;
|
|
|
|
}
|
|
|
|
QColor getBottomAboveLineColor() const { return m_bottomAboveLineColor; }
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This widget is only used to set the background color of the playToolBar
|
|
|
|
// using the styleSheet. And to put a line in the upper zone
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI ToolBarContainer final : public QFrame {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
ToolBarContainer(QWidget *parent = 0);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
protected:
|
2016-06-19 20:06:29 +12:00
|
|
|
void paintEvent(QPaintEvent *event) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
QString DVAPI operator+(const QString &a, const TFilePath &fp);
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // GUTIL_H
|