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>
shun-iwasawa f2e168
#include <qscreen></qscreen>
shun-iwasawa f2e168
#include <qwindow></qwindow>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
shun-iwasawa f2e168
namespace {
shun-iwasawa f2e168
inline bool hasScreensWithDifferentDevPixRatio() {
shun-iwasawa f2e168
  static bool ret     = false;
shun-iwasawa f2e168
  static bool checked = false;
shun-iwasawa f2e168
  if (!checked) {  // check once
shun-iwasawa f2e168
    int dpr = QApplication::desktop()->devicePixelRatio();
shun-iwasawa f2e168
    for (auto screen : QGuiApplication::screens()) {
shun-iwasawa f2e168
      if ((int)screen->devicePixelRatio() != dpr) {
shun-iwasawa f2e168
        ret = true;
shun-iwasawa f2e168
        break;
shun-iwasawa f2e168
      }
shun-iwasawa f2e168
    }
shun-iwasawa f2e168
    checked = true;
shun-iwasawa f2e168
  }
shun-iwasawa f2e168
  return ret;
shun-iwasawa f2e168
}
shun-iwasawa f2e168
shun-iwasawa f2e168
int getHighestDevicePixelRatio() {
shun-iwasawa f2e168
  static int highestDevPixRatio = 0;
shun-iwasawa f2e168
  if (highestDevPixRatio == 0) {
shun-iwasawa f2e168
    for (auto screen : QGuiApplication::screens())
shun-iwasawa f2e168
      highestDevPixRatio =
shun-iwasawa f2e168
          std::max(highestDevPixRatio, (int)screen->devicePixelRatio());
shun-iwasawa f2e168
  }
shun-iwasawa f2e168
  return highestDevPixRatio;
shun-iwasawa f2e168
}
shun-iwasawa f2e168
}  // namespace
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 f2e168
    pixmap.setDevicePixelRatio(getDevicePixelRatio());
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 f2e168
  static int devPixRatio = getHighestDevicePixelRatio();
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 f2e168
int getDevicePixelRatio(const QWidget *widget) {
shun-iwasawa f2e168
  if (hasScreensWithDifferentDevPixRatio() && widget) {
shun-iwasawa f2e168
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
shun-iwasawa f2e168
    return widget->screen()->devicePixelRatio();
shun-iwasawa f2e168
#else
shun-iwasawa f2e168
    if (!widget->windowHandle()) widget->winId();
shun-iwasawa f2e168
    if (widget->windowHandle())
shun-iwasawa f2e168
      return widget->windowHandle()->devicePixelRatio();
shun-iwasawa f2e168
#endif
shun-iwasawa f2e168
  }
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 c50ec4
QPixmap compositePixmap(QPixmap pixmap, const qreal &opacity, const QSize &size,
Kite c50ec4
                        const int leftAdj, const int topAdj, QColor bgColor) {
shun-iwasawa f2e168
  static int devPixRatio = getHighestDevicePixelRatio();
Kite 521c84
Kite c50ec4
  // Sets size of destination pixmap for source to be drawn onto, if size is
Kite c50ec4
  // empty use source pixmap size, else use custom size.
Kite c50ec4
  QPixmap destination(size.isEmpty() ? pixmap.size() : size * devPixRatio);
Kite c50ec4
  destination.setDevicePixelRatio(devPixRatio);
Kite c50ec4
  destination.fill(bgColor);
Kite 521c84
Kite 521c84
  if (!pixmap.isNull()) {
Kite c50ec4
    QPainter p(&destination);
Kite c50ec4
    pixmap = pixmap.scaled(pixmap.size(), Qt::KeepAspectRatio);
Kite c50ec4
    pixmap.setDevicePixelRatio(devPixRatio);
Kite 521c84
    p.setBackgroundMode(Qt::TransparentMode);
Kite 521c84
    p.setBackground(QBrush(Qt::transparent));
Kite c50ec4
    p.eraseRect(pixmap.rect());
Kite 521c84
    p.setOpacity(opacity);
Kite c50ec4
    p.drawPixmap(leftAdj, topAdj, pixmap);
Kite 521c84
  }
Kite c50ec4
  return destination;
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 52018c
  pixmap = QPixmap::fromImage(img);
Kite 52018c
  return pixmap;
Kite 52018c
}
Kite 52018c
Kite 52018c
//-----------------------------------------------------------------------------
Kite 52018c
shun-iwasawa de98cf
QIcon createQIcon(const char *iconSVGName, bool useFullOpacity,
shun-iwasawa de98cf
                  bool isForMenuItem) {
shun-iwasawa f2e168
  static int devPixRatio = getHighestDevicePixelRatio();
Kite 521c84
Kite 52018c
  QIcon themeIcon = QIcon::fromTheme(iconSVGName);
Kite c50ec4
Kite c50ec4
  // Get icon dimensions
Kite 52018c
  QSize iconSize(0, 0);
Kite 52018c
  for (QList<qsize> sizes = themeIcon.availableSizes(); !sizes.isEmpty();</qsize>
Kite 521c84
       sizes.removeFirst())
Kite c50ec4
    if (sizes.first().width() > iconSize.width())
Kite c50ec4
      iconSize = sizes.first() * devPixRatio;
Kite c50ec4
Kite c50ec4
  // Control lightness of the icons
Kite c50ec4
  const qreal activeOpacity   = 1;
Kite c50ec4
  const qreal baseOpacity     = useFullOpacity ? 1 : 0.8;
Kite c50ec4
  const qreal disabledOpacity = 0.15;
Kite c50ec4
luz paz 6454c4
  // Pseudo state name strings
Kite c50ec4
  QString overStr = QString(iconSVGName) + "_over";
Kite c50ec4
  QString onStr   = QString(iconSVGName) + "_on";
Kite c50ec4
Kite c50ec4
  //----------
Kite c50ec4
Kite c50ec4
  // Base pixmap
Kite c50ec4
  QPixmap themeIconPixmap(recolorPixmap(themeIcon.pixmap(iconSize)));
Kite c50ec4
  if (!themeIconPixmap.isNull()) {  // suppress message
Kite c50ec4
    themeIconPixmap.setDevicePixelRatio(devPixRatio);
Kite c50ec4
    themeIconPixmap = themeIconPixmap.scaled(iconSize, Qt::KeepAspectRatio,
Kite c50ec4
                                             Qt::SmoothTransformation);
Kite c50ec4
  }
Kite c50ec4
Kite c50ec4
  // Over pixmap
Kite c50ec4
  QPixmap overPixmap(recolorPixmap(QIcon::fromTheme(overStr).pixmap(iconSize)));
Kite c50ec4
  if (!overPixmap.isNull()) {  // suppress message
Kite c50ec4
    overPixmap.setDevicePixelRatio(devPixRatio);
Kite c50ec4
    overPixmap = overPixmap.scaled(iconSize, Qt::KeepAspectRatio,
Kite c50ec4
                                   Qt::SmoothTransformation);
Kite c50ec4
  }
Kite c50ec4
Kite c50ec4
  // On pixmap
Kite c50ec4
  QPixmap onPixmap(recolorPixmap(QIcon::fromTheme(onStr).pixmap(iconSize)));
Kite c50ec4
  if (!onPixmap.isNull()) {  // suppress message
Kite c50ec4
    onPixmap.setDevicePixelRatio(devPixRatio);
Kite c50ec4
    onPixmap = onPixmap.scaled(iconSize, Qt::KeepAspectRatio,
Kite c50ec4
                               Qt::SmoothTransformation);
Kite c50ec4
  }
Kite c50ec4
Kite c50ec4
  //----------
Kite c50ec4
Shinya Kitaoka 120a6e
  QIcon icon;
Toshihiro Shimizu 890ddd
shun-iwasawa bb8132
#ifdef _WIN32
shun-iwasawa bb8132
  bool showIconInMenu = Preferences::instance()->getBoolValue(showIconsInMenu);
shun-iwasawa bb8132
  // set transparent icon
shun-iwasawa de98cf
  if (isForMenuItem &&
shun-iwasawa de98cf
      themeIconPixmap.size() == QSize(16 * devPixRatio, 16 * devPixRatio) &&
shun-iwasawa bb8132
      !showIconInMenu) {
shun-iwasawa bb8132
    static QPixmap emptyPm(16 * devPixRatio, 16 * devPixRatio);
shun-iwasawa bb8132
    emptyPm.fill(Qt::transparent);
shun-iwasawa bb8132
shun-iwasawa bb8132
    icon.addPixmap(emptyPm, QIcon::Normal, QIcon::Off);
shun-iwasawa bb8132
    icon.addPixmap(emptyPm, QIcon::Normal, QIcon::On);
shun-iwasawa bb8132
    icon.addPixmap(emptyPm, QIcon::Disabled, QIcon::Off);
shun-iwasawa bb8132
    icon.addPixmap(emptyPm, QIcon::Disabled, QIcon::On);
shun-iwasawa bb8132
    icon.addPixmap(emptyPm, QIcon::Active);
shun-iwasawa bb8132
  } else
shun-iwasawa bb8132
#endif
shun-iwasawa bb8132
  {
shun-iwasawa bb8132
    // Base icon
shun-iwasawa bb8132
    icon.addPixmap(compositePixmap(themeIconPixmap, baseOpacity), QIcon::Normal,
shun-iwasawa bb8132
                   QIcon::Off);
Kite c50ec4
    icon.addPixmap(compositePixmap(themeIconPixmap, disabledOpacity),
shun-iwasawa bb8132
                   QIcon::Disabled, QIcon::Off);
shun-iwasawa bb8132
shun-iwasawa bb8132
    // Over icon
shun-iwasawa bb8132
    icon.addPixmap(!overPixmap.isNull()
shun-iwasawa bb8132
                       ? compositePixmap(overPixmap, activeOpacity)
shun-iwasawa bb8132
                       : compositePixmap(themeIconPixmap, activeOpacity),
shun-iwasawa bb8132
                   QIcon::Active);
shun-iwasawa bb8132
shun-iwasawa bb8132
    // On icon
shun-iwasawa bb8132
    if (!onPixmap.isNull()) {
shun-iwasawa bb8132
      icon.addPixmap(compositePixmap(onPixmap, activeOpacity), QIcon::Normal,
shun-iwasawa bb8132
                     QIcon::On);
shun-iwasawa bb8132
      icon.addPixmap(compositePixmap(onPixmap, disabledOpacity),
shun-iwasawa bb8132
                     QIcon::Disabled, QIcon::On);
shun-iwasawa bb8132
    } else {
shun-iwasawa bb8132
      icon.addPixmap(compositePixmap(themeIconPixmap, activeOpacity),
shun-iwasawa bb8132
                     QIcon::Normal, QIcon::On);
shun-iwasawa bb8132
      icon.addPixmap(compositePixmap(themeIconPixmap, disabledOpacity),
shun-iwasawa bb8132
                     QIcon::Disabled, QIcon::On);
shun-iwasawa bb8132
    }
Kite c50ec4
  }
Kite c50ec4
  //----------
Kite c50ec4
Kite c50ec4
  // For icons intended for menus that are 16x16 in dimensions, to repurpose
Kite c50ec4
  // them for use in toolbars that are set for 20x20 we want to draw them onto a
Kite c50ec4
  // 20x20 pixmap so they don't get resized in the GUI, they will be loaded into
Kite c50ec4
  // the icon along with the original 16x16 pixmap.
Kite c50ec4
Kite c50ec4
  if (themeIconPixmap.size() == QSize(16 * devPixRatio, 16 * devPixRatio)) {
Kite c50ec4
    const QSize drawOnSize(20, 20);
Kite c50ec4
    const int x = (drawOnSize.width() - 16) / 2;   // left adjust
Kite c50ec4
    const int y = (drawOnSize.height() - 16) / 2;  // top adjust
Kite c50ec4
Kite c50ec4
    // Base icon
Kite c50ec4
    icon.addPixmap(
Kite c50ec4
        compositePixmap(themeIconPixmap, baseOpacity, drawOnSize, x, y),
Kite c50ec4
        QIcon::Normal, QIcon::Off);
Kite c50ec4
    icon.addPixmap(
Kite c50ec4
        compositePixmap(themeIconPixmap, disabledOpacity, drawOnSize, x, y),
Kite c50ec4
        QIcon::Disabled, QIcon::Off);
Kite c50ec4
Kite c50ec4
    // Over icon
Kite 52018c
    icon.addPixmap(
Kite c50ec4
        !overPixmap.isNull()
Kite c50ec4
            ? compositePixmap(overPixmap, activeOpacity, drawOnSize, x, y)
Kite c50ec4
            : compositePixmap(themeIconPixmap, activeOpacity, drawOnSize, x, y),
Kite 52018c
        QIcon::Active);
Kite 52018c
Kite c50ec4
    // On icon
Kite 52018c
    if (!onPixmap.isNull()) {
Kite c50ec4
      icon.addPixmap(compositePixmap(onPixmap, activeOpacity, drawOnSize, x, y),
Kite c50ec4
                     QIcon::Normal, QIcon::On);
Kite 52018c
      icon.addPixmap(
Kite c50ec4
          compositePixmap(onPixmap, disabledOpacity, drawOnSize, x, y),
Kite c50ec4
          QIcon::Disabled, QIcon::On);
Kite 52018c
    } else {
Kite 52018c
      icon.addPixmap(
Kite c50ec4
          compositePixmap(themeIconPixmap, activeOpacity, drawOnSize, x, y),
Kite c50ec4
          QIcon::Normal, QIcon::On);
Kite c50ec4
      icon.addPixmap(
Kite c50ec4
          compositePixmap(themeIconPixmap, disabledOpacity, drawOnSize, x, y),
Kite c50ec4
          QIcon::Disabled, QIcon::On);
Kite 52018c
    }
Kite 521c84
  }
Kite c50ec4
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
shun-iwasawa 75b9b0
QIcon createTemporaryIconFromName(const char *commandName) {
Kite 949afd
  const int visibleIconSize   = 20;
Kite 949afd
  const int menubarIconSize   = 16;
Kite c50ec4
  const qreal activeOpacity   = 1;
Kite c50ec4
  const qreal baseOpacity     = 0.8;
Kite 949afd
  const qreal disabledOpacity = 0.15;
shun-iwasawa 75b9b0
  QString name(commandName);
shun-iwasawa 75b9b0
  QList<qchar> iconChar;</qchar>
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
  for (int i = 0; i < name.length(); i++) {
shun-iwasawa 75b9b0
    QChar c = name.at(i);
shun-iwasawa 75b9b0
    if (c.isUpper() && iconChar.size() < 2)
shun-iwasawa 75b9b0
      iconChar.append(c);
shun-iwasawa 75b9b0
    else if (c.isDigit()) {
shun-iwasawa 75b9b0
      if (iconChar.isEmpty())
shun-iwasawa 75b9b0
        iconChar.append(c);
shun-iwasawa 75b9b0
      else if (iconChar.size() <= 2) {
shun-iwasawa 75b9b0
        if (iconChar.size() == 2) iconChar.removeLast();
shun-iwasawa 75b9b0
        iconChar.append(c);
shun-iwasawa 75b9b0
        break;
shun-iwasawa 75b9b0
      }
shun-iwasawa 75b9b0
    }
shun-iwasawa 75b9b0
  }
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
  if (iconChar.isEmpty()) iconChar.append(name.at(0));
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
  QString iconStr;
shun-iwasawa 75b9b0
  for (auto c : iconChar) iconStr.append(c);
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
  QIcon icon;
shun-iwasawa 75b9b0
  // prepare for both normal and high dpi
shun-iwasawa 75b9b0
  for (int devPixelRatio = 1; devPixelRatio <= 2; devPixelRatio++) {
shun-iwasawa 75b9b0
    QPixmap transparentPm(menubarIconSize * devPixelRatio,
shun-iwasawa 75b9b0
                          menubarIconSize * devPixelRatio);
shun-iwasawa 75b9b0
    transparentPm.fill(Qt::transparent);
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
    int pxSize = visibleIconSize * devPixelRatio;
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
    QPixmap pixmap(pxSize, pxSize);
shun-iwasawa 75b9b0
    QPainter painter;
shun-iwasawa 75b9b0
    pixmap.fill(Qt::transparent);
shun-iwasawa 75b9b0
    painter.begin(&pixmap);
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
    painter.setPen(Preferences::instance()->getIconTheme() ? Qt::black
shun-iwasawa 75b9b0
                                                           : Qt::white);
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
    QRect rect(0, -2, pxSize, pxSize);
shun-iwasawa 75b9b0
    if (iconStr.size() == 2) {
shun-iwasawa 75b9b0
      painter.scale(0.6, 1.0);
shun-iwasawa 75b9b0
      rect.setRight(pxSize / 0.6);
shun-iwasawa 75b9b0
    }
shun-iwasawa 75b9b0
    QFont font = painter.font();
shun-iwasawa 75b9b0
    font.setPixelSize(pxSize);
shun-iwasawa 75b9b0
    painter.setFont(font);
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
    painter.drawText(rect, Qt::AlignCenter, iconStr);
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
    painter.end();
shun-iwasawa 75b9b0
Kite c50ec4
    // For menu only
Kite 02f89b
    icon.addPixmap(transparentPm, QIcon::Normal, QIcon::Off);
Kite 02f89b
    icon.addPixmap(transparentPm, QIcon::Active);
Kite 02f89b
    icon.addPixmap(transparentPm, QIcon::Normal, QIcon::On);
Kite c50ec4
    icon.addPixmap(transparentPm, QIcon::Disabled, QIcon::Off);
Kite c50ec4
    icon.addPixmap(transparentPm, QIcon::Disabled, QIcon::On);
Kite c50ec4
Kite c50ec4
    // For toolbars
Kite c50ec4
    icon.addPixmap(compositePixmap(pixmap, baseOpacity), QIcon::Normal,
Kite c50ec4
                   QIcon::Off);
Kite c50ec4
    icon.addPixmap(compositePixmap(pixmap, disabledOpacity), QIcon::Disabled,
Kite c50ec4
                   QIcon::Off);
Kite c50ec4
    icon.addPixmap(compositePixmap(pixmap, activeOpacity), QIcon::Active);
Kite c50ec4
    icon.addPixmap(compositePixmap(pixmap, activeOpacity), QIcon::Normal,
Kite c50ec4
                   QIcon::On);
Kite c50ec4
    icon.addPixmap(compositePixmap(pixmap, disabledOpacity), QIcon::Disabled,
Kite c50ec4
                   QIcon::On);
shun-iwasawa 75b9b0
  }
shun-iwasawa 75b9b0
  return icon;
shun-iwasawa 75b9b0
}
shun-iwasawa 75b9b0
shun-iwasawa 75b9b0
//-----------------------------------------------------------------------------
shun-iwasawa 75b9b0
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
}