Skip to content

Commit

Permalink
feat: follow parent/toplevelWidget flags
Browse files Browse the repository at this point in the history
Change-Id: If8482d21009f844c76ab9c9019990bbec42d07cc
  • Loading branch information
Iceyer committed Feb 2, 2018
1 parent 6c2d397 commit d1f7bad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
21 changes: 21 additions & 0 deletions examples/dwidget-examples/collections/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ DWIDGET_USE_NAMESPACE
MainWindow::MainWindow(QWidget *parent)
: DMainWindow(parent)
{
auto flags = windowFlags() & ~Qt::WindowMaximizeButtonHint;
flags = flags & ~Qt::WindowMinimizeButtonHint;
setWindowFlags(flags);

DThemeManager *themeManager = DThemeManager::instance();

initTabWidget();
Expand All @@ -66,6 +70,7 @@ MainWindow::MainWindow(QWidget *parent)
QPushButton *lightBUtton = new QPushButton("Light", this);
QPushButton *enableButtons = new QPushButton("Enable Titlebar ", this);
QPushButton *disableButtons = new QPushButton("Disable Titlebar", this);
QPushButton *toggleMinMaxButtons = new QPushButton("Toggle MinMax", this);
QPushButton *fullscreenButtons = new QPushButton("Fullscreen", this);

themeManager->setTheme(lightBUtton, "light");
Expand Down Expand Up @@ -95,10 +100,26 @@ MainWindow::MainWindow(QWidget *parent)
}
});

connect(toggleMinMaxButtons, &QPushButton::clicked, [ = ] {
auto flags = windowFlags();
if (flags.testFlag(Qt::WindowMinimizeButtonHint))
{
flags &= ~Qt::WindowMaximizeButtonHint;
flags &= ~Qt::WindowMinimizeButtonHint;
} else
{
flags |= Qt::WindowMaximizeButtonHint;
flags |= Qt::WindowMinimizeButtonHint;
}
setWindowFlags(flags);
show();
});

styleLayout->addWidget(darkButton);
styleLayout->addWidget(lightBUtton);
styleLayout->addWidget(enableButtons);
styleLayout->addWidget(disableButtons);
styleLayout->addWidget(toggleMinMaxButtons);
styleLayout->addWidget(fullscreenButtons);
styleLayout->addStretch();

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dbuttonlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ IconButton* DButtonList::getButtonByIndex(int index){

void DButtonList::clear(){
Q_FOREACH (QAbstractButton* button, m_buttonGroup->buttons()) {
qDebug() << static_cast<IconButton*>(button)->text();
// qDebug() << static_cast<IconButton*>(button)->text();
static_cast<IconButton*>(button)->disconnect();
m_buttonGroup->removeButton(static_cast<IconButton*>(button));
}
Expand Down
30 changes: 13 additions & 17 deletions src/widgets/dtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class DTitlebarPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate

Qt::WindowFlags disableFlags;
bool mousePressed = false;
bool useWindowFlags = false;
bool embedMode = false;
bool autoHideOnFullscreen = false;

Expand Down Expand Up @@ -267,17 +266,21 @@ void DTitlebarPrivate::updateFullscreen()

void DTitlebarPrivate::updateButtonsState(Qt::WindowFlags type)
{
D_Q(DTitlebar);

bool isFullscreen = q->topLevelWidget()->windowState().testFlag(Qt::WindowFullScreen);

if (titleLabel) {
titleLabel->setVisible((type & Qt::WindowTitleHint) && !embedMode);
}
if (iconLabel) {
iconLabel->setVisible((type & Qt::WindowTitleHint) && !embedMode);
}

minButton->setVisible((type & Qt::WindowMinimizeButtonHint) && !embedMode);
maxButton->setVisible((type & Qt::WindowMaximizeButtonHint) && !embedMode);
closeButton->setVisible((type & Qt::WindowCloseButtonHint) && !embedMode);
optionButton->setVisible(type & Qt::WindowSystemMenuHint);
minButton->setVisible((type & Qt::WindowMinimizeButtonHint) && !embedMode && !isFullscreen);
maxButton->setVisible(type.testFlag(Qt::WindowMaximizeButtonHint) && !embedMode && !isFullscreen);
closeButton->setVisible((type & Qt::WindowCloseButtonHint) && !embedMode && !isFullscreen);
optionButton->setVisible(type & Qt::WindowSystemMenuHint && !isFullscreen);
buttonArea->adjustSize();
buttonArea->resize(buttonArea->size());

Expand Down Expand Up @@ -348,10 +351,6 @@ void DTitlebarPrivate::_q_onTopWindowMotifHintsChanged(quint32 winId)
{
D_QC(DTitlebar);

if (useWindowFlags) {
return;
}

if (!DPlatformWindowHandle::isEnabledDXcb(q->window())) {
q->disconnect(DWindowManagerHelper::instance(), SIGNAL(windowMotifWMHintsChanged(quint32)),
q, SLOT(_q_onTopWindowMotifHintsChanged(quint32)));
Expand All @@ -373,11 +372,7 @@ void DTitlebarPrivate::_q_onTopWindowMotifHintsChanged(quint32 winId)
iconLabel->setVisible(decorations_hints.testFlag(DWindowManagerHelper::DECOR_TITLE));
}

minButton->setVisible(decorations_hints.testFlag(DWindowManagerHelper::DECOR_MINIMIZE) && !embedMode);
maxButton->setVisible(decorations_hints.testFlag(DWindowManagerHelper::DECOR_MAXIMIZE) && !embedMode);
optionButton->setVisible(decorations_hints.testFlag(DWindowManagerHelper::DECOR_MENU));
buttonArea->adjustSize();
buttonArea->resize(buttonArea->size());
// updateButtonsState(q->topLevelWidget()->windowFlags());

// minButton->setEnabled(functions_hints.testFlag(DWindowManagerHelper::FUNC_MINIMIZE) && !embedMode);
// maxButton->setEnabled(functions_hints.testFlag(DWindowManagerHelper::FUNC_MAXIMIZE) && !embedMode);
Expand Down Expand Up @@ -538,9 +533,7 @@ QWidget *DTitlebar::customWidget() const
/// and WindowMinMaxButtonsHint.
void DTitlebar::setWindowFlags(Qt::WindowFlags type)
{
D_D(DTitlebar);
d->useWindowFlags = true;
d->updateButtonsState(type);
topLevelWidget()->setWindowFlags(type);
}

#ifndef QT_NO_MENU
Expand Down Expand Up @@ -607,12 +600,15 @@ bool DTitlebar::eventFilter(QObject *obj, QEvent *event)
if (obj == d->parentWindow) {
switch (event->type()) {
case QEvent::WindowStateChange: {
// TODO: should parentWindow and topLevelWidget merge ???
d->maxButton->setMaximized(d->parentWindow->windowState() == Qt::WindowMaximized);
d->updateFullscreen();
d->updateButtonsState(topLevelWidget()->windowFlags());
break;
}
case QEvent::ShowToParent:
d->updateButtonsFunc();
d->updateButtonsState(topLevelWidget()->windowFlags());
break;
case QEvent::Resize:
if (d->autoHideOnFullscreen) {
Expand Down

0 comments on commit d1f7bad

Please sign in to comment.