Logo    
KDWinUtils
Helper library for MFC to Qt migration
Loading...
Searching...
No Matches
KWidgetBase< T > Class Template Reference

The KWidgetBase< T > class maps the MFC API of CWnd. More...

#include <kwidget.h>

Inheritance diagram for KWidgetBase< T >:
[legend]
Collaboration diagram for KWidgetBase< T >:
[legend]

Classes

struct  ScrollInfo
 Struct used to retrieve or set the scroll bar parameters maintains. More...
 

Public Types

enum class  Flag { NoFlags = 0x0000 , VScroll = 0x0001 , HScroll = 0x0002 , HelpInfo = 0x0004 }
 
enum class  ScrollMask : uint {
  Range = 0x0001 , Page = 0x0002 , Pos = 0x0004 , DisableNoScroll = 0x0008 ,
  TrackPos = 0x0010 , All = Range | Page | Pos | TrackPos
}
 

Public Member Functions

virtual bool Create (const KString &lpszWindowName, Flags dwStyle, const KRect &rect, QWidget *pParentWnd)
 Creates and initializes the child window associated with the CWnd object.
 
void DestroyWindow ()
 Asks for deletion of the widget.
 
bool eventFilter (QObject *watched, QEvent *event) override
 
void GetClientRect (KRect *rect) const
 Gets the dimensions of the widget.
 
template<typename U >
GetParent () const
 Retrieves the parent object of the widget, requires to pass the type of the parent.
 
template<typename U = T>
KDialogGetParentDialog () const
 Retrieves the parent widget as a KDialog. Returns nullptr if it's not a KDialog.
 
template<typename U = T>
KWidgetGetParentWidget () const
 Retrieves the parent widget as a KWidget. Returns nullptr if it's not a KWidget.
 
bool GetScrollInfo (Qt::Orientation nBar, ScrollInfo *lpScrollInfo, ScrollMasks nMask=ScrollMask::All)
 Retrieves the information that the ScrollInfo structure maintains about a scroll bar.
 
int GetScrollLimit (Qt::Orientation nBar)
 Retrieves the limit of the scroll bar.
 
int GetScrollPos (Qt::Orientation nBar) const
 Retrieves the current position of a scroll box.
 
void GetScrollRange (Qt::Orientation nBar, int *lpMinPos, int *lpMaxPos) const
 Copies the current minimum and maximum scroll-bar positions for the given scroll bar.
 
void GetWindowRect (KRect *rect) const
 Gets the screen coordinates of widget.
 
virtual void OnHelp ()
 Handles F1 Help within the application (using the current context).
 
bool PostMessage (unsigned int id, uint64_t wParam=0, int64_t lParam=0)
 Places a message in the application event loop, then returns without waiting for the window to process the message.

 
int64_t SendMessage (unsigned int id, uint64_t wParam=0, int64_t lParam=0)
 Sends a message to the object and does not return until it has processed the message.
 
void setFlag (Flag flag, bool on=true)
 Sets some flags on the widget.
 
bool SetScrollInfo (Qt::Orientation nBar, ScrollInfo *lpScrollInfo, bool bRedraw=true)
 Sets information about the scroll bar.
 
int SetScrollPos (Qt::Orientation nBar, int nPos, bool bRedraw=true)
 Sets the current position of a scroll box and, if specified, redraws the scroll bar to reflect the new position.
 
void SetScrollRange (Qt::Orientation nBar, int nMinPos, int nMaxPos, bool bRedraw=true)
 Sets minimum and maximum position values for the given scroll bar.
 
 ~KWidgetBase ()
 

Static Public Attributes

static constexpr char mfcIDProperty [] = "mfc_id"
 

Protected Types

using FocusHandler = std::function<void()>
 
using MessageHandler = std::function<int64_t(uint64_t, int64_t)>
 

Protected Member Functions

template<typename Class >
void connectKillFocus (QWidget *w, Class *object, void(Class::*method)())
 
