|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/gutil.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 |
3cc41f |
static int devPixRatio = QApplication::desktop()->devicePixelRatio();
|
|
shun_iwasawa |
3cc41f |
pixmap.setDevicePixelRatio(devPixRatio);
|
|
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 |
3cc41f |
static int devPixRatio = QApplication::desktop()->devicePixelRatio();
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
QIcon createQIcon(const char *iconSVGName) {
|
|
Shinya Kitaoka |
120a6e |
QString normal = QString(":Resources/") + iconSVGName + ".svg";
|
|
Shinya Kitaoka |
120a6e |
QString click = QString(":Resources/") + iconSVGName + "_click.svg";
|
|
Shinya Kitaoka |
120a6e |
QString over = QString(":Resources/") + iconSVGName + "_over.svg";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QIcon icon;
|
|
Shinya Kitaoka |
120a6e |
icon.addFile(normal, QSize(), QIcon::Normal, QIcon::Off);
|
|
shun_iwasawa |
3cc41f |
if (QFile::exists(click))
|
|
shun_iwasawa |
3cc41f |
icon.addFile(click, QSize(), QIcon::Normal, QIcon::On);
|
|
shun_iwasawa |
3cc41f |
else
|
|
shun_iwasawa |
3cc41f |
icon.addFile(normal, QSize(), QIcon::Normal, QIcon::On);
|
|
shun_iwasawa |
3cc41f |
if (QFile::exists(over))
|
|
shun_iwasawa |
3cc41f |
icon.addFile(over, QSize(), QIcon::Active);
|
|
shun_iwasawa |
3cc41f |
else
|
|
shun_iwasawa |
3cc41f |
icon.addFile(normal, 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 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 createQIconOnOff(const char *iconSVGName, bool withOver) {
|
|
Shinya Kitaoka |
120a6e |
QString on = QString(":Resources/") + iconSVGName + "_on.svg";
|
|
Shinya Kitaoka |
120a6e |
QString off = QString(":Resources/") + iconSVGName + "_off.svg";
|
|
Shinya Kitaoka |
120a6e |
QString over = QString(":Resources/") + iconSVGName + "_over.svg";
|
|
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 |
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 |
|
|
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;
|
|
Shinya Kitaoka |
120a6e |
foreach (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;
|
|
Shinya Kitaoka |
120a6e |
foreach (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 |
setFrameStyle(QFrame::StyledPanel);
|
|
Shinya Kitaoka |
120a6e |
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ToolBarContainer::paintEvent(QPaintEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
QPainter p(this);
|
|
Shinya Kitaoka |
120a6e |
p.setPen(QColor(120, 120, 120));
|
|
Shinya Kitaoka |
120a6e |
p.drawLine(0, 0, width(), 0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
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 |
}
|