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");
33 img = QImage(":/res/toolpal1.png");
37 sizeTPBM.rx() = img.width(), sizeTPBM.ry() = img.height();
38 sizeStamp.rx() = sizeTPBM.x() / 4, sizeStamp.ry() = sizeTPBM.y() / 3;
40 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
44 QSize ToolWindow::sizeHint() const
46 return QSize(sizeTPBM.x(), sizeTPBM.y());
49 void ToolWindow::paintEvent(QPaintEvent * event)
52 p.drawImage(QPoint(0, 0), img);
56 //need ul corner of bitmap, ul corner of dest, width/height
57 p.setCompositionMode(QPainter::RasterOp_NotSource);
58 // QPoint pt(sizeStamp.x() * (prevTool & 0x03), sizeStamp.y() * (prevTool >> 2));
59 QPoint pt(sizeStamp.x() * (prevTool % 4), sizeStamp.y() * (prevTool / 4));
60 p.drawImage(pt.x(), pt.y(), img, pt.x(), pt.y(), sizeStamp.x(), sizeStamp.y());
65 // Find which tool we're pointing at
67 ToolType ToolWindow::FindSelectedTool(void)
69 // Get mouse coords relative to the tool palette window
70 // wxPoint pt = ScreenToClient(wxGetMousePosition());
71 QPoint pt = mapFromGlobal(QCursor::pos());
72 //printf("pt = %u, %u\n", pt.x(), pt.y());
74 // Divide mouse coords by the bitmap stamp size to find which one is pointed to
75 uint32 x = (uint32)pt.x() / sizeStamp.x(), y = (uint32)pt.y() / sizeStamp.y();
77 // Preset failure into newTool, in case no new tool is selected
78 ToolType newTool = TOOLNone;
80 // NOTE: This works because x and y are UNSIGNED
82 newTool = (ToolType)((y * 4) + x);
84 // We don't have 11 yet, so fix this if the user selected the blank space