Logo    
KDWinUtils
Helper library for MFC to Qt migration
Loading...
Searching...
No Matches
kwidget.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of KDWinutils, KDAB's MFC to Qt migration tool.
4**
5** Copyright (C) 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6** All rights reserved.
7**
8** This file is intended solely for use by the migration tools and services
9** provided by Klarälvdalens Datakonsult AB.
10**
11** Any other use or distribution of this software that is not otherwise agreed
12** upon in writing and signed by an authorized representative of Klarälvdalens
13** Datakonsult AB, KDAB (USA) LLC, KDAB (Deutschland) GmbH & Co. K.G.,
14** KDAB (France) SAS, KDAB (UK), Ltd., or any future subsidiary of Klarälvdalens
15** Datakonsult AB is hereby prohibited.
16**
17** Contact info@kdab.com if any conditions stated above are unclear to you.
18**
19****************************************************************************/
20
21#pragma once
22
23#include "../corelib/krect.h"
24#include "../corelib/kstring.h"
26
27#include <QAbstractScrollArea>
28#include <QAbstractSlider>
29#include <QCoreApplication>
30#include <QKeyEvent>
31#include <QMouseEvent>
32#include <QScrollBar>
33#include <QVBoxLayout>
34#include <QWidget>
35
36#include <functional>
37#include <optional>
38#include <unordered_map>
39
40#ifdef KDWINUTILS_WITHMFC
41#include <afxwin.h>
42#endif
43
45
46class KWidget;
47class KDialog;
48
49constexpr char InternalScrollAreaName[] = "InternalScroll";
50
55class KMessageEvent : public QEvent
56{
57public:
58 explicit KMessageEvent(unsigned int messageId, uint64_t w, int64_t l)
59 : QEvent(static_cast<QEvent::Type>(KMessageEvent::Type))
60 , id(messageId)
61 , wparam(w)
62 , lparam(l)
63 {
64 }
65
66 enum {
67 Type = QEvent::User + 45687,
68 };
69
70 unsigned int id;
71 uint64_t wparam;
72 int64_t lparam;
73};
74
85template <typename T>
86class KWidgetBase : public T
87{
88public:
89 using T::T;
91
92 static constexpr char mfcIDProperty[] = "mfc_id";
93
94 bool eventFilter(QObject *watched, QEvent *event) override;
95
96 enum class Flag {
97 NoFlags = 0x0000,
98 VScroll = 0x0001,
99 HScroll = 0x0002,
100 HelpInfo = 0x0004,
101 };
102 Q_DECLARE_FLAGS(Flags, Flag)
108 void setFlag(Flag flag, bool on = true);
109
111 virtual bool Create(const KString &lpszWindowName, Flags dwStyle, const KRect &rect, QWidget *pParentWnd);
112
115 bool PostMessage(unsigned int id, uint64_t wParam = 0, int64_t lParam = 0);
116
118 int64_t SendMessage(unsigned int id, uint64_t wParam = 0, int64_t lParam = 0);
119
122
124 template <typename U>
125 U GetParent() const;
126
128 template <typename U = T>
130
132 template <typename U = T>
133 KDialog *GetParentDialog() const;
134
136 void GetClientRect(KRect *rect) const;
138 void GetWindowRect(KRect *rect) const;
139
140 enum class ScrollMask : uint {
141 Range = 0x0001,
142 Page = 0x0002,
143 Pos = 0x0004,
145 DisableNoScroll = 0x0008,
146 TrackPos = 0x0010,
148 All = Range | Page | Pos | TrackPos,
149 };
150 Q_DECLARE_FLAGS(ScrollMasks, ScrollMask)
151
152
158 {
159 ScrollMasks fMask;
160 int nMin = -1;
161 int nMax = -1;
162 unsigned int nPage = -1;
163 int nPos = -1;
164 int nTrackPos = -1;
165 };
166
168 bool GetScrollInfo(Qt::Orientation nBar, ScrollInfo *lpScrollInfo, ScrollMasks nMask = ScrollMask::All);
170 int GetScrollLimit(Qt::Orientation nBar);
172 int GetScrollPos(Qt::Orientation nBar) const;
174 void GetScrollRange(Qt::Orientation nBar, int *lpMinPos, int *lpMaxPos) const;
176 bool SetScrollInfo(Qt::Orientation nBar, ScrollInfo *lpScrollInfo, bool bRedraw = true);
179 int SetScrollPos(Qt::Orientation nBar, int nPos, bool bRedraw = true);
181 void SetScrollRange(Qt::Orientation nBar, int nMinPos, int nMaxPos, bool bRedraw = true);
182
184 virtual void OnHelp() { }
185
186protected:
187 using MessageHandler = std::function<int64_t(uint64_t, int64_t)>;
189 void connectMessage(int id, MessageHandler method);
191 template <typename Class>
192 void connectMessage(int id, Class *object, int64_t (Class::*method)(uint64_t, int64_t));
193
194 using FocusHandler = std::function<void()>;
195 void connectKillFocus(QWidget *w, FocusHandler method);
196 template <typename Class>
197 void connectKillFocus(QWidget *w, Class *object, void (Class::*method)());
198
200 void connectScroll(QAbstractSlider *abstractSlider);
205 template <typename Signal, typename Class>
206 void connectRange(const typename QtPrivate::FunctionPointer<Signal>::Object *firstWidget,
207 const typename QtPrivate::FunctionPointer<Signal>::Object *lastWidget, Signal signal,
208 Class *object, void (Class::*method)(unsigned int));
209
211 virtual bool OnHelpInfo(QKeyEvent *event) { return false; }
212
214 virtual void OnLButtonDblClk(QMouseEvent *event) { }
216 virtual void OnLButtonDown(QMouseEvent *event) { }
218 virtual void OnLButtonUp(QMouseEvent *event) { }
220 virtual void OnMButtonDblClk(QMouseEvent *event) { }
222 virtual void OnMButtonDown(QMouseEvent *event) { }
224 virtual void OnMButtonUp(QMouseEvent *event) { }
226 virtual void OnRButtonDblClk(QMouseEvent *event) { }
228 virtual void OnRButtonDown(QMouseEvent *event) { }
230 virtual void OnRButtonUp(QMouseEvent *event) { }
232 virtual void OnMouseMove(QMouseEvent *event) { }
233
235 virtual void OnKeyDown(QKeyEvent *event) { }
237 virtual void OnKeyUp(QKeyEvent *event) { }
238
240 virtual void OnPaint(QPaintEvent *event);
241
243 virtual void OnHScroll(int nSBCode, int nPos, QAbstractSlider *pScroll) { }
245 virtual void OnVScroll(int nSBCode, int nPos, QAbstractSlider *pScroll) { }
246
248 virtual void OnDestroy() { }
249
251 virtual void OnSize(QResizeEvent *event) { }
252
253 void mousePressEvent(QMouseEvent *event) override;
254 void mouseReleaseEvent(QMouseEvent *event) override;
255 void mouseDoubleClickEvent(QMouseEvent *event) override;
256 void mouseMoveEvent(QMouseEvent *event) override;
257 void paintEvent(QPaintEvent *event) override;
258 void keyPressEvent(QKeyEvent *event) override;
259 void keyReleaseEvent(QKeyEvent *event) override;
260 void resizeEvent(QResizeEvent *event) override;
261 bool event(QEvent *e) override;
262
263private:
264 friend class KPainter;
265
266 std::optional<int64_t> handleMessageEvent(unsigned int id, uint64_t wparam, int64_t lparam);
267 void handleFocusEvent(QObject *id);
268 QAbstractScrollArea *scrollArea() const;
269 QScrollBar *scrollBar(Qt::Orientation nBar) const;
270
271 std::unordered_map<unsigned int, MessageHandler> m_messageHandlers;
272 std::unordered_map<QObject *, FocusHandler> m_focusHandlers;
273 int64_t m_messageResult;
274 Flags m_flags;
275};
276
282class KDWINUTILS_EXPORT KWidget : public KWidgetBase<QWidget>
283{
284 Q_OBJECT
285public:
286 using KWidgetBase<QWidget>::KWidgetBase;
287};
288
290// KWidgetBase method implementations
292template <typename T>
294{
295 OnDestroy();
296}
297
298template <typename T>
299bool KWidgetBase<T>::eventFilter(QObject *watched, QEvent *event)
300{
301 if (watched->objectName() == InternalScrollAreaName && event->type() == QEvent::Paint) {
302 auto paintEvent = static_cast<QPaintEvent *>(event);
303 OnPaint(paintEvent);
304 }
305 if (event->type() == QEvent::FocusOut) {
306 handleFocusEvent(watched);
307 }
308 return T::eventFilter(watched, event);
309}
310
311template <typename T>
312void KWidgetBase<T>::setFlag(Flag flag, bool on)
313{
314 m_flags.setFlag(flag, on);
315}
316
317template <typename T>
318bool KWidgetBase<T>::Create(const KString &lpszWindowName, Flags dwStyle, const KRect &rect, QWidget *pParentWnd)
319{
320 m_flags |= dwStyle;
321
322 if (dwStyle.testAnyFlags({Flag::HScroll, Flag::VScroll})) {
323 auto scrollArea = new QAbstractScrollArea(this);
324 scrollArea->setObjectName(InternalScrollAreaName);
325 scrollArea->setFrameShape(QFrame::NoFrame);
326 scrollArea->setLineWidth(0);
327 auto layout = new QHBoxLayout(this);
328 layout->addWidget(scrollArea);
329 layout->setContentsMargins({});
330 connectScroll(scrollArea->horizontalScrollBar());
331 connectScroll(scrollArea->verticalScrollBar());
332 if (!dwStyle.testAnyFlag(Flag::HScroll))
333 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
334 if (!dwStyle.testAnyFlag(Flag::VScroll))
335 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
336 scrollArea->viewport()->setObjectName(InternalScrollAreaName);
337 scrollArea->viewport()->installEventFilter(this);
338 }
339
340 T::setParent(pParentWnd);
341 T::setGeometry(rect);
342
343 return true;
344}
345
346template <typename T>
347bool KWidgetBase<T>::PostMessage(unsigned int id, uint64_t wParam, int64_t lParam)
348{
349 auto message = new KMessageEvent(id, wParam, lParam);
350 QCoreApplication::postEvent(this, message);
351 return true;
352}
353
354template <typename T>
355int64_t KWidgetBase<T>::SendMessage(unsigned int id, uint64_t wParam, int64_t lParam)
356{
357 auto message = KMessageEvent(id, wParam, lParam);
358 QCoreApplication::sendEvent(this, &message);
359 return m_messageResult;
360}
361
362template <typename T>
364{
365 T::deleteLater();
366}
367
368template <typename T>
369template <typename U>
371{
372 return dynamic_cast<U>(T::parent());
373}
374
375template <typename T>
376template <typename U>
378{
379 return qobject_cast<KWidget *>(T::parent());
380}
381
382template <typename T>
384{
385 if (m_flags.testAnyFlags({Flag::HScroll, Flag::VScroll})) {
386 const auto &viewportRect = scrollArea()->viewport()->rect();
387 *rect = viewportRect;
388 } else {
389 rect->SetRect(0, 0, T::width(), T::height());
390 }
391}
392
393template <typename T>
395{
396 const auto &geom = T::frameGeometry();
397 rect->SetRect(T::x(), T::y(), geom.width(), geom.height());
398}
399
400template <typename T>
401bool KWidgetBase<T>::GetScrollInfo(Qt::Orientation nBar, ScrollInfo *lpScrollInfo, ScrollMasks nMask)
402{
403 auto sb = scrollBar(nBar);
404 if (nMask.testFlag(ScrollMask::Range)) {
405 lpScrollInfo->nMin = sb->minimum();
406 lpScrollInfo->nMax = sb->maximum();
407 }
408 if (nMask.testFlag(ScrollMask::Page))
409 lpScrollInfo->nPage = sb->pageStep();
410 if (nMask.testFlag(ScrollMask::Pos))
411 lpScrollInfo->nPos = sb->value();
412 if (nMask.testFlag(ScrollMask::TrackPos))
413 lpScrollInfo->nTrackPos = sb->sliderPosition();
414 lpScrollInfo->fMask = nMask;
415 return true;
416}
417
418template <typename T>
419int KWidgetBase<T>::GetScrollLimit(Qt::Orientation nBar)
420{
421 return scrollBar(nBar)->maximum();
422}
423
424template <typename T>
425int KWidgetBase<T>::GetScrollPos(Qt::Orientation nBar) const
426{
427 return scrollBar(nBar)->value();
428}
429
430template <typename T>
431void KWidgetBase<T>::GetScrollRange(Qt::Orientation nBar, int *lpMinPos, int *lpMaxPos) const
432{
433 *lpMinPos = scrollBar(nBar)->minimum();
434 *lpMaxPos = scrollBar(nBar)->maximum();
435}
436
437template <typename T>
438bool KWidgetBase<T>::SetScrollInfo(Qt::Orientation nBar, ScrollInfo *lpScrollInfo, bool /*bRedraw*/)
439{
440 auto sb = scrollBar(nBar);
441 if (lpScrollInfo->fMask.testFlag(ScrollMask::Range))
442 sb->setRange(lpScrollInfo->nMin, lpScrollInfo->nMax);
443 if (lpScrollInfo->fMask.testFlag(ScrollMask::Page))
444 sb->setPageStep(lpScrollInfo->nPage);
445 if (lpScrollInfo->fMask.testFlag(ScrollMask::TrackPos) && lpScrollInfo->nTrackPos != -1)
446 sb->setSliderPosition(lpScrollInfo->nTrackPos);
447 if (lpScrollInfo->fMask.testFlag(ScrollMask::Pos))
448 sb->setValue(lpScrollInfo->nPos);
449 if (lpScrollInfo->fMask.testFlag(ScrollMask::DisableNoScroll)) {
450 switch (nBar) {
451 case Qt::Horizontal:
452 scrollArea()->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
453 case Qt::Vertical:
454 scrollArea()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
455 }
456 }
457 return true;
458}
459
460template <typename T>
461int KWidgetBase<T>::SetScrollPos(Qt::Orientation nBar, int nPos, bool /*bRedraw*/)
462{
463 const int oldValue = scrollBar(nBar)->value();
464 scrollBar(nBar)->setValue(nPos);
465 return oldValue;
466}
467
468template <typename T>
469void KWidgetBase<T>::SetScrollRange(Qt::Orientation nBar, int nMinPos, int nMaxPos, bool /*bRedraw*/)
470{
471 scrollBar(nBar)->setRange(nMinPos, nMaxPos);
472}
473
474template <typename T>
476{
477 m_messageHandlers[id] = method;
478}
479
480template <typename T>
481void KWidgetBase<T>::handleFocusEvent(QObject *id)
482{
483 auto it = m_focusHandlers.find(id);
484 if (it != m_focusHandlers.end()) {
485 it->second;
486 }
487}
488
489template <typename T>
490template <typename Class>
491void KWidgetBase<T>::connectMessage(int id, Class *object, int64_t (Class::*method)(uint64_t, int64_t))
492{
493 connectMessage(id, [object, method](uint64_t wParam, int64_t lParam) {
494 return (object->*method)(wParam, lParam);
495 });
496}
497
498template <typename T>
500{
501 m_focusHandlers[w] = method;
502 w->installEventFilter(this);
503}
504
505template <typename T>
506template <typename Class>
507void KWidgetBase<T>::connectKillFocus(QWidget *w, Class *object, void (Class::*method)())
508{
509 connectKillFocus(w, [object, method]() {
510 return (object->*method)();
511 });
512}
513
514template <typename T>
515void KWidgetBase<T>::connectScroll(QAbstractSlider *abstractSlider)
516{
517 auto callback = [abstractSlider, this](int action) {
518 if (abstractSlider->orientation() == Qt::Horizontal)
519 OnHScroll(action, abstractSlider->sliderPosition(), abstractSlider);
520 else
521 OnVScroll(action, abstractSlider->sliderPosition(), abstractSlider);
522 };
523 T::connect(abstractSlider, &QAbstractSlider::actionTriggered, this, callback);
524}
525
526template <typename T>
527template <typename Signal, typename Class>
528inline void KWidgetBase<T>::connectRange(const typename QtPrivate::FunctionPointer<Signal>::Object *firstWidget,
529 const typename QtPrivate::FunctionPointer<Signal>::Object *lastWidget,
530 Signal signal, Class *object, void (Class::*method)(unsigned int))
531{
532 const int firstId = firstWidget->property(mfcIDProperty).toInt();
533 const int lastId = lastWidget->property(mfcIDProperty).toInt();
534 if (firstId == 0 || lastId == 0)
535 return;
536 auto widgets = T::template findChildren<QWidget *>();
537 for (auto widget : widgets) {
538 const int id = widget->property(mfcIDProperty).toInt();
539 if (id >= firstId && id <= lastId) {
540 T::connect(dynamic_cast<typename QtPrivate::FunctionPointer<Signal>::Object *>(widget), signal, object,
541 [object, method, id] {
542 (object->*method)(id);
543 });
544 }
545 }
546}
547
548template <typename T>
549void KWidgetBase<T>::OnPaint(QPaintEvent *event)
550{
551 T::paintEvent(event);
552}
553
554template <typename T>
555void KWidgetBase<T>::mousePressEvent(QMouseEvent *event)
556{
557 switch (event->button()) {
558 case Qt::LeftButton:
559 OnLButtonDown(event);
560 break;
561 case Qt::MiddleButton:
562 OnMButtonDown(event);
563 break;
564 case Qt::RightButton:
565 OnRButtonDown(event);
566 break;
567 default:
568 break;
569 }
570 T::mousePressEvent(event);
571}
572
573template <typename T>
574void KWidgetBase<T>::mouseReleaseEvent(QMouseEvent *event)
575{
576 switch (event->button()) {
577 case Qt::LeftButton:
578 OnLButtonUp(event);
579 break;
580 case Qt::MiddleButton:
581 OnMButtonUp(event);
582 break;
583 case Qt::RightButton:
584 OnRButtonUp(event);
585 break;
586 default:
587 break;
588 }
589 T::mouseReleaseEvent(event);
590}
591
592template <typename T>
594{
595 switch (event->button()) {
596 case Qt::LeftButton:
597 OnLButtonDblClk(event);
598 break;
599 case Qt::MiddleButton:
600 OnMButtonDblClk(event);
601 break;
602 case Qt::RightButton:
603 OnRButtonDblClk(event);
604 break;
605 default:
606 break;
607 }
608 T::mouseDoubleClickEvent(event);
609}
610
611template <typename T>
612inline void KWidgetBase<T>::mouseMoveEvent(QMouseEvent *event)
613{
614 OnMouseMove(event);
615 T::mouseMoveEvent(event);
616}
617
618template <typename T>
619void KWidgetBase<T>::paintEvent(QPaintEvent *event)
620{
621 // Do nothing if there's a scroll area (the widget is behind it anyway)
622 // Painting is done inside the eventFilter, on the viewport of the scrollArea
623 if (m_flags.testAnyFlags({Flag::HScroll, Flag::VScroll}))
624 return;
625 OnPaint(event);
626}
627
628template <typename T>
629void KWidgetBase<T>::keyPressEvent(QKeyEvent *event)
630{
631 if (event->key() == Qt::Key_F1 && event->modifiers() == Qt::NoModifier && m_flags.testFlag(Flag::HelpInfo)) {
632 OnHelpInfo(event);
633 OnHelp();
634 }
635 OnKeyDown(event);
636 T::keyPressEvent(event);
637}
638
639template <typename T>
640inline void KWidgetBase<T>::keyReleaseEvent(QKeyEvent *event)
641{
642 OnKeyUp(event);
643 T::keyReleaseEvent(event);
644}
645
646template <typename T>
647inline void KWidgetBase<T>::resizeEvent(QResizeEvent *event)
648{
649 T::resizeEvent(event);
650 OnSize(event);
651}
652
653template <typename T>
655{
656 if (e->type() == static_cast<QEvent::Type>(KMessageEvent::Type)) {
657 auto message = static_cast<KMessageEvent *>(e);
658 auto result = handleMessageEvent(message->id, message->wparam, message->lparam);
659 m_messageResult = result.value_or(0);
660 return result.has_value();
661 }
662 return T::event(e);
663}
664
665template <typename T>
666std::optional<int64_t> KWidgetBase<T>::handleMessageEvent(unsigned int id, uint64_t wparam, int64_t lparam)
667{
668 auto it = m_messageHandlers.find(id);
669 if (it == m_messageHandlers.end())
670 return {};
671 return it->second(wparam, lparam);
672}
673
674template <typename T>
675QAbstractScrollArea *KWidgetBase<T>::scrollArea() const
676{
677 return T::template findChild<QAbstractScrollArea *>(InternalScrollAreaName, Qt::FindDirectChildrenOnly);
678}
679
680template <typename T>
681QScrollBar *KWidgetBase<T>::scrollBar(Qt::Orientation nBar) const
682{
683 switch (nBar) {
684 case Qt::Horizontal:
685 return scrollArea()->horizontalScrollBar();
686 case Qt::Vertical:
687 return scrollArea()->verticalScrollBar();
688 }
689 return nullptr;
690}
691
The KDialog class is used to replace MFC KDialog.
Definition kdialog.h:40
Event use internally to map the MFC message handling.
Definition kwidget.h:56
uint64_t wparam
Definition kwidget.h:71
KMessageEvent(unsigned int messageId, uint64_t w, int64_t l)
Definition kwidget.h:58
unsigned int id
Definition kwidget.h:70
@ Type
Definition kwidget.h:67
int64_t lparam
Definition kwidget.h:72
The KPainter class is used to paint on a widget.
Definition kpainter.h:51
The KRect class defines a rectangle in the plane using integer precision.
Definition krect.h:40
void SetRect(int left, int top, int right, int bottom)
Sets the dimensions of KRect.
The KString class provides a Unicode character string.
Definition kstring.h:45
The KWidgetBase< T > class maps the MFC API of CWnd.
Definition kwidget.h:87
void connectKillFocus(QWidget *w, FocusHandler method)
Definition kwidget.h:499
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 proces...
Definition kwidget.h:347
virtual void OnHelp()
Handles F1 Help within the application (using the current context).
Definition kwidget.h:184
void connectMessage(int id, Class *object, int64_t(Class::*method)(uint64_t, int64_t))
Definition kwidget.h:491
void DestroyWindow()
Asks for deletion of the widget.
Definition kwidget.h:363
void setFlag(Flag flag, bool on=true)
Sets some flags on the widget.
Definition kwidget.h:312
virtual void OnLButtonDblClk(QMouseEvent *event)
Called when the user double-clicks the left mouse button.
Definition kwidget.h:214
virtual void OnDestroy()
Called when widget is being destroyed.
Definition kwidget.h:248
KWidget * GetParentWidget() const
Retrieves the parent widget as a KWidget. Returns nullptr if it's not a KWidget.
Definition kwidget.h:377
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.
Definition kwidget.h:355
int GetScrollLimit(Qt::Orientation nBar)
Retrieves the limit of the scroll bar.
Definition kwidget.h:419
void paintEvent(QPaintEvent *event) override
Definition kwidget.h:619
bool eventFilter(QObject *watched, QEvent *event) override
Definition kwidget.h:299
virtual void OnKeyDown(QKeyEvent *event)
Called when a key is pressed.
Definition kwidget.h:235
virtual bool OnHelpInfo(QKeyEvent *event)
Called by the framework when the user presses the F1 key.
Definition kwidget.h:211
static constexpr char mfcIDProperty[]
Definition kwidget.h:92
void keyPressEvent(QKeyEvent *event) override
Definition kwidget.h:629
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))
Definition kwidget.h:528
KDialog * GetParentDialog() const
Retrieves the parent widget as a KDialog. Returns nullptr if it's not a KDialog.
Definition kdialog.h:85
bool GetScrollInfo(Qt::Orientation nBar, ScrollInfo *lpScrollInfo, ScrollMasks nMask=ScrollMask::All)
Retrieves the information that the ScrollInfo structure maintains about a scroll bar.
Definition kwidget.h:401
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 ne...
Definition kwidget.h:461
virtual void OnMButtonDblClk(QMouseEvent *event)
Called when the user double-clicks the middle mouse button.
Definition kwidget.h:220
virtual void OnKeyUp(QKeyEvent *event)
Called when a key is released.
Definition kwidget.h:237
bool SetScrollInfo(Qt::Orientation nBar, ScrollInfo *lpScrollInfo, bool bRedraw=true)
Sets information about the scroll bar.
Definition kwidget.h:438
void GetClientRect(KRect *rect) const
Gets the dimensions of the widget.
Definition kwidget.h:383
void mouseReleaseEvent(QMouseEvent *event) override
Definition kwidget.h:574
virtual void OnSize(QResizeEvent *event)
Called after the size of CWnd has changed.
Definition kwidget.h:251
virtual void OnPaint(QPaintEvent *event)
Called to repaint a portion of the window.
Definition kwidget.h:549
virtual bool Create(const KString &lpszWindowName, Flags dwStyle, const KRect &rect, QWidget *pParentWnd)
Creates and initializes the child window associated with the CWnd object.
Definition kwidget.h:318
virtual void OnMouseMove(QMouseEvent *event)
Called when the mouse cursor moves.
Definition kwidget.h:232
void GetScrollRange(Qt::Orientation nBar, int *lpMinPos, int *lpMaxPos) const
Copies the current minimum and maximum scroll-bar positions for the given scroll bar.
Definition kwidget.h:431
virtual void OnRButtonUp(QMouseEvent *event)
Called when the user releases the right mouse button.
Definition kwidget.h:230
virtual void OnRButtonDown(QMouseEvent *event)
Called when the user presses the right mouse button.
Definition kwidget.h:228
void mouseDoubleClickEvent(QMouseEvent *event) override
Definition kwidget.h:593
std::function< void()> FocusHandler
Definition kwidget.h:194
void connectMessage(int id, MessageHandler method)
Definition kwidget.h:475
void resizeEvent(QResizeEvent *event) override
Definition kwidget.h:647
std::function< int64_t(uint64_t, int64_t)> MessageHandler
Definition kwidget.h:187
virtual void OnLButtonDown(QMouseEvent *event)
Called when the user presses the left mouse button.
Definition kwidget.h:216
virtual void OnVScroll(int nSBCode, int nPos, QAbstractSlider *pScroll)
Called when the user clicks the vertical scroll bar.
Definition kwidget.h:245
virtual void OnMButtonDown(QMouseEvent *event)
Called when the user presses the middle mouse button.
Definition kwidget.h:222
void GetWindowRect(KRect *rect) const
Gets the screen coordinates of widget.
Definition kwidget.h:394
void keyReleaseEvent(QKeyEvent *event) override
Definition kwidget.h:640
void mouseMoveEvent(QMouseEvent *event) override
Definition kwidget.h:612
virtual void OnHScroll(int nSBCode, int nPos, QAbstractSlider *pScroll)
Called when the user clicks the horizontal scroll bar.
Definition kwidget.h:243
virtual void OnRButtonDblClk(QMouseEvent *event)
Called when the user double-clicks the right mouse button.
Definition kwidget.h:226
void connectScroll(QAbstractSlider *abstractSlider)
Definition kwidget.h:515
int GetScrollPos(Qt::Orientation nBar) const
Retrieves the current position of a scroll box.
Definition kwidget.h:425
void mousePressEvent(QMouseEvent *event) override
Definition kwidget.h:555
bool event(QEvent *e) override
Definition kwidget.h:654
void SetScrollRange(Qt::Orientation nBar, int nMinPos, int nMaxPos, bool bRedraw=true)
Sets minimum and maximum position values for the given scroll bar.
Definition kwidget.h:469
virtual void OnLButtonUp(QMouseEvent *event)
Called when the user releases the left mouse button.
Definition kwidget.h:218
U GetParent() const
Retrieves the parent object of the widget, requires to pass the type of the parent.
Definition kwidget.h:370
void connectKillFocus(QWidget *w, Class *object, void(Class::*method)())
Definition kwidget.h:507
Flag
Definition kwidget.h:96
@ VScroll
Display a vertical scrollbar.
@ HelpInfo
The widget can handle the F1 key.
@ NoFlags
Reset all flags.
@ HScroll
Display an horizontal scrollbar.
ScrollMask
Definition kwidget.h:140
@ Page
The nPage member contains the page size for a proportional scroll bar.
@ DisableNoScroll
Disables the scrollbar instead of removing it if unnecessary.
@ Range
The nMin and nMax members contain the minimum and maximum values for the scrolling range.
@ All
Combination of all flags, except DisableNoScroll.
virtual void OnMButtonUp(QMouseEvent *event)
Called when the user releases the middle mouse button.
Definition kwidget.h:224
~KWidgetBase()
Definition kwidget.h:293
The KWidget class is used to replace MFC CWnd.
Definition kwidget.h:283
#define KDWINUTILS_EXPORT
Definition kdwinutils_export.h:31
#define KDWINUTILS_BEGIN_NAMESPACE
Definition kdwinutils_global.h:27
#define KDWINUTILS_END_NAMESPACE
Definition kdwinutils_global.h:28
constexpr char InternalScrollAreaName[]
Definition kwidget.h:49
Struct used to retrieve or set the scroll bar parameters maintains.
Definition kwidget.h:158
int nMin
Definition kwidget.h:160
int nPos
Definition kwidget.h:163
int nMax
Definition kwidget.h:161
ScrollMasks fMask
Definition kwidget.h:159
int nTrackPos
Definition kwidget.h:164
unsigned int nPage
Definition kwidget.h:162