Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
misc: minor tweaks
Browse files Browse the repository at this point in the history
1. Finish the simple title bar of the QOpenGLWidget demo
2. Minor improvements of the Quick implementation

Signed-off-by: Yuhang Zhao <[email protected]>
  • Loading branch information
wangwenx190 committed Apr 22, 2022
1 parent 130d174 commit 3f17626
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 13 deletions.
6 changes: 3 additions & 3 deletions examples/openglwidget/images.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/">
<file>images/qtlogo.png</file>
</qresource>
<qresource prefix="/">
<file>images/qtlogo.png</file>
</qresource>
</RCC>
50 changes: 43 additions & 7 deletions examples/openglwidget/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
#include "mainwindow.h"
#include "glwidget.h"
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qlabel.h>
#include <QtWidgets/qpushbutton.h>

FRAMELESSHELPER_USE_NAMESPACE

using namespace Global;

MainWindow::MainWindow(QWidget *parent) : FramelessWidget(parent)
{
Expand All @@ -33,19 +39,49 @@ MainWindow::MainWindow(QWidget *parent) : FramelessWidget(parent)

MainWindow::~MainWindow() = default;

void MainWindow::updateMaximizeButton()
{
m_maxBtn->setText(isZoomed() ? tr("RESTORE") : tr("MAXIMIZE"));
}

void MainWindow::setupUi()
{
resize(800, 600);
setWindowTitle(tr("QOpenGLWidget demo"));
m_titleBar.reset(new QWidget(this));
m_titleBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_titleBar->setFixedHeight(30);
m_titleLabel.reset(new QLabel(this));
QFont f = font();
f.setPointSize(kDefaultTitleBarFontPointSize);
m_titleLabel->setFont(f);
connect(this, &MainWindow::windowTitleChanged, m_titleLabel.data(), &QLabel::setText);
m_minBtn.reset(new QPushButton(this));
m_minBtn->setText(tr("MINIMIZE"));
connect(m_minBtn.data(), &QPushButton::clicked, this, &MainWindow::showMinimized);
m_maxBtn.reset(new QPushButton(this));
updateMaximizeButton();
connect(m_maxBtn.data(), &QPushButton::clicked, this, &MainWindow::toggleMaximized);
connect(this, &MainWindow::zoomedChanged, this, &MainWindow::updateMaximizeButton);
m_closeBtn.reset(new QPushButton(this));
m_closeBtn->setText(tr("CLOSE"));
connect(m_closeBtn.data(), &QPushButton::clicked, this, &MainWindow::close);
m_titleBarWidget.reset(new QWidget(this));
m_titleBarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_titleBarWidget->setFixedHeight(kDefaultTitleBarHeight);
const auto titleBarLayout = new QHBoxLayout(m_titleBarWidget.data());
titleBarLayout->setSpacing(0);
titleBarLayout->setContentsMargins(0, 0, 0, 0);
titleBarLayout->addSpacerItem(new QSpacerItem(kDefaultTitleBarTitleLabelMargin, kDefaultTitleBarTitleLabelMargin));
titleBarLayout->addWidget(m_titleLabel.data());
titleBarLayout->addStretch();
titleBarLayout->addWidget(m_minBtn.data());
titleBarLayout->addWidget(m_maxBtn.data());
titleBarLayout->addWidget(m_closeBtn.data());
m_titleBarWidget->setLayout(titleBarLayout);
m_glWidget.reset(new GLWidget(this));
const auto mainLayout = new QVBoxLayout(this);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->addWidget(m_titleBar.data());
mainLayout->addWidget(m_titleBarWidget.data());
mainLayout->addWidget(m_glWidget.data());
setLayout(mainLayout);
setTitleBarWidget(m_titleBar.data());
setTitleBarWidget(m_titleBarWidget.data());
resize(800, 600);
setWindowTitle(tr("QOpenGLWidget demo"));
}
14 changes: 13 additions & 1 deletion examples/openglwidget/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

#include <framelesswidget.h>

QT_BEGIN_NAMESPACE
class QLabel;
class QPushButton;
QT_END_NAMESPACE

class GLWidget;

class MainWindow : public FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidget)
Expand All @@ -37,10 +42,17 @@ class MainWindow : public FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidget)
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;

