|
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>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace DVGui;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QString fileSizeString(qint64 size, int precision)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (size < 1024)
|
|
Toshihiro Shimizu |
890ddd |
return QString::number(size) + " Bytes";
|
|
Toshihiro Shimizu |
890ddd |
else if (size < 1024 * 1024)
|
|
Toshihiro Shimizu |
890ddd |
return QString::number(size / (1024.0), 'f', precision) + " KB";
|
|
Toshihiro Shimizu |
890ddd |
else if (size < 1024 * 1024 * 1024)
|
|
Toshihiro Shimizu |
890ddd |
return QString::number(size / (1024 * 1024.0), 'f', precision) + " MB";
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return QString::number(size / (1024 * 1024 * 1024.0), 'f', precision) + " GB";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QImage rasterToQImage(const TRasterP &ras, bool premultiplied, bool mirrored)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (TRaster32P ras32 = ras) {
|
|
Toshihiro Shimizu |
890ddd |
QImage image(ras->getRawData(), ras->getLx(), ras->getLy(),
|
|
Toshihiro Shimizu |
890ddd |
premultiplied ? QImage::Format_ARGB32_Premultiplied : QImage::Format_ARGB32);
|
|
Toshihiro Shimizu |
890ddd |
if (mirrored)
|
|
Toshihiro Shimizu |
890ddd |
return image.mirrored();
|
|
Toshihiro Shimizu |
890ddd |
return image;
|
|
Toshihiro Shimizu |
890ddd |
} else if (TRasterGR8P ras8 = ras) {
|
|
Toshihiro Shimizu |
890ddd |
QImage image(ras->getRawData(), ras->getLx(), ras->getLy(), ras->getWrap(), QImage::Format_Indexed8);
|
|
Toshihiro Shimizu |
890ddd |
static QVector<qrgb> colorTable;</qrgb>
|
|
Toshihiro Shimizu |
890ddd |
if (colorTable.size() == 0) {
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < 256; i++)
|
|
Toshihiro Shimizu |
890ddd |
colorTable.append(QColor(i, i, i).rgb());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
image.setColorTable(colorTable);
|
|
Toshihiro Shimizu |
890ddd |
if (mirrored)
|
|
Toshihiro Shimizu |
890ddd |
return image.mirrored();
|
|
Toshihiro Shimizu |
890ddd |
return image;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return QImage();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QPixmap rasterToQPixmap(const TRaster32P &ras, bool premultiplied)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QPixmap pixmap;
|
|
Toshihiro Shimizu |
890ddd |
return pixmap.fromImage(rasterToQImage(ras, premultiplied));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P rasterFromQImage(QImage image, bool premultiply, bool mirror) //no need of const& - Qt uses implicit sharing...
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QImage copyImage = mirror ? image.mirrored() : image;
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P ras(image.width(), image.height(), image.width(), (TPixelRGBM32 *)copyImage.bits(), false);
|
|
Toshihiro Shimizu |
890ddd |
if (premultiply)
|
|
Toshihiro Shimizu |
890ddd |
TRop::premultiply(ras);
|
|
Toshihiro Shimizu |
890ddd |
return ras->clone();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P rasterFromQPixmap(QPixmap pixmap, bool premultiply, bool mirror) //no need of const& - Qt uses implicit sharing...
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QImage image = pixmap.toImage();
|
|
Toshihiro Shimizu |
890ddd |
return rasterFromQImage(image, premultiply, mirror);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void drawPolygon(QPainter &p,
|
|
Toshihiro Shimizu |
890ddd |
const std::vector<qpointf> &points,</qpointf>
|
|
Toshihiro Shimizu |
890ddd |
bool fill,
|
|
Toshihiro Shimizu |
890ddd |
const QColor colorFill,
|
|
Toshihiro Shimizu |
890ddd |
const QColor colorLine)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (points.size() == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
p.setPen(colorLine);
|
|
Toshihiro Shimizu |
890ddd |
QPolygonF E0Polygon;
|
|
Toshihiro Shimizu |
890ddd |
int i = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < (int)points.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
E0Polygon << QPointF(points[i]);
|
|
Toshihiro Shimizu |
890ddd |
E0Polygon << QPointF(points[0]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QPainterPath E0Path;
|
|
Toshihiro Shimizu |
890ddd |
E0Path.addPolygon(E0Polygon);
|
|
Toshihiro Shimizu |
890ddd |
if (fill)
|
|
Toshihiro Shimizu |
890ddd |
p.fillPath(E0Path, QBrush(colorFill));
|
|
Toshihiro Shimizu |
890ddd |
p.drawPath(E0Path);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void drawArrow(QPainter &p,
|
|
Toshihiro Shimizu |
890ddd |
const QPointF a, const QPointF b, const QPointF c,
|
|
Toshihiro Shimizu |
890ddd |
bool fill,
|
|
Toshihiro Shimizu |
890ddd |
const QColor colorFill,
|
|
Toshihiro Shimizu |
890ddd |
const QColor colorLine)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::vector<qpointf> pts;</qpointf>
|
|
Toshihiro Shimizu |
890ddd |
pts.push_back(a);
|
|
Toshihiro Shimizu |
890ddd |
pts.push_back(b);
|
|
Toshihiro Shimizu |
890ddd |
pts.push_back(c);
|
|
Toshihiro Shimizu |
890ddd |
drawPolygon(p, pts, fill, colorFill, colorLine);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QPixmap scalePixmapKeepingAspectRatio(QPixmap pixmap, QSize size, QColor color)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (pixmap.isNull() || pixmap.size() == size)
|
|
Toshihiro Shimizu |
890ddd |
return pixmap;
|
|
Toshihiro Shimizu |
890ddd |
QPixmap scaledPixmap = pixmap.scaled(size.width(), size.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
Toshihiro Shimizu |
890ddd |
QPixmap newPixmap(size);
|
|
Toshihiro Shimizu |
890ddd |
newPixmap.fill(color);
|
|
Toshihiro Shimizu |
890ddd |
QPainter painter(&newPixmap);
|
|
Toshihiro Shimizu |
890ddd |
painter.drawPixmap(double(size.width() - scaledPixmap.width()) * 0.5,
|
|
Toshihiro Shimizu |
890ddd |
double(size.height() - scaledPixmap.height()) * 0.5,
|
|
Toshihiro Shimizu |
890ddd |
scaledPixmap);
|
|
Toshihiro Shimizu |
890ddd |
return newPixmap;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QIcon createQIcon(const char *iconSVGName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString normal = QString(":Resources/") + iconSVGName + ".svg";
|
|
Toshihiro Shimizu |
890ddd |
QString click = QString(":Resources/") + iconSVGName + "_click.svg";
|
|
Toshihiro Shimizu |
890ddd |
QString over = QString(":Resources/") + iconSVGName + "_over.svg";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QIcon icon;
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(normal, QSize(), QIcon::Normal, QIcon::Off);
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(click, QSize(), QIcon::Normal, QIcon::On);
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(over, QSize(), QIcon::Active);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return icon;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QIcon createQIconPNG(const char *iconPNGName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString normal = QString(":Resources/") + iconPNGName + ".png";
|
|
Toshihiro Shimizu |
890ddd |
QString click = QString(":Resources/") + iconPNGName + "_click.png";
|
|
Toshihiro Shimizu |
890ddd |
QString over = QString(":Resources/") + iconPNGName + "_over.png";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QIcon icon;
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(normal, QSize(), QIcon::Normal, QIcon::Off);
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(click, QSize(), QIcon::Normal, QIcon::On);
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(over, QSize(), QIcon::Active);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return icon;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QIcon createQIconOnOff(const char *iconSVGName, bool withOver)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString on = QString(":Resources/") + iconSVGName + "_on.svg";
|
|
Toshihiro Shimizu |
890ddd |
QString off = QString(":Resources/") + iconSVGName + "_off.svg";
|
|
Toshihiro Shimizu |
890ddd |
QString over = QString(":Resources/") + iconSVGName + "_over.svg";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QIcon icon;
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(off, QSize(), QIcon::Normal, QIcon::Off);
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(on, QSize(), QIcon::Normal, QIcon::On);
|
|
Toshihiro Shimizu |
890ddd |
if (withOver)
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(over, QSize(), QIcon::Active);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(on, QSize(), QIcon::Active);
|
|
Toshihiro Shimizu |
890ddd |
return icon;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QIcon createQIconOnOffPNG(const char *iconPNGName, bool withOver)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString on = QString(":Resources/") + iconPNGName + "_on.png";
|
|
Toshihiro Shimizu |
890ddd |
QString off = QString(":Resources/") + iconPNGName + "_off.png";
|
|
Toshihiro Shimizu |
890ddd |
QString over = QString(":Resources/") + iconPNGName + "_over.png";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QIcon icon;
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(off, QSize(), QIcon::Normal, QIcon::Off);
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(on, QSize(), QIcon::Normal, QIcon::On);
|
|
Toshihiro Shimizu |
890ddd |
if (withOver)
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(over, QSize(), QIcon::Active);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
icon.addFile(on, QSize(), QIcon::Active);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return icon;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QString toQString(const TFilePath &path)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return QString::fromStdWString(path.getWideString());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isSpaceString(const QString &str)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
QString space(" ");
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < str.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
if (str.at(i) != space.at(0))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isValidFileName(const QString &fileName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (fileName.isEmpty() ||
|
|
Toshihiro Shimizu |
890ddd |
fileName.contains(":") ||
|
|
Toshihiro Shimizu |
890ddd |
fileName.contains("\\") ||
|
|
Toshihiro Shimizu |
890ddd |
fileName.contains("/") ||
|
|
Toshihiro Shimizu |
890ddd |
fileName.contains(">") ||
|
|
Toshihiro Shimizu |
890ddd |
fileName.contains("<") ||
|
|
Toshihiro Shimizu |
890ddd |
fileName.contains("*") ||
|
|
Toshihiro Shimizu |
890ddd |
fileName.contains("|") ||
|
|
Toshihiro Shimizu |
890ddd |
fileName.contains("\"") ||
|
|
Toshihiro Shimizu |
890ddd |
fileName.contains("?") ||
|
|
Toshihiro Shimizu |
890ddd |
fileName.trimmed().isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isValidFileName_message(const QString &fileName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
eabf18 |
return isValidFileName(fileName) ? true : (DVGui::error(QObject::tr("The file name cannot be empty or contain any of the following "
|
|
Toshihiro Shimizu |
890ddd |
"characters: (new line) \\ / : * ? \" |")),
|
|
Toshihiro Shimizu |
890ddd |
false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QString elideText(const QString &srcText, const QFont &font, int width)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QFontMetrics metrix(font);
|
|
Toshihiro Shimizu |
890ddd |
int srcWidth = metrix.width(srcText);
|
|
Toshihiro Shimizu |
890ddd |
if (srcWidth < width)
|
|
Toshihiro Shimizu |
890ddd |
return srcText;
|
|
Toshihiro Shimizu |
890ddd |
int tilde = metrix.width("~");
|
|
Toshihiro Shimizu |
890ddd |
int block = (width - tilde) / 2;
|
|
Toshihiro Shimizu |
890ddd |
QString text("");
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < srcText.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
text += srcText.at(i);
|
|
Toshihiro Shimizu |
890ddd |
if (metrix.width(text) > block)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
text[i] = '~';
|
|
Toshihiro Shimizu |
890ddd |
QString endText("");
|
|
Toshihiro Shimizu |
890ddd |
for (i = srcText.size() - 1; i >= 0; i--) {
|
|
Toshihiro Shimizu |
890ddd |
endText.push_front(srcText.at(i));
|
|
Toshihiro Shimizu |
890ddd |
if (metrix.width(endText) > block)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
endText.remove(0, 1);
|
|
Toshihiro Shimizu |
890ddd |
text += endText;
|
|
Toshihiro Shimizu |
890ddd |
return text;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QString elideText(const QString &srcText, const QFontMetrics &fm, int width, const QString &elideSymbol)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString text(srcText);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = text.size(); i > 1 && fm.width(text) > width;)
|
|
Toshihiro Shimizu |
890ddd |
text = srcText.left(--i).append(elideSymbol);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return text;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QUrl pathToUrl(const TFilePath &path)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return QUrl::fromLocalFile(QString::fromStdWString(path.getWideString()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isResource(const QString &path)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const TFilePath fp(path.toStdWString());
|
|
Toshihiro Shimizu |
890ddd |
TFileType::Type type = TFileType::getInfo(fp);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (TFileType::isViewable(type) || type & TFileType::MESH_IMAGE || type == TFileType::AUDIO_LEVEL || type == TFileType::TABSCENE || type == TFileType::TOONZSCENE || fp.getType() == "tpl");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isResource(const QUrl &url)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return isResource(url.toLocalFile());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isResourceOrFolder(const QUrl &url)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
struct locals {
|
|
Toshihiro Shimizu |
890ddd |
static inline bool isDir(const QString &path)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return QFileInfo(path).isDir();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}; // locals
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const QString &path = url.toLocalFile();
|
|
Toshihiro Shimizu |
890ddd |
return (isResource(path) || locals::isDir(path));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool acceptResourceDrop(const QList<qurl> &urls)</qurl>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int count = 0;
|
|
Toshihiro Shimizu |
890ddd |
foreach (const QUrl &url, urls) {
|
|
Toshihiro Shimizu |
890ddd |
if (isResource(url))
|
|
Toshihiro Shimizu |
890ddd |
++count;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (count > 0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool acceptResourceOrFolderDrop(const QList<qurl> &urls)</qurl>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int count = 0;
|
|
Toshihiro Shimizu |
890ddd |
foreach (const QUrl &url, urls) {
|
|
Toshihiro Shimizu |
890ddd |
if (isResourceOrFolder(url))
|
|
Toshihiro Shimizu |
890ddd |
++count;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (count > 0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QPainterPath strokeToPainterPath(TStroke *stroke)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QPainterPath path;
|
|
Toshihiro Shimizu |
890ddd |
int i, chunkSize = stroke->getChunkCount();
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < chunkSize; i++) {
|
|
Toshihiro Shimizu |
890ddd |
const TThickQuadratic *q = stroke->getChunk(i);
|
|
Toshihiro Shimizu |
890ddd |
if (i == 0)
|
|
Toshihiro Shimizu |
890ddd |
path.moveTo(toQPointF(q->getThickP0()));
|
|
Toshihiro Shimizu |
890ddd |
path.quadTo(toQPointF(q->getThickP1()), toQPointF(q->getThickP2()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return path;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// TabBarContainter
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TabBarContainter::TabBarContainter(QWidget *parent)
|
|
Toshihiro Shimizu |
890ddd |
: QFrame(parent)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
setObjectName("TabBarContainer");
|
|
Toshihiro Shimizu |
890ddd |
setFrameStyle(QFrame::StyledPanel);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TabBarContainter::paintEvent(QPaintEvent *event)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QPainter p(this);
|
|
Toshihiro Shimizu |
890ddd |
p.setPen(QColor(120, 120, 120));
|
|
Toshihiro Shimizu |
890ddd |
p.drawLine(0, height() - 2, width(), height() - 2);
|
|
Toshihiro Shimizu |
890ddd |
p.setPen(Qt::white);
|
|
Toshihiro Shimizu |
890ddd |
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 |
|
|
Toshihiro Shimizu |
890ddd |
ToolBarContainer::ToolBarContainer(QWidget *parent)
|
|
Toshihiro Shimizu |
890ddd |
: QFrame(parent)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
setObjectName("ToolBarContainer");
|
|
Toshihiro Shimizu |
890ddd |
setFrameStyle(QFrame::StyledPanel);
|
|
Toshihiro Shimizu |
890ddd |
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void ToolBarContainer::paintEvent(QPaintEvent *event)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QPainter p(this);
|
|
Toshihiro Shimizu |
890ddd |
p.setPen(QColor(120, 120, 120));
|
|
Toshihiro Shimizu |
890ddd |
p.drawLine(0, 0, width(), 0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QString operator+(const QString &a, const TFilePath &fp)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return a + QString::fromStdWString(fp.getWideString());
|
|
Toshihiro Shimizu |
890ddd |
}
|