// Who When What
// --- ---------- -------------------------------------------------------------
// JLH 08/28/2008 Created this file
+// JLH 03/11/2009 Converted from wxWidgets to Qt
//
// FIXED:
#include "toolwindow.h"
#include "types.h"
-// Pixmap resources
-#include "res/toolpal1.xpm" // Docs say this is portable... Let's see!
-
-
-BEGIN_EVENT_TABLE(ToolWindow, wxFrame)
- EVT_PAINT(ToolWindow::OnPaint)
-END_EVENT_TABLE()
-
-
-ToolWindow::ToolWindow(wxFrame * parent, const wxString &title, const wxPoint &pos,
- const wxSize &size, long style): wxFrame(parent, -1, title, pos, size, style),
- bmp(NULL), prevTool(TOOLNone)
+ToolWindow::ToolWindow(void): QWidget(NULL, Qt::Window | Qt::FramelessWindowHint),
+ prevTool(TOOLNone)
{
- bmp = new wxBitmap(toolpal1_xpm);
+ img = QImage(":/res/toolpal1.xpm");
// Set up sizes
- sizeTPBM.x = bmp->GetWidth(), sizeTPBM.y = bmp->GetHeight();
- sizeStamp.x = sizeTPBM.x / 4, sizeStamp.y = sizeTPBM.y / 2;
+ sizeTPBM.rx() = img.width(), sizeTPBM.ry() = img.height();
+ sizeStamp.rx() = sizeTPBM.x() / 4, sizeStamp.ry() = sizeTPBM.y() / 2;
- SetSize(0, 0, sizeTPBM.x, sizeTPBM.y);
- Show(false);
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ setVisible(false);
}
-ToolWindow::~ToolWindow()
+QSize ToolWindow::sizeHint() const
{
- if (bmp)
- delete bmp;
+ return QSize(sizeTPBM.x(), sizeTPBM.y());
}
-void ToolWindow::OnPaint(wxPaintEvent &e)
+void ToolWindow::paintEvent(QPaintEvent * event)
{
- wxPaintDC dc(this);
-
- wxMemoryDC memDC;
- memDC.SelectObject(*bmp);
- dc.Blit(0, 0, sizeTPBM.x, sizeTPBM.y, &memDC, 0, 0, wxCOPY);
+ QPainter p(this);
+ p.drawImage(QPoint(0, 0), img);
if (prevTool != -1)
{
//need ul corner of bitmap, ul corner of dest, width/height
- wxPoint pt(sizeStamp.x * (prevTool & 0x03), sizeStamp.y * (prevTool >> 2));
- dc.Blit(pt.x, pt.y, sizeStamp.x, sizeStamp.y, &memDC, pt.x, pt.y, wxSRC_INVERT);
+ p.setCompositionMode(QPainter::RasterOp_NotSource);
+ QPoint pt(sizeStamp.x() * (prevTool & 0x03), sizeStamp.y() * (prevTool >> 2));
+ p.drawImage(pt.x(), pt.y(), img, pt.x(), pt.y(), sizeStamp.x(), sizeStamp.y());
}
-
- memDC.SelectObject(wxNullBitmap);
}
//
ToolType ToolWindow::FindSelectedTool(void)
{
// Get mouse coords relative to the tool palette window
- wxPoint pt = ScreenToClient(wxGetMousePosition());
+// wxPoint pt = ScreenToClient(wxGetMousePosition());
+ QPoint pt = mapFromGlobal(QCursor::pos());
+//printf("pt = %u, %u\n", pt.x(), pt.y());
// Divide mouse coords by the bitmap stamp size to find which one is pointed to
- uint32 x = (uint32)pt.x / sizeStamp.x, y = (uint32)pt.y / sizeStamp.y;
+ uint32 x = (uint32)pt.x() / sizeStamp.x(), y = (uint32)pt.y() / sizeStamp.y();
// Preset failure into newTool, in case no new tool is selected
ToolType newTool = TOOLNone;