-//\r
-// TOOLWINDOW.CPP - Tool Palette window\r
-// by James L. Hammons\r
-// (C) 2008 Underground Software\r
-//\r
-// JLH = James L. Hammons <jlhamm@acm.org>\r
-//\r
-// Who When What\r
-// --- ---------- -------------------------------------------------------------\r
-// JLH 08/28/2008 Created this file\r
-//\r
-\r
-// FIXED:\r
-//\r
-// STILL TO BE DONE:\r
-//\r
-//\r
-\r
-// Uncomment this for debugging...\r
-#define DEBUG\r
-#define DEBUGFOO // Various tool debugging...\r
-#define DEBUGTP // Toolpalette debugging...\r
-\r
-#include "toolwindow.h"\r
-#include "types.h"\r
-\r
-// Pixmap resources\r
-\r
-#include "res/toolpal1.xpm" // Docs say this is portable... Let's see!\r
-\r
-\r
-BEGIN_EVENT_TABLE(ToolWindow, wxFrame)\r
- EVT_PAINT(ToolWindow::OnPaint)\r
-END_EVENT_TABLE()\r
-\r
-\r
-ToolWindow::ToolWindow(wxFrame * parent, const wxString &title, const wxPoint &pos,\r
- const wxSize &size, long style): wxFrame(parent, -1, title, pos, size, style),\r
- bmp(NULL), prevTool(TOOLNone)\r
-{\r
- bmp = new wxBitmap(toolpal1_xpm);\r
-\r
- // Set up sizes\r
-\r
- sizeTPBM.x = bmp->GetWidth(), sizeTPBM.y = bmp->GetHeight();\r
- sizeStamp.x = sizeTPBM.x / 4, sizeStamp.y = sizeTPBM.y / 2;\r
-\r
- SetSize(0, 0, sizeTPBM.x, sizeTPBM.y);\r
- Show(false);\r
-}\r
-\r
-ToolWindow::~ToolWindow()\r
-{\r
- if (bmp)\r
- delete bmp;\r
-}\r
-\r
-void ToolWindow::OnPaint(wxPaintEvent &e)\r
-{\r
- wxPaintDC dc(this);\r
-\r
- wxMemoryDC memDC;\r
- memDC.SelectObject(*bmp);\r
- dc.Blit(0, 0, sizeTPBM.x, sizeTPBM.y, &memDC, 0, 0, wxCOPY);\r
-\r
- if (prevTool != -1)\r
- {\r
- //need ul corner of bitmap, ul corner of dest, width/height\r
- wxPoint pt(sizeStamp.x * (prevTool & 0x03), sizeStamp.y * (prevTool >> 2));\r
- dc.Blit(pt.x, pt.y, sizeStamp.x, sizeStamp.y, &memDC, pt.x, pt.y, wxSRC_INVERT);\r
- }\r
-\r
- memDC.SelectObject(wxNullBitmap);\r
-}\r
-\r
-//\r
-// Find which tool we're pointing at\r
-//\r
-ToolType ToolWindow::FindSelectedTool(void)\r
-{\r
- // Get mouse coords relative to the tool palette window\r
- wxPoint pt = ScreenToClient(wxGetMousePosition());\r
-\r
- // Divide mouse coords by the bitmap stamp size to find which one is pointed to\r
- uint32 x = (uint32)pt.x / sizeStamp.x, y = (uint32)pt.y / sizeStamp.y;\r
-\r
- // Preset failure into newTool, in case no new tool is selected\r
- ToolType newTool = TOOLNone;\r
-\r
- // NOTE: This works because x and y are UNSIGNED\r
- if (x < 4 && y < 2)\r
- newTool = (ToolType)((y * 4) + x);\r
-\r
- return newTool;\r
-}\r
+//
+// TOOLWINDOW.CPP - Tool Palette window
+// by James L. Hammons
+// (C) 2008 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who When What
+// --- ---------- -----------------------------------------------------------
+// JLH 08/28/2008 Created this file
+// JLH 03/11/2009 Converted from wxWidgets to Qt
+//
+
+// FIXED:
+//
+// STILL TO BE DONE:
+//
+//
+
+// Uncomment this for debugging...
+#define DEBUG
+#define DEBUGFOO // Various tool debugging...
+#define DEBUGTP // Toolpalette debugging...
+
+#include "toolwindow.h"
+
+
+ToolWindow::ToolWindow(void): QWidget(NULL, Qt::Window | Qt::FramelessWindowHint),
+ prevTool(TOOLNone)
+{
+// img = QImage(":/res/toolpal1.xpm");
+ img = QImage(":/res/toolpal1.png");
+
+ // Set up sizes
+
+ sizeTPBM.rx() = img.width(), sizeTPBM.ry() = img.height();
+ sizeStamp.rx() = sizeTPBM.x() / 4, sizeStamp.ry() = sizeTPBM.y() / 3;
+
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ setVisible(false);
+}
+
+QSize ToolWindow::sizeHint() const
+{
+ return QSize(sizeTPBM.x(), sizeTPBM.y());
+}
+
+void ToolWindow::paintEvent(QPaintEvent * event)
+{
+ QPainter p(this);
+ p.drawImage(QPoint(0, 0), img);
+
+ if (prevTool != -1)
+ {
+ //need ul corner of bitmap, ul corner of dest, width/height
+ p.setCompositionMode(QPainter::RasterOp_NotSource);
+// QPoint pt(sizeStamp.x() * (prevTool & 0x03), sizeStamp.y() * (prevTool >> 2));
+ QPoint pt(sizeStamp.x() * (prevTool % 4), sizeStamp.y() * (prevTool / 4));
+ p.drawImage(pt.x(), pt.y(), img, pt.x(), pt.y(), sizeStamp.x(), sizeStamp.y());
+ }
+}
+
+//
+// Find which tool we're pointing at
+//
+ToolType ToolWindow::FindSelectedTool(void)
+{
+ // Get mouse coords relative to the tool palette window
+// 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_t x = (uint32_t)pt.x() / sizeStamp.x(), y = (uint32_t)pt.y() / sizeStamp.y();
+
+ // Preset failure into newTool, in case no new tool is selected
+ ToolType newTool = TOOLNone;
+
+ // NOTE: This works because x and y are UNSIGNED
+ if (x < 4 && y < 3)
+ newTool = (ToolType)((y * 4) + x);
+
+ // We don't have 11 yet, so fix this if the user selected the blank space
+//now we do!
+// if (newTool > 10)
+// newTool = TOOLNone;
+
+ return newTool;
+}
+