void connectKillFocus (QWidget *w, FocusHandler method)
 
template<typename Class >
void connectMessage (int id, Class *object, int64_t(Class::*method)(uint64_t, int64_t))
 
void connectMessage (int id, MessageHandler method)
 
template<typename Signal , typename Class >
void connectRange (const typename QtPrivate::FunctionPointer< Signal >::Object *firstWidget, const typename QtPrivate::FunctionPointer< Signal >::Object *lastWidget, Signal signal, Class *object, void(Class::*method)(unsigned int))
 
void connectScroll (QAbstractSlider *abstractSlider)
 
bool event (QEvent *e) override
 
void keyPressEvent (QKeyEvent *event) override
 
void keyReleaseEvent (QKeyEvent *event) override
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
virtual void OnDestroy ()
 Called when widget is being destroyed.
 
virtual bool OnHelpInfo (QKeyEvent *event)
 Called by the framework when the user presses the F1 key.
 
virtual void OnHScroll (int nSBCode, int nPos, QAbstractSlider *pScroll)
 Called when the user clicks the horizontal scroll bar.
 
virtual void OnKeyDown (QKeyEvent *event)
 Called when a key is pressed.
 
virtual void OnKeyUp (QKeyEvent *event)
 Called when a key is released.
 
virtual void OnLButtonDblClk (QMouseEvent *event)
 Called when the user double-clicks the left mouse button.
 
virtual void OnLButtonDown (QMouseEvent *event)
 Called when the user presses the left mouse button.
 
virtual void OnLButtonUp (QMouseEvent *event)
 Called when the user releases the left mouse button.
 
virtual void OnMButtonDblClk (QMouseEvent *event)
 Called when the user double-clicks the middle mouse button.
 
virtual void OnMButtonDown (QMouseEvent *event)
 Called when the user presses the middle mouse button.
 
virtual void OnMButtonUp (QMouseEvent *event)
 Called when the user releases the middle mouse button.
 
virtual void OnMouseMove (QMouseEvent *event)
 Called when the mouse cursor moves.
 
virtual void OnPaint (QPaintEvent *event)
 Called to repaint a portion of the window.
 
virtual void OnRButtonDblClk (QMouseEvent *event)
 Called when the user double-clicks the right mouse button.
 
virtual void OnRButtonDown (QMouseEvent *event)
 Called when the user presses the right mouse button.
 
virtual void OnRButtonUp (QMouseEvent *event)
 Called when the user releases the right mouse button.
 
virtual void OnSize (QResizeEvent *event)
 Called after the size of CWnd has changed.
 
virtual void OnVScroll (int nSBCode, int nPos, QAbstractSlider *pScroll)
 Called when the user clicks the vertical scroll bar.
 
