2 // TOOLWINDOW.CPP - Tool Palette window
4 // (C) 2008 Underground Software
6 // JLH = James L. Hammons <jlhamm@acm.org>
9 // --- ---------- -------------------------------------------------------------
10 // JLH 08/28/2008 Created this file
11 // JLH 03/11/2009 Converted from wxWidgets to Qt
20 // Uncomment this for debugging...
22 #define DEBUGFOO // Various tool debugging...
23 #define DEBUGTP // Toolpalette debugging...
25 #include "toolwindow.h"
29 ToolWindow::ToolWindow(void): QWidget(NULL, Qt::Window | Qt::FramelessWindowHint),
32 img = QImage(":/res/toolpal1.xpm");
36 sizeTPBM.rx() = img.width(), sizeTPBM.ry() = img.height();
37 sizeStamp.rx() = sizeTPBM.x() / 4, sizeStamp.ry() = sizeTPBM.y() / 2;
39 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
43 QSize ToolWindow::sizeHint() const
45 return QSize(sizeTPBM.x(), sizeTPBM.y());
48 void ToolWindow::paintEvent(QPaintEvent * event)
51 p.drawImage(QPoint(0, 0), img);
55 //need ul corner of bitmap, ul corner of dest, width/height
56 p.setCompositionMode(QPainter::RasterOp_NotSource);
57 QPoint pt(sizeStamp.x() * (prevTool & 0x03), sizeStamp.y() * (prevTool >> 2));
58 p.drawImage(pt.x(), pt.y(), img, pt.x(), pt.y(), sizeStamp.x(), sizeStamp.y());
63 // Find which tool we're pointing at
65 ToolType ToolWindow::FindSelectedTool(void)
67 // Get mouse coords relative to the tool palette window
68 // wxPoint pt = ScreenToClient(wxGetMousePosition());
69 QPoint pt = mapFromGlobal(QCursor::pos());
70 //printf("pt = %u, %u\n", pt.x(), pt.y());
72 // Divide mouse coords by the bitmap stamp size to find which one is pointed to
73 uint32 x = (uint32)pt.x() / sizeStamp.x(), y = (uint32)pt.y() / sizeStamp.y();
75 // Preset failure into newTool, in case no new tool is selected
76 ToolType newTool = TOOLNone;
78 // NOTE: This works because x and y are UNSIGNED
80 newTool = (ToolType)((y * 4) + x);