00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qbitmap.h>
00023 #include <qcursor.h>
00024 #include <qimage.h>
00025 #include <qpainter.h>
00026
00027 #include <kcursor.h>
00028 #include <kiconloader.h>
00029 #include <kstandarddirs.h>
00030
00031 #include "kis_cursor.h"
00032 #include "kis_factory.h"
00033
00034 KisCursor::KisCursor() {}
00035
00036
00037
00038
00039 QCursor KisCursor::arrowCursor()
00040 {
00041 return Qt::arrowCursor;
00042 }
00043
00044 QCursor KisCursor::upArrowCursor()
00045 {
00046 return Qt::upArrowCursor;
00047 }
00048
00049 QCursor KisCursor::crossCursor()
00050 {
00051 return Qt::crossCursor;
00052 }
00053
00054 QCursor KisCursor::waitCursor()
00055 {
00056 return Qt::waitCursor;
00057 }
00058
00059 QCursor KisCursor::ibeamCursor()
00060 {
00061 return Qt::ibeamCursor;
00062 }
00063
00064 QCursor KisCursor::sizeVerCursor()
00065 {
00066 return Qt::sizeVerCursor;
00067 }
00068
00069 QCursor KisCursor::sizeHorCursor()
00070 {
00071 return Qt::sizeHorCursor;
00072 }
00073
00074 QCursor KisCursor::sizeBDiagCursor()
00075 {
00076 return Qt::sizeBDiagCursor;
00077 }
00078
00079 QCursor KisCursor::sizeFDiagCursor()
00080 {
00081 return Qt::sizeFDiagCursor;
00082 }
00083
00084 QCursor KisCursor::sizeAllCursor()
00085 {
00086 return Qt::sizeAllCursor;
00087 }
00088
00089 QCursor KisCursor::blankCursor()
00090 {
00091 return Qt::blankCursor;
00092 }
00093
00094 QCursor KisCursor::splitVCursor()
00095 {
00096 return Qt::splitVCursor;
00097 }
00098
00099 QCursor KisCursor::splitHCursor()
00100 {
00101 return Qt::splitHCursor;
00102 }
00103
00104 QCursor KisCursor::pointingHandCursor()
00105 {
00106 return Qt::pointingHandCursor;
00107 }
00108
00109
00110
00111
00112
00113
00114 QCursor KisCursor::pickerCursor()
00115 {
00116 static unsigned char picker_bits[] = {
00117 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a,
00118 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f,
00119 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02,
00120 0x00, 0x72, 0x01, 0x00, 0x39, 0x00, 0x80, 0x1c, 0x00, 0x40, 0x0e, 0x00,
00121 0x20, 0x07, 0x00, 0x90, 0x03, 0x00, 0xc8, 0x01, 0x00, 0xe4, 0x00, 0x00,
00122 0x74, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00};
00123
00124 QBitmap picker_bitmap(24, 24, picker_bits, true);
00125 QBitmap picker_mask = picker_bitmap.createHeuristicMask( false );
00126
00127 return QCursor( picker_bitmap, picker_mask, 1, 22 );
00128 }
00129
00130
00131 QCursor KisCursor::pickerPlusCursor()
00132 {
00133 static unsigned char pickerplus_bits[] = {
00134 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a,
00135 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f,
00136 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02,
00137 0x00, 0x72, 0x01, 0x00, 0x39, 0x0c, 0x80, 0x1c, 0x0c, 0x40, 0x0e, 0x0c,
00138 0x20, 0x07, 0x0c, 0x90, 0x83, 0x7f, 0xc8, 0x81, 0x7f, 0xe4, 0x00, 0x0c,
00139 0x74, 0x00, 0x0c, 0x32, 0x00, 0x0c, 0x0a, 0x00, 0x0c, 0x00, 0x00, 0x00};
00140
00141 QBitmap picker_bitmap(24, 24, pickerplus_bits, true);
00142 QBitmap picker_mask = picker_bitmap.createHeuristicMask( false );
00143
00144 return QCursor( picker_bitmap, picker_mask, 1, 22 );
00145 }
00146
00147
00148 QCursor KisCursor::pickerMinusCursor()
00149 {
00150 static unsigned char pickerminus_bits[] = {
00151 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a,
00152 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f,
00153 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02,
00154 0x00, 0x72, 0x01, 0x00, 0x39, 0x00, 0x80, 0x1c, 0x00, 0x40, 0x0e, 0x00,
00155 0x20, 0x07, 0x00, 0x90, 0xc3, 0x7f, 0xc8, 0xc1, 0x7f, 0xe4, 0x00, 0x00,
00156 0x74, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00};
00157
00158 QBitmap picker_bitmap(24, 24, pickerminus_bits, true);
00159 QBitmap picker_mask = picker_bitmap.createHeuristicMask( false );
00160
00161 return QCursor( picker_bitmap, picker_mask, 1, 22 );
00162 }
00163
00164
00165
00166 QCursor KisCursor::penCursor()
00167 {
00168 static unsigned char pen_bits[] = {
00169 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x7d,
00170 0x00, 0x80, 0x7e, 0x00, 0x40, 0x7f, 0x00, 0xa0, 0x3f, 0x00, 0xd0, 0x1f,
00171 0x00, 0xe8, 0x0f, 0x00, 0xf4, 0x07, 0x00, 0xfa, 0x03, 0x00, 0xfd, 0x01,
00172 0x80, 0xfe, 0x00, 0x40, 0x7f, 0x00, 0xa0, 0x3f, 0x00, 0xf0, 0x1f, 0x00,
00173 0xd0, 0x0f, 0x00, 0x88, 0x07, 0x00, 0x88, 0x03, 0x00, 0xe4, 0x01, 0x00,
00174 0x7c, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00};
00175
00176 QBitmap pen_bitmap( 24, 24, pen_bits, true );
00177 QBitmap pen_mask = pen_bitmap.createHeuristicMask( false );
00178
00179 return QCursor( pen_bitmap, pen_mask, 1, 22 );
00180 }
00181
00182 QCursor KisCursor::brushCursor()
00183 {
00184 static unsigned char brush_bits[] = {
00185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x68, 0x00,
00186 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0xfd, 0x00,
00187 0x00, 0x80, 0x7e, 0x00, 0x00, 0x40, 0x3f, 0x00, 0x00, 0xa0, 0x1f, 0x00,
00188 0x00, 0xd0, 0x0f, 0x00, 0x00, 0xe8, 0x07, 0x00, 0x00, 0xf4, 0x03, 0x00,
00189 0x00, 0xe4, 0x01, 0x00, 0x00, 0xc2, 0x00, 0x00, 0x80, 0x41, 0x00, 0x00,
00190 0x40, 0x32, 0x00, 0x00, 0xa0, 0x0f, 0x00, 0x00, 0xd0, 0x0f, 0x00, 0x00,
00191 0xd0, 0x0f, 0x00, 0x00, 0xe8, 0x07, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00,
00192 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
00193
00194 QBitmap brush_bitmap( 25, 23, brush_bits, true );
00195 QBitmap brush_mask = brush_bitmap.createHeuristicMask( false );
00196
00197 return QCursor( brush_bitmap, brush_mask, 1, 21 );
00198 }
00199
00200 QCursor KisCursor::airbrushCursor()
00201 {
00202 static unsigned char airbrush_bits[] = {
00203 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x68, 0x00, 0x00, 0x74,
00204 0x00, 0x00, 0x7a, 0xf0, 0x00, 0x3d, 0x08, 0x81, 0x1e, 0xe8, 0x41, 0x0f,
00205 0xe8, 0xa1, 0x07, 0xe8, 0xd1, 0x03, 0xe8, 0xe9, 0x01, 0xe8, 0xf5, 0x00,
00206 0xe8, 0x7b, 0x00, 0xf0, 0x33, 0x00, 0xf0, 0x23, 0x1f, 0xa0, 0x9f, 0x3f,
00207 0xd0, 0xff, 0x31, 0xe8, 0xf7, 0x30, 0xf4, 0x03, 0x18, 0xfc, 0x01, 0x0c,
00208 0xf8, 0x00, 0x06, 0x76, 0x00, 0x03, 0x36, 0x00, 0x03, 0x00, 0x00, 0x00};
00209
00210 QBitmap airbrush_bitmap( 24, 24, airbrush_bits, true );
00211 QBitmap airbrush_mask = airbrush_bitmap.createHeuristicMask( false );
00212
00213 return QCursor( airbrush_bitmap, airbrush_mask, 1, 22 );
00214 }
00215
00216 QCursor KisCursor::eraserCursor()
00217 {
00218 static unsigned char eraser_bits[] = {
00219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1d, 0x00,
00220 0x00, 0x80, 0x3e, 0x00, 0x00, 0x40, 0x7f, 0x00, 0x00, 0xa0, 0xff, 0x00,
00221 0x00, 0xd0, 0xff, 0x00, 0x00, 0xe8, 0x7f, 0x00, 0x00, 0xf4, 0x3f, 0x00,
00222 0x00, 0xfe, 0x1f, 0x00, 0x00, 0xf9, 0x0f, 0x00, 0x80, 0xf2, 0x07, 0x00,
00223 0x40, 0xe7, 0x03, 0x00, 0xa0, 0xcf, 0x01, 0x00, 0xd0, 0x9f, 0x00, 0x00,
00224 0xe8, 0x7f, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0xf2, 0x1f, 0x00, 0x00,
00225 0xe2, 0x0f, 0x00, 0x00, 0xc4, 0x07, 0x00, 0x00, 0x88, 0x03, 0x00, 0x00,
00226 0x10, 0x01, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
00227
00228 QBitmap eraser_bitmap( 25, 24, eraser_bits, true );
00229 QBitmap eraser_mask = eraser_bitmap.createHeuristicMask( false );
00230
00231 return QCursor( eraser_bitmap, eraser_mask, 7, 22 );
00232 }
00233
00234 QCursor KisCursor::fillerCursor()
00235 {
00236 static unsigned char filler_bits[] = {
00237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x28, 0x00,
00238 0x00, 0x54, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x85, 0x00, 0x80, 0x0a, 0x01,
00239 0x40, 0x11, 0x01, 0xe0, 0x00, 0x02, 0x58, 0x01, 0x04, 0x2c, 0x02, 0x04,
00240 0x44, 0x04, 0x08, 0x0c, 0x08, 0x18, 0x3c, 0x00, 0x14, 0x5c, 0x00, 0x0a,
00241 0x9c, 0x01, 0x05, 0x1c, 0x82, 0x02, 0x18, 0x4c, 0x01, 0x18, 0xb0, 0x00,
00242 0x08, 0x60, 0x00, 0x00, 0x00, 0x00};
00243
00244 QBitmap filler_bitmap( 22, 22, filler_bits, true );
00245 QBitmap filler_mask = filler_bitmap.createHeuristicMask( false );
00246
00247 return QCursor( filler_bitmap, filler_mask, 3, 20 );
00248 }
00249
00250 QCursor KisCursor::colorChangerCursor()
00251 {
00252 static unsigned char colorChanger_bits[] = {
00253 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x10, 0x01, 0x0e, 0x08, 0x02, 0x11,
00254 0x04, 0x82, 0x20, 0x64, 0x84, 0x20, 0x92, 0x44, 0x46, 0x12, 0x49, 0x5f,
00255 0x12, 0x31, 0x5f, 0x22, 0x01, 0x5f, 0xc2, 0x00, 0x4e, 0x02, 0x00, 0x40,
00256 0xc2, 0x00, 0x46, 0xe2, 0x01, 0x4f, 0xe4, 0x19, 0x2f, 0xe4, 0x3d, 0x2f,
00257 0xe8, 0x3d, 0x17, 0xd0, 0x3c, 0x10, 0x20, 0x38, 0x08, 0x40, 0x00, 0x06,
00258 0x80, 0x81, 0x01, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00};
00259
00260 QBitmap colorChanger_bitmap( 24, 23, colorChanger_bits, true );
00261 QBitmap colorChanger_mask = colorChanger_bitmap.createHeuristicMask( false );
00262
00263 return QCursor( colorChanger_bitmap, colorChanger_mask, 12, 10 );
00264 }
00265
00266 QCursor KisCursor::zoomCursor()
00267 {
00268 static unsigned char zoom_bits[] = {
00269 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0xf0, 0x3f, 0x00, 0x38, 0x70, 0x00,
00270 0x8c, 0xcf, 0x00, 0x0c, 0xdf, 0x00, 0x36, 0xbf, 0x01, 0xb6, 0xbf, 0x01,
00271 0xf6, 0xbf, 0x01, 0xf6, 0xbf, 0x01, 0xe6, 0x9f, 0x00, 0xcc, 0xcf, 0x00,
00272 0x9c, 0xe7, 0x01, 0x38, 0x70, 0x03, 0xf0, 0xbf, 0x05, 0xc0, 0xef, 0x0b,
00273 0x00, 0xc0, 0x17, 0x00, 0x80, 0x2f, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x7e,
00274 0x00, 0x00, 0x7c, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00};
00275
00276 QBitmap zoom_bitmap( 24, 23, zoom_bits, true );
00277 QBitmap zoom_mask = zoom_bitmap.createHeuristicMask( false );
00278
00279 return QCursor( zoom_bitmap, zoom_mask, 9, 8 );
00280 }
00281
00282 QCursor KisCursor::moveCursor()
00283 {
00284 static unsigned char move_bits[] = {
00285 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x7e, 0x00,
00286 0x00, 0xff, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00,
00287 0x10, 0x18, 0x08, 0x18, 0x18, 0x18, 0x1c, 0x18, 0x38, 0xfe, 0xff, 0x7f,
00288 0xfe, 0xff, 0x7f, 0x1c, 0x18, 0x38, 0x18, 0x18, 0x18, 0x10, 0x18, 0x08,
00289 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0xff, 0x00,
00290 0x00, 0x7e, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00};
00291
00292 QBitmap move_bitmap( 24, 24, move_bits, true );
00293 QBitmap move_mask = move_bitmap.createHeuristicMask( false );
00294
00295 return QCursor( move_bitmap, move_mask, 12, 11 );
00296 }
00297
00298 QCursor KisCursor::handCursor()
00299 {
00300 return KCursor::handCursor();
00301 }
00302
00303 QCursor KisCursor::selectCursor()
00304 {
00305 static unsigned char select_bits[] = {
00306 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00,
00307 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00,
00308 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0xff, 0xff, 0x7f,
00309 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00,
00310 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00,
00311 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00};
00312
00313 QBitmap select_bitmap(23, 23, select_bits, true);
00314 QBitmap select_mask = select_bitmap.createHeuristicMask( false );
00315
00316 return QCursor( select_bitmap, select_mask, 11, 11 );
00317 }
00318
00319 QCursor KisCursor::openHandCursor()
00320 {
00321 return load("openhand_cursor.xpm");
00322 }
00323
00324 QCursor KisCursor::closedHandCursor()
00325 {
00326 return load("closedhand_cursor.xpm");
00327 }
00328
00329 QCursor KisCursor::rotateCursor()
00330 {
00331 return load("rotate_cursor.xpm");
00332 }
00333
00334 QCursor KisCursor::load(const QString & iconName, int hotspotX, int hotspotY)
00335 {
00336 QString filename = KisFactory::instance()->dirs()->findResource("kis_pics", iconName);
00337 QImage cursorImage;
00338
00339 cursorImage.load(filename);
00340 Q_ASSERT(!cursorImage.isNull());
00341 Q_ASSERT(cursorImage.hasAlphaBuffer());
00342
00343 QBitmap bitmap(cursorImage.width(), cursorImage.height());
00344 QBitmap mask(cursorImage.width(), cursorImage.height());
00345
00346 QPainter bitmapPainter(&bitmap);
00347 QPainter maskPainter(&mask);
00348
00349 for (Q_INT32 x = 0; x < cursorImage.width(); ++x) {
00350 for (Q_INT32 y = 0; y < cursorImage.height(); ++y) {
00351
00352 QRgb pixel = cursorImage.pixel(x, y);
00353
00354 if (qAlpha(pixel) < 128) {
00355 bitmapPainter.setPen(Qt::color0);
00356 maskPainter.setPen(Qt::color0);
00357 } else {
00358 maskPainter.setPen(Qt::color1);
00359
00360 if (qGray(pixel) < 128) {
00361 bitmapPainter.setPen(Qt::color1);
00362 } else {
00363 bitmapPainter.setPen(Qt::color0);
00364 }
00365 }
00366
00367 bitmapPainter.drawPoint(x, y);
00368 maskPainter.drawPoint(x, y);
00369 }
00370 }
00371
00372 return QCursor(bitmap, mask, hotspotX, hotspotY);
00373 }
00374