void paintEvent (QPaintEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 

Friends

class KPainter
 

Detailed Description

template<typename T>
class KWidgetBase< T >

The KWidgetBase< T > class maps the MFC API of CWnd.

This class is a template class, as we need this API for QWidget, QDialog but also QMainWindow. This is the easiest way to add the same API for all of them.

Warning
Unfortunately, there's no direct inheritance anymore between KWidget and KDialog. Meaning that one as to pass the type when using GetParent, or use the GetParentDialog / GetParentWidget methods.
See also
https://learn.microsoft.com/en-us/cpp/mfc/reference/cwnd-class

Member Typedef Documentation

◆ FocusHandler

template<typename T >
using KWidgetBase< T >::FocusHandler = std::function<void()>
protected

◆ MessageHandler

template<typename T >
using KWidgetBase< T >::MessageHandler = std::function<int64_t(uint64_t, int64_t)>
protected

Member Enumeration Documentation

◆ Flag

template<typename T >
enum class KWidgetBase::Flag
strong
Enumerator
NoFlags 

Reset all flags.

VScroll 

Display a vertical scrollbar.

HScroll 

Display an horizontal scrollbar.

HelpInfo 

The widget can handle the F1 key.

◆ ScrollMask

template<typename T >
enum class KWidgetBase::ScrollMask : uint
strong
Enumerator
Range 

The nMin and nMax members contain the minimum and maximum values for the scrolling range.

Page 

The nPage member contains the page size for a proportional scroll bar.

Pos 

The nPos member contains the scroll box position, which is not updated while the user drags the scroll box.

DisableNoScroll 

Disables the scrollbar instead of removing it if unnecessary.

TrackPos 

The nTrackPos member contains the current position of the scroll box while the user is dragging it.

All 

Combination of all flags, except DisableNoScroll.

Constructor & Destructor Documentation

◆ ~KWidgetBase()

template<typename T >
KWidgetBase< T >::~KWidgetBase ( )

Member Function Documentation

◆ connectKillFocus() [1/2]

template<typename T >
template<typename Class >
void KWidgetBase< T >::connectKillFocus ( QWidget * w,
Class * object,
void(Class::* method )() )
protected

◆ connectKillFocus() [2/2]

template<typename T >
void KWidgetBase< T >::connectKillFocus ( QWidget * w,
FocusHandler method )
protected

◆ connectMessage() [1/2]

template<typename T >
template<typename Class >
void KWidgetBase< T >::connectMessage ( int id,
Class * object,
int64_t(Class::* method )(uint64_t, int64_t) )
protected

Calls this method to add a message handler, replaces the ON_MESSAGE

◆ connectMessage() [2/2]

template<typename T >
void KWidgetBase< T >::connectMessage ( int id,
MessageHandler method )
protected

Calls this method to add a message handler, replaces the ON_MESSAGE

◆ connectRange()

template<typename T >
template<typename Signal , typename Class >
void KWidgetBase< T >::connectRange ( const typename QtPrivate::FunctionPointer< Signal >::Object * firstWidget,
const typename QtPrivate::FunctionPointer< Signal >::Object * lastWidget,
Signal signal,
Class * object,
void(Class::* method )(unsigned int) )
inlineprotected

Calls this method to do a range connection on multiple widgets ON_CONTROL_RANGE. It is using the idValue property to determine the range.

◆ connectScroll()

template<typename T >
void KWidgetBase< T >::connectScroll ( QAbstractSlider * abstractSlider)
protected

Call this method for each scrollbars/sliders to connect to the On[V|H]Scroll methods

◆ Create()

template<typename T >
bool KWidgetBase< T >::Create ( const KString & lpszWindowName,
Flags dwStyle,
const KRect & rect,
QWidget * pParentWnd )
virtual

Creates and initializes the child window associated with the CWnd object.

◆ DestroyWindow()

template<typename T >
void KWidgetBase< T >::DestroyWindow ( )

Asks for deletion of the widget.

◆ event()

template<typename T >
bool KWidgetBase< T >::event ( QEvent * e)
overrideprotected

◆ eventFilter()

template<typename T >
bool KWidgetBase< T >::eventFilter ( QObject * watched,
QEvent * event )
override

◆ GetClientRect()

template<typename T >
void KWidgetBase< T >::GetClientRect ( KRect * rect) const

Gets the dimensions of the widget.

◆ GetParent()

template<typename T >
template<typename U >
U KWidgetBase< T >::GetParent ( ) const

Retrieves the parent object of the widget, requires to pass the type of the parent.

◆ GetParentDialog()

template<typename T >
template<typename U >
KDialog * KWidgetBase< T >::GetParentDialog ( ) const
inline

Retrieves the parent widget as a KDialog. Returns nullptr if it's not a KDialog.

◆ GetParentWidget()

template<typename T >
template<typename U >
KWidget * KWidgetBase< T >::GetParentWidget ( ) const
inline

Retrieves the parent widget as a KWidget. Returns nullptr if it's not a KWidget.

◆ GetScrollInfo()

template<typename T >
bool KWidgetBase< T >::GetScrollInfo ( Qt::Orientation nBar,
ScrollInfo * lpScrollInfo,
ScrollMasks nMask = ScrollMask::All )

Retrieves the information that the ScrollInfo structure maintains about a scroll bar.

◆ GetScrollLimit()

template<typename T >
int KWidgetBase< T >::GetScrollLimit ( Qt::Orientation nBar)

Retrieves the limit of the scroll bar.

◆ GetScrollPos()

template<typename T >
int KWidgetBase< T >::GetScrollPos ( Qt::Orientation nBar) const

Retrieves the current position of a scroll box.

◆ GetScrollRange()

template<typename T >
void KWidgetBase< T >::GetScrollRange ( Qt::Orientation nBar,
int * lpMinPos,
int * lpMaxPos ) const

Copies the current minimum and maximum scroll-bar positions for the given scroll bar.

◆ GetWindowRect()

template<typename T >
void KWidgetBase< T >::GetWindowRect ( KRect * rect) const

Gets the screen coordinates of widget.

◆ keyPressEvent()

template<typename T >
void KWidgetBase< T >::keyPressEvent ( QKeyEvent * event)
overrideprotected

◆ keyReleaseEvent()

template<typename T >
void KWidgetBase< T >::keyReleaseEvent ( QKeyEvent * event)
inlineoverrideprotected

◆ mouseDoubleClickEvent()

template<typename T >
void KWidgetBase< T >::mouseDoubleClickEvent ( QMouseEvent * event)
overrideprotected

◆ mouseMoveEvent()

template<typename T >
void KWidgetBase< T >::mouseMoveEvent ( QMouseEvent * event)
inlineoverrideprotected

◆ mousePressEvent()

template<typename T >
void KWidgetBase< T >::mousePressEvent ( QMouseEvent * event)
overrideprotected

◆ mouseReleaseEvent()

template<typename T >
void KWidgetBase< T >::mouseReleaseEvent ( QMouseEvent * event)
overrideprotected

◆ OnDestroy()

template<typename T >
virtual void KWidgetBase< T >::OnDestroy ( )
inlineprotectedvirtual

Called when widget is being destroyed.

◆ OnHelp()

template<typename T >
virtual void KWidgetBase< T >::OnHelp ( )
inlinevirtual

Handles F1 Help within the application (using the current context).

◆ OnHelpInfo()

template<typename T >
virtual bool KWidgetBase< T >::OnHelpInfo ( QKeyEvent * event)
inlineprotectedvirtual

Called by the framework when the user presses the F1 key.

◆ OnHScroll()

template<typename T >
virtual void KWidgetBase< T >::OnHScroll ( int nSBCode,
int nPos,
QAbstractSlider * pScroll )
inlineprotectedvirtual

Called when the user clicks the horizontal scroll bar.

◆ OnKeyDown()

template<typename T >
virtual void KWidgetBase< T >::OnKeyDown ( QKeyEvent * event)
inlineprotectedvirtual

Called when a key is pressed.

◆ OnKeyUp()

template<typename T >
virtual void KWidgetBase< T >::OnKeyUp ( QKeyEvent * event)
inlineprotectedvirtual

Called when a key is released.

◆ OnLButtonDblClk()

template<typename T >
virtual void KWidgetBase< T >::OnLButtonDblClk ( QMouseEvent * event)
inlineprotectedvirtual

Called when the user double-clicks the left mouse button.

◆ OnLButtonDown()

template<typename T >
virtual void KWidgetBase< T >::OnLButtonDown ( QMouseEvent * event)
inlineprotectedvirtual

Called when the user presses the left mouse button.

◆ OnLButtonUp()

template<typename T >
virtual void KWidgetBase< T >::OnLButtonUp ( QMouseEvent * event)
inlineprotectedvirtual

Called when the user releases the left mouse button.

◆ OnMButtonDblClk()

template<typename T >
virtual void KWidgetBase< T >::OnMButtonDblClk ( QMouseEvent * event)
inlineprotectedvirtual

Called when the user double-clicks the middle mouse button.

◆ OnMButtonDown()

template<typename T >
virtual void KWidgetBase< T >::OnMButtonDown ( QMouseEvent * event)
inlineprotectedvirtual

Called when the user presses the middle mouse button.

◆ OnMButtonUp()

template<typename T >
virtual void KWidgetBase< T >::OnMButtonUp ( QMouseEvent * event)
inlineprotectedvirtual

Called when the user releases the middle mouse button.

◆ OnMouseMove()

template<typename T >
virtual void KWidgetBase< T >::OnMouseMove ( QMouseEvent * event)
inlineprotectedvirtual

Called when the mouse cursor moves.

◆ OnPaint()

template<typename T >
void KWidgetBase< T >::OnPaint ( QPaintEvent * event)
protectedvirtual

Called to repaint a portion of the window.

◆ OnRButtonDblClk()

template<typename T >
virtual void KWidgetBase< T >::OnRButtonDblClk ( QMouseEvent * event)
inlineprotectedvirtual

Called when the user double-clicks the right mouse button.

◆ OnRButtonDown()

template<typename T >
virtual void KWidgetBase< T >::OnRButtonDown ( QMouseEvent * event)
inlineprotectedvirtual

Called when the user presses the right mouse button.

◆ OnRButtonUp()

template<typename T >
virtual void KWidgetBase< T >::OnRButtonUp ( QMouseEvent * event)
inlineprotectedvirtual

Called when the user releases the right mouse button.

◆ OnSize()

template<typename T >
virtual void KWidgetBase< T >::OnSize ( QResizeEvent * event)
inlineprotectedvirtual

Called after the size of CWnd has changed.

◆ OnVScroll()

template<typename T >
virtual void KWidgetBase< T >::OnVScroll ( int nSBCode,
int nPos,
QAbstractSlider * pScroll )
inlineprotectedvirtual

Called when the user clicks the vertical scroll bar.

◆ paintEvent()

template<typename T >
void KWidgetBase< T >::paintEvent ( QPaintEvent * event)
overrideprotected

◆ PostMessage()

template<typename T >
bool KWidgetBase< T >::PostMessage ( unsigned int id,
uint64_t wParam = 0,
int64_t lParam = 0 )

Places a message in the application event loop, then returns without waiting for the window to process the message.

◆ resizeEvent()

template<typename T >
void KWidgetBase< T >::resizeEvent ( QResizeEvent * event)
inlineoverrideprotected

◆ SendMessage()

template<typename T >
int64_t KWidgetBase< T >::SendMessage ( unsigned int id,
uint64_t wParam = 0,
int64_t lParam = 0 )

Sends a message to the object and does not return until it has processed the message.

◆ setFlag()

template<typename T >
void KWidgetBase< T >::setFlag ( Flag flag,
bool on = true )

Sets some flags on the widget.

Display a scrollarea with either a vertical, an horizontal or both scrollbars, the client rect becomes the inner part of the frame.

◆ SetScrollInfo()

template<typename T >
bool KWidgetBase< T >::SetScrollInfo ( Qt::Orientation nBar,
ScrollInfo * lpScrollInfo,
bool bRedraw = true )

Sets information about the scroll bar.

◆ SetScrollPos()

template<typename T >
int KWidgetBase< T >::SetScrollPos ( Qt::Orientation nBar,
int nPos,
bool bRedraw = true )

Sets the current position of a scroll box and, if specified, redraws the scroll bar to reflect the new position.

◆ SetScrollRange()

template<typename T >
void KWidgetBase< T >::SetScrollRange ( Qt::Orientation nBar,
int nMinPos,
int nMaxPos,
bool bRedraw = true )

Sets minimum and maximum position values for the given scroll bar.

Friends And Related Symbol Documentation

◆ KPainter

template<typename T >
friend class KPainter
friend

Member Data Documentation

◆ mfcIDProperty

template<typename T >
char KWidgetBase< T >::mfcIDProperty[] = "mfc_id"
staticconstexpr

The documentation for this class was generated from the following files: