Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Kite 521c84
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "tfiletype.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "tcurves.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tmsgcore.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qpixmap></qpixmap>
Toshihiro Shimizu 890ddd
#include <qimage></qimage>
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qpainterpath></qpainterpath>
Toshihiro Shimizu 890ddd
#include <qicon></qicon>
Toshihiro Shimizu 890ddd
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
#include <qapplication></qapplication>
Toshihiro Shimizu 890ddd
#include <qmouseevent></qmouseevent>
Toshihiro Shimizu 890ddd
#include <qtabletevent></qtabletevent>
Toshihiro Shimizu 890ddd
#include <qkeyevent></qkeyevent>
Toshihiro Shimizu 890ddd
#include <qurl></qurl>
Toshihiro Shimizu 890ddd
#include <qfileinfo></qfileinfo>
shun_iwasawa 3cc41f
#include <qdesktopwidget></qdesktopwidget>
shun_iwasawa 3cc41f
#include <qsvgrenderer></qsvgrenderer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString fileSizeString(qint64 size, int precision) {
Shinya Kitaoka 120a6e
  if (size < 1024)
Shinya Kitaoka 120a6e
    return QString::number(size) + " Bytes";
Shinya Kitaoka 120a6e
  else if (size < 1024 * 1024)
Shinya Kitaoka 120a6e
    return QString::number(size / (1024.0), 'f', precision) + " KB";
Shinya Kitaoka 120a6e
  else if (size < 1024 * 1024 * 1024)
