nodeguy/src/lib/QtGui/QIcon.ts
Atul R 01a6476f9c
Separate events and signals (#287)
* Wip

* Improve constructor typings

* Fixes types for Gui and Core

* QtGui

* Remove unnecessary imports and fix types on abstract classes

* Adds half of qwidgets

* Add all widgets

* cleans up

* fix failing test

* lint fix

* fix demo
2019-12-20 18:33:05 +05:30

58 lines
1.7 KiB
TypeScript

import addon from '../utils/addon';
import { Component, NativeElement } from '../core/Component';
import { QPixmap } from './QPixmap';
import { QVariant } from '../QtCore/QVariant';
import { checkIfNativeElement } from '../utils/helpers';
export enum QIconMode {
Normal,
Disabled,
Active,
Selected,
}
export enum QIconState {
Off,
On,
}
export class QIcon extends Component {
native: NativeElement;
constructor();
constructor(native: NativeElement);
constructor(filePath: string);
constructor(arg?: string | NativeElement) {
super();
if (typeof arg === 'string') {
const imagePath = arg;
this.native = new addon.QIcon(imagePath);
} else if (checkIfNativeElement(arg)) {
this.native = arg as NativeElement;
} else {
this.native = new addon.QIcon();
}
}
pixmap(width: number, height: number, mode?: QIconMode, state?: QIconState): QPixmap {
let nativePixmap;
if (mode && state) {
nativePixmap = this.native.pixmap(width, height, mode, state);
} else if (mode) {
nativePixmap = this.native.pixmap(width, height, mode);
} else {
nativePixmap = this.native.pixmap(width, height);
}
return new QPixmap(nativePixmap);
}
isMask(): boolean {
return this.native.isMask();
}
setIsMask(isMask: boolean): void {
this.native.setIsMask(isMask);
}
cacheKey(): number {
return this.native.cacheKey();
}
static fromQVariant(variant: QVariant): QIcon {
return new QIcon(addon.QIcon.fromQVariant(variant.native));
}
}