* Add `clearFocus()` to `QWidget` * Add `Alignment` param to `QBoxLayout.addWidget()` * Add `setViewportMargins()` & `viewportMargins()` to `QScrollArea` * Add `QEvent` methods to all event related subclasses * Tell C++ that our 0 is zero and not a null pointer
103 lines
3.3 KiB
TypeScript
103 lines
3.3 KiB
TypeScript
import addon from '../utils/addon';
|
|
import { NodeWidget } from './QWidget';
|
|
import { NativeElement } from '../core/Component';
|
|
import { QAbstractScrollArea, QAbstractScrollAreaSignals } from './QAbstractScrollArea';
|
|
import { AlignmentFlag } from '../QtEnums';
|
|
import { Margins } from '../utils/Margins';
|
|
|
|
/**
|
|
|
|
> A `QScrollArea` provides a scrolling view onto another widget.
|
|
|
|
* **This class is a JS wrapper around Qt's [QScrollArea class](https://doc.qt.io/qt-5/qscrollarea.html)**
|
|
|
|
### Example
|
|
|
|
```javascript
|
|
const { QScrollArea } = require("@nodegui/nodegui");
|
|
|
|
const scrollArea = new QScrollArea();
|
|
scrollArea.setInlineStyle("flex: 1; width:'100%';");
|
|
|
|
const imageLabel = new QLabel();
|
|
const pixmap = new QPixmap(
|
|
path.resolve(__dirname, "../extras/assets/kitchen.png")
|
|
);
|
|
imageLabel.setPixmap(pixmap);
|
|
|
|
scrollArea.setWidget(imageLabel);
|
|
```
|
|
*/
|
|
export class QScrollArea extends QAbstractScrollArea<QScrollAreaSignals> {
|
|
native: NativeElement;
|
|
contentWidget?: NodeWidget<any> | null;
|
|
constructor();
|
|
constructor(parent: NodeWidget<any>);
|
|
constructor(parent?: NodeWidget<any>) {
|
|
let native;
|
|
if (parent) {
|
|
native = new addon.QScrollArea(parent.native);
|
|
} else {
|
|
native = new addon.QScrollArea();
|
|
}
|
|
super(native);
|
|
this.native = native;
|
|
this.setNodeParent(parent);
|
|
}
|
|
setAlignment(alignment: AlignmentFlag): void {
|
|
this.setProperty('alignment', alignment);
|
|
}
|
|
alignment(): AlignmentFlag {
|
|
return this.property('alignment').toInt();
|
|
}
|
|
setWidgetResizable(resizable: boolean): void {
|
|
this.setProperty('widgetResizable', resizable);
|
|
}
|
|
widgetResizable(): boolean {
|
|
return this.property('widgetResizable').toBool();
|
|
}
|
|
ensureVisible(x: number, y: number, xmargin = 50, ymargin = 50): void {
|
|
this.native.ensureVisible(x, y, xmargin, ymargin);
|
|
}
|
|
ensureWidgetVisible(childWidget: NodeWidget<any>, xmargin = 50, ymargin = 50): void {
|
|
this.native.ensureWidgetVisible(childWidget.native, xmargin, ymargin);
|
|
}
|
|
setWidget(widget: NodeWidget<any>): void {
|
|
this.contentWidget = widget;
|
|
this.native.setWidget(widget.native);
|
|
}
|
|
widget(): NodeWidget<any> | null {
|
|
if (this.contentWidget) {
|
|
return this.contentWidget;
|
|
}
|
|
return null;
|
|
}
|
|
takeWidget(): NodeWidget<any> | null {
|
|
// react:✓
|
|
const contentWidget = this.contentWidget;
|
|
this.contentWidget = null;
|
|
if (contentWidget) {
|
|
this.native.takeWidget();
|
|
return contentWidget;
|
|
}
|
|
return null;
|
|
}
|
|
setViewportMargins(left: number, top: number, right: number, bottom: number): void {
|
|
// Technically part of QAbstractScrollArea, but the C++ side has subclass specific
|
|
// code needed, and setViewportMargins() isn't implemented yet for all of the
|
|
// subclasses.
|
|
this.native.setViewportMargins(left, top, right, bottom);
|
|
}
|
|
viewportMargins(): Margins {
|
|
const marginsArray = this.native.viewportMargins();
|
|
return {
|
|
left: marginsArray[0],
|
|
top: marginsArray[1],
|
|
right: marginsArray[2],
|
|
bottom: marginsArray[3],
|
|
};
|
|
}
|
|
}
|
|
|
|
export type QScrollAreaSignals = QAbstractScrollAreaSignals;
|