Move QColor from QtCore to QtGui (#311)
* Change QColor from QtCore to QtGui * lint
This commit is contained in:
parent
609e243866
commit
9fada0e168
@ -36,6 +36,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/deps/yoga/event/event.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/deps/yoga/internal/experiments.cpp"
|
||||
# wrapped cpps
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QColor/qcolor_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QClipboard/qclipboard_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp"
|
||||
@ -53,7 +54,6 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QSize/qsize_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QRect/qrect_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QPoint/qpoint_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QColor/qcolor_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QUrl/qurl_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QWidget/qwidget_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#include "QtCore/QColor/qcolor_wrap.h"
|
||||
#include "QtGui/QColor/qcolor_wrap.h"
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtCore/QVariant/qvariant_wrap.h"
|
||||
@ -1,8 +1,8 @@
|
||||
#include "QtWidgets/QPainter/qpainter_wrap.h"
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtCore/QColor/qcolor_wrap.h"
|
||||
#include "QtCore/QPoint/qpoint_wrap.h"
|
||||
#include "QtGui/QColor/qcolor_wrap.h"
|
||||
#include "QtWidgets/QWidget/qwidget_wrap.h"
|
||||
#include "core/Component/component_wrap.h"
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include <napi.h>
|
||||
|
||||
#include "QtCore/QColor/qcolor_wrap.h"
|
||||
#include "QtCore/QObject/qobject_wrap.h"
|
||||
#include "QtCore/QPoint/qpoint_wrap.h"
|
||||
#include "QtCore/QRect/qrect_wrap.h"
|
||||
@ -9,6 +8,7 @@
|
||||
#include "QtCore/QVariant/qvariant_wrap.h"
|
||||
#include "QtGui/QApplication/qapplication_wrap.h"
|
||||
#include "QtGui/QClipboard/qclipboard_wrap.h"
|
||||
#include "QtGui/QColor/qcolor_wrap.h"
|
||||
#include "QtGui/QCursor/qcursor_wrap.h"
|
||||
#include "QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h"
|
||||
#include "QtGui/QEvent/QMouseEvent/qmouseevent_wrap.h"
|
||||
|
||||
105
src/demo.ts
105
src/demo.ts
@ -1,56 +1,87 @@
|
||||
import { FlexLayout, QMainWindow, QWidget } from './index';
|
||||
import { QLabel } from './lib/QtWidgets/QLabel';
|
||||
import { QSystemTrayIcon } from './lib/QtWidgets/QSystemTrayIcon';
|
||||
import { QMenu } from './lib/QtWidgets/QMenu';
|
||||
import { QAction } from './lib/QtWidgets/QAction';
|
||||
import { QFont, QFontWeight, QFontCapitalization, QFontStretch } from './lib/QtGui/QFont';
|
||||
import {
|
||||
FlexLayout,
|
||||
PenStyle,
|
||||
WidgetEventTypes,
|
||||
QColor,
|
||||
QMainWindow,
|
||||
QPainter,
|
||||
QPoint,
|
||||
QWidget,
|
||||
RenderHint,
|
||||
} from './index';
|
||||
|
||||
const win = new QMainWindow();
|
||||
const center = new QWidget();
|
||||
const layout = new FlexLayout();
|
||||
const hourHand = [new QPoint(7, 8), new QPoint(-7, 8), new QPoint(0, -40)];
|
||||
const minuteHand = [new QPoint(7, 8), new QPoint(-7, 8), new QPoint(0, -70)];
|
||||
const secondHand = [new QPoint(4, 8), new QPoint(-4, 8), new QPoint(0, -70)];
|
||||
const hourColor = new QColor(127, 0, 127);
|
||||
const minuteColor = new QColor(0, 127, 127, 191);
|
||||
const secondColor = new QColor(0, 0, 0);
|
||||
|
||||
const label = new QLabel();
|
||||
const tray = new QSystemTrayIcon();
|
||||
const menu = new QMenu();
|
||||
const action = new QAction();
|
||||
center.setLayout(layout);
|
||||
win.setWindowTitle('Analog Clock');
|
||||
|
||||
const font = new QFont('serif', 40, QFontWeight.ExtraLight, true);
|
||||
font.setCapitalization(QFontCapitalization.AllUppercase);
|
||||
font.setStretch(QFontStretch.UltraCondensed);
|
||||
const side = Math.min(win.geometry().width(), win.geometry().height());
|
||||
|
||||
const family = font.family();
|
||||
const pointSize = font.pointSize();
|
||||
const weight = font.weight();
|
||||
const italic = font.italic();
|
||||
const capitalization = font.capitalization();
|
||||
const stretch = font.stretch();
|
||||
console.log({ family, pointSize, weight, italic, capitalization, stretch });
|
||||
function repaint(): void {
|
||||
win.repaint();
|
||||
setTimeout(repaint, 1000);
|
||||
}
|
||||
|
||||
action.setText('action1');
|
||||
action.setFont(font);
|
||||
menu.addAction(action);
|
||||
setTimeout(repaint, 1000);
|
||||
win.addEventListener(WidgetEventTypes.Paint, () => {
|
||||
const time = new Date();
|
||||
|
||||
const font2 = new QFont(font);
|
||||
font2.setFamily('mono');
|
||||
font2.setCapitalization(QFontCapitalization.Capitalize);
|
||||
font2.setStretch(QFontStretch.ExtraExpanded);
|
||||
font2.setPointSize(20);
|
||||
const painter = new QPainter(win);
|
||||
painter.setRenderHint(RenderHint.Antialiasing);
|
||||
painter.translate(win.geometry().width() / 2, win.geometry().height() / 2);
|
||||
painter.scale(side / 200.0, side / 200.0);
|
||||
|
||||
const action2 = new QAction();
|
||||
action2.setText('action2');
|
||||
action2.setFont(font2);
|
||||
menu.addAction(action2);
|
||||
painter.setPen(PenStyle.NoPen);
|
||||
painter.setBrush(hourColor);
|
||||
|
||||
tray.setContextMenu(menu);
|
||||
painter.save();
|
||||
painter.rotate(30.0 * (time.getHours() + time.getMinutes() / 60.0));
|
||||
painter.drawConvexPolygon(hourHand);
|
||||
painter.restore();
|
||||
|
||||
tray.show();
|
||||
painter.setPen(hourColor);
|
||||
|
||||
label.setText('Hello!');
|
||||
layout.addWidget(label);
|
||||
for (let i = 0; i < 12; ++i) {
|
||||
painter.drawLine(88, 0, 96, 0);
|
||||
painter.rotate(30.0);
|
||||
}
|
||||
|
||||
painter.setPen(PenStyle.NoPen);
|
||||
painter.setBrush(minuteColor);
|
||||
|
||||
painter.save();
|
||||
painter.rotate(6.0 * (time.getMinutes() + time.getSeconds() / 60.0));
|
||||
painter.drawConvexPolygon(minuteHand);
|
||||
painter.restore();
|
||||
|
||||
painter.setBrush(secondColor);
|
||||
painter.setPen(PenStyle.NoPen);
|
||||
|
||||
painter.save();
|
||||
painter.rotate(360 * (time.getSeconds() / 60.0));
|
||||
painter.drawConvexPolygon(secondHand);
|
||||
painter.restore();
|
||||
|
||||
painter.setPen(minuteColor);
|
||||
for (let j = 0; j < 60; ++j) {
|
||||
if (j % 5 != 0) {
|
||||
painter.drawLine(92, 0, 96, 0);
|
||||
}
|
||||
painter.rotate(6.0);
|
||||
}
|
||||
painter.end();
|
||||
});
|
||||
|
||||
win.setCentralWidget(center);
|
||||
win.resize(400, 400);
|
||||
|
||||
win.show();
|
||||
(global as any).win = win;
|
||||
(global as any).tray = tray;
|
||||
|
||||
@ -63,7 +63,7 @@ export { QVariant } from './lib/QtCore/QVariant';
|
||||
export { QSize } from './lib/QtCore/QSize';
|
||||
export { QRect } from './lib/QtCore/QRect';
|
||||
export { QPoint } from './lib/QtCore/QPoint';
|
||||
export { QColor } from './lib/QtCore/QColor';
|
||||
export { QColor } from './lib/QtGui/QColor';
|
||||
export { QUrl, ParsingMode } from './lib/QtCore/QUrl';
|
||||
// Layouts:
|
||||
export { QBoxLayout, QBoxLayoutSignals } from './lib/QtWidgets/QBoxLayout';
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Component, NativeElement } from '../core/Component';
|
||||
import addon from '../utils/addon';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { QVariant } from './QVariant';
|
||||
import { QVariant } from '../QtCore/QVariant';
|
||||
import { GlobalColor } from '../QtEnums';
|
||||
|
||||
export class QColor extends Component {
|
||||
@ -1,6 +1,6 @@
|
||||
import { QColor } from '../QColor';
|
||||
import { GlobalColor } from '../../QtEnums';
|
||||
import { QVariant } from '../QVariant';
|
||||
import { QVariant } from '../../QtCore/QVariant';
|
||||
|
||||
describe('QColor', () => {
|
||||
it('initialize empty', () => {
|
||||
@ -1,7 +1,7 @@
|
||||
import addon from '../utils/addon';
|
||||
import { Component, NativeElement } from '../core/Component';
|
||||
import { PenStyle } from '../QtEnums';
|
||||
import { QColor } from '../QtCore/QColor';
|
||||
import { QColor } from '../QtGui/QColor';
|
||||
import { QPoint } from '../QtCore/QPoint';
|
||||
|
||||
export enum RenderHint {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user