Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef GUTIL_H
Toshihiro Shimizu 890ddd
#define GUTIL_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
#include <qimage></qimage>
Toshihiro Shimizu 890ddd
#include <qframe></qframe>
Toshihiro Shimizu 890ddd
#include <qcolor></qcolor>
Toshihiro Shimizu 890ddd
#include "traster.h"
Kite 521c84
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TOONZQT_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// forward declaration
Toshihiro Shimizu 890ddd
class TMouseEvent;
Toshihiro Shimizu 890ddd
class QMouseEvent;
Toshihiro Shimizu 890ddd
class QTabletEvent;
Toshihiro Shimizu 890ddd
class QKeyEvent;
Toshihiro Shimizu 890ddd
class QUrl;
Toshihiro Shimizu 890ddd
class TFilePath;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// Constant definition
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
const QColor grey120(120, 120, 120);
Toshihiro Shimizu 890ddd
const QColor grey210(210, 210, 210);
Toshihiro Shimizu 890ddd
const QColor grey225(225, 225, 225);
Toshihiro Shimizu 890ddd
const QColor grey190(190, 190, 190);
Toshihiro Shimizu 890ddd
const QColor grey150(150, 150, 150);
Toshihiro Shimizu 890ddd
konero 7bed16
struct SvgRenderParams {
konero 7bed16
  QSize size;
konero 7bed16
  QRectF rect;
konero 7bed16
};
konero 7bed16
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class QPainter;
Toshihiro Shimizu 890ddd
class QIcon;
Toshihiro Shimizu 890ddd
class TFilePath;
Toshihiro Shimizu 890ddd
class QPainterPath;
Toshihiro Shimizu 890ddd
class TStroke;
Toshihiro Shimizu 890ddd
Campbell Barton ea4f7e
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Kite 521c84
QString DVAPI getIconThemePath(const QString &filePath);
Kite 521c84
Kite 521c84
//-----------------------------------------------------------------------------
Kite 521c84
Toshihiro Shimizu 890ddd
QString DVAPI fileSizeString(qint64 size, int precision = 2);
Toshihiro Shimizu 890ddd
Campbell Barton ea4f7e
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QImage DVAPI rasterToQImage(const TRasterP &ras, bool premultiplied = true,
Shinya Kitaoka 120a6e
                            bool mirrored = true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun_iwasawa 3cc41f
QPixmap DVAPI rasterToQPixmap(const TRaster32P &ras, bool premultiplied = true,
shun_iwasawa 3cc41f
                              bool setDevPixRatio = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRaster32P DVAPI rasterFromQImage(QImage image, bool premultiply = true,
Shinya Kitaoka 120a6e
                                  bool mirror = true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRaster32P DVAPI rasterFromQPixmap(QPixmap pixmap, bool premultiply = true,
Shinya Kitaoka 120a6e
                                   bool mirror = true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DVAPI drawPolygon(QPainter &p, const std::vector<qpointf> &points,</qpointf>
Shinya Kitaoka 120a6e
                       bool fill = false, const QColor colorFill = Qt::white,
Shinya Kitaoka 120a6e
                       const QColor colorLine = Qt::black);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DVAPI drawArrow(QPainter &p, const QPointF a, const QPointF b,
Shinya Kitaoka 120a6e
                     const QPointF c, bool fill = false,
Shinya Kitaoka 120a6e
                     const QColor colorFill = Qt::white,
Shinya Kitaoka 120a6e
                     const QColor colorLine = Qt::black);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QPixmap DVAPI scalePixmapKeepingAspectRatio(QPixmap p, QSize size,
Shinya Kitaoka 120a6e
                                            QColor color = Qt::white);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
shun_iwasawa 3cc41f
konero 7bed16
SvgRenderParams calculateSvgRenderParams(const QSize &desiredSize,
konero 7bed16
                                         QSize &imageSize,
konero 7bed16
                                         Qt::AspectRatioMode aspectRatioMode);
konero 7bed16
konero 7bed16
//-----------------------------------------------------------------------------
konero 7bed16
shun_iwasawa 3cc41f
QPixmap DVAPI
konero 7bed16
svgToPixmap(const QString &svgFilePath, QSize size = QSize(),
shun_iwasawa 3cc41f
            Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio,
shun_iwasawa 3cc41f
            QColor bgColor                      = Qt::transparent);
shun_iwasawa 3cc41f
shun_iwasawa 3cc41f
//-----------------------------------------------------------------------------
konero 7bed16
konero 7bed16
QImage DVAPI
konero 7bed16
svgToImage(const QString &svgFilePath, QSize size = QSize(),
konero 7bed16
           Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio,
konero 7bed16
           QColor bgColor                      = Qt::transparent);
konero 7bed16
konero 7bed16
//-----------------------------------------------------------------------------
shun_iwasawa 3cc41f
// returns device-pixel ratio. It is 1 for normal monitors and 2 (or higher
shun_iwasawa 3cc41f
// ratio) for high DPI monitors. Setting "Display > Set custom text size(DPI)"
shun_iwasawa 3cc41f
// for Windows corresponds to this ratio.
shun-iwasawa f2e168
int DVAPI getDevicePixelRatio(const QWidget *widget = nullptr);
shun_iwasawa 3cc41f
shun_iwasawa 3cc41f
//-----------------------------------------------------------------------------
Kite 521c84
konero 7bed16
QImage DVAPI adjustImageOpacity(const QImage &input, qreal opacity = 1.0);
konero 7bed16
konero 7bed16
//-----------------------------------------------------------------------------
konero 7bed16
konero 7bed16
QImage DVAPI compositeImage(const QImage &input, QSize newSize = QSize(),
konero 7bed16
                            bool scaleInput = false,
konero 7bed16
                            QColor bgColor  = Qt::transparent);
konero 7bed16
konero 7bed16
//-----------------------------------------------------------------------------
konero 7bed16
konero 7bed16
QPixmap DVAPI convertImageToPixmap(const QImage &image);
konero 7bed16
konero 7bed16
//-----------------------------------------------------------------------------
konero 7bed16
konero 7bed16
QImage DVAPI
konero 7bed16
generateIconImage(const QString &iconSVGName, qreal opacity = qreal(1.0),
konero 7bed16
                  QSize newSize                       = QSize(),
konero 7bed16
                  Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio);
konero 7bed16
konero 7bed16
//-----------------------------------------------------------------------------
konero 7bed16
konero 7bed16
QPixmap DVAPI
konero 7bed16
generateIconPixmap(const QString &iconSVGName, qreal opacity = qreal(1.0),
konero 7bed16
                   QSize newSize                       = QSize(),
konero 7bed16
                   Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio);
konero 7bed16
konero 7bed16
//-----------------------------------------------------------------------------
konero 7bed16
konero 7bed16
void DVAPI addImagesToIcon(QIcon &icon, const QImage &baseImg,
konero 7bed16
                           const QImage &overImg = QImage(),
konero 7bed16
                           const QImage &onImg   = QImage(),
konero 7bed16
                           bool useFullOpacity   = false);
konero 7bed16
konero 7bed16
//-----------------------------------------------------------------------------
konero 7bed16
konero 7bed16
void DVAPI addPixmapToAllModesAndStates(QIcon &icon, const QPixmap &pixmap);
konero 7bed16
konero 7bed16
//-----------------------------------------------------------------------------
konero 7bed16
konero 7bed16
QIcon DVAPI createQIcon(const QString &iconSVGName, bool useFullOpacity = false,
konero 7bed16
                        bool isForMenuItem = false, QSize newSize = QSize());
Toshihiro Shimizu 890ddd
QIcon DVAPI createQIconPNG(const char *iconPNGName);
Toshihiro Shimizu 890ddd
QIcon DVAPI createQIconOnOffPNG(const char *iconPNGName, bool withOver = true);
shun-iwasawa 75b9b0
QIcon DVAPI createTemporaryIconFromName(const char *commandName);
Toshihiro Shimizu 890ddd
2fc36c
inline QSize dimension2QSize(const TDimension &sz) {
Shinya Kitaoka 120a6e
  return QSize(sz.lx, sz.ly);
Shinya Kitaoka 120a6e
}
2fc36c
inline TDimension qsize2Dimension(const QSize &sz) {
Shinya Kitaoka 120a6e
  return TDimension(sz.width(), sz.height());
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
QString DVAPI toQString(const TFilePath &path);
Toshihiro Shimizu 890ddd
bool DVAPI isSpaceString(const QString &str);
Toshihiro Shimizu 890ddd
bool DVAPI isValidFileName(const QString &fileName);
Toshihiro Shimizu 890ddd
bool DVAPI isValidFileName_message(const QString &fileName);
manongjohn 7f3150
bool DVAPI isReservedFileName(const QString &fileName);
manongjohn 7f3150
bool DVAPI isReservedFileName_message(const QString &fileName);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString DVAPI elideText(const QString &columnName, const QFont &font,
Shinya Kitaoka 120a6e
                        int width);
Shinya Kitaoka 120a6e
QString DVAPI elideText(const QString &columnName, const QFontMetrics &fm,
Shinya Kitaoka 120a6e
                        int width, const QString &elideSymbol);
Toshihiro Shimizu 890ddd
QUrl DVAPI pathToUrl(const TFilePath &path);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool DVAPI isResource(const QString &path);
Toshihiro Shimizu 890ddd
bool DVAPI isResource(const QUrl &url);
Toshihiro Shimizu 890ddd
bool DVAPI isResourceOrFolder(const QUrl &url);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool DVAPI acceptResourceDrop(const QList<qurl> &urls);</qurl>
Toshihiro Shimizu 890ddd
bool DVAPI acceptResourceOrFolderDrop(const QList<qurl> &urls);</qurl>
Toshihiro Shimizu 890ddd
2fc36c
inline QPointF toQPointF(const TPointD &p) { return QPointF(p.x, p.y); }
2fc36c
inline QPointF toQPointF(const TPoint &p) { return QPointF(p.x, p.y); }
2fc36c
inline QPoint toQPoint(const TPoint &p) { return QPoint(p.x, p.y); }
shun_iwasawa 0cae24
inline TPointD toTPointD(const QPointF &p) { return TPointD(p.x(), p.y()); }
shun_iwasawa 0cae24
inline TPointD toTPointD(const QPoint &p) { return TPointD(p.x(), p.y()); }
2fc36c
inline TPoint toTPoint(const QPoint &p) { return TPoint(p.x(), p.y()); }
Toshihiro Shimizu 890ddd
2fc36c
inline QRect toQRect(const TRect &r) {
Shinya Kitaoka 120a6e
  return QRect(r.x0, r.y0, r.getLx(), r.getLy());
Shinya Kitaoka 120a6e
}
2fc36c
inline QRectF toQRectF(const TRectD &r) {
Shinya Kitaoka 120a6e
  return QRectF(r.x0, r.y0, r.getLx(), r.getLy());
Shinya Kitaoka 120a6e
}
2fc36c
inline QRectF toQRectF(const TRect &r) {
Shinya Kitaoka 120a6e
  return QRectF(r.x0, r.y0, r.getLx(), r.getLy());
Shinya Kitaoka 120a6e
}
2fc36c
inline TRect toTRect(const QRect &r) {
Shinya Kitaoka 120a6e
  return TRect(r.left(), r.top(), r.right(), r.bottom());
Shinya Kitaoka 120a6e
}
2fc36c
inline TRectD toTRectD(const QRectF &r) {
Shinya Kitaoka 120a6e
  return TRectD(r.left(), r.top(), r.right(), r.bottom());
Shinya Kitaoka 120a6e
}
2fc36c
inline TRectD toTRectD(const QRect &r) {
Shinya Kitaoka 120a6e
  return TRectD(r.left(), r.top(), r.right() + 1, r.bottom() + 1);
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QPainterPath DVAPI strokeToPainterPath(TStroke *stroke);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
// This widget is only used to set the background color of the tabBar
Toshihiro Shimizu 890ddd
// using the styleSheet.
Toshihiro Shimizu 890ddd
// It is also used to take 6px on the left before the tabBar
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI TabBarContainter final : public QFrame {
Jeremy Bullock 0f89c5
  Q_OBJECT
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TabBarContainter(QWidget *parent = 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Jeremy Bullock 0f89c5
  QColor m_bottomBelowLineColor, m_bottomAboveLineColor;
Jeremy Bullock 0f89c5
  Q_PROPERTY(QColor BottomBelowLineColor READ getBottomBelowLineColor WRITE
Jeremy Bullock 0f89c5
                 setBottomBelowLineColor);
Jeremy Bullock 0f89c5
  Q_PROPERTY(QColor BottomAboveLineColor READ getBottomAboveLineColor WRITE
Jeremy Bullock 0f89c5
                 setBottomAboveLineColor);
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *event) override;
Jeremy Bullock 0f89c5
  void setBottomBelowLineColor(const QColor &color) {
Jeremy Bullock 0f89c5
    m_bottomBelowLineColor = color;
Jeremy Bullock 0f89c5
  }
Jeremy Bullock 0f89c5
  QColor getBottomBelowLineColor() const { return m_bottomBelowLineColor; }
Jeremy Bullock 0f89c5
  void setBottomAboveLineColor(const QColor &color) {
Jeremy Bullock 0f89c5
    m_bottomAboveLineColor = color;
Jeremy Bullock 0f89c5
  }
Jeremy Bullock 0f89c5
  QColor getBottomAboveLineColor() const { return m_bottomAboveLineColor; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
// This widget is only used to set the background color of the playToolBar
Toshihiro Shimizu 890ddd
// using the styleSheet. And to put a line in the upper zone
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI ToolBarContainer final : public QFrame {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ToolBarContainer(QWidget *parent = 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *event) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QString DVAPI operator+(const QString &a, const TFilePath &fp);
Toshihiro Shimizu 890ddd
konero 7bed16
//-----------------------------------------------------------------------------
konero 7bed16
// Theme Manager
konero 7bed16
// For managing icon themes
konero 7bed16
konero 7bed16
class DVAPI ThemeManager {  // singleton
konero 7bed16
public:
konero 7bed16
  static ThemeManager &getInstance();
konero 7bed16
konero 7bed16
  void buildIconPathsMap(const QString &path);
konero 7bed16
  bool hasIcon(const QString &iconName) const;
konero 7bed16
  QString getIconPath(const QString &iconName) const;
konero 7bed16
konero 7bed16
  qreal getOnOpacity() const;
konero 7bed16
  qreal getOffOpacity() const;
konero 7bed16
  qreal getDisabledOpacity() const;
konero 7bed16
konero 7bed16
  QImage recolorBlackPixels(const QImage &image, QColor color = QColor());
konero 7bed16
  QPixmap recolorBlackPixels(const QPixmap &input, QColor color = QColor());
konero 7bed16
konero 7bed16
  // Debug
konero 7bed16
  void printiconPathsMap();
konero 7bed16
konero 7bed16
  ThemeManager(ThemeManager const &)   = delete;
konero 7bed16
  void operator=(ThemeManager const &) = delete;
konero 7bed16
  ~ThemeManager();
konero 7bed16
konero 7bed16
private:
konero 7bed16
  ThemeManager();
konero 7bed16
konero 7bed16
  class ThemeManagerImpl;                  // forward declaration
konero 7bed16
  std::unique_ptr<thememanagerimpl> impl;  // opaque pointer</thememanagerimpl>
konero 7bed16
};
konero 7bed16
konero 7bed16
QString DVAPI getIconPath(const QString &path);
konero 7bed16
Shinya Kitaoka 120a6e
#endif  // GUTIL_H