Commit 1414c583 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Make cursor loading more robust

parent 33c17d0f
......@@ -168,6 +168,7 @@ qt5_add_resources(krita_SRCS krita.qrc
${CMAKE_SOURCE_DIR}/pics/icons.qrc
data/aboutdata/aboutdata.qrc
data/shaders/shaders.qrc
data/cursors/shaders.qrc
)
add_executable(krita ${krita_SRCS})
......
......@@ -5,7 +5,6 @@ add_subdirectory( patterns )
add_subdirectory( gradients )
add_subdirectory( profiles )
add_subdirectory( templates )
add_subdirectory( cursors )
add_subdirectory( workspaces )
add_subdirectory( themes )
add_subdirectory( predefined_image_sizes )
......
install( FILES
cursor-cross.xpm
cursor-round.xpm
precise-pick-layer-icon.xpm
color-picker_image_background.xpm
color-picker_image_foreground.xpm
color-picker_layer_background.xpm
color-picker_layer_foreground.xpm
exposure-cursor-gesture.xpm
gamma-cursor-gesture.xpm
cursor-triangle_lefthanded.xpm
cursor-triangle_righthanded.xpm
rotate_discrete.xpm
rotate_smooth.xpm
zoom_discrete.xpm
zoom_smooth.xpm
DESTINATION ${DATA_INSTALL_DIR}/krita/pics)
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>color-picker_image_background.xpm</file>
<file>color-picker_image_foreground.xpm</file>
<file>color-picker_layer_background.xpm</file>
<file>color-picker_layer_foreground.xpm</file>
<file>cursor-cross.xpm</file>
<file>cursor-round.xpm</file>
<file>cursor-triangle_lefthanded.xpm</file>
<file>cursor-triangle_righthanded.xpm</file>
<file>exposure-cursor-gesture.xpm</file>
<file>gamma-cursor-gesture.xpm</file>
<file>precise-pick-layer-icon.xpm</file>
<file>rotate_discrete.xpm</file>
<file>rotate_smooth.xpm</file>
<file>zoom_discrete.xpm</file>
<file>zoom_smooth.xpm</file>
</qresource>
</RCC>
......@@ -339,23 +339,13 @@ bool KisApplication::start(const KisApplicationArguments &args)
QDir appdir(applicationDirPath());
appdir.cdUp();
//KoResourcePaths::addXdgDataPrefix(appdir.absolutePath() + "/share");
//KoResourcePaths::addPrefix(appdir.absolutePath());
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
// If there's no kdehome, set it and restart the process.
if (!env.contains("KDEHOME")) {
qputenv("KDEHOME", QFile::encodeName(QDesktopServices::storageLocation(QDesktopServices::DataLocation)));
}
if (!env.contains("XDG_DATA_DIRS")) {
qputenv("XDG_DATA_DIRS", QFile::encodeName(appdir.absolutePath() + "/share"));
}
if (!env.contains("KDEDIR")) {
qputenv("KDEDIR", QFile::encodeName(appdir.absolutePath()));
}
if (!env.contains("KDEDIRS")) {
qputenv("KDEDIRS", QFile::encodeName(appdir.absolutePath()));
qDebug() << "Setting XDG_DATA_DIRS" << KoResourcePaths::getApplicationRoot() + "/share";
qputenv("XDG_DATA_DIRS", QFile::encodeName(KoResourcePaths::getApplicationRoot() + "/share"));
}
qputenv("PATH", QFile::encodeName(appdir.absolutePath() + "/bin" + ";"
+ appdir.absolutePath() + "/lib" + ";"
+ appdir.absolutePath() + "/lib/kde4" + ";"
......
......@@ -29,7 +29,7 @@
#include <QPainter>
#include <QtGlobal>
#include <qmath.h>
#include <QDebug>
#include <KoResourcePaths.h>
......@@ -128,17 +128,17 @@ QCursor KisCursor::pickerCursor()
QCursor KisCursor::pickerPlusCursor()
{
static const unsigned char pickerplus_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x80, 0x1e,
0x00, 0x00, 0x40, 0x1f, 0x00, 0x00, 0xb0, 0x1f, 0x00, 0x00, 0xe8, 0x0f,
0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0xa8, 0x03, 0x00, 0x00, 0x64, 0x03,
0x00, 0x00, 0x72, 0x01, 0x00, 0x00, 0xb9, 0x00, 0x00, 0x80, 0x1c, 0x00,
0x00, 0x40, 0x0e, 0x00, 0x00, 0x20, 0x07, 0x00, 0x00, 0x90, 0x03, 0x00,
0x00, 0xc8, 0x01, 0x01, 0x40, 0xe4, 0x00, 0x01, 0x40, 0x74, 0xc0, 0x07,
0x40, 0x3c, 0x00, 0x01, 0x40, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x80, 0x1e,
0x00, 0x00, 0x40, 0x1f, 0x00, 0x00, 0xb0, 0x1f, 0x00, 0x00, 0xe8, 0x0f,
0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0xa8, 0x03, 0x00, 0x00, 0x64, 0x03,
0x00, 0x00, 0x72, 0x01, 0x00, 0x00, 0xb9, 0x00, 0x00, 0x80, 0x1c, 0x00,
0x00, 0x40, 0x0e, 0x00, 0x00, 0x20, 0x07, 0x00, 0x00, 0x90, 0x03, 0x00,
0x00, 0xc8, 0x01, 0x01, 0x40, 0xe4, 0x00, 0x01, 0x40, 0x74, 0xc0, 0x07,
0x40, 0x3c, 0x00, 0x01, 0x40, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00
};
QBitmap picker_bitmap = bitmapFromData(QSize(32, 32), pickerplus_bits);
......@@ -151,17 +151,17 @@ QCursor KisCursor::pickerPlusCursor()
QCursor KisCursor::pickerMinusCursor()
{
static const unsigned char pickerminus_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x80, 0x1e,
0x00, 0x00, 0x40, 0x1f, 0x00, 0x00, 0xb0, 0x1f, 0x00, 0x00, 0xe8, 0x0f,
0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0xa8, 0x03, 0x00, 0x00, 0x64, 0x03,
0x00, 0x00, 0x72, 0x01, 0x00, 0x00, 0xb9, 0x00, 0x00, 0x80, 0x1c, 0x00,
0x00, 0x40, 0x0e, 0x00, 0x00, 0x20, 0x07, 0x00, 0x00, 0x90, 0x03, 0x00,
0x00, 0xc8, 0x01, 0x00, 0x40, 0xe4, 0x00, 0x00, 0x40, 0x74, 0xc0, 0x07,
0x40, 0x3c, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x80, 0x1e,
0x00, 0x00, 0x40, 0x1f, 0x00, 0x00, 0xb0, 0x1f, 0x00, 0x00, 0xe8, 0x0f,
0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0xa8, 0x03, 0x00, 0x00, 0x64, 0x03,
0x00, 0x00, 0x72, 0x01, 0x00, 0x00, 0xb9, 0x00, 0x00, 0x80, 0x1c, 0x00,
0x00, 0x40, 0x0e, 0x00, 0x00, 0x20, 0x07, 0x00, 0x00, 0x90, 0x03, 0x00,
0x00, 0xc8, 0x01, 0x00, 0x40, 0xe4, 0x00, 0x00, 0x40, 0x74, 0xc0, 0x07,
0x40, 0x3c, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00
};
QBitmap picker_bitmap = bitmapFromData(QSize(32, 32), pickerminus_bits);
......@@ -395,16 +395,17 @@ QCursor KisCursor::rotateCursor()
return load("rotate_cursor.xpm");
}
QCursor KisCursor::load(const QString & iconName, int hotspotX, int hotspotY)
QCursor KisCursor::load(const QString & cursorName, int hotspotX, int hotspotY)
{
QString filename = KoResourcePaths::findResource("kis_pics", iconName);
QImage cursorImage;
cursorImage.load(filename);
QImage cursorImage = QImage(":/" + cursorName);
if (cursorImage.isNull()) {
qWarning() << "Could not load cursor" << cursorName;
return Qt::ArrowCursor;
}
\
#ifdef Q_OS_WIN
// cursor width must be multiple of 16 on Windows
int bitmapWidth = qCeil(cursorImage.width() / 16.0) * 16;
int bitmapWidth = qCeil(cursorImage.width() / 16.0) * 16;
if (hotspotX < 0) {
hotspotX = cursorImage.width() / 2;
}
......
......@@ -81,12 +81,15 @@ public:
static QCursor closedHandCursor(); // Pan tool cursor
static QCursor rotateCursor(); // Transform tool cursor
// Makes a 32x32 bitmap that is compatible with different platforms
static QBitmap bitmapFromData(const QSize& size, const unsigned char* data);
// Load a cursor from an image file. The image should have an alpha channel
// and will be converted to black and white on loading. Any format loadable by
// QImage can be used.
static QCursor load(const QString & imageFilename, int hotspotX = -1, int hotspotY = -1);
static QCursor load(const QString & cursorName, int hotspotX = -1, int hotspotY = -1);
private:
// Makes a 32x32 bitmap that is compatible with different platforms
static QBitmap bitmapFromData(const QSize& size, const unsigned char* data);
};
#endif // __kis_cursor_h__
......@@ -127,6 +127,11 @@ KoResourcePaths::~KoResourcePaths()
{
}
QString KoResourcePaths::getApplicationRoot()
{
return getInstallationPrefix();
}
void KoResourcePaths::addResourceType(const char *type, const char *basetype,
const QString &relativeName, bool priority)
{
......
......@@ -54,6 +54,8 @@ public:
};
Q_DECLARE_FLAGS(SearchOptions, SearchOption)
static QString getApplicationRoot();
/**
* Adds suffixes for types.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment