diff --git a/include/wx/colour.h b/include/wx/colour.h index 1651f63d44..9caceccaef 100644 --- a/include/wx/colour.h +++ b/include/wx/colour.h @@ -65,7 +65,7 @@ DECLARE_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLIMPEXP_CORE) not need the wxGDIObject machinery to handle colors, please add it to the list of ports which do not need it. */ -#if defined( __WXMAC__ ) || defined( __WXMSW__ ) +#if defined( __WXMAC__ ) || defined( __WXMSW__ ) || defined( __WXQT__ ) #define wxCOLOUR_IS_GDIOBJECT 0 #else #define wxCOLOUR_IS_GDIOBJECT 1 diff --git a/include/wx/qt/colour.h b/include/wx/qt/colour.h index 8629217134..b7f5755ff9 100644 --- a/include/wx/qt/colour.h +++ b/include/wx/qt/colour.h @@ -10,37 +10,35 @@ #ifndef _WX_QT_COLOUR_H_ #define _WX_QT_COLOUR_H_ -#include +class QColor; class WXDLLIMPEXP_CORE wxColour : public wxColourBase { public: DEFINE_STD_WXCOLOUR_CONSTRUCTORS - wxColour(const QColor& color) : m_qtColor(color) {} + wxColour(const QColor& color); - virtual bool IsOk() const { return m_qtColor.isValid(); } + virtual bool IsOk() const; - unsigned char Red() const { return m_qtColor.red(); } - unsigned char Green() const { return m_qtColor.green(); } - unsigned char Blue() const { return m_qtColor.blue(); } - unsigned char Alpha() const { return m_qtColor.alpha(); } + unsigned char Red() const; + unsigned char Green() const; + unsigned char Blue() const; + unsigned char Alpha() const; - bool operator==(const wxColour& color) const - { return m_qtColor == color.m_qtColor; } - bool operator!=(const wxColour& color) const - { return m_qtColor != color.m_qtColor; } + bool operator==(const wxColour& color) const; + bool operator!=(const wxColour& color) const; int GetPixel() const; - QColor GetHandle() const { return m_qtColor; }; + QColor GetQColor() const; protected: - virtual void - InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) - { m_qtColor.setRgb(r, g, b, a); } + void Init(); + virtual void InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a); private: - QColor m_qtColor; + unsigned char red, green, blue, alpha; + bool valid; wxDECLARE_DYNAMIC_CLASS(wxColour); }; diff --git a/include/wx/qt/cursor.h b/include/wx/qt/cursor.h index 0db340209c..47320195dc 100644 --- a/include/wx/qt/cursor.h +++ b/include/wx/qt/cursor.h @@ -16,7 +16,6 @@ class WXDLLIMPEXP_CORE wxCursor : public wxCursorBase { public: wxCursor() { } - wxCursor( const wxCursor & ); wxCursor(wxStockCursor id) { InitFromStock(id); } #if WXWIN_COMPATIBILITY_2_8 wxCursor(int id) { InitFromStock((wxStockCursor)id); } @@ -28,8 +27,9 @@ public: int hotSpotX = 0, int hotSpotY = 0); #endif - QCursor m_qtCursor; - + virtual wxPoint GetHotSpot() const; + QCursor &GetHandle() const; + protected: void InitFromStock( wxStockCursor cursorId ); #if wxUSE_IMAGE diff --git a/include/wx/qt/window.h b/include/wx/qt/window.h index 300274003f..2689f51303 100644 --- a/include/wx/qt/window.h +++ b/include/wx/qt/window.h @@ -82,6 +82,7 @@ public: virtual void Refresh( bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL ); + virtual bool SetCursor( const wxCursor &cursor ) wxOVERRIDE; virtual bool SetFont(const wxFont& font); // get the (average) character size for the current font diff --git a/src/qt/bitmap.cpp b/src/qt/bitmap.cpp index acd76c3466..da42ecd9e9 100644 --- a/src/qt/bitmap.cpp +++ b/src/qt/bitmap.cpp @@ -215,7 +215,7 @@ wxBitmap::wxBitmap(const wxCursor& cursor) // note that pixmap could be invalid if is not a pixmap cursor // also, a wxCursor::GetHandle method could be implemented instead of // accessing the member variable directly - QPixmap pix = cursor.m_qtCursor.pixmap(); + QPixmap pix = cursor.GetHandle().pixmap(); m_refData = new wxBitmapRefData(pix); } @@ -511,7 +511,7 @@ bool wxMask::InitFromColour(const wxBitmap& bitmap, const wxColour& colour) return false; delete m_qtBitmap; - m_qtBitmap = new QBitmap(bitmap.GetHandle()->createMaskFromColor(colour.GetHandle())); + m_qtBitmap = new QBitmap(bitmap.GetHandle()->createMaskFromColor(colour.GetQColor())); return true; } diff --git a/src/qt/brush.cpp b/src/qt/brush.cpp index 5f997c9a05..9c16a35c9d 100644 --- a/src/qt/brush.cpp +++ b/src/qt/brush.cpp @@ -95,7 +95,7 @@ wxBrush::wxBrush() wxBrush::wxBrush(const wxColour& col, wxBrushStyle style ) { m_refData = new wxBrushRefData(); - M_BRUSHDATA.setColor(col.GetHandle()); + M_BRUSHDATA.setColor(col.GetQColor()); M_BRUSHDATA.setStyle(ConvertBrushStyle(style)); M_STYLEDATA = style; } @@ -103,7 +103,7 @@ wxBrush::wxBrush(const wxColour& col, wxBrushStyle style ) wxBrush::wxBrush(const wxColour& col, int style) { m_refData = new wxBrushRefData(); - M_BRUSHDATA.setColor(col.GetHandle()); + M_BRUSHDATA.setColor(col.GetQColor()); M_BRUSHDATA.setStyle(ConvertBrushStyle((wxBrushStyle)style)); M_STYLEDATA = (wxBrushStyle)style; } @@ -122,7 +122,7 @@ wxBrush::wxBrush(const wxBitmap& stipple) void wxBrush::SetColour(const wxColour& col) { AllocExclusive(); - M_BRUSHDATA.setColor(col.GetHandle()); + M_BRUSHDATA.setColor(col.GetQColor()); } void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) diff --git a/src/qt/calctrl.cpp b/src/qt/calctrl.cpp index d05b4f973e..cf0e216b19 100644 --- a/src/qt/calctrl.cpp +++ b/src/qt/calctrl.cpp @@ -229,7 +229,7 @@ void wxCalendarCtrl::SetHoliday(size_t day) date.setDate(date.year(), date.month(), day); QTextCharFormat format = m_qtCalendar->dateTextFormat(date); - format.setForeground(m_colHolidayFg.GetHandle()); + format.setForeground(m_colHolidayFg.GetQColor()); m_qtCalendar->setDateTextFormat(date, format); } @@ -249,9 +249,9 @@ void wxCalendarCtrl::RefreshHolidays() if ( m_windowStyle & wxCAL_SHOW_HOLIDAYS ) { if ( m_colHolidayFg.IsOk() ) - format.setForeground(m_colHolidayFg.GetHandle()); + format.setForeground(m_colHolidayFg.GetQColor()); if ( m_colHolidayBg.IsOk() ) - format.setBackground(m_colHolidayBg.GetHandle()); + format.setBackground(m_colHolidayBg.GetQColor()); } else { @@ -278,9 +278,9 @@ void wxCalendarCtrl::SetHeaderColours(const wxColour& colFg, const wxColour& col QTextCharFormat format = m_qtCalendar->headerTextFormat(); if ( m_colHeaderFg.IsOk() ) - format.setForeground(m_colHeaderFg.GetHandle()); + format.setForeground(m_colHeaderFg.GetQColor()); if ( m_colHeaderBg.IsOk() ) - format.setBackground(m_colHeaderBg.GetHandle()); + format.setBackground(m_colHeaderBg.GetQColor()); m_qtCalendar->setHeaderTextFormat(format); } @@ -303,9 +303,9 @@ void wxCalendarCtrl::SetAttr(size_t day, wxCalendarDateAttr *attr) QTextCharFormat format = m_qtCalendar->dateTextFormat(date); if ( attr->HasTextColour() ) - format.setForeground(attr->GetTextColour().GetHandle()); + format.setForeground(attr->GetTextColour().GetQColor()); if ( attr->HasBackgroundColour() ) - format.setBackground(attr->GetBackgroundColour().GetHandle()); + format.setBackground(attr->GetBackgroundColour().GetQColor()); wxMISSING_IMPLEMENTATION( "Setting font" ); diff --git a/src/qt/colordlg.cpp b/src/qt/colordlg.cpp index 7a34b1cca3..2a09d6fe6b 100644 --- a/src/qt/colordlg.cpp +++ b/src/qt/colordlg.cpp @@ -29,10 +29,10 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data ) if ( m_data.GetChooseFull() ) { for (int i=0; isetCurrentColor(m_data.GetColour().GetHandle()); + GetHandle()->setCurrentColor(m_data.GetColour().GetQColor()); return wxTopLevelWindow::Create( parent, wxID_ANY, ""); } diff --git a/src/qt/colour.cpp b/src/qt/colour.cpp index bad77af5d6..de42a7a26a 100644 --- a/src/qt/colour.cpp +++ b/src/qt/colour.cpp @@ -18,8 +18,32 @@ #include "wx/colour.h" #endif // WX_PRECOMP +#include "wx/colour.h" #include "wx/qt/private/utils.h" +#include + +wxColour::wxColour(const QColor& color) +{ + InitRGBA(color.red(), color.green(), color.blue(), color.alpha()); +} + +bool wxColour::IsOk() const { return valid; } + +unsigned char wxColour::Red() const { return red; } +unsigned char wxColour::Green() const { return green; } +unsigned char wxColour::Blue() const { return blue; } +unsigned char wxColour::Alpha() const { return alpha; } + +bool wxColour::operator==(const wxColour& color) const +{ + return red == color.red && green == color.green && blue == color.blue && alpha == color.alpha; +} + +bool wxColour::operator!=(const wxColour& color) const +{ + return !(*this == color); +} int wxColour::GetPixel() const { @@ -27,4 +51,20 @@ int wxColour::GetPixel() const return 0; } -#include "wx/colour.h" +QColor wxColour::GetQColor() const +{ + if( valid ) + return QColor(red, green, blue, alpha); + return QColor(); +} + +void wxColour::Init() +{ + valid = false; +} + +void wxColour::InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) +{ + red = r, green = g, blue = b, alpha = a; + valid = true; +} diff --git a/src/qt/cursor.cpp b/src/qt/cursor.cpp index 85714af8cc..442e250458 100644 --- a/src/qt/cursor.cpp +++ b/src/qt/cursor.cpp @@ -20,19 +20,19 @@ #endif // WX_PRECOMP #include "wx/cursor.h" - +#include "wx/qt/private/converter.h" void wxSetCursor(const wxCursor& cursor) { - if (cursor.m_qtCursor.shape() == Qt::ArrowCursor) + if (cursor.GetHandle().shape() == Qt::ArrowCursor) QApplication::restoreOverrideCursor(); else - QApplication::setOverrideCursor(cursor.m_qtCursor); + QApplication::setOverrideCursor(cursor.GetHandle()); } void wxBeginBusyCursor(const wxCursor *cursor) { - QApplication::setOverrideCursor(cursor->m_qtCursor); + QApplication::setOverrideCursor(cursor->GetHandle()); } bool wxIsBusy() @@ -45,13 +45,22 @@ void wxEndBusyCursor() QApplication::restoreOverrideCursor(); } +//----------------------------------------------------------------------------- +// wxCursorRefData +//----------------------------------------------------------------------------- + +class wxCursorRefData: public wxGDIRefData +{ +public: + wxCursorRefData() {} + wxCursorRefData( const wxCursorRefData& data ) : m_qtCursor(data.m_qtCursor) {} + wxCursorRefData( QCursor &c ) : m_qtCursor(c) {} + + QCursor m_qtCursor; +}; wxIMPLEMENT_DYNAMIC_CLASS(wxCursor, wxGDIObject); -wxCursor::wxCursor( const wxCursor &cursor ) -{ - m_qtCursor = cursor.m_qtCursor; -} #if wxUSE_IMAGE wxCursor::wxCursor(const wxString& cursor_file, @@ -77,14 +86,26 @@ wxCursor::wxCursor(const wxImage& img) } #endif +wxPoint wxCursor::GetHotSpot() const +{ + return wxQtConvertPoint(GetHandle().hotSpot()); +} + +QCursor &wxCursor::GetHandle() const +{ + return static_cast(m_refData)->m_qtCursor; +} + void wxCursor::InitFromStock( wxStockCursor cursorId ) { + AllocExclusive(); + Qt::CursorShape qt_cur; switch (cursorId) { case wxCURSOR_BLANK: { - m_qtCursor = QBitmap(); + GetHandle() = QBitmap(); return; } // case wxCURSOR_ARROW: @@ -125,28 +146,29 @@ void wxCursor::InitFromStock( wxStockCursor cursorId ) break; } - m_qtCursor.setShape(qt_cur); + GetHandle().setShape(qt_cur); } #if wxUSE_IMAGE void wxCursor::InitFromImage( const wxImage & image ) { - m_qtCursor = *wxBitmap(image).GetHandle(); + AllocExclusive(); + GetHandle() = QCursor(*wxBitmap(image).GetHandle(), + image.HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) ? + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) : -1, + image.HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ? + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) : -1); } #endif // wxUSE_IMAGE wxGDIRefData *wxCursor::CreateGDIRefData() const { - //return new wxCursorRefData; - return NULL; + return new wxCursorRefData; } -wxGDIRefData * -wxCursor::CloneGDIRefData(const wxGDIRefData * data) const +wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const { -// return new wxCursorRefData(data->bitmap()); - return NULL; - + return new wxCursorRefData(*(wxCursorRefData *)data); } diff --git a/src/qt/dc.cpp b/src/qt/dc.cpp index f8ae9e3f54..2a17e94726 100644 --- a/src/qt/dc.cpp +++ b/src/qt/dc.cpp @@ -93,7 +93,7 @@ void wxQtDCImpl::QtPreparePainter( ) } else { - wxLogDebug(wxT("wxQtDCImpl::QtPreparePainter not active!")); +// wxLogDebug(wxT("wxQtDCImpl::QtPreparePainter not active!")); } } @@ -157,7 +157,7 @@ void wxQtDCImpl::SetBrush(const wxBrush& brush) { // Use a monochrome mask: use foreground color for the mask QBrush b(brush.GetHandle()); - b.setColor(m_textForegroundColour.GetHandle()); + b.setColor(m_textForegroundColour.GetQColor()); b.setTexture(b.texture().mask()); m_qtPainter->setBrush(b); } @@ -584,7 +584,7 @@ void wxQtDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, // Save pen/brush savedBrush = m_qtPainter->brush(); // Fill with text background color ("no fill" like in wxGTK): - m_qtPainter->setBrush(QBrush(m_textBackgroundColour.GetHandle())); + m_qtPainter->setBrush(QBrush(m_textBackgroundColour.GetQColor())); } // Draw @@ -629,8 +629,8 @@ void wxQtDCImpl::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, QPen savedPen = m_qtPainter->pen(); //Use text colors - m_qtPainter->setBackground(QBrush(m_textBackgroundColour.GetHandle())); - m_qtPainter->setPen(QPen(m_textForegroundColour.GetHandle())); + m_qtPainter->setBackground(QBrush(m_textBackgroundColour.GetQColor())); + m_qtPainter->setPen(QPen(m_textForegroundColour.GetQColor())); //Draw m_qtPainter->drawPixmap(x, y, pix); @@ -660,7 +660,7 @@ void wxQtDCImpl::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, void wxQtDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y) { QPen savedPen = m_qtPainter->pen(); - m_qtPainter->setPen(QPen(m_textForegroundColour.GetHandle())); + m_qtPainter->setPen(QPen(m_textForegroundColour.GetQColor())); // Disable logical function QPainter::CompositionMode savedOp = m_qtPainter->compositionMode(); @@ -674,7 +674,7 @@ void wxQtDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y) QBrush savedBrush = m_qtPainter->background(); //Use text colors - m_qtPainter->setBackground(QBrush(m_textBackgroundColour.GetHandle())); + m_qtPainter->setBackground(QBrush(m_textBackgroundColour.GetQColor())); //Draw m_qtPainter->drawText(x, y, 1, 1, Qt::TextDontClip, wxQtConvertString(text)); @@ -703,7 +703,7 @@ void wxQtDCImpl::DoDrawRotatedText(const wxString& text, m_qtPainter->rotate(-angle); QPen savedPen = m_qtPainter->pen(); - m_qtPainter->setPen(QPen(m_textForegroundColour.GetHandle())); + m_qtPainter->setPen(QPen(m_textForegroundColour.GetQColor())); // Disable logical function QPainter::CompositionMode savedOp = m_qtPainter->compositionMode(); @@ -717,7 +717,7 @@ void wxQtDCImpl::DoDrawRotatedText(const wxString& text, QBrush savedBrush = m_qtPainter->background(); //Use text colors - m_qtPainter->setBackground(QBrush(m_textBackgroundColour.GetHandle())); + m_qtPainter->setBackground(QBrush(m_textBackgroundColour.GetQColor())); //Draw m_qtPainter->drawText(x, y, 1, 1, Qt::TextDontClip, wxQtConvertString(text)); diff --git a/src/qt/listctrl.cpp b/src/qt/listctrl.cpp index fdf6972be7..ad8ecf2b8b 100644 --- a/src/qt/listctrl.cpp +++ b/src/qt/listctrl.cpp @@ -344,9 +344,9 @@ bool wxListCtrl::SetItem(wxListItem& info) if ( info.GetFont().IsOk() ) qitem->setFont(col, info.GetFont().GetHandle() ); if ( info.GetTextColour().IsOk() ) - qitem->setTextColor(col, info.GetTextColour().GetHandle()); + qitem->setTextColor(col, info.GetTextColour().GetQColor()); if ( info.GetBackgroundColour().IsOk() ) - qitem->setBackgroundColor(col, info.GetBackgroundColour().GetHandle()); + qitem->setBackgroundColor(col, info.GetBackgroundColour().GetQColor()); } return true; } diff --git a/src/qt/pen.cpp b/src/qt/pen.cpp index bf265dcd62..f09d93108c 100644 --- a/src/qt/pen.cpp +++ b/src/qt/pen.cpp @@ -247,7 +247,7 @@ wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style) m_refData = new wxPenRefData(); M_PENDATA.setWidth(width); M_PENDATA.setStyle(ConvertPenStyle(style)); - M_PENDATA.setColor(colour.GetHandle()); + M_PENDATA.setColor(colour.GetQColor()); } wxPen::wxPen(const wxColour& col, int width, int style) @@ -255,7 +255,7 @@ wxPen::wxPen(const wxColour& col, int width, int style) m_refData = new wxPenRefData(); M_PENDATA.setWidth(width); M_PENDATA.setStyle(ConvertPenStyle((wxPenStyle)style)); - M_PENDATA.setColor(col.GetHandle()); + M_PENDATA.setColor(col.GetQColor()); } @@ -276,7 +276,7 @@ bool wxPen::operator!=(const wxPen& pen) const void wxPen::SetColour(const wxColour& col) { AllocExclusive(); - M_PENDATA.setColor(col.GetHandle()); + M_PENDATA.setColor(col.GetQColor()); } void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b) diff --git a/src/qt/window.cpp b/src/qt/window.cpp index 57695a1ef2..b29cd08531 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -228,13 +228,11 @@ bool wxWindowQt::Create( wxWindowQt * parent, wxWindowID id, const wxPoint & pos QtSetScrollBar( wxVERTICAL ); } else - { m_qtWindow = new wxQtWidget( parent, this ); - } - - GetHandle()->setMouseTracking(true); } + + GetHandle()->setMouseTracking(true); if ( !wxWindowBase::CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) return false; @@ -433,6 +431,15 @@ void wxWindowQt::Refresh( bool WXUNUSED( eraseBackground ), const wxRect *rect ) } } +bool wxWindowQt::SetCursor( const wxCursor &cursor ) +{ + if (!wxWindowBase::SetCursor(cursor)) + return false; + + GetHandle()->setCursor(cursor.GetHandle()); + + return true; +} bool wxWindowQt::SetFont( const wxFont &font ) { @@ -1131,6 +1138,8 @@ bool wxWindowQt::QtHandleResizeEvent ( QWidget *WXUNUSED( handler ), QResizeEven bool wxWindowQt::QtHandleWheelEvent ( QWidget *WXUNUSED( handler ), QWheelEvent *event ) { wxMouseEvent e( wxEVT_MOUSEWHEEL ); + e.SetPosition( wxQtConvertPoint( event->pos() ) ); + e.m_wheelAxis = ( event->orientation() == Qt::Vertical ) ? wxMOUSE_WHEEL_VERTICAL : wxMOUSE_WHEEL_HORIZONTAL; e.m_wheelRotation = event->delta(); e.m_linesPerAction = 3;