PageRenderTime 25ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/sqscripter/wx/src/qt/utils.cpp

https://gitlab.com/msakuta/VastSpace
C++ | 174 lines | 127 code | 31 blank | 16 comment | 12 complexity | b56a3641feb6c6812e7da258676fed9c MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0, GPL-2.0, AGPL-3.0
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: src/qt/utils.cpp
  3. // Author: Peter Most, Javier Torres, Mariano Reingart
  4. // Copyright: (c) 2010 wxWidgets dev team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. // For compilers that support precompilation, includes "wx.h".
  8. #include "wx/wxprec.h"
  9. #ifdef __BORLANDC__
  10. #pragma hdrstop
  11. #endif
  12. #include <QtGui/QCursor>
  13. #include <QtWidgets/QApplication>
  14. #include <QtWidgets/QDesktopWidget>
  15. #include <QtGui/QDesktopServices>
  16. #include <QtCore/QUrl>
  17. #ifndef WX_PRECOMP
  18. #include "wx/cursor.h"
  19. #include "wx/log.h"
  20. #include "wx/window.h"
  21. #endif // WX_PRECOMP
  22. #include "wx/utils.h"
  23. #include "wx/qt/private/utils.h"
  24. #include "wx/qt/private/converter.h"
  25. void wxMissingImplementation( const char fileName[], unsigned lineNumber,
  26. const char feature[] )
  27. {
  28. // Make it look similar to the assert messages:
  29. fprintf( stderr, "%s(%d): Missing implementation of \"%s\"\n", fileName, lineNumber, feature );
  30. }
  31. void wxQtFillMouseButtons( Qt::MouseButtons buttons, wxMouseState *state )
  32. {
  33. state->SetLeftDown( buttons.testFlag( Qt::LeftButton ) );
  34. state->SetRightDown( buttons.testFlag( Qt::RightButton ) );
  35. state->SetMiddleDown( buttons.testFlag( Qt::MidButton ) );
  36. state->SetAux1Down( buttons.testFlag( Qt::XButton1 ) );
  37. state->SetAux2Down( buttons.testFlag( Qt::XButton2 ) );
  38. }
  39. #if wxUSE_GUI
  40. wxPoint wxGetMousePosition()
  41. {
  42. return wxQtConvertPoint( QCursor::pos() );
  43. }
  44. void wxGetMousePosition( int *x, int *y )
  45. {
  46. wxPoint position = wxGetMousePosition();
  47. *x = position.x;
  48. *y = position.y;
  49. }
  50. #endif
  51. #if wxUSE_GUI
  52. wxMouseState wxGetMouseState()
  53. {
  54. wxMouseState ms;
  55. wxQtFillMouseButtons( QApplication::mouseButtons(), &ms );
  56. return ms;
  57. }
  58. #endif
  59. wxWindow *wxFindWindowAtPoint(const wxPoint& pt)
  60. {
  61. /* Another option is to use QApplication::topLevelAt()
  62. * but that gives the QWidget so the wxWindow list must
  63. * be traversed comparing with this, or use the pointer from
  64. * a wxQtWidget/wxQtFrame to the window, but they have
  65. * no standard interface to return that. */
  66. return wxGenericFindWindowAtPoint( pt );
  67. }
  68. wxWindow *wxFindWindowAtPointer(wxPoint& pt)
  69. {
  70. pt = wxQtConvertPoint( QCursor::pos() );
  71. return wxFindWindowAtPoint( pt );
  72. }
  73. bool wxGetKeyState(wxKeyCode key)
  74. {
  75. /* FIXME: Qt doesn't provide a method to check the state of keys others
  76. * than modifiers (shift, control, alt, meta). A platform-specific method
  77. * is needed, probably one per platform Qt runs on. */
  78. switch ( key )
  79. {
  80. case WXK_CONTROL:
  81. return QApplication::keyboardModifiers().testFlag(Qt::ControlModifier);
  82. case WXK_SHIFT:
  83. return QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier);
  84. case WXK_ALT:
  85. return QApplication::keyboardModifiers().testFlag(Qt::AltModifier);
  86. case WXK_WINDOWS_LEFT:
  87. return QApplication::keyboardModifiers().testFlag(Qt::MetaModifier);
  88. default:
  89. wxMISSING_IMPLEMENTATION( "wxGetKeyState for non-modifiers keys" );
  90. return false;
  91. }
  92. }
  93. int wxDisplayDepth()
  94. {
  95. return QApplication::desktop()->depth();
  96. }
  97. void wxDisplaySize(int *width, int *height)
  98. {
  99. if ( width != NULL )
  100. *width = QApplication::desktop()->width();
  101. if ( height != NULL )
  102. *height = QApplication::desktop()->height();
  103. }
  104. void wxDisplaySizeMM(int *width, int *height)
  105. {
  106. if ( width != NULL )
  107. *width = QApplication::desktop()->widthMM();
  108. if ( height != NULL )
  109. *height = QApplication::desktop()->heightMM();
  110. }
  111. void wxBell()
  112. {
  113. QApplication::beep();
  114. }
  115. void wxClientDisplayRect(int *x, int *y, int *width, int *height)
  116. {
  117. QRect r = QApplication::desktop()->availableGeometry();
  118. *x = r.x();
  119. *y = r.y();
  120. *width = r.width();
  121. *height = r.height();
  122. }
  123. wxWindow *wxGetActiveWindow()
  124. {
  125. QWidget *w = QApplication::activeWindow();
  126. wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetLast();
  127. while (node)
  128. {
  129. wxWindow* win = node->GetData();
  130. if ( win->GetHandle() == w )
  131. return win;
  132. node = node->GetPrevious();
  133. }
  134. return NULL;
  135. }
  136. bool wxColourDisplay()
  137. {
  138. return QApplication::desktop()->depth() > 1;
  139. }
  140. bool wxLaunchDefaultApplication(const wxString& path, int WXUNUSED( flags ) )
  141. {
  142. return QDesktopServices::openUrl( QUrl::fromLocalFile( wxQtConvertString( path ) ) );
  143. }