forked from github_mirror/framelesshelper
misc: minor tweaks
1. Finish the simple title bar of the QOpenGLWidget demo 2. Minor improvements of the Quick implementation Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
130d174dc2
commit
3f17626c64
|
@ -1,5 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>images/qtlogo.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/">
|
||||
<file>images/qtlogo.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
@ -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"));
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
@ -37,10 +42,17 @@ public:
|
|||
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;
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
module org.wangwenx190.FramelessHelper
|
||||
linktarget FramelessHelperQuick
|
||||
plugin FramelessHelperQuick
|
||||
classname FramelessHelperQuickPlugin
|
||||
typeinfo FramelessHelperQuick.qmltypes
|
||||
prefer :/org/wangwenx190/FramelessHelper/
|
Loading…
Reference in New Issue