Shinya Kitaoka 120a6e
    return QString::number(size / (1024 * 1024.0), 'f', precision) + " MB";
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return QString::number(size / (1024 * 1024 * 1024.0), 'f', precision) +
Shinya Kitaoka 120a6e
           " GB";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QImage rasterToQImage(const TRasterP &ras, bool premultiplied, bool mirrored) {
Shinya Kitaoka 120a6e
  if (TRaster32P ras32 = ras) {
Shinya Kitaoka 120a6e
    QImage image(ras->getRawData(), ras->getLx(), ras->getLy(),
Shinya Kitaoka 120a6e
                 premultiplied ? QImage::Format_ARGB32_Premultiplied
Shinya Kitaoka 120a6e
                               : QImage::Format_ARGB32);
Shinya Kitaoka 120a6e
    if (mirrored) return image.mirrored();
Shinya Kitaoka 120a6e
    return image;
Shinya Kitaoka 120a6e
  } else if (TRasterGR8P ras8 = ras) {
Shinya Kitaoka 120a6e
    QImage image(ras->getRawData(), ras->getLx(), ras->getLy(), ras->getWrap(),
Shinya Kitaoka 120a6e
                 QImage::Format_Indexed8);
Shinya Kitaoka 120a6e
    static QVector<qrgb> colorTable;</qrgb>
Shinya Kitaoka 120a6e
    if (colorTable.size() == 0) {
Shinya Kitaoka 120a6e
      int i;
Shinya Kitaoka 120a6e
      for (i = 0; i < 256; i++) colorTable.append(QColor(i, i, i).rgb());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    image.setColorTable(colorTable);
Shinya Kitaoka 120a6e
    if (mirrored) return image.mirrored();
Shinya Kitaoka 120a6e
    return image;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return QImage();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun_iwasawa 3cc41f
QPixmap rasterToQPixmap(const TRaster32P &ras, bool premultiplied,
shun_iwasawa 3cc41f
                        bool setDevPixRatio) {
shun_iwasawa 3cc41f
  QPixmap pixmap = QPixmap::fromImage(rasterToQImage(ras, premultiplied));
shun_iwasawa 3cc41f
  if (setDevPixRatio) {
shun_iwasawa 1c961d
    pixmap.setDevicePixelRatio(getDevPixRatio());
shun_iwasawa 3cc41f
  }
shun_iwasawa 3cc41f
  return pixmap;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRaster32P rasterFromQImage(
Shinya Kitaoka 120a6e
    QImage image, bool premultiply,
Shinya Kitaoka 120a6e
    bool mirror)  // no need of const& - Qt uses implicit sharing...
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  QImage copyImage = mirror ? image.mirrored() : image;
Shinya Kitaoka 120a6e
  TRaster32P ras(image.width(), image.height(), image.width(),
Shinya Kitaoka 120a6e
                 (TPixelRGBM32 *)copyImage.bits(), false);
Shinya Kitaoka 120a6e
  if (premultiply) TRop::premultiply(ras);
Shinya Kitaoka 120a6e
  return ras->clone();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRaster32P rasterFromQPixmap(
Shinya Kitaoka 120a6e
    QPixmap pixmap, bool premultiply,
Shinya Kitaoka 120a6e
    bool mirror)  // no need of const& - Qt uses implicit sharing...
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  QImage image = pixmap.toImage();
Shinya Kitaoka 120a6e
  return rasterFromQImage(image, premultiply, mirror);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void drawPolygon(QPainter &p, const std::vector<qpointf> &points, bool fill,</qpointf>
Shinya Kitaoka 120a6e
                 const QColor colorFill, const QColor colorLine) {
Shinya Kitaoka 120a6e
  if (points.size() == 0) return;
Shinya Kitaoka 120a6e
  p.setPen(colorLine);
Shinya Kitaoka 120a6e
  QPolygonF E0Polygon;
Shinya Kitaoka 120a6e
  int i = 0;
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)points.size(); i++) E0Polygon << QPointF(points[i]);
Shinya Kitaoka 120a6e
  E0Polygon << QPointF(points[0]);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPainterPath E0Path;
Shinya Kitaoka 120a6e
  E0Path.addPolygon(E0Polygon);
Shinya Kitaoka 120a6e
  if (fill) p.fillPath(E0Path, QBrush(colorFill));
Shinya Kitaoka 120a6e
  p.drawPath(E0Path);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void drawArrow(QPainter &p, const QPointF a, const QPointF b, const QPointF c,
Shinya Kitaoka 120a6e
               bool fill, const QColor colorFill, const QColor colorLine) {
Shinya Kitaoka 120a6e
  std::vector<qpointf> pts;</qpointf>
Shinya Kitaoka 120a6e
  pts.push_back(a);
Shinya Kitaoka 120a6e
  pts.push_back(b);
Shinya Kitaoka 120a6e
  pts.push_back(c);
Shinya Kitaoka 120a6e
  drawPolygon(p, pts, fill, colorFill, colorLine);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QPixmap scalePixmapKeepingAspectRatio(QPixmap pixmap, QSize size,
Shinya Kitaoka 120a6e
                                      QColor color) {
shun_iwasawa 3cc41f
  if (pixmap.isNull()) return pixmap;
shun_iwasawa 3cc41f
  if (pixmap.devicePixelRatio() > 1.0) size *= pixmap.devicePixelRatio();
shun_iwasawa 3cc41f
  if (pixmap.size() == size) return pixmap;
Shinya Kitaoka 120a6e
  QPixmap scaledPixmap =
Shinya Kitaoka 120a6e
      pixmap.scaled(size.width(), size.height(), Qt::KeepAspectRatio,
Shinya Kitaoka 120a6e
                    Qt::SmoothTransformation);
Shinya Kitaoka 120a6e
  QPixmap newPixmap(size);
Shinya Kitaoka 120a6e
  newPixmap.fill(color);
Shinya Kitaoka 120a6e
  QPainter painter(&newPixmap);
Shinya Kitaoka 120a6e
  painter.drawPixmap(double(size.width() - scaledPixmap.width()) * 0.5,
Shinya Kitaoka 120a6e
                     double(size.height() - scaledPixmap.height()) * 0.5,
Shinya Kitaoka 120a6e
                     scaledPixmap);
shun_iwasawa 3cc41f
  newPixmap.setDevicePixelRatio(pixmap.devicePixelRatio());
Shinya Kitaoka 120a6e
  return newPixmap;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun_iwasawa 3cc41f
QPixmap svgToPixmap(const QString &svgFilePath, const QSize &size,
shun_iwasawa 3cc41f
                    Qt::AspectRatioMode aspectRatioMode, QColor bgColor) {
shun_iwasawa 1c961d
  static int devPixRatio = getDevPixRatio();
shun_iwasawa 3cc41f
  QSvgRenderer svgRenderer(svgFilePath);
shun_iwasawa 3cc41f
  QSize pixmapSize;
shun_iwasawa 3cc41f
  QRectF renderRect;
shun_iwasawa 3cc41f
  if (size.isEmpty()) {
shun_iwasawa 3cc41f
    pixmapSize = svgRenderer.defaultSize() * devPixRatio;
shun_iwasawa 3cc41f
    renderRect = QRectF(QPointF(), QSizeF(pixmapSize));
shun_iwasawa 3cc41f
  } else {
shun_iwasawa 3cc41f
    pixmapSize = size * devPixRatio;
shun_iwasawa 3cc41f
    if (aspectRatioMode == Qt::KeepAspectRatio ||
shun_iwasawa 3cc41f
        aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
shun_iwasawa 3cc41f
      QSize imgSize = svgRenderer.defaultSize();
shun_iwasawa 3cc41f
      QPointF scaleFactor((float)pixmapSize.width() / (float)imgSize.width(),
shun_iwasawa 3cc41f
                          (float)pixmapSize.height() / (float)imgSize.height());
shun_iwasawa 3cc41f
      float factor = (aspectRatioMode == Qt::KeepAspectRatio)
shun_iwasawa 3cc41f
                         ? std::min(scaleFactor.x(), scaleFactor.y())
shun_iwasawa 3cc41f
                         : std::max(scaleFactor.x(), scaleFactor.y());
shun_iwasawa 3cc41f
      QSizeF renderSize(factor * (float)imgSize.width(),
shun_iwasawa 3cc41f
                        factor * (float)imgSize.height());
shun_iwasawa 3cc41f
      QPointF topLeft(
shun_iwasawa 3cc41f
          ((float)pixmapSize.width() - renderSize.width()) * 0.5f,
shun_iwasawa 3cc41f
          ((float)pixmapSize.height() - renderSize.height()) * 0.5f);
shun_iwasawa 3cc41f
      renderRect = QRectF(topLeft, renderSize);
shun_iwasawa 3cc41f
    } else {  // Qt::IgnoreAspectRatio:
shun_iwasawa 3cc41f
      renderRect = QRectF(QPointF(), QSizeF(pixmapSize));
shun_iwasawa 3cc41f
    }
shun_iwasawa 3cc41f
  }
shun_iwasawa 3cc41f
  QPixmap pixmap(pixmapSize);
shun_iwasawa 3cc41f
  QPainter painter;
shun_iwasawa 3cc41f
  pixmap.fill(bgColor);
shun_iwasawa 3cc41f
  painter.begin(&pixmap);
shun_iwasawa 3cc41f
  svgRenderer.render(&painter, renderRect);
shun_iwasawa 3cc41f
  painter.end();
shun_iwasawa 3cc41f
  pixmap.setDevicePixelRatio(devPixRatio);
shun_iwasawa 3cc41f
  return pixmap;
shun_iwasawa 3cc41f
}
shun_iwasawa 3cc41f
shun_iwasawa 3cc41f
//-----------------------------------------------------------------------------
shun_iwasawa 3cc41f
shun_iwasawa 3cc41f
int getDevPixRatio() {
shun_iwasawa 3cc41f
  static int devPixRatio = QApplication::desktop()->devicePixelRatio();
shun_iwasawa 3cc41f
  return devPixRatio;
shun_iwasawa 3cc41f
}
shun_iwasawa 3cc41f
shun_iwasawa 3cc41f
//-----------------------------------------------------------------------------
shun_iwasawa 3cc41f
Kite 521c84
QString getIconThemePath(const QString &fileSVGPath) {
Kite 521c84
  // Use as follows:
Kite 521c84
  // QPixmap pixmapIcon = getIconThemePath("path/to/file.svg");
Kite 521c84
  // Is equal to:            :icons/*theme*/path/to/file.svg
Toshihiro Shimizu 890ddd
Kite 521c84
  // Set themeable directory
Kite 521c84
  static QString theme = Preferences::instance()->getIconTheme()
Kite 521c84
                             ? ":icons/dark/"
Kite 521c84
                             : ":icons/light/";
Kite 521c84
Kite 521c84
  // If no file in light icon theme directory, fallback to dark directory
Kite 521c84
  if (!QFile::exists(QString(theme + fileSVGPath))) theme = ":icons/dark/";
Kite 521c84
Kite 521c84
  return theme + fileSVGPath;
Kite 521c84
}
Kite 521c84
Kite 521c84
//-----------------------------------------------------------------------------
Kite 521c84
Kite 521c84
QPixmap setOpacity(QPixmap pixmap, const qreal &opacity) {
Kite 521c84
  static int devPixRatio = getDevPixRatio();
Kite 521c84
  const QSize pixmapSize(pixmap.width() * devPixRatio,
Kite 521c84
                         pixmap.height() * devPixRatio);
Kite 521c84
Kite 521c84
  QPixmap opacityPixmap(pixmapSize);
Kite 521c84
  opacityPixmap.setDevicePixelRatio(devPixRatio);
Kite 521c84
  opacityPixmap.fill(Qt::transparent);
Kite 521c84
Kite 521c84
  if (!pixmap.isNull()) {
Kite 521c84
    QPainter p(&opacityPixmap);
Kite 521c84
    QPixmap normalPixmap = pixmap.scaled(pixmapSize, Qt::KeepAspectRatio);
Kite 521c84
    normalPixmap.setDevicePixelRatio(devPixRatio);
Kite 521c84
    p.setBackgroundMode(Qt::TransparentMode);
Kite 521c84
    p.setBackground(QBrush(Qt::transparent));
Kite 521c84
    p.eraseRect(normalPixmap.rect());
Kite 521c84
    p.setOpacity(opacity);
Kite 521c84
    p.drawPixmap(0, 0, normalPixmap);
Kite 521c84
  }
Kite 521c84
  return opacityPixmap;
Kite 521c84
}
Kite 521c84
Kite 521c84
//-----------------------------------------------------------------------------
Kite 521c84
Kite 521c84
QPixmap recolorPixmap(QPixmap pixmap, QColor color) {
Kite 521c84
  // Change black pixels to any chosen color
Kite 521c84
  QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
Kite 521c84
  for (int y = 0; y < img.height(); y++) {
Kite 521c84
    QRgb *pixel = reinterpret_cast<qrgb *="">(img.scanLine(y));</qrgb>
Kite 521c84
    QRgb *end   = pixel + img.width();
Kite 521c84
    for (; pixel != end; pixel++) {
Kite 521c84
      // Only recolor zero value (black) pixels
Kite 521c84
      if (QColor::fromRgba(*pixel).value() == 0)
Kite 521c84
        *pixel =
Kite 521c84
            QColor(color.red(), color.green(), color.blue(), qAlpha(*pixel))
Kite 521c84
                .rgba();
Kite 521c84
    }
Kite 521c84
  }
Kite 521c84
  return pixmap = QPixmap::fromImage(img);
Kite 521c84
}
Kite 521c84
Kite 521c84
//-----------------------------------------------------------------------------
Kite 521c84
Kite 521c84
QIcon createQIcon(const char *iconSVGName, bool useFullOpacity) {
Kite 521c84
  QIcon normalIcon = QIcon::fromTheme(iconSVGName);
Kite 521c84
Kite 521c84
  QSize iconSize(0, 0);  // Get largest
Kite 521c84
  for (QList<qsize> sizes = normalIcon.availableSizes(); !sizes.isEmpty();</qsize>
Kite 521c84
       sizes.removeFirst())
Kite 521c84
    if (sizes.first().width() > iconSize.width()) iconSize = sizes.first();
Kite 521c84
Kite 521c84
  const qreal offOpacity      = 0.8;
Kite 521c84
  const qreal disabledOpacity = 0.15;
Kite 521c84
  QString overStr             = QString(iconSVGName) + "_over";
Kite 521c84
  QString onStr               = QString(iconSVGName) + "_on";
Kite 521c84
  QPixmap normalPm            = recolorPixmap(normalIcon.pixmap(iconSize));
Kite 521c84
  QPixmap overPm = recolorPixmap(QIcon::fromTheme(overStr).pixmap(iconSize));
Kite 521c84
  QPixmap onPm   = recolorPixmap(QIcon::fromTheme(onStr).pixmap(iconSize));
Shinya Kitaoka 120a6e
  QIcon icon;
Toshihiro Shimizu 890ddd
Kite 521c84
  // Off
Kite 521c84
  icon.addPixmap(useFullOpacity ? normalPm : setOpacity(normalPm, offOpacity),
Kite 521c84
                 QIcon::Normal, QIcon::Off);
Kite 521c84
  icon.addPixmap(setOpacity(normalPm, disabledOpacity), QIcon::Disabled);
Kite 521c84
Kite 521c84
  // Over
Kite 521c84
  icon.addPixmap(!overPm.isNull() ? overPm : normalPm, QIcon::Active);
Kite 521c84
Kite 521c84
  // On
Kite 521c84
  if (!onPm.isNull()) {
Kite 521c84
    icon.addPixmap(onPm, QIcon::Normal, QIcon::On);
Kite 521c84
    icon.addPixmap(setOpacity(onPm, disabledOpacity), QIcon::Disabled,
Kite 521c84
                   QIcon::On);
Kite 521c84
  } else {
Kite 521c84
    // If file doesn't exist, let's add an opaque normal pixmap
Kite 521c84
    icon.addPixmap(normalPm, QIcon::Normal, QIcon::On);
Kite 521c84
    icon.addPixmap(setOpacity(normalPm, disabledOpacity), QIcon::Disabled,
Kite 521c84
                   QIcon::On);
Kite 521c84
  }
Shinya Kitaoka 120a6e
  return icon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QIcon createQIconPNG(const char *iconPNGName) {
Shinya Kitaoka 120a6e
  QString normal = QString(":Resources/") + iconPNGName + ".png";
Shinya Kitaoka 120a6e
  QString click  = QString(":Resources/") + iconPNGName + "_click.png";
Shinya Kitaoka 120a6e
  QString over   = QString(":Resources/") + iconPNGName + "_over.png";
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QIcon icon;
Shinya Kitaoka 120a6e
  icon.addFile(normal, QSize(), QIcon::Normal, QIcon::Off);
Shinya Kitaoka 120a6e
  icon.addFile(click, QSize(), QIcon::Normal, QIcon::On);
Shinya Kitaoka 120a6e
  icon.addFile(over, QSize(), QIcon::Active);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return icon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QIcon createQIconOnOffPNG(const char *iconPNGName, bool withOver) {
Shinya Kitaoka 120a6e
  QString on   = QString(":Resources/") + iconPNGName + "_on.png";
Shinya Kitaoka 120a6e
  QString off  = QString(":Resources/") + iconPNGName + "_off.png";
Shinya Kitaoka 120a6e
  QString over = QString(":Resources/") + iconPNGName + "_over.png";
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QIcon icon;
Shinya Kitaoka 120a6e
  icon.addFile(off, QSize(), QIcon::Normal, QIcon::Off);
Shinya Kitaoka 120a6e
  icon.addFile(on, QSize(), QIcon::Normal, QIcon::On);
Shinya Kitaoka 120a6e
  if (withOver)
Shinya Kitaoka 120a6e
    icon.addFile(over, QSize(), QIcon::Active);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    icon.addFile(on, QSize(), QIcon::Active);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return icon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString toQString(const TFilePath &path) {
Shinya Kitaoka 120a6e
  return QString::fromStdWString(path.getWideString());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool isSpaceString(const QString &str) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  QString space(" ");
Shinya Kitaoka 120a6e
  for (i = 0; i < str.size(); i++)
Shinya Kitaoka 120a6e
    if (str.at(i) != space.at(0)) return false;
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool isValidFileName(const QString &fileName) {
Shinya Kitaoka 120a6e
  if (fileName.isEmpty() || fileName.contains(":") || fileName.contains("\\") ||
Shinya Kitaoka 120a6e
      fileName.contains("/") || fileName.contains(">") ||
Shinya Kitaoka 120a6e
      fileName.contains("<") || fileName.contains("*") ||
Shinya Kitaoka 120a6e
      fileName.contains("|") || fileName.contains("\"") ||
Shinya Kitaoka 120a6e
      fileName.contains("?") || fileName.trimmed().isEmpty())
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool isValidFileName_message(const QString &fileName) {
Shinya Kitaoka 120a6e
  return isValidFileName(fileName)
Shinya Kitaoka 120a6e
             ? true
Shinya Kitaoka 120a6e
             : (DVGui::error(
Shinya Kitaoka 120a6e
                    QObject::tr("The file name cannot be empty or contain any "
Shinya Kitaoka 120a6e
                                "of the following "
Shinya Kitaoka 120a6e
                                "characters: (new line) \\ / : * ? \" |")),
Shinya Kitaoka 120a6e
                false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
manongjohn 7f3150
bool isReservedFileName(const QString &fileName) {
manongjohn 7f3150
#ifdef _WIN32
manongjohn 7f3150
  std::vector<qstring> invalidNames{</qstring>
manongjohn 7f3150
      "AUX",  "CON",  "NUL",  "PRN",  "COM1", "COM2", "COM3", "COM4",
manongjohn 7f3150
      "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3",
manongjohn 7f3150
      "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"};
manongjohn 7f3150
manongjohn 7f3150
  if (std::find(invalidNames.begin(), invalidNames.end(), fileName) !=
manongjohn 7f3150
      invalidNames.end())
manongjohn 7f3150
    return true;
manongjohn 7f3150
#endif
manongjohn 7f3150
manongjohn 7f3150
  return false;
manongjohn 7f3150
}
manongjohn 7f3150
manongjohn 7f3150
//-----------------------------------------------------------------------------
manongjohn 7f3150
manongjohn 7f3150
bool isReservedFileName_message(const QString &fileName) {
manongjohn 7f3150
  return isReservedFileName(fileName)
manongjohn 7f3150
             ? (DVGui::error(QObject::tr(
manongjohn 7f3150
                    "That is a reserved file name and cannot be used.")),
manongjohn 7f3150
                true)
manongjohn 7f3150
             : false;
manongjohn 7f3150
}
manongjohn 7f3150
manongjohn 7f3150
//-----------------------------------------------------------------------------
manongjohn 7f3150
Shinya Kitaoka 120a6e
QString elideText(const QString &srcText, const QFont &font, int width) {
Shinya Kitaoka 120a6e
  QFontMetrics metrix(font);
Shinya Kitaoka 120a6e
  int srcWidth = metrix.width(srcText);
Shinya Kitaoka 120a6e
  if (srcWidth < width) return srcText;
Shinya Kitaoka 120a6e
  int tilde = metrix.width("~");
Shinya Kitaoka 120a6e
  int block = (width - tilde) / 2;
Shinya Kitaoka 120a6e
  QString text("");
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < srcText.size(); i++) {
Shinya Kitaoka 120a6e
    text += srcText.at(i);
Shinya Kitaoka 120a6e
    if (metrix.width(text) > block) break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  text[i] = '~';
Shinya Kitaoka 120a6e
  QString endText("");
Shinya Kitaoka 120a6e
  for (i = srcText.size() - 1; i >= 0; i--) {
Shinya Kitaoka 120a6e
    endText.push_front(srcText.at(i));
Shinya Kitaoka 120a6e
    if (metrix.width(endText) > block) break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  endText.remove(0, 1);
Shinya Kitaoka 120a6e
  text += endText;
Shinya Kitaoka 120a6e
  return text;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString elideText(const QString &srcText, const QFontMetrics &fm, int width,
Shinya Kitaoka 120a6e
                  const QString &elideSymbol) {
Shinya Kitaoka 120a6e
  QString text(srcText);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int i = text.size(); i > 1 && fm.width(text) > width;)
Shinya Kitaoka 120a6e
    text = srcText.left(--i).append(elideSymbol);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return text;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QUrl pathToUrl(const TFilePath &path) {
Shinya Kitaoka 120a6e
  return QUrl::fromLocalFile(QString::fromStdWString(path.getWideString()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool isResource(const QString &path) {
Shinya Kitaoka 120a6e
  const TFilePath fp(path.toStdWString());
Shinya Kitaoka 120a6e
  TFileType::Type type = TFileType::getInfo(fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return (TFileType::isViewable(type) || type & TFileType::MESH_IMAGE ||
Shinya Kitaoka 120a6e
          type == TFileType::AUDIO_LEVEL || type == TFileType::TABSCENE ||
Shinya Kitaoka 120a6e
          type == TFileType::TOONZSCENE || fp.getType() == "tpl");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool isResource(const QUrl &url) { return isResource(url.toLocalFile()); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool isResourceOrFolder(const QUrl &url) {
Shinya Kitaoka 120a6e
  struct locals {
Shinya Kitaoka 120a6e
    static inline bool isDir(const QString &path) {
Shinya Kitaoka 120a6e
      return QFileInfo(path).isDir();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  };  // locals
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const QString &path = url.toLocalFile();
Shinya Kitaoka 120a6e
  return (isResource(path) || locals::isDir(path));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool acceptResourceDrop(const QList<qurl> &urls) {</qurl>
Shinya Kitaoka 120a6e
  int count = 0;
otakuto dfe1cf
  for (const QUrl &url : urls) {
Shinya Kitaoka 120a6e
    if (isResource(url))
Shinya Kitaoka 120a6e
      ++count;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return (count > 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool acceptResourceOrFolderDrop(const QList<qurl> &urls) {</qurl>
Shinya Kitaoka 120a6e
  int count = 0;
otakuto dfe1cf
  for (const QUrl &url : urls) {
Shinya Kitaoka 120a6e
    if (isResourceOrFolder(url))
Shinya Kitaoka 120a6e
      ++count;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return (count > 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QPainterPath strokeToPainterPath(TStroke *stroke) {
Shinya Kitaoka 120a6e
  QPainterPath path;
Shinya Kitaoka 120a6e
  int i, chunkSize = stroke->getChunkCount();
Shinya Kitaoka 120a6e
  for (i = 0; i < chunkSize; i++) {
Shinya Kitaoka 120a6e
    const TThickQuadratic *q = stroke->getChunk(i);
Shinya Kitaoka 120a6e
    if (i == 0) path.moveTo(toQPointF(q->getThickP0()));
Shinya Kitaoka 120a6e
    path.quadTo(toQPointF(q->getThickP1()), toQPointF(q->getThickP2()));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return path;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TabBarContainter
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TabBarContainter::TabBarContainter(QWidget *parent) : QFrame(parent) {
Shinya Kitaoka 120a6e
  setObjectName("TabBarContainer");
Shinya Kitaoka 120a6e
  setFrameStyle(QFrame::StyledPanel);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TabBarContainter::paintEvent(QPaintEvent *event) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Jeremy Bullock 0f89c5
  p.setPen(getBottomAboveLineColor());
Shinya Kitaoka 120a6e
  p.drawLine(0, height() - 2, width(), height() - 2);
Jeremy Bullock 0f89c5
  p.setPen(getBottomBelowLineColor());
Shinya Kitaoka 120a6e
  p.drawLine(0, height() - 1, width(), height() - 1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// ToolBarContainer
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ToolBarContainer::ToolBarContainer(QWidget *parent) : QFrame(parent) {
Shinya Kitaoka 120a6e
  setObjectName("ToolBarContainer");
Shinya Kitaoka 120a6e
  setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Kite 521c84
void ToolBarContainer::paintEvent(QPaintEvent *event) { QPainter p(this); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString operator+(const QString &a, const TFilePath &fp) {
Shinya Kitaoka 120a6e
  return a + QString::fromStdWString(fp.getWideString());
Toshihiro Shimizu 890ddd
}