]> Shamusworld >> Repos - ttedit/blobdiff - src/toolwindow.cpp
Fix zoom to zoom in/out from the center.
[ttedit] / src / toolwindow.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 80f90e4..fda5b8e
@@ -6,8 +6,9 @@
 // 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:
 #define DEBUGTP                                // Toolpalette debugging...
 
 #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");
+       img = QImage(":/res/toolpal1.png");
 
        // 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() / 3;
 
-       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));
+               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());
        }
-
-       memDC.SelectObject(wxNullBitmap);
 }
 
 //
@@ -79,17 +66,25 @@ void ToolWindow::OnPaint(wxPaintEvent &e)
 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_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 < 2)
+       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;
 }
+