Skip to content

Commit

Permalink
qt: Use QImage instead of QImageReader to load mouse cursor images.
Browse files Browse the repository at this point in the history
Some combination of QImageReader, QImage, QPixmap, QCursor and the wzfs wz:: virtual file system apparently doesn't
work in Qt 4.8.2 (but works in Qt 4.8.1).

The following error was printed (multiple times) to the shell:
QCursor: Cannot create bitmap cursor; invalid bitmap(s)

Fixes ticket:3562.
  • Loading branch information
Cyp committed Jul 30, 2012
1 parent 06f10ca commit df32833
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions lib/qtgame/wzapp_qt.cpp
Expand Up @@ -22,7 +22,7 @@
* Qt-related functions.
*/

#include <QtGui/QImageReader>
#include <QtGui/QImage>
#include <QtGui/QBitmap>
#include <QtGui/QPainter>
#include <QtGui/QMouseEvent>
Expand Down Expand Up @@ -112,11 +112,9 @@ unsigned screenHeight = 0; // Declared in frameint.h.
static void inputAddBuffer(UDWORD key, utf_32_char unicode);
static int WZkeyToQtKey(int code);

void WzMainWindow::loadCursor(CURSOR cursor, int x, int y, QImageReader &buffer)
void WzMainWindow::loadCursor(CURSOR cursor, int x, int y, QImage const &buffer)
{
buffer.device()->reset();
buffer.setClipRect(QRect(x, y, 32, 32));
cursors[cursor] = new QCursor(QPixmap::fromImage(buffer.read()));
cursors[cursor] = new QCursor(QPixmap::fromImage(buffer.copy(x, y, 32, 32)));
}

WzMainWindow::WzMainWindow(QSize resolution, const QGLFormat &format, QWidget *parent) : QtGameWidget(resolution, format, parent)
Expand All @@ -135,10 +133,10 @@ WzMainWindow::WzMainWindow(QSize resolution, const QGLFormat &format, QWidget *p
#endif
setWindowTitle(PACKAGE_NAME);

QImageReader buffer("wz::images/intfac5.png", "PNG");
if (!buffer.canRead())
QImage buffer("wz::images/intfac5.png", "PNG");
if (buffer.isNull())
{
debug(LOG_ERROR, "Failed to read cursor image: %s", buffer.errorString().toAscii().constData());
debug(LOG_ERROR, "Failed to read cursor image.");
}
loadCursor(CURSOR_EMBARK, 0, 128, buffer);
loadCursor(CURSOR_DEST, 32, 128, buffer);
Expand Down
4 changes: 2 additions & 2 deletions lib/qtgame/wzapp_qt.h
Expand Up @@ -21,7 +21,7 @@
#define WZAPP_H

#include <QtGui/QApplication>
#include <QtGui/QImageReader>
#include <QtGui/QImage>
#include <QtOpenGL/QGLWidget>
#include <QtCore/QBuffer>
#include <QtCore/QTime>
Expand All @@ -44,7 +44,7 @@ class WzMainWindow : public QtGameWidget
Q_OBJECT

private:
void loadCursor(CURSOR cursor, int x, int y, QImageReader &buffer);
void loadCursor(CURSOR cursor, int x, int y, QImage const &buffer);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
Expand Down

0 comments on commit df32833

Please sign in to comment.