public Q_SLOTS:
void updateMaximizeButton();

private:
void setupUi();

private:
QScopedPointer<QWidget> m_titleBar;
QScopedPointer<QLabel> m_titleLabel;
QScopedPointer<QPushButton> m_minBtn;
QScopedPointer<QPushButton> m_maxBtn;
QScopedPointer<QPushButton> m_closeBtn;
QScopedPointer<QWidget> m_titleBarWidget;
QScopedPointer<GLWidget> m_glWidget;
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <framelesshelpercore_global.h>
#if __has_include(<QtQml/qqmlregistration.h>)
#include <QtQml/qqmlregistration.h>
# include <QtQml/qqmlregistration.h>
#endif

#ifndef FRAMELESSHELPER_QUICK_API
Expand Down
19 changes: 18 additions & 1 deletion include/FramelessHelper/Quick/framelessquickhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#pragma once

#include "framelesshelperquick_global.h"
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
# include <QtQml/qqmlextensionplugin.h>
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))

QT_BEGIN_NAMESPACE
class QQmlEngine;
Expand All @@ -35,6 +38,20 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
namespace FramelessHelper::Quick
{
FRAMELESSHELPER_QUICK_API void registerTypes(QQmlEngine *engine);
}
} // namespace FramelessHelper::Quick

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
class FRAMELESSHELPER_QUICK_API FramelessHelperQuickPlugin : public QQmlEngineExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)

public:
explicit FramelessHelperQuickPlugin(QObject *parent = nullptr);
~FramelessHelperQuickPlugin() override;

void initializeEngine(QQmlEngine *engine, const char *uri) override;
};
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))

FRAMELESSHELPER_END_NAMESPACE
3 changes: 3 additions & 0 deletions src/quick/framelesshelperquick.qrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<RCC>
<qresource prefix="/org/wangwenx190/FramelessHelper">
<file alias="qmldir">module/qmldir</file>
</qresource>
<qresource prefix="/org.wangwenx190.FramelessHelper">
<file alias="images/dark/chrome-close.svg">../core/images/dark/chrome-close.svg</file>
<file alias="images/dark/chrome-maximize.svg">../core/images/dark/chrome-maximize.svg</file>
Expand Down
22 changes: 22 additions & 0 deletions src/quick/framelessquickhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,26 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine)
qmlRegisterModule(QUICK_URI_FULL);
}

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
FramelessHelperQuickPlugin::FramelessHelperQuickPlugin(QObject *parent) : QQmlEngineExtensionPlugin(parent)
{
}

FramelessHelperQuickPlugin::~FramelessHelperQuickPlugin() = default;

void FramelessHelperQuickPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
Q_ASSERT(engine);
Q_ASSERT(uri);
if (!engine || !uri) {
return;
}
Q_ASSERT(QLatin1String(uri) == QLatin1String(FRAMELESSHELPER_QUICK_URI));
if (QLatin1String(uri) != QLatin1String(FRAMELESSHELPER_QUICK_URI)) {
return;
}
FramelessHelper::Quick::registerTypes(engine);
}
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))

FRAMELESSHELPER_END_NAMESPACE
6 changes: 6 additions & 0 deletions src/quick/module/qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module org.wangwenx190.FramelessHelper
linktarget FramelessHelperQuick
plugin FramelessHelperQuick
classname FramelessHelperQuickPlugin
typeinfo FramelessHelperQuick.qmltypes
prefer :/org/wangwenx190/FramelessHelper/

0 comments on commit 3f17626

Please sign in to comment.