|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/gutil.h"
|
|
Kite |
521c84 |
#include "toonz/preferences.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzQt includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/dvdialog.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "traster.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfilepath.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfiletype.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstroke.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcurves.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tmsgcore.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qpixmap></qpixmap>
|
|
Toshihiro Shimizu |
890ddd |
#include <qimage></qimage>
|
|
Toshihiro Shimizu |
890ddd |
#include <qpainter></qpainter>
|
|
Toshihiro Shimizu |
890ddd |
#include <qpainterpath></qpainterpath>
|
|
Toshihiro Shimizu |
890ddd |
#include <qicon></qicon>
|
|
Toshihiro Shimizu |
890ddd |
#include <qstring></qstring>
|
|
Toshihiro Shimizu |
890ddd |
#include <qapplication></qapplication>
|
|
Toshihiro Shimizu |
890ddd |
#include <qmouseevent></qmouseevent>
|
|
Toshihiro Shimizu |
890ddd |
#include <qtabletevent></qtabletevent>
|
|
Toshihiro Shimizu |
890ddd |
#include <qkeyevent></qkeyevent>
|
|
Toshihiro Shimizu |
890ddd |
#include <qurl></qurl>
|
|
Toshihiro Shimizu |
890ddd |
#include <qfileinfo></qfileinfo>
|
|
shun_iwasawa |
3cc41f |
#include <qdesktopwidget></qdesktopwidget>
|
|
shun_iwasawa |
3cc41f |
#include <qsvgrenderer></qsvgrenderer>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace DVGui;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QString fileSizeString(qint64 size, int precision) {
|
|
Shinya Kitaoka |
120a6e |
if (size < 1024)
|
|
Shinya Kitaoka |
120a6e |
return QString::number(size) + " Bytes";
|
|
Shinya Kitaoka |
120a6e |
else if (size < 1024 * 1024)
|
|
Shinya Kitaoka |
120a6e |
return QString::number(size / (1024.0), 'f', precision) + " KB";
|
|
Shinya Kitaoka |
120a6e |
else if (size < 1024 * 1024 * 1024)
|
|
Shinya Kitaoka |
120a6e |
return QString::number(size / (1024 * 1024.0), 'f', precision) + " MB";
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return QString::number(size / (1024 * 1024 * 1024.0), 'f', precision) +
|
|
Shinya Kitaoka |
120a6e |
" GB";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QImage rasterToQImage(const TRasterP &ras, bool premultiplied, bool mirrored) {
|
|
Shinya Kitaoka |
120a6e |
if (TRaster32P ras32 = ras) {
|
|
Shinya Kitaoka |
120a6e |
QImage image(ras->getRawData(), ras->getLx(), ras->getLy(),
|
|
Shinya Kitaoka |
120a6e |
premultiplied ? QImage::Format_ARGB32_Premultiplied
|
|
Shinya Kitaoka |
120a6e |
: QImage::Format_ARGB32);
|
|
Shinya Kitaoka |
120a6e |
if (mirrored) return image.mirrored();
|
|
Shinya Kitaoka |
120a6e |
return image;
|
|
Shinya Kitaoka |
120a6e |
} else if (TRasterGR8P ras8 = ras) {
|
|
Shinya Kitaoka |
120a6e |
QImage image(ras->getRawData(), ras->getLx(), ras->getLy(), ras->getWrap(),
|
|
Shinya Kitaoka |
120a6e |
QImage::Format_Indexed8);
|
|
Shinya Kitaoka |
120a6e |
static QVector<qrgb> colorTable;</qrgb>
|
|
Shinya Kitaoka |
120a6e |
if (colorTable.size() == 0) {
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < 256; i++) colorTable.append(QColor(i, i, i).rgb());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
image.setColorTable(colorTable);
|
|
Shinya Kitaoka |
120a6e |
if (mirrored) return image.mirrored();
|
|
Shinya Kitaoka |
120a6e |
return image;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return QImage();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
3cc41f |
QPixmap rasterToQPixmap(const TRaster32P &ras, bool premultiplied,
|
|
shun_iwasawa |
3cc41f |
bool setDevPixRatio) {
|
|
shun_iwasawa |
3cc41f |
QPixmap pixmap = QPixmap::fromImage(rasterToQImage(ras, premultiplied));
|
|
shun_iwasawa |
3cc41f |
if (setDevPixRatio) {
|
|
shun_iwasawa |
1c961d |
pixmap.setDevicePixelRatio(getDevPixRatio());
|
|
shun_iwasawa |
3cc41f |
}
|
|
shun_iwasawa |
3cc41f |
return pixmap;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRaster32P rasterFromQImage(
|
|
Shinya Kitaoka |
120a6e |
QImage image, bool premultiply,
|
|
Shinya Kitaoka |
120a6e |
bool mirror) // no need of const& - Qt uses implicit sharing...
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
QImage copyImage = mirror ? image.mirrored() : image;
|
|
Shinya Kitaoka |
120a6e |
TRaster32P ras(image.width(), image.height(), image.width(),
|
|
Shinya Kitaoka |
120a6e |
(TPixelRGBM32 *)copyImage.bits(), false);
|
|
Shinya Kitaoka |
120a6e |
if (premultiply) TRop::premultiply(ras);
|
|
Shinya Kitaoka |
120a6e |
return ras->clone();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRaster32P rasterFromQPixmap(
|
|
Shinya Kitaoka |
120a6e |
QPixmap pixmap, bool premultiply,
|
|
Shinya Kitaoka |
120a6e |
bool mirror) // no need of const& - Qt uses implicit sharing...
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
QImage image = pixmap.toImage();
|
|
Shinya Kitaoka |
120a6e |
return rasterFromQImage(image, premultiply, mirror);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void drawPolygon(QPainter &p, const std::vector<qpointf> &points, bool fill,</qpointf>
|
|
Shinya Kitaoka |
120a6e |
const QColor colorFill, const QColor colorLine) {
|
|
Shinya Kitaoka |
120a6e |
if (points.size() == 0) return;
|
|
Shinya Kitaoka |
120a6e |
p.setPen(colorLine);
|
|
Shinya Kitaoka |
120a6e |
QPolygonF E0Polygon;
|
|
Shinya Kitaoka |
120a6e |
int i = 0;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)points.size(); i++) E0Polygon << QPointF(points[i]);
|
|
Shinya Kitaoka |
120a6e |
E0Polygon << QPointF(points[0]);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QPainterPath E0Path;
|
|
Shinya Kitaoka |
120a6e |
E0Path.addPolygon(E0Polygon);
|
|
Shinya Kitaoka |
120a6e |
if (fill) p.fillPath(E0Path, QBrush(colorFill));
|
|
Shinya Kitaoka |
120a6e |
p.drawPath(E0Path);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void drawArrow(QPainter &p, const QPointF a, const QPointF b, const QPointF c,
|
|
Shinya Kitaoka |
120a6e |
bool fill, const QColor colorFill, const QColor colorLine) {
|
|
Shinya Kitaoka |
120a6e |
std::vector<qpointf> pts;</qpointf>
|
|
Shinya Kitaoka |
120a6e |
pts.push_back(a);
|
|
Shinya Kitaoka |
120a6e |
pts.push_back(b);
|
|
Shinya Kitaoka |
120a6e |
pts.push_back(c);
|
|
Shinya Kitaoka |
120a6e |
drawPolygon(p, pts, fill, colorFill, colorLine);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QPixmap scalePixmapKeepingAspectRatio(QPixmap pixmap, QSize size,
|
|
Shinya Kitaoka |
120a6e |
QColor color) {
|
|
shun_iwasawa |
3cc41f |
if (pixmap.isNull()) return pixmap;
|
|
shun_iwasawa |
3cc41f |
if (pixmap.devicePixelRatio() > 1.0) size *= pixmap.devicePixelRatio();
|
|
shun_iwasawa |
3cc41f |
if (pixmap.size() == size) return pixmap;
|
|
Shinya Kitaoka |
120a6e |
QPixmap scaledPixmap =
|
|
Shinya Kitaoka |
120a6e |
pixmap.scaled(size.width(), size.height(), Qt::KeepAspectRatio,
|
|
Shinya Kitaoka |
120a6e |
Qt::SmoothTransformation);
|
|
Shinya Kitaoka |
120a6e |
QPixmap newPixmap(size);
|
|
Shinya Kitaoka |
120a6e |
newPixmap.fill(color);
|
|
Shinya Kitaoka |
120a6e |
QPainter painter(&newPixmap);
|
|
Shinya Kitaoka |
120a6e |
painter.drawPixmap(double(size.width() - scaledPixmap.width()) * 0.5,
|
|
Shinya Kitaoka |
120a6e |
double(size.height() - scaledPixmap.height()) * 0.5,
|
|
Shinya Kitaoka |
120a6e |
scaledPixmap);
|
|
shun_iwasawa |
3cc41f |
newPixmap.setDevicePixelRatio(pixmap.devicePixelRatio());
|
|
Shinya Kitaoka |
120a6e |
return newPixmap;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
3cc41f |
QPixmap svgToPixmap(const QString &svgFilePath, const QSize &size,
|
|
shun_iwasawa |
3cc41f |
Qt::AspectRatioMode aspectRatioMode, QColor bgColor) {
|
|
shun_iwasawa |
1c961d |
static int devPixRatio = getDevPixRatio();
|
|
shun_iwasawa |
3cc41f |
QSvgRenderer svgRenderer(svgFilePath);
|
|
shun_iwasawa |
3cc41f |
QSize pixmapSize;
|
|
shun_iwasawa |
3cc41f |
QRectF renderRect;
|
|
shun_iwasawa |
3cc41f |
if (size.isEmpty()) {
|
|
shun_iwasawa |
3cc41f |
pixmapSize = svgRenderer.defaultSize() * devPixRatio;
|
|
shun_iwasawa |
3cc41f |
renderRect = QRectF(QPointF(), QSizeF(pixmapSize));
|
|
shun_iwasawa |
3cc41f |
} else {
|
|
shun_iwasawa |
3cc41f |
pixmapSize = size * devPixRatio;
|
|
shun_iwasawa |
3cc41f |
if (aspectRatioMode == Qt::KeepAspectRatio ||
|
|
shun_iwasawa |
3cc41f |
aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
|
|
shun_iwasawa |
3cc41f |
QSize imgSize = svgRenderer.defaultSize();
|
|
shun_iwasawa |
3cc41f |
QPointF scaleFactor((float)pixmapSize.width() / (float)imgSize.width(),
|
|
shun_iwasawa |
3cc41f |
(float)pixmapSize.height() / (float)imgSize.height());
|
|
shun_iwasawa |
3cc41f |
float factor = (aspectRatioMode == Qt::KeepAspectRatio)
|
|
shun_iwasawa |
3cc41f |
? std::min(scaleFactor.x(), scaleFactor.y())
|
|
shun_iwasawa |
3cc41f |
: std::max(scaleFactor.x(), scaleFactor.y());
|
|
shun_iwasawa |
3cc41f |
QSizeF renderSize(factor * (float)imgSize.width(),
|
|
shun_iwasawa |
3cc41f |
factor * (float)imgSize.height());
|
|
shun_iwasawa |
3cc41f |
QPointF topLeft(
|
|
shun_iwasawa |
3cc41f |
((float)pixmapSize.width() - renderSize.width()) * 0.5f,
|
|
shun_iwasawa |
3cc41f |
((float)pixmapSize.height() - renderSize.height()) * 0.5f);
|
|
shun_iwasawa |
3cc41f |
renderRect = QRectF(topLeft, renderSize);
|
|
shun_iwasawa |
3cc41f |
} else { // Qt::IgnoreAspectRatio:
|
|
shun_iwasawa |
3cc41f |
renderRect = QRectF(QPointF(), QSizeF(pixmapSize));
|
|
shun_iwasawa |
3cc41f |
}
|
|
shun_iwasawa |
3cc41f |
}
|
|
shun_iwasawa |
3cc41f |
QPixmap pixmap(pixmapSize);
|
|
shun_iwasawa |
3cc41f |
QPainter painter;
|
|
shun_iwasawa |
3cc41f |
pixmap.fill(bgColor);
|
|
shun_iwasawa |
3cc41f |
painter.begin(&pixmap);
|
|
shun_iwasawa |
3cc41f |
svgRenderer.render(&painter, renderRect);
|
|
shun_iwasawa |
3cc41f |
painter.end();
|
|
shun_iwasawa |
3cc41f |
pixmap.setDevicePixelRatio(devPixRatio);
|
|
shun_iwasawa |
3cc41f |
return pixmap;
|
|
shun_iwasawa |
3cc41f |
}
|
|
shun_iwasawa |
3cc41f |
|
|
shun_iwasawa |
3cc41f |
//-----------------------------------------------------------------------------
|
|
shun_iwasawa |
3cc41f |
|
|
shun_iwasawa |
3cc41f |
int getDevPixRatio() {
|
|
shun_iwasawa |
3cc41f |
static int devPixRatio = QApplication::desktop()->devicePixelRatio();
|
|
shun_iwasawa |
3cc41f |
return devPixRatio;
|
|
shun_iwasawa |
3cc41f |
}
|
|
shun_iwasawa |
3cc41f |
|
|
shun_iwasawa |
3cc41f |
//-----------------------------------------------------------------------------
|
|
shun_iwasawa |
3cc41f |
|
|
Kite |
521c84 |
QString getIconThemePath(const QString &fileSVGPath) {
|
|
Kite |
521c84 |
// Use as follows:
|
|
Kite |
521c84 |
// QPixmap pixmapIcon = getIconThemePath("path/to/file.svg");
|
|
Kite |
521c84 |
// Is equal to: :icons/*theme*/path/to/file.svg
|
|
Toshihiro Shimizu |
890ddd |
|
|
Kite |
521c84 |
// Set themeable directory
|
|
Kite |
521c84 |
static QString theme = Preferences::instance()->getIconTheme()
|
|
Kite |
521c84 |
? ":icons/dark/"
|
|
Kite |
521c84 |
: ":icons/light/";
|
|
Kite |
521c84 |
|
|
Kite |
521c84 |
// If no file in light icon theme directory, fallback to dark directory
|
|
Kite |
521c84 |
if (!QFile::exists(QString(theme + fileSVGPath))) theme = ":icons/dark/";
|
|
Kite |
521c84 |
|
|
Kite |
521c84 |
return theme + fileSVGPath;
|
|
Kite |
521c84 |
}
|
|
Kite |
521c84 |
|
|
Kite |
521c84 |
//-----------------------------------------------------------------------------
|
|
Kite |
521c84 |
|
|
Kite |
521c84 |
QPixmap setOpacity(QPixmap pixmap, const qreal &opacity) {
|
|
Kite |
521c84 |
static int devPixRatio = getDevPixRatio();
|
|
Kite |
521c84 |
const QSize pixmapSize(pixmap.width() * devPixRatio,
|
|
Kite |
521c84 |
pixmap.height() * devPixRatio);
|
|
Kite |
521c84 |
|
|
Kite |
521c84 |
QPixmap opacityPixmap(pixmapSize);
|
|
Kite |
521c84 |
opacityPixmap.setDevicePixelRatio(devPixRatio);
|
|
Kite |
521c84 |
opacityPixmap.fill(Qt::transparent);
|
|
Kite |
521c84 |
|
|
Kite |
521c84 |
if (!pixmap.isNull()) {
|
|
Kite |
521c84 |
QPainter p(&opacityPixmap);
|
|
Kite |
521c84 |
QPixmap normalPixmap = pixmap.scaled(pixmapSize, Qt::KeepAspectRatio);
|
|
Kite |
521c84 |
normalPixmap.setDevicePixelRatio(devPixRatio);
|
|
Kite |
521c84 |
p.setBackgroundMode(Qt::TransparentMode);
|
|
Kite |
521c84 |
p.setBackground(QBrush(Qt::transparent));
|
|
Kite |
521c84 |
p.eraseRect(normalPixmap.rect());
|
|
Kite |
521c84 |
p.setOpacity(opacity);
|
|
Kite |
521c84 |
p.drawPixmap(0, 0, normalPixmap);
|
|
Kite |
521c84 |
}
|
|
Kite |
521c84 |
return opacityPixmap;
|
|
Kite |
521c84 |
}
|
|
Kite |
521c84 |
|
|
Kite |
521c84 |
//-----------------------------------------------------------------------------
|
|
Kite |
521c84 |
|
|
Kite |
521c84 |
QPixmap recolorPixmap(QPixmap pixmap, QColor color) {
|
|
Kite |
521c84 |
// Change black pixels to any chosen color
|
|
Kite |
521c84 |
QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
|
|
Kite |
521c84 |
for (int y = 0; y < img.height(); y++) {
|
|
Kite |
521c84 |
QRgb *pixel = reinterpret_cast<qrgb *="">(img.scanLine(y));</qrgb>
|
|
Kite |
521c84 |
QRgb *end = pixel + img.width();
|
|
Kite |
521c84 |
for (; pixel != end; pixel++) {
|
|
Kite |
521c84 |
// Only recolor zero value (black) pixels
|
|
Kite |
521c84 |
if (QColor::fromRgba(*pixel).value() == 0)
|
|
Kite |
521c84 |
*pixel =
|
|
Kite |
521c84 |
QColor(color.red(), color.green(), color.blue(), qAlpha(*pixel))
|
|
Kite |
521c84 |
.rgba();
|
|
Kite |
521c84 |
}
|
|
Kite |
521c84 |
}
|
|
Kite |
52018c |
pixmap = QPixmap::fromImage(img);
|
|
Kite |
52018c |
return pixmap;
|
|
Kite |
52018c |
}
|
|
Kite |
52018c |
|
|
Kite |
52018c |
//-----------------------------------------------------------------------------
|
|
Kite |
52018c |
|
|
Kite |
52018c |
QPixmap compositePixmap(QPixmap pixmap, qreal opacity, int canvasWidth,
|
|
Kite |
52018c |
int canvasHeight, int iconWidth, int iconHeight,
|
|
Kite |
52018c |
int offset) {
|
|
Kite |
52018c |
/* Creates a composite pixmap from two pixmaps. The canvas controls the final
|
|
Kite |
52018c |
* size, whereas pixmap is the image to be composited ontop. You can control
|
|
Kite |
52018c |
* the position of pixmap by setting an offset (top-left), default is 0. */
|
|
Kite |
52018c |
|
|
Kite |
52018c |
static int devPixRatio = getDevPixRatio();
|
|
Kite |
52018c |
|
|
Kite |
52018c |
QPixmap canvas(canvasWidth, canvasHeight);
|
|
Kite |
52018c |
canvas.fill(Qt::transparent); // set this to a color to debug
|
|
Kite |
52018c |
QPixmap combined(canvasWidth, canvasHeight);
|
|
Kite |
52018c |
combined.fill(Qt::transparent);
|
|
Kite |
52018c |
if (!pixmap.isNull()) {
|
|
Kite |
52018c |
QPainter painter;
|
|
Kite |
52018c |
painter.begin(&combined);
|
|
Kite |
52018c |
QRect canvasRect(0, 0, canvasWidth, canvasHeight);
|
|
Kite |
52018c |
painter.drawPixmap(canvasRect, canvas);
|
|
Kite |
52018c |
painter.setOpacity(opacity);
|
|
Kite |
52018c |
QRect iconRect(offset, offset, iconWidth, iconHeight);
|
|
Kite |
52018c |
painter.drawPixmap(iconRect, pixmap);
|
|
Kite |
52018c |
painter.end();
|
|
Kite |
52018c |
}
|
|
Kite |
52018c |
|
|
Kite |
52018c |
return combined;
|
|
Kite |
521c84 |
}
|
|
Kite |
521c84 |
|
|
Kite |
521c84 |
//-----------------------------------------------------------------------------
|
|
Kite |
521c84 |
|
|
Kite |
521c84 |
QIcon createQIcon(const char *iconSVGName, bool useFullOpacity) {
|
|
Kite |
52018c |
static int devPixRatio = getDevPixRatio();
|
|
Kite |
521c84 |
|
|
Kite |
52018c |
// get icon size
|
|
Kite |
52018c |
QIcon themeIcon = QIcon::fromTheme(iconSVGName);
|
|
Kite |
52018c |
QSize iconSize(0, 0);
|
|
Kite |
52018c |
for (QList<qsize> sizes = themeIcon.availableSizes(); !sizes.isEmpty();</qsize>
|
|
Kite |
521c84 |
sizes.removeFirst())
|
|
Kite |
521c84 |
if (sizes.first().width() > iconSize.width()) iconSize = sizes.first();
|
|
Kite |
521c84 |
|
|
Kite |
52018c |
QString overStr = QString(iconSVGName) + "_over";
|
|
Kite |
52018c |
QString onStr = QString(iconSVGName) + "_on";
|
|
Kite |
52018c |
QPixmap themeIconPixmap = recolorPixmap(themeIcon.pixmap(iconSize));
|
|
Kite |
52018c |
QPixmap overPixmap =
|
|
Kite |
52018c |
recolorPixmap(QIcon::fromTheme(overStr).pixmap(iconSize));
|
|
Kite |
52018c |
QPixmap onPixmap = recolorPixmap(QIcon::fromTheme(onStr).pixmap(iconSize));
|
|
Shinya Kitaoka |
120a6e |
QIcon icon;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Kite |
52018c |
// build icon
|
|
Kite |
52018c |
for (int devPixRatio = 1; devPixRatio <= 2; devPixRatio++) {
|
|
Kite |
52018c |
int iconW = themeIconPixmap.width();
|
|
Kite |
52018c |
int iconH = themeIconPixmap.height();
|
|
Kite |
52018c |
int canvasW = iconW;
|
|
Kite |
52018c |
int canvasH = iconH;
|
|
Kite |
52018c |
int offset = 0;
|
|
Kite |
52018c |
const qreal normalOpacity = useFullOpacity ? 1 : 0.8;
|
|
Kite |
52018c |
const qreal disabledOpacity = 0.15;
|
|
Kite |
52018c |
const qreal onOpacity = 1;
|
|
Kite |
52018c |
|
|
Kite |
52018c |
// off
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(themeIconPixmap, normalOpacity, canvasW,
|
|
Kite |
52018c |
canvasH, iconW, iconH),
|
|
Kite |
52018c |
QIcon::Normal, QIcon::Off);
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(themeIconPixmap, disabledOpacity, canvasW,
|
|
Kite |
52018c |
canvasH, iconW, iconH),
|
|
Kite |
52018c |
QIcon::Disabled);
|
|
Kite |
52018c |
|
|
Kite |
52018c |
// over
|
|
Kite |
52018c |
icon.addPixmap(
|
|
Kite |
52018c |
compositePixmap(!overPixmap.isNull() ? overPixmap : themeIconPixmap,
|
|
Kite |
52018c |
onOpacity, canvasW, canvasH, iconW, iconH),
|
|
Kite |
52018c |
QIcon::Active);
|
|
Kite |
52018c |
|
|
Kite |
52018c |
// on
|
|
Kite |
52018c |
if (!onPixmap.isNull()) {
|
|
Kite |
52018c |
icon.addPixmap(
|
|
Kite |
52018c |
compositePixmap(onPixmap, onOpacity, canvasW, canvasH, iconW, iconH),
|
|
Kite |
52018c |
QIcon::Normal, QIcon::On);
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(onPixmap, normalOpacity, canvasW, canvasH,
|
|
Kite |
52018c |
iconW, iconH),
|
|
Kite |
52018c |
QIcon::Disabled, QIcon::On);
|
|
Kite |
52018c |
} else {
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(themeIconPixmap, onOpacity, canvasW,
|
|
Kite |
52018c |
canvasH, iconW, iconH),
|
|
Kite |
52018c |
QIcon::Normal, QIcon::On);
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(themeIconPixmap, disabledOpacity, canvasW,
|
|
Kite |
52018c |
canvasH, iconW, iconH),
|
|
Kite |
52018c |
QIcon::Disabled, QIcon::On);
|
|
Kite |
52018c |
}
|
|
Kite |
521c84 |
|
|
Kite |
52018c |
/* If size is 16x16 (suitable for menu) we composite it onto a separate
|
|
Kite |
52018c |
* 20x20 pixmap so that it is compatible with toolbars, otherwise it will be
|
|
Kite |
52018c |
* scaled up and blur. You need to add icons to all QIcon modes otherwise it
|
|
Kite |
52018c |
* will use the original size, which is undesirable. This is equal to having
|
|
Kite |
52018c |
* two sets loaded into the icon (16x16 and 20x20) and is dynamically used
|
|
Kite |
52018c |
* depending on iconSize for toolbars.
|
|
Kite |
52018c |
*/
|
|
Kite |
52018c |
if (iconSize == (QSize(16, 16))) {
|
|
Kite |
52018c |
canvasW = 20 * devPixRatio;
|
|
Kite |
52018c |
canvasH = 20 * devPixRatio;
|
|
Kite |
52018c |
offset = 2 * devPixRatio;
|
|
Kite |
52018c |
|
|
Kite |
52018c |
// off
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(themeIconPixmap, normalOpacity, canvasW,
|
|
Kite |
52018c |
canvasH, iconW, iconH, offset),
|
|
Kite |
52018c |
QIcon::Normal, QIcon::Off);
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(themeIconPixmap, disabledOpacity, canvasW,
|
|
Kite |
52018c |
canvasH, iconW, iconH, offset),
|
|
Kite |
52018c |
QIcon::Disabled);
|
|
Kite |
52018c |
// over
|
|
Kite |
52018c |
icon.addPixmap(
|
|
Kite |
52018c |
compositePixmap(!overPixmap.isNull() ? overPixmap : themeIconPixmap,
|
|
Kite |
52018c |
onOpacity, canvasW, canvasH, iconW, iconH, offset),
|
|
Kite |
52018c |
QIcon::Active);
|
|
Kite |
52018c |
|
|
Kite |
52018c |
// on
|
|
Kite |
52018c |
if (!onPixmap.isNull()) {
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(onPixmap, onOpacity, canvasW, canvasH,
|
|
Kite |
52018c |
iconW, iconH, offset),
|
|
Kite |
52018c |
QIcon::Normal, QIcon::On);
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(onPixmap, disabledOpacity, canvasW,
|
|
Kite |
52018c |
canvasH, iconW, iconH, offset),
|
|
Kite |
52018c |
QIcon::Disabled, QIcon::On);
|
|
Kite |
52018c |
} else {
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(themeIconPixmap, onOpacity, canvasW,
|
|
Kite |
52018c |
canvasH, iconW, iconH, offset),
|
|
Kite |
52018c |
QIcon::Normal, QIcon::On);
|
|
Kite |
52018c |
icon.addPixmap(compositePixmap(themeIconPixmap, disabledOpacity,
|
|
Kite |
52018c |
canvasW, canvasH, iconW, iconH, offset),
|
|
Kite |
52018c |
QIcon::Disabled, QIcon::On);
|
|
Kite |
52018c |
}
|
|
Kite |
52018c |
}
|
|
Kite |
521c84 |
}
|
|
Shinya Kitaoka |
120a6e |
return icon;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QIcon createQIconPNG(const char *iconPNGName) {
|
|
Shinya Kitaoka |
120a6e |
QString normal = QString(":Resources/") + iconPNGName + ".png";
|
|
Shinya Kitaoka |
120a6e |
QString click = QString(":Resources/") + iconPNGName + "_click.png";
|
|
Shinya Kitaoka |
120a6e |
QString over = QString(":Resources/") + iconPNGName + "_over.png";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QIcon icon;
|
|
Shinya Kitaoka |
120a6e |
icon.addFile(normal, QSize(), QIcon::Normal, QIcon::Off);
|
|
Shinya Kitaoka |
120a6e |
icon.addFile(click, QSize(), QIcon::Normal, QIcon::On);
|
|
Shinya Kitaoka |
120a6e |
icon.addFile(over, QSize(), QIcon::Active);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return icon;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QIcon createQIconOnOffPNG(const char *iconPNGName, bool withOver) {
|
|
Shinya Kitaoka |
120a6e |
QString on = QString(":Resources/") + iconPNGName + "_on.png";
|
|
Shinya Kitaoka |
120a6e |
QString off = QString(":Resources/") + iconPNGName + "_off.png";
|
|
Shinya Kitaoka |
120a6e |
QString over = QString(":Resources/") + iconPNGName + "_over.png";
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QIcon icon;
|
|
Shinya Kitaoka |
120a6e |
icon.addFile(off, QSize(), QIcon::Normal, QIcon::Off);
|
|
Shinya Kitaoka |
120a6e |
icon.addFile(on, QSize(), QIcon::Normal, QIcon::On);
|
|
Shinya Kitaoka |
120a6e |
if (withOver)
|
|
Shinya Kitaoka |
120a6e |
icon.addFile(over, QSize(), QIcon::Active);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
icon.addFile(on, QSize(), QIcon::Active);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return icon;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
75b9b0 |
QIcon createTemporaryIconFromName(const char *commandName) {
|
|
Kite |
949afd |
const int visibleIconSize = 20;
|
|
Kite |
949afd |
const int menubarIconSize = 16;
|
|
Kite |
949afd |
const qreal normalOpacity = 0.8;
|
|
Kite |
949afd |
const qreal disabledOpacity = 0.15;
|
|
Kite |
949afd |
const qreal onOpacity = 1;
|
|
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 |
|
|
shun-iwasawa |
75b9b0 |
icon.addPixmap(transparentPm);
|
|
shun-iwasawa |
75b9b0 |
icon.addPixmap(transparentPm, QIcon::Disabled);
|
|
Kite |
949afd |
icon.addPixmap(compositePixmap(pixmap, normalOpacity, pxSize, pxSize,
|
|
Kite |
949afd |
pixmap.width(), pixmap.height()),
|
|
Kite |
949afd |
QIcon::Normal, QIcon::Off);
|
|
Kite |
949afd |
icon.addPixmap(compositePixmap(pixmap, onOpacity, pxSize, pxSize,
|
|
Kite |
949afd |
pixmap.width(), pixmap.height()),
|
|
Kite |
949afd |
QIcon::Normal, QIcon::On);
|
|
Kite |
949afd |
icon.addPixmap(compositePixmap(pixmap, onOpacity, pxSize, pxSize,
|
|
Kite |
949afd |
pixmap.width(), pixmap.height()),
|
|
Kite |
949afd |
QIcon::Active);
|
|
Kite |
949afd |
icon.addPixmap(compositePixmap(pixmap, disabledOpacity, pxSize, pxSize,
|
|
Kite |
949afd |
pixmap.width(), pixmap.height()),
|
|
Kite |
949afd |
QIcon::Disabled);
|
|
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 |
}
|