1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-02-06 21:48:24 +08:00

update frameless; update wizard

This commit is contained in:
jared 2020-10-28 12:59:25 +08:00
parent c80f79a909
commit a79d044e03
6 changed files with 33 additions and 13 deletions

View File

@ -58,8 +58,7 @@ static bool isFullWin(QQuickView *win)
TaoFrameLessView::TaoFrameLessView(QWindow *parent) : QQuickView(parent) TaoFrameLessView::TaoFrameLessView(QWindow *parent) : QQuickView(parent)
{ {
setFlags(/*Qt::CustomizeWindowHint | */ Qt::Window | Qt::FramelessWindowHint setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
| Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
setResizeMode(SizeRootObjectToView); setResizeMode(SizeRootObjectToView);
// WS_THICKFRAME 带回Areo效果 // WS_THICKFRAME 带回Areo效果
@ -79,13 +78,33 @@ void TaoFrameLessView::setTitleItem(QQuickItem *item)
{ {
m_titleItem = item; m_titleItem = item;
} }
QRect TaoFrameLessView::calcCenterGeo(const QRect &screenGeo, const QSize &normalSize)
{
int w = normalSize.width();
int h = normalSize.height();
int x = screenGeo.x() + (screenGeo.width() - w) / 2;
int y = screenGeo.y() + (screenGeo.height() - h) / 2;
if (screenGeo.width() < w)
{
x = screenGeo.x();
w = screenGeo.width();
}
if (screenGeo.height() < h)
{
y = screenGeo.y();
h = screenGeo.height();
}
return { x, y, w, h };
}
void TaoFrameLessView::moveToScreenCenter() void TaoFrameLessView::moveToScreenCenter()
{ {
auto geo = screen()->availableGeometry(); auto geo = calcCenterGeo(screen()->availableGeometry(), size());
int w = width(); if (minimumWidth() > geo.width() || minimumHeight() > geo.height())
int h = height(); {
auto pos = QPoint { geo.x() + (geo.width() - w) / 2, geo.y() + (geo.height() - h) / 2 }; setMinimumSize(geo.size());
setPosition(pos.x(), pos.y()); }
setGeometry(geo);
update(); update();
} }

View File

@ -13,6 +13,8 @@ public:
void moveToScreenCenter(); void moveToScreenCenter();
bool isMax() const { return m_isMax; } bool isMax() const { return m_isMax; }
QQuickItem *titleItem() const { return m_titleItem; } QQuickItem *titleItem() const { return m_titleItem; }
static QRect calcCenterGeo(const QRect &screenGeo, const QSize &normalSize);
public slots: public slots:
void setIsMax(bool isMax); void setIsMax(bool isMax);
void setTitleItem(QQuickItem *item); void setTitleItem(QQuickItem *item);

View File

@ -6,8 +6,8 @@
#include <QLocale> #include <QLocale>
#include <QQuickView> #include <QQuickView>
#include <QQmlEngine> #include <QQmlEngine>
const static auto cEnglisthStr = QStringLiteral("English"); const static auto cEnglisthStr = u8"English";
const static auto cChineseStr = QStringLiteral("简体中文"); const static auto cChineseStr = u8"简体中文";
Trans::Trans(QObject *parent) : QTranslator(parent) {} Trans::Trans(QObject *parent) : QTranslator(parent) {}
void Trans::beforeUiReady(QQmlContext *ctx) void Trans::beforeUiReady(QQmlContext *ctx)

View File

@ -18,7 +18,6 @@ Item {
pRoot = pRoot.parent pRoot = pRoot.parent
} }
wizardComp.createObject(pRoot) wizardComp.createObject(pRoot)
// wizardComp.createObject(pRoot, {x: pRoot.x, y: pRoot.y, width: pRoot.width, height: pRoot.height})
} }
Component { Component {
id: wizardComp id: wizardComp
@ -31,13 +30,11 @@ Item {
destroy(wizard) destroy(wizard)
} }
CusWizardPage { CusWizardPage {
z: 1
visible: wizard.currentIndex === 0 visible: wizard.currentIndex === 0
wizardText: qsTr("titleRect can control window") wizardText: qsTr("titleRect can control window")
focusRect: Qt.rect(0,0, wizard.parent.width, 80) focusRect: Qt.rect(0,0, wizard.parent.width, 80)
} }
CusWizardPage { CusWizardPage {
z: 1
visible: wizard.currentIndex === 1 visible: wizard.currentIndex === 1
wizardText: qsTr("middle rect for control") wizardText: qsTr("middle rect for control")
focusRect: Qt.rect(200,200, 200, 200) focusRect: Qt.rect(200,200, 200, 200)

View File

@ -32,6 +32,7 @@ int main(int argc, char **argv)
TaoFrameLessView view; TaoFrameLessView view;
view.setMinimumSize({ 800, 600 }); view.setMinimumSize({ 800, 600 });
view.resize(1440, 960); view.resize(1440, 960);
view.moveToScreenCenter();
Trans trans; Trans trans;
AppInfo appInfo; AppInfo appInfo;
trans.beforeUiReady(view.rootContext()); trans.beforeUiReady(view.rootContext());

View File

@ -6,6 +6,7 @@ import "../.."
Item { Item {
id: pageItem id: pageItem
z: 1
anchors.fill: parent anchors.fill: parent
property rect focusRect property rect focusRect
property string wizardText property string wizardText
@ -24,7 +25,7 @@ Item {
GradientStop { position: 0.0; color: "transparent" } GradientStop { position: 0.0; color: "transparent" }
GradientStop { position: 0.8; color: maskColor } GradientStop { position: 0.8; color: maskColor }
} }
opacity: maskOpacity opacity: maskOpacity / 2
} }
} }
Row { Row {